1 /*****************************************************************************
2 * corba.c : CORBA (ORBit) remote control plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 the VideoLAN team
7 * Authors: Olivier Aubert <oaubert@lisi.univ-lyon1.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include "MediaControl.h"
29 #include "orbit/poa/portableserver-poa-type.h"
32 #include <vlc/mediacontrol.h>
40 /* FIXME: replace this to ~/.vlc/vlc-ior.ref thanks to
41 config_GetHomeDir( ) */
43 #define VLC_IOR_FILE "/tmp/vlc-ior.ref"
45 #define VLC_IOR_FILE "vlc-ior-ref"
48 #define MC_TRY exception = mediacontrol_exception_init( exception )
49 #define MC_EXCEPT( return_value ) \
50 if ( exception->code )\
52 corba_raise( ev, exception ); \
53 mediacontrol_exception_free( exception ); \
54 return return_value; \
55 } else { mediacontrol_exception_free( exception ); }
57 #define handle_exception( m ) if( ev->_major != CORBA_NO_EXCEPTION ) \
59 msg_Err( servant->p_intf, m ); \
63 #define handle_exception_no_servant( p,m ) if( ev->_major != CORBA_NO_EXCEPTION ) \
69 static void corba_raise( CORBA_Environment *ev, mediacontrol_Exception *exception )
71 char *corba_exception=NULL;
74 switch( exception->code )
76 case mediacontrol_InternalException:
77 corba_exception = ( char* )VLC_InternalException__alloc();
78 i_type = ex_VLC_InternalException;
80 case mediacontrol_PlaylistException:
81 corba_exception = ( char* )VLC_PlaylistException__alloc();
82 i_type = ex_VLC_PlaylistException;
84 case mediacontrol_InvalidPosition:
85 corba_exception = ( char* )VLC_InvalidPosition__alloc();
86 i_type = ex_VLC_InvalidPosition;
88 case mediacontrol_PositionKeyNotSupported:
89 corba_exception = ( char* )VLC_PositionKeyNotSupported__alloc();
90 i_type = ex_VLC_PositionKeyNotSupported;
92 case mediacontrol_PositionOriginNotSupported:
93 corba_exception = ( char* )VLC_PositionOriginNotSupported__alloc();
94 i_type = ex_VLC_PositionOriginNotSupported;
97 ( (VLC_InternalException* )corba_exception )->message = CORBA_string_dup( exception->message );
98 CORBA_exception_set( ev, CORBA_USER_EXCEPTION, i_type, corba_exception );
102 static mediacontrol_Position* corba_position_corba_to_c( const VLC_Position* position )
104 mediacontrol_Position* retval;
106 retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
109 retval->origin = position->origin;
110 retval->key = position->key;
111 retval->value = position->value;
115 static VLC_Position* corba_position_c_to_corba( const mediacontrol_Position* position )
117 VLC_Position* retval;
119 retval = ( VLC_Position* )malloc( sizeof( VLC_Position ) );
122 retval->origin = position->origin;
123 retval->key = position->key;
124 retval->value = position->value;
128 /*****************************************************************************
129 * intf_sys_t: description and status of corba interface
130 *****************************************************************************/
134 GMainLoop* corbaloop;
135 mediacontrol_Instance *mc;
136 msg_subscription_t* p_sub; /* message bank subscription */
139 /*** App-specific servant structures ***/
141 /* We can add attributes to this structure, which is both a pointer on a
142 specific structure, and on a POA_VLC_MediaControl ( servant ). Cf
143 http://developer.gnome.org/doc/guides/corba/html/corba-poa-example.html */
147 POA_VLC_MediaControl servant;
148 PortableServer_POA poa;
149 /* Ajouter ici les attributs utiles */
150 mediacontrol_Instance *mc;
151 intf_thread_t *p_intf;
152 } impl_POA_VLC_MediaControl;
154 /* Beginning of the CORBA code generated in Mediacontrol-skelimpl.c */
156 /*** Implementation stub prototypes ***/
158 static void impl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl *
159 servant, CORBA_Environment * ev );
162 impl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant,
163 const VLC_PositionOrigin an_origin,
164 const VLC_PositionKey a_key,
165 CORBA_Environment * ev );
168 impl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant,
169 const VLC_Position * a_position,
170 CORBA_Environment * ev );
173 impl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant,
174 const VLC_Position * a_position,
175 CORBA_Environment * ev );
178 impl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant,
179 const VLC_Position * a_position,
180 CORBA_Environment * ev );
183 impl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant,
184 const VLC_Position * a_position,
185 CORBA_Environment * ev );
188 impl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant,
189 const VLC_Position * a_position,
190 CORBA_Environment * ev );
193 impl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant,
194 CORBA_Environment * ev );
197 impl_VLC_MediaControl_playlist_add_item( impl_POA_VLC_MediaControl * servant,
198 const CORBA_char * a_file,
199 CORBA_Environment * ev );
202 impl_VLC_MediaControl_playlist_clear( impl_POA_VLC_MediaControl * servant,
203 CORBA_Environment * ev );
205 static VLC_PlaylistSeq
206 *impl_VLC_MediaControl_playlist_get_list( impl_POA_VLC_MediaControl *
207 servant, CORBA_Environment * ev );
209 static VLC_RGBPicture
210 *impl_VLC_MediaControl_snapshot( impl_POA_VLC_MediaControl * servant,
211 const VLC_Position * a_position,
212 CORBA_Environment * ev );
214 static VLC_RGBPictureSeq
215 *impl_VLC_MediaControl_all_snapshots( impl_POA_VLC_MediaControl * servant,
216 CORBA_Environment * ev );
219 impl_VLC_MediaControl_display_text( impl_POA_VLC_MediaControl * servant,
220 const CORBA_char * message,
221 const VLC_Position * begin,
222 const VLC_Position * end,
223 CORBA_Environment * ev );
225 static VLC_StreamInformation
226 *impl_VLC_MediaControl_get_stream_information( impl_POA_VLC_MediaControl *
228 CORBA_Environment * ev );
230 static CORBA_unsigned_short
231 impl_VLC_MediaControl_sound_get_volume( impl_POA_VLC_MediaControl * servant,
232 CORBA_Environment * ev );
235 impl_VLC_MediaControl_sound_set_volume( impl_POA_VLC_MediaControl * servant,
236 const CORBA_unsigned_short volume,
237 CORBA_Environment * ev );
239 /*** epv structures ***/
241 static PortableServer_ServantBase__epv impl_VLC_MediaControl_base_epv = {
242 NULL, /* _private data */
243 ( gpointer ) & impl_VLC_MediaControl__destroy, /* finalize routine */
244 NULL, /* default_POA routine */
246 static POA_VLC_MediaControl__epv impl_VLC_MediaControl_epv = {
249 ( gpointer ) & impl_VLC_MediaControl_get_media_position,
251 ( gpointer ) & impl_VLC_MediaControl_set_media_position,
253 ( gpointer ) & impl_VLC_MediaControl_start,
255 ( gpointer ) & impl_VLC_MediaControl_pause,
257 ( gpointer ) & impl_VLC_MediaControl_resume,
259 ( gpointer ) & impl_VLC_MediaControl_stop,
261 ( gpointer ) & impl_VLC_MediaControl_exit,
263 ( gpointer ) & impl_VLC_MediaControl_playlist_add_item,
265 ( gpointer ) & impl_VLC_MediaControl_playlist_clear,
267 ( gpointer ) & impl_VLC_MediaControl_playlist_get_list,
269 ( gpointer ) & impl_VLC_MediaControl_snapshot,
271 ( gpointer ) & impl_VLC_MediaControl_all_snapshots,
273 ( gpointer ) & impl_VLC_MediaControl_display_text,
275 ( gpointer ) & impl_VLC_MediaControl_get_stream_information,
277 ( gpointer ) & impl_VLC_MediaControl_sound_get_volume,
279 ( gpointer ) & impl_VLC_MediaControl_sound_set_volume,
283 /*** vepv structures ***/
285 static POA_VLC_MediaControl__vepv impl_VLC_MediaControl_vepv = {
286 &impl_VLC_MediaControl_base_epv,
287 &impl_VLC_MediaControl_epv,
290 /*** Stub implementations ***/
292 static VLC_MediaControl
293 impl_VLC_MediaControl__create( PortableServer_POA poa, CORBA_Environment * ev )
295 VLC_MediaControl retval;
296 impl_POA_VLC_MediaControl *newservant;
297 PortableServer_ObjectId *objid;
299 newservant = g_new0( impl_POA_VLC_MediaControl, 1 );
300 newservant->servant.vepv = &impl_VLC_MediaControl_vepv;
302 ( PortableServer_POA ) CORBA_Object_duplicate( (CORBA_Object ) poa, ev );
303 POA_VLC_MediaControl__init( (PortableServer_Servant ) newservant, ev );
304 /* Before servant is going to be activated all
305 * private attributes must be initialized. */
307 /* ------ init private attributes here ------ */
308 newservant->mc = NULL;
309 /* ------ ---------- end ------------- ------ */
311 objid = PortableServer_POA_activate_object( poa, newservant, ev );
313 retval = PortableServer_POA_servant_to_reference( poa, newservant, ev );
319 impl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl * servant,
320 CORBA_Environment * ev )
322 CORBA_Object_release( (CORBA_Object ) servant->poa, ev );
324 /* No further remote method calls are delegated to
325 * servant and you may free your private attributes. */
326 /* ------ free private attributes here ------ */
327 /* ------ ---------- end ------------- ------ */
329 POA_VLC_MediaControl__fini( (PortableServer_Servant ) servant, ev );
334 /* Beginning of the CORBA functions that we define */
336 /* Returns the current position in the stream. The returned value can
337 be relative or absolute ( according to PositionOrigin ) and the unit
338 is set by PositionKey */
340 impl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant,
341 const VLC_PositionOrigin an_origin,
342 const VLC_PositionKey a_key,
343 CORBA_Environment * ev )
345 VLC_Position* retval = NULL;
346 mediacontrol_Position *p_pos;
347 mediacontrol_Exception *exception = NULL;
350 p_pos = mediacontrol_get_media_position( servant->mc, an_origin, a_key, exception );
351 MC_EXCEPT( *retval );
353 retval = corba_position_c_to_corba( p_pos );
358 /* Sets the media position */
360 impl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant,
361 const VLC_Position * a_position,
362 CORBA_Environment * ev )
364 mediacontrol_Position *p_pos;
365 mediacontrol_Exception *exception = NULL;
367 p_pos = corba_position_corba_to_c( a_position );
370 mediacontrol_set_media_position( servant->mc, p_pos, exception );
377 /* Starts playing a stream */
379 impl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant,
380 const VLC_Position * a_position, CORBA_Environment * ev )
382 mediacontrol_Position *p_pos;
383 mediacontrol_Exception *exception = NULL;
385 p_pos = corba_position_corba_to_c( a_position );
388 mediacontrol_start( servant->mc, p_pos, exception );
396 impl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant,
397 const VLC_Position * a_position, CORBA_Environment * ev )
399 mediacontrol_Position *p_pos;
400 mediacontrol_Exception *exception = NULL;
402 p_pos = corba_position_corba_to_c( a_position );
405 mediacontrol_pause( servant->mc, p_pos, exception );
413 impl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant,
414 const VLC_Position * a_position, CORBA_Environment * ev )
416 mediacontrol_Position *p_pos;
417 mediacontrol_Exception *exception = NULL;
419 p_pos = corba_position_corba_to_c( a_position );
422 mediacontrol_resume( servant->mc, p_pos, exception );
430 impl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant,
431 const VLC_Position * a_position, CORBA_Environment * ev )
433 mediacontrol_Position *p_pos;
434 mediacontrol_Exception *exception = NULL;
436 p_pos = corba_position_corba_to_c( a_position );
439 mediacontrol_pause( servant->mc, p_pos, exception );
447 impl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant,
448 CORBA_Environment * ev )
450 mediacontrol_exit( servant->mc );
455 impl_VLC_MediaControl_playlist_add_item( impl_POA_VLC_MediaControl * servant,
456 const CORBA_char * psz_file,
457 CORBA_Environment * ev )
459 mediacontrol_Exception *exception = NULL;
462 mediacontrol_playlist_add_item( servant->mc, psz_file, exception );
469 impl_VLC_MediaControl_playlist_clear( impl_POA_VLC_MediaControl * servant,
470 CORBA_Environment * ev )
472 mediacontrol_Exception *exception = NULL;
475 mediacontrol_playlist_clear( servant->mc, exception );
481 static VLC_PlaylistSeq *
482 impl_VLC_MediaControl_playlist_get_list( impl_POA_VLC_MediaControl * servant,
483 CORBA_Environment * ev )
485 VLC_PlaylistSeq *retval = NULL;
486 mediacontrol_Exception *exception = NULL;
487 mediacontrol_PlaylistSeq* p_ps;
491 p_ps = mediacontrol_playlist_get_list( servant->mc, exception );
494 retval = VLC_PlaylistSeq__alloc();
495 retval->_buffer = VLC_PlaylistSeq_allocbuf( p_ps->size );
496 retval->_length = p_ps->size;
498 for( i_index = 0 ; i_index < p_ps->size ; i_index++ )
500 retval->_buffer[i_index] = CORBA_string_dup( p_ps->data[i_index] );
502 CORBA_sequence_set_release( retval, TRUE );
504 mediacontrol_PlaylistSeq__free( p_ps );
509 createRGBPicture( mediacontrol_RGBPicture* p_pic )
511 VLC_RGBPicture *retval;
513 retval = VLC_RGBPicture__alloc();
516 retval->width = p_pic->width;
517 retval->height = p_pic->height;
518 retval->type = p_pic->type;
519 retval->date = p_pic->date;
521 retval->data._maximum = p_pic->size;
522 retval->data._length = p_pic->size;
523 retval->data._buffer = VLC_ByteSeq_allocbuf( p_pic->size );
524 memcpy( retval->data._buffer, p_pic->data, p_pic->size );
525 /* CORBA_sequence_set_release( &( retval->data ), FALSE ); */
530 static VLC_RGBPicture *
531 impl_VLC_MediaControl_snapshot( impl_POA_VLC_MediaControl * servant,
532 const VLC_Position * a_position,
533 CORBA_Environment * ev )
535 VLC_RGBPicture *retval = NULL;
536 mediacontrol_RGBPicture* p_pic = NULL;
537 mediacontrol_Position *p_pos;
538 mediacontrol_Exception *exception = NULL;
540 p_pos = corba_position_corba_to_c( a_position );
543 p_pic = mediacontrol_snapshot( servant->mc, p_pos, exception );
546 retval = createRGBPicture( p_pic );
547 mediacontrol_RGBPicture__free( p_pic );
551 static VLC_RGBPictureSeq *
552 impl_VLC_MediaControl_all_snapshots( impl_POA_VLC_MediaControl * servant,
553 CORBA_Environment * ev )
555 VLC_RGBPictureSeq *retval = NULL;
556 mediacontrol_RGBPicture** p_piclist = NULL;
557 mediacontrol_RGBPicture** p_tmp = NULL;
558 mediacontrol_Exception *exception = NULL;
563 p_piclist = mediacontrol_all_snapshots( servant->mc, exception );
566 for( p_tmp = p_piclist ; *p_tmp != NULL ; p_tmp++ )
569 retval = VLC_RGBPictureSeq__alloc();
570 retval->_buffer = VLC_RGBPictureSeq_allocbuf( i_size );
571 retval->_length = i_size;
573 for( i_index = 0 ; i_index < i_size ; i_index++ )
575 mediacontrol_RGBPicture *p_pic = p_piclist[i_index];
576 VLC_RGBPicture *p_rgb;
578 p_rgb = &( retval->_buffer[i_index] );
580 p_rgb->width = p_pic->width;
581 p_rgb->height = p_pic->height;
582 p_rgb->type = p_pic->type;
583 p_rgb->date = p_pic->date;
585 p_rgb->data._maximum = p_pic->size;
586 p_rgb->data._length = p_pic->size;
587 p_rgb->data._buffer = VLC_ByteSeq_allocbuf( p_pic->size );
588 memcpy( p_rgb->data._buffer, p_pic->data, p_pic->size );
589 mediacontrol_RGBPicture__free( p_pic );
597 impl_VLC_MediaControl_display_text( impl_POA_VLC_MediaControl * servant,
598 const CORBA_char * message,
599 const VLC_Position * begin,
600 const VLC_Position * end,
601 CORBA_Environment * ev )
603 mediacontrol_Position *p_begin = NULL;
604 mediacontrol_Position *p_end = NULL;
605 mediacontrol_Exception *exception = NULL;
607 p_begin = corba_position_corba_to_c( begin );
608 p_end = corba_position_corba_to_c( end );
610 mediacontrol_display_text( servant->mc, message, p_begin, p_end, exception );
618 static VLC_StreamInformation *
619 impl_VLC_MediaControl_get_stream_information( impl_POA_VLC_MediaControl *
620 servant, CORBA_Environment * ev )
622 mediacontrol_Exception *exception = NULL;
623 mediacontrol_StreamInformation *p_si = NULL;
624 VLC_StreamInformation *retval = NULL;
627 p_si = mediacontrol_get_stream_information( servant->mc, mediacontrol_MediaTime, exception );
630 retval = VLC_StreamInformation__alloc();
636 retval->streamstatus = p_si->streamstatus;
637 retval->url = CORBA_string_dup( p_si->url );
638 retval->position = p_si->position;
639 retval->length = p_si->length;
646 static CORBA_unsigned_short
647 impl_VLC_MediaControl_sound_get_volume( impl_POA_VLC_MediaControl * servant,
648 CORBA_Environment * ev )
650 CORBA_short retval = 0;
651 mediacontrol_Exception *exception = NULL;
654 retval = mediacontrol_sound_get_volume( servant->mc, exception );
661 impl_VLC_MediaControl_sound_set_volume( impl_POA_VLC_MediaControl * servant,
662 const CORBA_unsigned_short volume,
663 CORBA_Environment * ev )
665 mediacontrol_Exception *exception = NULL;
668 mediacontrol_sound_set_volume( servant->mc, volume, exception );
672 /* ( Real ) end of the CORBA code generated in Mediacontrol-skelimpl.c */
674 /*****************************************************************************
676 *****************************************************************************/
677 static int Open ( vlc_object_t * );
678 static void Close ( vlc_object_t * );
679 static void Run ( intf_thread_t * );
681 /*****************************************************************************
683 *****************************************************************************/
685 set_category( CAT_INTERFACE );
686 set_subcategory( SUBCAT_INTERFACE_CONTROL );
687 add_category_hint( N_( "Corba control" ), NULL, VLC_FALSE );
689 #define REACTIVITY_TEXT N_("Reactivity" )
690 #define REACTIVITY_LONGTEXT N_( \
691 "The corba interface will handle events every 50ms/Reactivity. " \
692 "5000 appears to be a sensible value." )
694 set_description( _( "corba control module" ) );
695 set_capability( "interface", 10 );
696 add_integer( "corba-reactivity", 5000, NULL, REACTIVITY_TEXT,
697 REACTIVITY_LONGTEXT, VLC_TRUE );
698 set_callbacks( Open, Close );
701 /*****************************************************************************
702 * intf_Open: initialize and create stuff
703 *****************************************************************************/
704 static int Open( vlc_object_t *p_this )
706 intf_thread_t *p_intf = ( intf_thread_t * )p_this;
708 /* Allocate instance and initialize some members */
709 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
710 if( p_intf->p_sys == NULL )
712 msg_Err( p_intf, "Out of memory" );
716 /* Initialize the fields of the p_intf struct */
717 p_intf->pf_run = Run;
719 p_intf->p_sys->mc = NULL;
720 p_intf->p_sys->orb = NULL;
721 p_intf->p_sys->corbaloop = NULL;
726 /*****************************************************************************
727 * intf_Close: destroy interface
728 *****************************************************************************/
729 static void Close( vlc_object_t *p_this )
731 intf_thread_t *p_intf = ( intf_thread_t * )p_this;
732 CORBA_Environment* ev = NULL;
734 ev = CORBA_exception__alloc();
735 CORBA_ORB_shutdown( p_intf->p_sys->orb, FALSE, ev );
736 handle_exception_no_servant( p_intf, "Error in Close" );
738 /* Destroy structure */
739 free( p_intf->p_sys );
743 Function called regularly to handle various tasks( mainly CORBA calls )
745 static gboolean Manage( gpointer p_interface )
747 intf_thread_t *p_intf = ( intf_thread_t* )p_interface;
748 CORBA_boolean b_work_pending;
749 CORBA_Environment* ev;
751 ev = CORBA_exception__alloc();
754 b_work_pending = CORBA_ORB_work_pending( p_intf->p_sys->orb, ev );
755 if( ev->_major != CORBA_NO_EXCEPTION )
757 msg_Err( p_intf, "Exception in CORBA events check loop" );
761 vlc_mutex_lock( &p_intf->change_lock );
764 CORBA_ORB_perform_work( p_intf->p_sys->orb, ev );
766 if( intf_ShouldDie( p_intf ) )
768 vlc_mutex_unlock( &p_intf->change_lock );
769 CORBA_ORB_shutdown( p_intf->p_sys->orb, TRUE, ev );
770 g_main_loop_quit( p_intf->p_sys->corbaloop );
775 vlc_mutex_unlock( &p_intf->change_lock );
780 /*****************************************************************************
782 *****************************************************************************
783 * this part of the interface is in a separate thread so that we can call
784 * g_main_loop_run() from within it without annoying the rest of the program.
785 *****************************************************************************/
786 static void Run( intf_thread_t *p_intf )
788 CORBA_Environment* ev = NULL;
789 PortableServer_POA root_poa;
790 PortableServer_POAManager root_poa_manager;
791 guint i_event_source;
792 CORBA_char* psz_objref;
793 impl_POA_VLC_MediaControl *servant = NULL;
794 VLC_MediaControl corba_instance;
795 mediacontrol_Instance *mc_instance;
796 mediacontrol_Exception *exception = NULL;
798 char* ppsz_argv[] = { "mc" };
801 ev = CORBA_exception__alloc();
803 p_intf->p_sys->orb = CORBA_ORB_init( &i_argc, ppsz_argv, "orbit-local-orb", ev );
805 /* Should be cleaner this way ( cf
806 http://www.fifi.org/doc/gnome-dev-doc/html/C/orbitgtk.html ) but it
807 functions well enough in the ugly way so that I do not bother
809 /* p_intf->p_sys->orb = gnome_CORBA_init ( "VLC", NULL, &argc, &argv, 0, NULL, ev ); */
811 handle_exception_no_servant( p_intf, "Exception during CORBA_ORB_init" );
813 root_poa = ( PortableServer_POA )CORBA_ORB_resolve_initial_references( p_intf->p_sys->orb, "RootPOA", ev );
814 handle_exception( "Exception during RootPOA initialization" );
816 corba_instance = impl_VLC_MediaControl__create( root_poa, ev );
817 handle_exception( "Exception during MediaControl initialization" );
819 servant = ( impl_POA_VLC_MediaControl* )PortableServer_POA_reference_to_servant( root_poa, corba_instance, ev );
820 handle_exception( "Exception during MediaControl access" );
823 mc_instance = mediacontrol_new_from_object((vlc_object_t* )p_intf, exception );
826 p_intf->p_sys->mc = mc_instance;
828 servant->p_intf = p_intf;
829 servant->mc = p_intf->p_sys->mc;
831 psz_objref = CORBA_ORB_object_to_string( p_intf->p_sys->orb, corba_instance, ev );
832 handle_exception( "Exception during IOR generation" );
834 msg_Warn( p_intf, "MediaControl IOR :" );
835 msg_Warn( p_intf, psz_objref );
837 /* We write the IOR in a file. */
840 /* no need for Unicode transliteration as long as VLC_IOR_FILE
842 fp = fopen( VLC_IOR_FILE, "w" );
845 msg_Err( p_intf, "Cannot write the IOR to %s ( %d ).", VLC_IOR_FILE, errno );
849 fprintf( fp, "%s", psz_objref );
851 msg_Warn( p_intf, "IOR written to %s", VLC_IOR_FILE );
855 root_poa_manager = PortableServer_POA__get_the_POAManager( root_poa, ev );
856 handle_exception( "Exception during POAManager resolution" );
858 PortableServer_POAManager_activate( root_poa_manager, ev );
859 handle_exception( "Exception during POAManager activation" );
861 msg_Info( p_intf, "corba remote control interface initialized" );
864 // Tentative de gestion du nommage...
866 CosNaming_NamingContext name_service;
867 CosNaming_NameComponent name_component[3] = {{"GNOME", "subcontext"},
868 {"Servers", "subcontext"},
870 CosNaming_Name name = {3, 3, name_component, CORBA_FALSE};
872 name_service = CORBA_ORB_resolve_initial_references( p_intf->p_sys->orb,
875 handle_exception( "Error: could not get name service: %s\n",
876 CORBA_exception_id( ev ) );
877 msg_Warn( p_intf, "Name service OK" );
879 CosNaming_NamingContext_bind( name_service, &name, p_intf->p_sys->mc, ev );
880 handle_exception( "Error: could not register object: %s\n",
881 CORBA_exception_id( ev ) );
885 /* The time factor should be 1/1000 but it is a little too
886 slow. Make it 1/10000 */
887 i_reactivity = config_GetInt( p_intf, "corba-reactivity" );
888 i_event_source = g_timeout_add( INTF_IDLE_SLEEP / i_reactivity, Manage, p_intf );
889 p_intf->p_sys->corbaloop = g_main_loop_new( NULL, FALSE );
890 g_main_loop_run( p_intf->p_sys->corbaloop );
893 g_source_remove( i_event_source );
894 unlink( VLC_IOR_FILE );
896 /* Make sure we exit ( In case other interfaces have been spawned ) */
897 mediacontrol_exit( p_intf->p_sys->mc );