📄 corba.c
字号:
/***************************************************************************** * corba.c : CORBA (ORBit) remote control plugin for vlc ***************************************************************************** * Copyright (C) 2001 VideoLAN * $Id: corba.c 10101 2005-03-02 16:47:31Z robux4 $ * * Authors: Olivier Aubert <oaubert@lisi.univ-lyon1.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************//* For CORBA */#include "MediaControl.h"#include "orbit/poa/portableserver-poa-type.h"#include "mediacontrol-core.h"#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.h>#include <vlc/aout.h>#include <errno.h>#include <unistd.h>/* FIXME: replace this to ~/.vlc/vlc-ior.ref thanks to config_GetHomeDir( ) */#ifndef __WIN32__#define VLC_IOR_FILE "/tmp/vlc-ior.ref"#else#define VLC_IOR_FILE "vlc-ior-ref"#endif#define MC_TRY exception = mediacontrol_exception_init( exception )#define MC_EXCEPT( return_value ) \ if ( exception->code )\ { \ corba_raise( ev, exception ); \ mediacontrol_exception_free( exception ); \ return return_value; \ } else { mediacontrol_exception_free( exception ); }#define handle_exception( m ) if( ev->_major != CORBA_NO_EXCEPTION ) \ { \ msg_Err( servant->p_intf, m ); \ return; \ }#define handle_exception_no_servant( p,m ) if( ev->_major != CORBA_NO_EXCEPTION ) \ { \ msg_Err( p, m ); \ return; \ }static void corba_raise( CORBA_Environment *ev, mediacontrol_Exception *exception ){ char *corba_exception=NULL; char* i_type = NULL; switch( exception->code ) { case mediacontrol_InternalException: corba_exception = ( char* )VLC_InternalException__alloc(); i_type = ex_VLC_InternalException; break; case mediacontrol_PlaylistException: corba_exception = ( char* )VLC_PlaylistException__alloc(); i_type = ex_VLC_PlaylistException; break; case mediacontrol_InvalidPosition: corba_exception = ( char* )VLC_InvalidPosition__alloc(); i_type = ex_VLC_InvalidPosition; break; case mediacontrol_PositionKeyNotSupported: corba_exception = ( char* )VLC_PositionKeyNotSupported__alloc(); i_type = ex_VLC_PositionKeyNotSupported; break; case mediacontrol_PositionOriginNotSupported: corba_exception = ( char* )VLC_PositionOriginNotSupported__alloc(); i_type = ex_VLC_PositionOriginNotSupported; break; } ( (VLC_InternalException* )corba_exception )->message = CORBA_string_dup( exception->message ); CORBA_exception_set( ev, CORBA_USER_EXCEPTION, i_type, corba_exception ); return;}static mediacontrol_Position* corba_position_corba_to_c( const VLC_Position* position ){ mediacontrol_Position* retval; retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) ); if( ! retval ) return NULL; retval->origin = position->origin; retval->key = position->key; retval->value = position->value; return retval;}static VLC_Position* corba_position_c_to_corba( const mediacontrol_Position* position ){ VLC_Position* retval; retval = ( VLC_Position* )malloc( sizeof( VLC_Position ) ); if( ! retval ) return NULL; retval->origin = position->origin; retval->key = position->key; retval->value = position->value; return retval;}/***************************************************************************** * intf_sys_t: description and status of corba interface *****************************************************************************/struct intf_sys_t{ CORBA_ORB orb; GMainLoop* corbaloop; mediacontrol_Instance *mc; msg_subscription_t* p_sub; /* message bank subscription */};/*** App-specific servant structures ***//* We can add attributes to this structure, which is both a pointer on a specific structure, and on a POA_VLC_MediaControl ( servant ). Cf http://developer.gnome.org/doc/guides/corba/html/corba-poa-example.html */typedef struct{ POA_VLC_MediaControl servant; PortableServer_POA poa; /* Ajouter ici les attributs utiles */ mediacontrol_Instance *mc; intf_thread_t *p_intf;} impl_POA_VLC_MediaControl;/* Beginning of the CORBA code generated in Mediacontrol-skelimpl.c *//* BEGIN INSERT *//*** Implementation stub prototypes ***/static void impl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static VLC_Positionimpl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant, const VLC_PositionOrigin an_origin, const VLC_PositionKey a_key, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_playlist_add_item( impl_POA_VLC_MediaControl * servant, const CORBA_char * a_file, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_playlist_clear( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static VLC_PlaylistSeq*impl_VLC_MediaControl_playlist_get_list( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static VLC_RGBPicture*impl_VLC_MediaControl_snapshot( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev );static VLC_RGBPictureSeq*impl_VLC_MediaControl_all_snapshots( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_display_text( impl_POA_VLC_MediaControl * servant, const CORBA_char * message, const VLC_Position * begin, const VLC_Position * end, CORBA_Environment * ev );static VLC_StreamInformation*impl_VLC_MediaControl_get_stream_information( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static CORBA_unsigned_shortimpl_VLC_MediaControl_sound_get_volume( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev );static voidimpl_VLC_MediaControl_sound_set_volume( impl_POA_VLC_MediaControl * servant, const CORBA_unsigned_short volume, CORBA_Environment * ev );/*** epv structures ***/static PortableServer_ServantBase__epv impl_VLC_MediaControl_base_epv = { NULL, /* _private data */ ( gpointer ) & impl_VLC_MediaControl__destroy, /* finalize routine */ NULL, /* default_POA routine */};static POA_VLC_MediaControl__epv impl_VLC_MediaControl_epv = { NULL, /* _private */ ( gpointer ) & impl_VLC_MediaControl_get_media_position, ( gpointer ) & impl_VLC_MediaControl_set_media_position, ( gpointer ) & impl_VLC_MediaControl_start, ( gpointer ) & impl_VLC_MediaControl_pause, ( gpointer ) & impl_VLC_MediaControl_resume, ( gpointer ) & impl_VLC_MediaControl_stop, ( gpointer ) & impl_VLC_MediaControl_exit, ( gpointer ) & impl_VLC_MediaControl_playlist_add_item, ( gpointer ) & impl_VLC_MediaControl_playlist_clear, ( gpointer ) & impl_VLC_MediaControl_playlist_get_list, ( gpointer ) & impl_VLC_MediaControl_snapshot, ( gpointer ) & impl_VLC_MediaControl_all_snapshots, ( gpointer ) & impl_VLC_MediaControl_display_text, ( gpointer ) & impl_VLC_MediaControl_get_stream_information, ( gpointer ) & impl_VLC_MediaControl_sound_get_volume, ( gpointer ) & impl_VLC_MediaControl_sound_set_volume,};/*** vepv structures ***/static POA_VLC_MediaControl__vepv impl_VLC_MediaControl_vepv = { &impl_VLC_MediaControl_base_epv, &impl_VLC_MediaControl_epv,};/*** Stub implementations ***/static VLC_MediaControlimpl_VLC_MediaControl__create( PortableServer_POA poa, CORBA_Environment * ev ){ VLC_MediaControl retval; impl_POA_VLC_MediaControl *newservant; PortableServer_ObjectId *objid; newservant = g_new0( impl_POA_VLC_MediaControl, 1 ); newservant->servant.vepv = &impl_VLC_MediaControl_vepv; newservant->poa = ( PortableServer_POA ) CORBA_Object_duplicate( (CORBA_Object ) poa, ev ); POA_VLC_MediaControl__init( (PortableServer_Servant ) newservant, ev ); /* Before servant is going to be activated all * private attributes must be initialized. */ /* ------ init private attributes here ------ */ newservant->mc = NULL; /* ------ ---------- end ------------- ------ */ objid = PortableServer_POA_activate_object( poa, newservant, ev ); CORBA_free( objid ); retval = PortableServer_POA_servant_to_reference( poa, newservant, ev ); return retval;}static voidimpl_VLC_MediaControl__destroy( impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev ){ CORBA_Object_release( (CORBA_Object ) servant->poa, ev ); /* No further remote method calls are delegated to * servant and you may free your private attributes. */ /* ------ free private attributes here ------ */ /* ------ ---------- end ------------- ------ */ POA_VLC_MediaControl__fini( (PortableServer_Servant ) servant, ev );}/* END INSERT *//* Beginning of the CORBA functions that we define *//* Returns the current position in the stream. The returned value can be relative or absolute ( according to PositionOrigin ) and the unit is set by PositionKey */static VLC_Positionimpl_VLC_MediaControl_get_media_position( impl_POA_VLC_MediaControl * servant, const VLC_PositionOrigin an_origin, const VLC_PositionKey a_key, CORBA_Environment * ev ){ VLC_Position* retval = NULL; mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; MC_TRY; p_pos = mediacontrol_get_media_position( servant->mc, an_origin, a_key, exception ); MC_EXCEPT( *retval ); retval = corba_position_c_to_corba( p_pos ); free( p_pos ); return *retval;}/* Sets the media position */static voidimpl_VLC_MediaControl_set_media_position( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev ){ mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; p_pos = corba_position_corba_to_c( a_position ); MC_TRY; mediacontrol_set_media_position( servant->mc, p_pos, exception ); MC_EXCEPT(); free( p_pos ); return;}/* Starts playing a stream */static voidimpl_VLC_MediaControl_start( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev ){ mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; p_pos = corba_position_corba_to_c( a_position ); MC_TRY; mediacontrol_start( servant->mc, p_pos, exception ); MC_EXCEPT(); free( p_pos ); return;}static voidimpl_VLC_MediaControl_pause( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev ){ mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; p_pos = corba_position_corba_to_c( a_position ); MC_TRY; mediacontrol_pause( servant->mc, p_pos, exception ); MC_EXCEPT(); free( p_pos ); return;}static voidimpl_VLC_MediaControl_resume( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev ){ mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; p_pos = corba_position_corba_to_c( a_position ); MC_TRY; mediacontrol_resume( servant->mc, p_pos, exception ); MC_EXCEPT(); free( p_pos ); return;}static voidimpl_VLC_MediaControl_stop( impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev ){ mediacontrol_Position *p_pos; mediacontrol_Exception *exception = NULL; p_pos = corba_position_corba_to_c( a_position ); MC_TRY; mediacontrol_pause( servant->mc, p_pos, exception ); MC_EXCEPT(); free( p_pos ); return;}static voidimpl_VLC_MediaControl_exit( impl_POA_VLC_MediaControl * servant,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -