Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

corba.c

00001 /*****************************************************************************
00002  * corba.c : CORBA (ORBit) remote control plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2001 the VideoLAN team
00005  * $Id: corba.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Olivier Aubert <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 /* For CORBA */
00028 #include "MediaControl.h"
00029 #include "orbit/poa/portableserver-poa-type.h"
00030 #include "mediacontrol-core.h"
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034 #include <vlc/vout.h>
00035 #include <vlc/aout.h>
00036 
00037 #include <errno.h>
00038 #include <unistd.h>
00039 
00040 /* FIXME: replace this to ~/.vlc/vlc-ior.ref thanks to
00041    config_GetHomeDir( ) */
00042 #ifndef __WIN32__
00043 #define VLC_IOR_FILE "/tmp/vlc-ior.ref"
00044 #else
00045 #define VLC_IOR_FILE "vlc-ior-ref"
00046 #endif
00047 
00048 #define MC_TRY exception = mediacontrol_exception_init( exception )
00049 #define MC_EXCEPT( return_value )  \
00050   if ( exception->code )\
00051   { \
00052       corba_raise( ev, exception ); \
00053       mediacontrol_exception_free( exception ); \
00054       return return_value; \
00055   } else { mediacontrol_exception_free( exception ); }
00056 
00057 #define handle_exception( m ) if( ev->_major != CORBA_NO_EXCEPTION ) \
00058     { \
00059         msg_Err( servant->p_intf, m ); \
00060         return; \
00061     }
00062 
00063 #define handle_exception_no_servant( p,m ) if( ev->_major != CORBA_NO_EXCEPTION ) \
00064     { \
00065         msg_Err( p, m ); \
00066         return; \
00067     }
00068 
00069 static void corba_raise( CORBA_Environment *ev, mediacontrol_Exception *exception )
00070 {
00071     char *corba_exception=NULL;
00072     char* i_type = NULL;
00073  
00074     switch( exception->code )
00075     {
00076     case mediacontrol_InternalException:
00077         corba_exception = ( char* )VLC_InternalException__alloc();
00078         i_type = ex_VLC_InternalException;
00079         break;
00080     case mediacontrol_PlaylistException:
00081         corba_exception = ( char* )VLC_PlaylistException__alloc();
00082         i_type = ex_VLC_PlaylistException;
00083         break;
00084     case mediacontrol_InvalidPosition:
00085         corba_exception = ( char* )VLC_InvalidPosition__alloc();
00086         i_type = ex_VLC_InvalidPosition;
00087         break;
00088     case mediacontrol_PositionKeyNotSupported:
00089         corba_exception = ( char* )VLC_PositionKeyNotSupported__alloc();
00090         i_type = ex_VLC_PositionKeyNotSupported;
00091         break;
00092     case mediacontrol_PositionOriginNotSupported:
00093         corba_exception = ( char* )VLC_PositionOriginNotSupported__alloc();
00094         i_type = ex_VLC_PositionOriginNotSupported;
00095         break;
00096     }
00097     ( (VLC_InternalException* )corba_exception )->message = CORBA_string_dup( exception->message );
00098     CORBA_exception_set( ev, CORBA_USER_EXCEPTION, i_type, corba_exception );
00099     return;
00100 }
00101 
00102 static mediacontrol_Position* corba_position_corba_to_c( const VLC_Position* position )
00103 {
00104     mediacontrol_Position* retval;
00105     
00106     retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
00107     if( ! retval )
00108         return NULL;
00109     retval->origin = position->origin;
00110     retval->key    = position->key;
00111     retval->value  = position->value;
00112     return retval;
00113 }
00114 
00115 static VLC_Position* corba_position_c_to_corba( const mediacontrol_Position* position )
00116 {
00117     VLC_Position* retval;
00118 
00119     retval = ( VLC_Position* )malloc( sizeof( VLC_Position ) );
00120     if( ! retval )
00121         return NULL;
00122     retval->origin = position->origin;
00123     retval->key    = position->key;
00124     retval->value  = position->value;
00125     return retval;
00126 }
00127 
00128 /*****************************************************************************
00129  * intf_sys_t: description and status of corba interface
00130  *****************************************************************************/
00131 struct intf_sys_t
00132 {
00133     CORBA_ORB                 orb;
00134     GMainLoop*                corbaloop;
00135     mediacontrol_Instance     *mc;
00136     msg_subscription_t* p_sub;  /* message bank subscription */
00137 };
00138 
00139 /*** App-specific servant structures ***/
00140 
00141 /* We can add attributes to this structure, which is both a pointer on a
00142    specific structure, and on a POA_VLC_MediaControl ( servant ). Cf
00143    http://developer.gnome.org/doc/guides/corba/html/corba-poa-example.html */
00144 
00145 typedef struct
00146 {
00147     POA_VLC_MediaControl servant;
00148     PortableServer_POA poa;
00149     /* Ajouter ici les attributs utiles */
00150     mediacontrol_Instance     *mc;
00151     intf_thread_t             *p_intf;
00152 } impl_POA_VLC_MediaControl;
00153 
00154 /* Beginning of the CORBA code generated in Mediacontrol-skelimpl.c */
00155 /* BEGIN INSERT */
00156 /*** Implementation stub prototypes ***/
00157 
00158 static void impl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl *
00159                                             servant, CORBA_Environment * ev );
00160 
00161 static VLC_Position
00162 impl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant,
00163                                           const VLC_PositionOrigin an_origin,
00164                                           const VLC_PositionKey a_key,
00165                                           CORBA_Environment * ev );
00166 
00167 static void
00168 impl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant,
00169                                           const VLC_Position * a_position,
00170                                           CORBA_Environment * ev );
00171 
00172 static void
00173 impl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant,
00174                              const VLC_Position * a_position,
00175                              CORBA_Environment * ev );
00176 
00177 static void
00178 impl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant,
00179                              const VLC_Position * a_position,
00180                              CORBA_Environment * ev );
00181 
00182 static void
00183 impl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant,
00184                               const VLC_Position * a_position,
00185                               CORBA_Environment * ev );
00186 
00187 static void
00188 impl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant,
00189                             const VLC_Position * a_position,
00190                             CORBA_Environment * ev );
00191 
00192 static void
00193 impl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant,
00194                             CORBA_Environment * ev );
00195 
00196 static void
00197 impl_VLC_MediaControl_playlist_add_item( impl_POA_VLC_MediaControl * servant,
00198                                          const CORBA_char * a_file,
00199                                          CORBA_Environment * ev );
00200 
00201 static void
00202 impl_VLC_MediaControl_playlist_clear( impl_POA_VLC_MediaControl * servant,
00203                                       CORBA_Environment * ev );
00204 
00205 static VLC_PlaylistSeq
00206 *impl_VLC_MediaControl_playlist_get_list( impl_POA_VLC_MediaControl *
00207                                           servant, CORBA_Environment * ev );
00208 
00209 static VLC_RGBPicture
00210 *impl_VLC_MediaControl_snapshot( impl_POA_VLC_MediaControl * servant,
00211                                  const VLC_Position * a_position,
00212                                  CORBA_Environment * ev );
00213 
00214 static VLC_RGBPictureSeq
00215 *impl_VLC_MediaControl_all_snapshots( impl_POA_VLC_MediaControl * servant,
00216                                       CORBA_Environment * ev );
00217 
00218 static void
00219 impl_VLC_MediaControl_display_text( impl_POA_VLC_MediaControl * servant,
00220                                     const CORBA_char * message,
00221                                     const VLC_Position * begin,
00222                                     const VLC_Position * end,
00223                                     CORBA_Environment * ev );
00224 
00225 static VLC_StreamInformation
00226 *impl_VLC_MediaControl_get_stream_information( impl_POA_VLC_MediaControl *
00227                                                servant,
00228                                                CORBA_Environment * ev );
00229 
00230 static CORBA_unsigned_short
00231 impl_VLC_MediaControl_sound_get_volume( impl_POA_VLC_MediaControl * servant,
00232                                         CORBA_Environment * ev );
00233 
00234 static void
00235 impl_VLC_MediaControl_sound_set_volume( impl_POA_VLC_MediaControl * servant,
00236                                         const CORBA_unsigned_short volume,
00237                                         CORBA_Environment * ev );
00238 
00239 /*** epv structures ***/
00240 
00241 static PortableServer_ServantBase__epv impl_VLC_MediaControl_base_epv = {
00242     NULL,                       /* _private data */
00243     ( gpointer ) & impl_VLC_MediaControl__destroy,      /* finalize routine */
00244     NULL,                       /* default_POA routine */
00245 };
00246 static POA_VLC_MediaControl__epv impl_VLC_MediaControl_epv = {
00247     NULL,                       /* _private */
00248 
00249     ( gpointer ) & impl_VLC_MediaControl_get_media_position,
00250 
00251     ( gpointer ) & impl_VLC_MediaControl_set_media_position,
00252 
00253     ( gpointer ) & impl_VLC_MediaControl_start,
00254 
00255     ( gpointer ) & impl_VLC_MediaControl_pause,
00256 
00257     ( gpointer ) & impl_VLC_MediaControl_resume,
00258 
00259     ( gpointer ) & impl_VLC_MediaControl_stop,
00260 
00261     ( gpointer ) & impl_VLC_MediaControl_exit,
00262 
00263     ( gpointer ) & impl_VLC_MediaControl_playlist_add_item,
00264 
00265     ( gpointer ) & impl_VLC_MediaControl_playlist_clear,
00266 
00267     ( gpointer ) & impl_VLC_MediaControl_playlist_get_list,
00268 
00269     ( gpointer ) & impl_VLC_MediaControl_snapshot,
00270 
00271     ( gpointer ) & impl_VLC_MediaControl_all_snapshots,
00272 
00273     ( gpointer ) & impl_VLC_MediaControl_display_text,
00274 
00275     ( gpointer ) & impl_VLC_MediaControl_get_stream_information,
00276 
00277     ( gpointer ) & impl_VLC_MediaControl_sound_get_volume,
00278 
00279     ( gpointer ) & impl_VLC_MediaControl_sound_set_volume,
00280 
00281 };
00282 
00283 /*** vepv structures ***/
00284 
00285 static POA_VLC_MediaControl__vepv impl_VLC_MediaControl_vepv = {
00286     &impl_VLC_MediaControl_base_epv,
00287     &impl_VLC_MediaControl_epv,
00288 };
00289 
00290 /*** Stub implementations ***/
00291 
00292 static VLC_MediaControl
00293 impl_VLC_MediaControl__create( PortableServer_POA poa, CORBA_Environment * ev )
00294 {
00295     VLC_MediaControl retval;
00296     impl_POA_VLC_MediaControl *newservant;
00297     PortableServer_ObjectId *objid;
00298 
00299     newservant = g_new0( impl_POA_VLC_MediaControl, 1 );
00300     newservant->servant.vepv = &impl_VLC_MediaControl_vepv;
00301     newservant->poa =
00302         ( PortableServer_POA ) CORBA_Object_duplicate( (CORBA_Object ) poa, ev );
00303     POA_VLC_MediaControl__init( (PortableServer_Servant ) newservant, ev );
00304     /* Before servant is going to be activated all
00305      * private attributes must be initialized.  */
00306 
00307     /* ------ init private attributes here ------ */
00308     newservant->mc = NULL;
00309     /* ------ ---------- end ------------- ------ */
00310 
00311     objid = PortableServer_POA_activate_object( poa, newservant, ev );
00312     CORBA_free( objid );
00313     retval = PortableServer_POA_servant_to_reference( poa, newservant, ev );
00314 
00315     return retval;
00316 }
00317 
00318 static void
00319 impl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl * servant,
00320                                 CORBA_Environment * ev )
00321 {
00322     CORBA_Object_release( (CORBA_Object ) servant->poa, ev );
00323 
00324     /* No further remote method calls are delegated to 
00325      * servant and you may free your private attributes. */
00326     /* ------ free private attributes here ------ */
00327     /* ------ ---------- end ------------- ------ */
00328 
00329     POA_VLC_MediaControl__fini( (PortableServer_Servant ) servant, ev );
00330 }
00331 
00332 /* END INSERT */
00333 
00334 /* Beginning of the CORBA functions that we define */
00335 
00336 /* Returns the current position in the stream. The returned value can
00337    be relative or absolute ( according to PositionOrigin ) and the unit
00338    is set by PositionKey */
00339 static VLC_Position
00340 impl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant,
00341                                           const VLC_PositionOrigin an_origin,
00342                                           const VLC_PositionKey a_key,
00343                                           CORBA_Environment * ev )
00344 {
00345     VLC_Position* retval = NULL;
00346     mediacontrol_Position *p_pos;
00347     mediacontrol_Exception *exception = NULL;
00348 
00349     MC_TRY;
00350     p_pos = mediacontrol_get_media_position( servant->mc, an_origin, a_key, exception );
00351     MC_EXCEPT( *retval );
00352 
00353     retval = corba_position_c_to_corba( p_pos );
00354     free( p_pos );
00355     return *retval;
00356 }
00357 
00358 /* Sets the media position */
00359 static void
00360 impl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant,
00361                                           const VLC_Position * a_position,
00362                                           CORBA_Environment * ev )
00363 {
00364     mediacontrol_Position *p_pos;
00365     mediacontrol_Exception *exception = NULL;
00366 
00367     p_pos = corba_position_corba_to_c( a_position );
00368   
00369     MC_TRY;
00370     mediacontrol_set_media_position( servant->mc, p_pos, exception );
00371     MC_EXCEPT();
00372     free( p_pos );
00373 
00374     return;
00375 }
00376 
00377 /* Starts playing a stream */
00378 static void
00379 impl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant,
00380                              const VLC_Position * a_position, CORBA_Environment * ev )
00381 {
00382     mediacontrol_Position *p_pos;
00383     mediacontrol_Exception *exception = NULL;
00384 
00385     p_pos = corba_position_corba_to_c( a_position );
00386   
00387     MC_TRY;
00388     mediacontrol_start( servant->mc, p_pos, exception );
00389     MC_EXCEPT();
00390 
00391     free( p_pos );
00392     return;
00393 }
00394 
00395 static void
00396 impl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant,
00397                              const VLC_Position * a_position, CORBA_Environment * ev )
00398 {
00399     mediacontrol_Position *p_pos;
00400     mediacontrol_Exception *exception = NULL;
00401 
00402     p_pos = corba_position_corba_to_c( a_position );
00403   
00404     MC_TRY;
00405     mediacontrol_pause( servant->mc, p_pos, exception );
00406     MC_EXCEPT();
00407 
00408     free( p_pos );
00409     return;
00410 }
00411 
00412 static void
00413 impl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant,
00414                               const VLC_Position * a_position, CORBA_Environment * ev )
00415 {
00416     mediacontrol_Position *p_pos;
00417     mediacontrol_Exception *exception = NULL;
00418 
00419     p_pos = corba_position_corba_to_c( a_position );
00420   
00421     MC_TRY;
00422     mediacontrol_resume( servant->mc, p_pos, exception );
00423     MC_EXCEPT();
00424 
00425     free( p_pos );
00426     return;
00427 }
00428 
00429 static void
00430 impl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant,
00431                             const VLC_Position * a_position, CORBA_Environment * ev )
00432 {
00433     mediacontrol_Position *p_pos;
00434     mediacontrol_Exception *exception = NULL;
00435 
00436     p_pos = corba_position_corba_to_c( a_position );
00437   
00438     MC_TRY;
00439     mediacontrol_pause( servant->mc, p_pos, exception );
00440     MC_EXCEPT();
00441 
00442     free( p_pos );
00443     return;
00444 }
00445 
00446 static void
00447 impl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant,
00448                             CORBA_Environment * ev )
00449 {
00450     mediacontrol_exit( servant->mc );
00451     return;
00452 }
00453 
00454 static void
00455 impl_VLC_MediaControl_playlist_add_item( impl_POA_VLC_MediaControl * servant,
00456                                          const CORBA_char * psz_file,
00457                                          CORBA_Environment * ev )
00458 {
00459     mediacontrol_Exception *exception = NULL;
00460   
00461     MC_TRY;
00462     mediacontrol_playlist_add_item( servant->mc, psz_file, exception );
00463     MC_EXCEPT();
00464 
00465     return;
00466 }
00467 
00468 static void
00469 impl_VLC_MediaControl_playlist_clear( impl_POA_VLC_MediaControl * servant,
00470                                       CORBA_Environment * ev )
00471 {
00472     mediacontrol_Exception *exception = NULL;
00473   
00474     MC_TRY;
00475     mediacontrol_playlist_clear( servant->mc, exception );
00476     MC_EXCEPT();
00477 
00478     return;
00479 }
00480 
00481 static VLC_PlaylistSeq *
00482 impl_VLC_MediaControl_playlist_get_list( impl_POA_VLC_MediaControl * servant,
00483                                          CORBA_Environment * ev )
00484 {
00485     VLC_PlaylistSeq *retval = NULL;
00486     mediacontrol_Exception *exception = NULL;
00487     mediacontrol_PlaylistSeq* p_ps;
00488     int i_index;
00489    
00490     MC_TRY;
00491     p_ps = mediacontrol_playlist_get_list( servant->mc, exception );
00492     MC_EXCEPT( retval );
00493 
00494     retval = VLC_PlaylistSeq__alloc();
00495     retval->_buffer = VLC_PlaylistSeq_allocbuf( p_ps->size );
00496     retval->_length = p_ps->size;
00497   
00498     for( i_index = 0 ; i_index < p_ps->size ; i_index++ )
00499     {
00500         retval->_buffer[i_index] = CORBA_string_dup( p_ps->data[i_index] );
00501     }
00502     CORBA_sequence_set_release( retval, TRUE );
00503   
00504     mediacontrol_PlaylistSeq__free( p_ps );
00505     return retval;
00506 }
00507 
00508 VLC_RGBPicture*
00509 createRGBPicture( mediacontrol_RGBPicture* p_pic )
00510 {
00511     VLC_RGBPicture *retval;
00512   
00513     retval = VLC_RGBPicture__alloc();
00514     if( retval )
00515     {
00516         retval->width  = p_pic->width;
00517         retval->height = p_pic->height;
00518         retval->type   = p_pic->type;
00519         retval->date   = p_pic->date;
00520       
00521         retval->data._maximum = p_pic->size;
00522         retval->data._length = p_pic->size;
00523         retval->data._buffer = VLC_ByteSeq_allocbuf( p_pic->size );
00524         memcpy( retval->data._buffer, p_pic->data, p_pic->size );
00525         /* CORBA_sequence_set_release( &( retval->data ), FALSE ); */
00526     }
00527     return retval;
00528 }
00529 
00530 static VLC_RGBPicture *
00531 impl_VLC_MediaControl_snapshot( impl_POA_VLC_MediaControl * servant,
00532                                 const VLC_Position * a_position,
00533                                 CORBA_Environment * ev )
00534 {
00535     VLC_RGBPicture *retval = NULL;
00536     mediacontrol_RGBPicture* p_pic = NULL;
00537     mediacontrol_Position *p_pos;
00538     mediacontrol_Exception *exception = NULL;
00539 
00540     p_pos = corba_position_corba_to_c( a_position );
00541   
00542     MC_TRY;
00543     p_pic = mediacontrol_snapshot( servant->mc, p_pos, exception );
00544     MC_EXCEPT( retval );
00545   
00546     retval = createRGBPicture( p_pic );
00547     mediacontrol_RGBPicture__free( p_pic );
00548     return retval;
00549 }
00550 
00551 static VLC_RGBPictureSeq *
00552 impl_VLC_MediaControl_all_snapshots( impl_POA_VLC_MediaControl * servant,
00553                                      CORBA_Environment * ev )
00554 {
00555     VLC_RGBPictureSeq *retval = NULL;
00556     mediacontrol_RGBPicture** p_piclist = NULL;
00557     mediacontrol_RGBPicture** p_tmp = NULL;
00558     mediacontrol_Exception *exception = NULL;
00559     int i_size = 0;
00560     int i_index;
00561   
00562     MC_TRY;
00563     p_piclist = mediacontrol_all_snapshots( servant->mc, exception );
00564     MC_EXCEPT( retval );
00565 
00566     for( p_tmp = p_piclist ; *p_tmp != NULL ; p_tmp++ )
00567         i_size++;
00568   
00569     retval = VLC_RGBPictureSeq__alloc();
00570     retval->_buffer = VLC_RGBPictureSeq_allocbuf( i_size );
00571     retval->_length = i_size;
00572 
00573     for( i_index = 0 ; i_index < i_size ; i_index++ )
00574     {
00575         mediacontrol_RGBPicture *p_pic = p_piclist[i_index];
00576         VLC_RGBPicture *p_rgb;
00577       
00578         p_rgb = &( retval->_buffer[i_index] );
00579       
00580         p_rgb->width  = p_pic->width;
00581         p_rgb->height = p_pic->height;
00582         p_rgb->type   = p_pic->type;
00583         p_rgb->date   = p_pic->date;
00584       
00585         p_rgb->data._maximum = p_pic->size;
00586         p_rgb->data._length  = p_pic->size;
00587         p_rgb->data._buffer  = VLC_ByteSeq_allocbuf( p_pic->size );
00588         memcpy( p_rgb->data._buffer, p_pic->data, p_pic->size );
00589         mediacontrol_RGBPicture__free( p_pic );
00590     }
00591   
00592     free( p_piclist );
00593     return retval;
00594 }
00595 
00596 static void
00597 impl_VLC_MediaControl_display_text( impl_POA_VLC_MediaControl * servant,
00598                                     const CORBA_char * message,
00599                                     const VLC_Position * begin,
00600                                     const VLC_Position * end,
00601                                     CORBA_Environment * ev )
00602 {
00603     mediacontrol_Position *p_begin = NULL;
00604     mediacontrol_Position *p_end = NULL;
00605     mediacontrol_Exception *exception = NULL;
00606 
00607     p_begin = corba_position_corba_to_c( begin );
00608     p_end = corba_position_corba_to_c( end );
00609     MC_TRY;
00610     mediacontrol_display_text( servant->mc, message, p_begin, p_end, exception );
00611     MC_EXCEPT();
00612 
00613     free( p_begin );
00614     free( p_end );
00615     return;
00616 }
00617 
00618 static VLC_StreamInformation *
00619 impl_VLC_MediaControl_get_stream_information( impl_POA_VLC_MediaControl *
00620                                               servant, CORBA_Environment * ev )
00621 {
00622     mediacontrol_Exception *exception = NULL;
00623     mediacontrol_StreamInformation *p_si = NULL;
00624     VLC_StreamInformation *retval = NULL;
00625 
00626     MC_TRY;
00627     p_si = mediacontrol_get_stream_information( servant->mc, mediacontrol_MediaTime, exception );
00628     MC_EXCEPT( retval );
00629 
00630     retval = VLC_StreamInformation__alloc();
00631     if( ! retval )
00632     {
00633         return NULL;
00634     }
00635 
00636     retval->streamstatus = p_si->streamstatus;
00637     retval->url          = CORBA_string_dup( p_si->url );
00638     retval->position     = p_si->position;
00639     retval->length       = p_si->length;
00640   
00641     free( p_si->url );
00642     free( p_si );
00643     return retval;
00644 }
00645 
00646 static CORBA_unsigned_short
00647 impl_VLC_MediaControl_sound_get_volume( impl_POA_VLC_MediaControl * servant,
00648                                         CORBA_Environment * ev )
00649 {
00650     CORBA_short retval = 0;
00651     mediacontrol_Exception *exception = NULL;
00652   
00653     MC_TRY;
00654     retval = mediacontrol_sound_get_volume( servant->mc, exception );
00655     MC_EXCEPT( retval );
00656 
00657     return retval;
00658 }
00659 
00660 static void
00661 impl_VLC_MediaControl_sound_set_volume( impl_POA_VLC_MediaControl * servant,
00662                                         const CORBA_unsigned_short volume,
00663                                         CORBA_Environment * ev )
00664 {
00665     mediacontrol_Exception *exception = NULL;
00666   
00667     MC_TRY;
00668     mediacontrol_sound_set_volume( servant->mc, volume, exception );
00669     MC_EXCEPT();
00670 }
00671 
00672 /* ( Real ) end of the CORBA code generated in Mediacontrol-skelimpl.c */
00673 
00674 /*****************************************************************************
00675  * Local prototypes.
00676  *****************************************************************************/
00677 static int  Open         ( vlc_object_t * );
00678 static void Close        ( vlc_object_t * );
00679 static void Run          ( intf_thread_t * );
00680 
00681 /*****************************************************************************
00682  * Module descriptor
00683  *****************************************************************************/
00684 vlc_module_begin();
00685 set_category( CAT_INTERFACE );
00686 set_subcategory( SUBCAT_INTERFACE_CONTROL );
00687 add_category_hint( N_( "Corba control" ), NULL, VLC_FALSE );
00688 
00689 set_description( _( "corba control module" ) );
00690 set_capability( "interface", 10 );
00691 add_integer( "corba-reactivity", 5000, NULL, "Internal reactivity factor", "Internal reactivity factor ( gtk timeout is INTF_IDLE_SLEEP / factor )", VLC_TRUE );
00692 set_callbacks( Open, Close );
00693 vlc_module_end();
00694 
00695 /*****************************************************************************
00696  * intf_Open: initialize and create stuff
00697  *****************************************************************************/
00698 static int Open( vlc_object_t *p_this )
00699 {
00700     intf_thread_t *p_intf = ( intf_thread_t * )p_this;
00701 
00702     /* Allocate instance and initialize some members */
00703     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00704     if( p_intf->p_sys == NULL )
00705     {
00706         msg_Err( p_intf, "Out of memory" );
00707         return VLC_ENOMEM;
00708     }
00709 
00710     /* Initialize the fields of the p_intf struct */
00711     p_intf->pf_run = Run;
00712 
00713     p_intf->p_sys->mc = NULL;
00714     p_intf->p_sys->orb = NULL;
00715     p_intf->p_sys->corbaloop = NULL;
00716 
00717     return VLC_SUCCESS;
00718 }
00719 
00720 /*****************************************************************************
00721  * intf_Close: destroy interface
00722  *****************************************************************************/
00723 static void Close( vlc_object_t *p_this )
00724 {
00725     intf_thread_t *p_intf = ( intf_thread_t * )p_this;
00726     CORBA_Environment*        ev = NULL;
00727 
00728     ev = CORBA_exception__alloc();
00729     CORBA_ORB_shutdown( p_intf->p_sys->orb, FALSE, ev );
00730     handle_exception_no_servant( p_intf, "Error in Close" );
00731 
00732     /* Destroy structure */
00733     free( p_intf->p_sys );
00734 }
00735 
00736 /*
00737   Function called regularly to handle various tasks( mainly CORBA calls )
00738 */
00739 static gboolean Manage( gpointer p_interface )
00740 {
00741     intf_thread_t *p_intf = ( intf_thread_t* )p_interface;
00742     CORBA_boolean b_work_pending;
00743     CORBA_Environment* ev;
00744 
00745     ev = CORBA_exception__alloc();
00746 
00747     /* CORBA */
00748     b_work_pending = CORBA_ORB_work_pending( p_intf->p_sys->orb, ev );
00749     if( ev->_major != CORBA_NO_EXCEPTION )
00750     {
00751         msg_Err( p_intf, "Exception in CORBA events check loop" );
00752         return FALSE;
00753     }
00754   
00755     vlc_mutex_lock( &p_intf->change_lock );
00756 
00757     if( b_work_pending )
00758         CORBA_ORB_perform_work( p_intf->p_sys->orb, ev );
00759   
00760     if( p_intf->b_die )
00761     {
00762         vlc_mutex_unlock( &p_intf->change_lock );
00763         CORBA_ORB_shutdown( p_intf->p_sys->orb, TRUE, ev );
00764         g_main_loop_quit( p_intf->p_sys->corbaloop );
00765         /* Just in case */
00766         return( TRUE );
00767     }
00768 
00769     vlc_mutex_unlock( &p_intf->change_lock );
00770 
00771     return TRUE;
00772 }
00773 
00774 /*****************************************************************************
00775  * Run: main loop
00776  *****************************************************************************
00777  * this part of the interface is in a separate thread so that we can call
00778  * g_main_loop_run() from within it without annoying the rest of the program.
00779  *****************************************************************************/
00780 static void Run( intf_thread_t *p_intf )
00781 {
00782     CORBA_Environment*        ev = NULL;
00783     PortableServer_POA        root_poa;
00784     PortableServer_POAManager root_poa_manager;
00785     guint                     i_event_source;
00786     CORBA_char*               psz_objref;
00787     impl_POA_VLC_MediaControl *servant = NULL;
00788     VLC_MediaControl          corba_instance;
00789     mediacontrol_Instance     *mc_instance;
00790     mediacontrol_Exception    *exception = NULL;
00791     int i_argc = 1;
00792     char* ppsz_argv[] = { "mc" };
00793     int i_reactivity;
00794 
00795     ev = CORBA_exception__alloc();
00796 
00797     p_intf->p_sys->orb = CORBA_ORB_init( &i_argc, ppsz_argv, "orbit-local-orb", ev );
00798 
00799     /* Should be cleaner this way ( cf
00800        http://www.fifi.org/doc/gnome-dev-doc/html/C/orbitgtk.html ) but it
00801        functions well enough in the ugly way so that I do not bother
00802        cleaning it */
00803     /* p_intf->p_sys->orb = gnome_CORBA_init ( "VLC", NULL, &argc, &argv, 0, NULL, ev ); */
00804 
00805     handle_exception_no_servant( p_intf, "Exception during CORBA_ORB_init" );
00806 
00807     root_poa = ( PortableServer_POA )CORBA_ORB_resolve_initial_references( p_intf->p_sys->orb, "RootPOA", ev );
00808     handle_exception( "Exception during RootPOA initialization" );
00809 
00810     corba_instance = impl_VLC_MediaControl__create( root_poa, ev );
00811     handle_exception( "Exception during MediaControl initialization" );
00812 
00813     servant = ( impl_POA_VLC_MediaControl* )PortableServer_POA_reference_to_servant( root_poa, corba_instance, ev );
00814     handle_exception( "Exception during MediaControl access" );
00815 
00816     MC_TRY;
00817     mc_instance = mediacontrol_new_from_object((vlc_object_t* )p_intf, exception );
00818     MC_EXCEPT();
00819 
00820     p_intf->p_sys->mc = mc_instance;
00821 
00822     servant->p_intf = p_intf;
00823     servant->mc = p_intf->p_sys->mc;
00824 
00825     psz_objref = CORBA_ORB_object_to_string( p_intf->p_sys->orb, corba_instance, ev );
00826     handle_exception( "Exception during IOR generation" );
00827 
00828     msg_Warn( p_intf, "MediaControl IOR :" );
00829     msg_Warn( p_intf, psz_objref );
00830 
00831     /* We write the IOR in a file. */
00832     {
00833         FILE* fp;
00834         fp = fopen( VLC_IOR_FILE, "w" );
00835         if( fp == NULL )
00836         {
00837             msg_Err( p_intf, "Cannot write the IOR to %s ( %d ).", VLC_IOR_FILE, errno );
00838         }
00839         else
00840         {
00841             fprintf( fp, "%s", psz_objref );
00842             fclose( fp );
00843             msg_Warn( p_intf, "IOR written to %s", VLC_IOR_FILE );
00844         }
00845     }
00846   
00847     root_poa_manager = PortableServer_POA__get_the_POAManager( root_poa, ev );
00848     handle_exception( "Exception during POAManager resolution" );
00849 
00850     PortableServer_POAManager_activate( root_poa_manager, ev );
00851     handle_exception( "Exception during POAManager activation" );
00852 
00853     msg_Info( p_intf, "corba remote control interface initialized" );
00854 
00855     /*
00856     // Tentative de gestion du nommage...
00857     {
00858     CosNaming_NamingContext name_service;
00859     CosNaming_NameComponent name_component[3] = {{"GNOME", "subcontext"},
00860     {"Servers", "subcontext"},
00861     {"vlc", "server"} };
00862     CosNaming_Name name = {3, 3, name_component, CORBA_FALSE};
00863 
00864     name_service = CORBA_ORB_resolve_initial_references( p_intf->p_sys->orb,
00865     "NameService",
00866     ev );
00867     handle_exception( "Error: could not get name service: %s\n",
00868     CORBA_exception_id( ev ) );
00869     msg_Warn( p_intf, "Name service OK" );
00870 
00871     CosNaming_NamingContext_bind( name_service, &name, p_intf->p_sys->mc, ev );
00872     handle_exception( "Error: could not register object: %s\n",
00873     CORBA_exception_id( ev ) );
00874     }
00875     */
00876 
00877     /* The time factor should be 1/1000 but it is a little too
00878        slow. Make it 1/10000 */
00879     i_reactivity = config_GetInt( p_intf, "corba-reactivity" );
00880     i_event_source = g_timeout_add( INTF_IDLE_SLEEP / i_reactivity, Manage, p_intf );
00881     p_intf->p_sys->corbaloop = g_main_loop_new( NULL, FALSE );
00882     g_main_loop_run( p_intf->p_sys->corbaloop );
00883 
00884     /* Cleaning */
00885     g_source_remove( i_event_source );
00886     unlink( VLC_IOR_FILE );
00887 
00888     /* Make sure we exit ( In case other interfaces have been spawned ) */
00889     mediacontrol_exit( p_intf->p_sys->mc );
00890 
00891     return;
00892 }

Generated on Tue Dec 20 10:14:30 2005 for vlc-0.8.4a by  doxygen 1.4.2