📄 corba.c
字号:
break; default: i_whence |= INPUT_SEEK_SET; break; } l_offset_destination = a_position->value; /* msg_Warn (servant->p_intf, "Offset destination : %d", l_offset_destination); */ /* Now we can set the position. The lock is taken in the input_Seek function (cf input_ext-intf.c) */ input_Seek (p_input, l_offset_destination, i_whence); return;}/* Starts playing a stream */static voidimpl_VLC_MediaControl_start(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev){ intf_thread_t * p_intf = servant->p_intf; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); msg_Warn (servant->p_intf, "Calling MediaControl::start"); if( p_playlist == NULL ) { /* FIXME: we should raise an appropriate exception, but we must define it in the IDL first */ msg_Err (servant->p_intf, "no playlist available"); return; } vlc_mutex_lock( &p_playlist->object_lock ); if( p_playlist->i_size ) { vlc_mutex_unlock( &p_playlist->object_lock ); playlist_Play( p_playlist ); vlc_object_release( p_playlist ); } else { vlc_mutex_unlock( &p_playlist->object_lock ); vlc_object_release( p_playlist ); msg_Err (servant->p_intf, "playlist empty"); } return;}static voidimpl_VLC_MediaControl_pause(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev){ input_thread_t *p_input = servant->p_intf->p_sys->p_input; msg_Warn (servant->p_intf, "calling MediaControl::pause"); if( p_input != NULL ) { input_SetStatus( p_input, INPUT_STATUS_PAUSE ); } return;}static voidimpl_VLC_MediaControl_resume(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev){ input_thread_t *p_input = servant->p_intf->p_sys->p_input; msg_Warn (servant->p_intf, "calling MediaControl::resume"); if( p_input != NULL ) { input_SetStatus( p_input, INPUT_STATUS_PAUSE ); } return;}static voidimpl_VLC_MediaControl_stop(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev){ intf_thread_t * p_intf = servant->p_intf; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); msg_Warn (servant->p_intf, "calling MediaControl::stop"); if( p_playlist != NULL ) { playlist_Stop( p_playlist ); vlc_object_release( p_playlist ); } return;}static voidimpl_VLC_MediaControl_exit(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev){ msg_Warn (servant->p_intf, "calling MediaControl::exit"); vlc_mutex_lock( &servant->p_intf->change_lock ); servant->p_intf->b_die = TRUE; vlc_mutex_unlock( &servant->p_intf->change_lock );}static voidimpl_VLC_MediaControl_add_to_playlist(impl_POA_VLC_MediaControl * servant, const CORBA_char * psz_file, CORBA_Environment * ev){ intf_thread_t * p_intf = servant->p_intf; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); msg_Warn (servant->p_intf, "calling MediaControl::add_to_playlist %s", psz_file); if ( p_playlist == NULL ) { msg_Err (servant->p_intf, "no playlist defined"); /* FIXME: should return an exception */ return; } playlist_Add (p_playlist, psz_file, psz_file , PLAYLIST_REPLACE, 0); vlc_object_release( p_playlist ); return;}static VLC_PlaylistSeq *impl_VLC_MediaControl_get_playlist(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev){ VLC_PlaylistSeq *retval; int i_index; intf_thread_t * p_intf = servant->p_intf; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); int i_playlist_size; msg_Warn (servant->p_intf, "calling MediaControl::get_playlist"); vlc_mutex_lock( &p_playlist->object_lock ); i_playlist_size = p_playlist->i_size; retval = VLC_PlaylistSeq__alloc (); retval->_buffer = VLC_PlaylistSeq_allocbuf (i_playlist_size); retval->_length = i_playlist_size; for (i_index = 0 ; i_index < i_playlist_size ; i_index++) { retval->_buffer[i_index] = CORBA_string_dup (p_playlist->pp_items[i_index]->psz_name); } vlc_mutex_unlock( &p_playlist->object_lock ); vlc_object_release( p_playlist ); CORBA_sequence_set_release (retval, TRUE); return retval;}/* (Real) end of the CORBA code generated in Mediacontrol-skelimpl.c *//***************************************************************************** * Local prototypes. *****************************************************************************/static int Open ( vlc_object_t * );static void Close ( vlc_object_t * );static void Run ( intf_thread_t * );/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin(); set_description( _("Corba control module") ); set_capability( "interface", 10 ); set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * intf_Open: initialize and create stuff *****************************************************************************/static int Open( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t *)p_this; /* Allocate instance and initialize some members */ p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) { msg_Err( p_intf, "out of memory" ); return VLC_ENOMEM; } /* Initialize the fields of the p_intf struct */ p_intf->pf_run = Run; p_intf->p_sys->b_playing = VLC_FALSE; p_intf->p_sys->p_input = NULL; p_intf->p_sys->orb = NULL; p_intf->p_sys->mc = NULL; p_intf->p_sys->root_poa = NULL; p_intf->p_sys->root_poa_manager = NULL; p_intf->p_sys->corbaloop = NULL; return VLC_SUCCESS;}/***************************************************************************** * intf_Close: destroy interface *****************************************************************************/static void Close( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t *)p_this; CORBA_Environment* ev = NULL; ev = CORBA_exception__alloc (); CORBA_ORB_shutdown (p_intf->p_sys->orb, FALSE, ev); handle_exception_no_servant (p_intf, "erreur dans Close"); if( p_intf->p_sys->p_input ) { vlc_object_release( p_intf->p_sys->p_input ); } /* Destroy structure */ free( p_intf->p_sys );}/* Function called regularly to handle various tasks (mainly CORBA calls) */static gboolean Manage (gpointer p_interface){ intf_thread_t *p_intf = (intf_thread_t*)p_interface; CORBA_boolean b_work_pending; CORBA_Environment* ev; ev = CORBA_exception__alloc (); /* CORBA */ b_work_pending = CORBA_ORB_work_pending (p_intf->p_sys->orb, ev); if(ev->_major != CORBA_NO_EXCEPTION) { msg_Err (p_intf, "exception in the CORBA events check"); return FALSE; } vlc_mutex_lock( &p_intf->change_lock ); /* Update the input */ if( p_intf->p_sys->p_input == NULL ) { p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE ); } else if( p_intf->p_sys->p_input->b_dead ) { vlc_object_release( p_intf->p_sys->p_input ); p_intf->p_sys->p_input = NULL; } if( p_intf->p_sys->p_input ) { input_thread_t *p_input = p_intf->p_sys->p_input; vlc_mutex_lock( &p_input->stream.stream_lock ); if ( !p_input->b_die ) { /* New input or stream map change */ if( p_input->stream.b_changed ) { /* FIXME: We should notify our client that the input changed */ /* E_(GtkModeManage)( p_intf ); */ p_intf->p_sys->b_playing = 1; } } vlc_mutex_unlock( &p_input->stream.stream_lock ); } else if( p_intf->p_sys->b_playing && !p_intf->b_die ) { /* FIXME: We should notify our client that the input changed */ /* E_(GtkModeManage)( p_intf ); */ p_intf->p_sys->b_playing = 0; } /* CORBA calls handling. Beware: no lock is taken (since p_pinput can be null) */ if (b_work_pending) CORBA_ORB_perform_work (p_intf->p_sys->orb, ev); if( p_intf->b_die ) { vlc_mutex_unlock( &p_intf->change_lock ); g_main_loop_quit (p_intf->p_sys->corbaloop); /* Just in case */ return( FALSE ); } vlc_mutex_unlock( &p_intf->change_lock ); return TRUE;}/***************************************************************************** * Run: main loop ***************************************************************************** * this part of the interface is in a separate thread so that we can call * g_main_loop_run() from within it without annoying the rest of the program. *****************************************************************************/static void Run ( intf_thread_t *p_intf ){ CORBA_Environment* ev = NULL; guint i_event_source; CORBA_char* psz_objref; impl_POA_VLC_MediaControl *servant = NULL; int i_argc = 1; char* ppsz_argv[] = { "mc" }; msg_Warn (p_intf, "Entering Run"); ev = CORBA_exception__alloc (); /* To be able to use CORBA in a MT app */ linc_set_threaded (TRUE); p_intf->p_sys->orb = CORBA_ORB_init(&i_argc, ppsz_argv, "orbit-local-orb", ev); /* Should be cleaner this way (cf http://www.fifi.org/doc/gnome-dev-doc/html/C/orbitgtk.html) but it functions well enough in the ugly way so that I do not bother cleaning it */ /* p_intf->p_sys->orb = gnome_CORBA_init ("VLC", NULL, &argc, &argv, 0, NULL, ev); */ handle_exception_no_servant (p_intf, "exception during CORBA_ORB_init"); p_intf->p_sys->root_poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(p_intf->p_sys->orb, "RootPOA", ev); handle_exception ("exception during RootPOA initialization"); p_intf->p_sys->mc = impl_VLC_MediaControl__create(p_intf->p_sys->root_poa, ev); handle_exception ("exception during MediaControl initialization"); servant = (impl_POA_VLC_MediaControl*)PortableServer_POA_reference_to_servant(p_intf->p_sys->root_poa, p_intf->p_sys->mc, ev); handle_exception ("exception during MediaControl access"); servant->p_intf = p_intf; psz_objref = CORBA_ORB_object_to_string(p_intf->p_sys->orb, p_intf->p_sys->mc, ev); handle_exception ("exception during IOR generation"); msg_Warn (p_intf, "MediaControl IOR :"); msg_Warn (p_intf, psz_objref); /* We write the IOR in a file. */ { FILE* fp; fp = fopen (VLC_IOR_FILE, "w"); if (fp == NULL) { msg_Err (servant->p_intf, "cannot write the IOR to %s (%d).", VLC_IOR_FILE, errno); } else { fprintf (fp, "%s", psz_objref); fclose (fp); msg_Warn (servant->p_intf, "IOR written to %s", VLC_IOR_FILE); } } msg_Warn (p_intf, "get_the_POAManager (state %s)", p_intf->p_sys->root_poa); p_intf->p_sys->root_poa_manager = PortableServer_POA__get_the_POAManager(p_intf->p_sys->root_poa, ev); handle_exception ("exception during POAManager resolution"); msg_Warn (p_intf, "activating POAManager"); PortableServer_POAManager_activate(p_intf->p_sys->root_poa_manager, ev); handle_exception ("exception during POAManager activation"); msg_Info(p_intf, "corba remote control interface initialized" ); /* // Tentative de gestion du nommage... { CosNaming_NamingContext name_service; CosNaming_NameComponent name_component[3] = {{"GNOME", "subcontext"}, {"Servers", "subcontext"}, {"vlc", "server"} }; CosNaming_Name name = {3, 3, name_component, CORBA_FALSE}; name_service = CORBA_ORB_resolve_initial_references (p_intf->p_sys->orb, "NameService", ev); handle_exception ("could not get name service: %s\n", CORBA_exception_id(ev)); msg_Warn (p_intf, "Name service OK"); CosNaming_NamingContext_bind (name_service, &name, p_intf->p_sys->mc, ev); handle_exception ("could not register object: %s\n", CORBA_exception_id(ev)); } */ /* The time factor should be 1/1000 but it is a little too slow. Make it 1/10000 */ i_event_source = g_timeout_add (INTF_IDLE_SLEEP / 10000, Manage, p_intf); msg_Warn (p_intf, "entering mainloop"); p_intf->p_sys->corbaloop = g_main_loop_new (NULL, FALSE); g_main_loop_run (p_intf->p_sys->corbaloop); /* Cleaning */ g_source_remove( i_event_source ); unlink (VLC_IOR_FILE); msg_Warn (p_intf, "normal termination of VLC corba module"); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -