📄 dbus.c
字号:
if( dbus_error_is_set( &error ) ) { msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } p_playlist = pl_Yield( (vlc_object_t*) p_this ); playlist_Add( p_playlist, psz_mrl, NULL, PLAYLIST_APPEND | ( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) , PLAYLIST_END, true, false ); pl_Release( (vlc_object_t*) p_this ); dbus_int32_t i_success = 0; ADD_INT32( &i_success ); REPLY_SEND;}DBUS_METHOD( GetCurrentTrack ){ REPLY_INIT; OUT_ARGUMENTS; playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this ); dbus_int32_t i_position = p_playlist->i_current_index; pl_Release( (vlc_object_t*) p_this ); ADD_INT32( &i_position ); REPLY_SEND;}DBUS_METHOD( GetMetadata ){ REPLY_INIT; OUT_ARGUMENTS; DBusError error; dbus_error_init( &error ); dbus_int32_t i_position; playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this ); PL_LOCK; dbus_message_get_args( p_from, &error, DBUS_TYPE_INT32, &i_position, DBUS_TYPE_INVALID ); if( dbus_error_is_set( &error ) ) { PL_UNLOCK; pl_Release( (vlc_object_t*) p_this ); msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } if( i_position < p_playlist->current.i_size ) { GetInputMeta( p_playlist->current.p_elems[i_position]->p_input, &args ); } PL_UNLOCK; pl_Release( (vlc_object_t*) p_this ); REPLY_SEND;}DBUS_METHOD( GetLength ){ REPLY_INIT; OUT_ARGUMENTS; playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this ); dbus_int32_t i_elements = p_playlist->current.i_size; pl_Release( (vlc_object_t*) p_this ); ADD_INT32( &i_elements ); REPLY_SEND;}DBUS_METHOD( DelTrack ){ REPLY_INIT; DBusError error; dbus_error_init( &error ); dbus_int32_t i_position; playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this ); dbus_message_get_args( p_from, &error, DBUS_TYPE_INT32, &i_position, DBUS_TYPE_INVALID ); if( dbus_error_is_set( &error ) ) { msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } PL_LOCK; if( i_position < p_playlist->current.i_size ) { playlist_DeleteFromInput( p_playlist, p_playlist->current.p_elems[i_position]->p_input->i_id, pl_Locked ); } PL_UNLOCK; pl_Release( (vlc_object_t*) p_this ); REPLY_SEND;}DBUS_METHOD( SetLoop ){ REPLY_INIT; OUT_ARGUMENTS; DBusError error; dbus_bool_t b_loop; vlc_value_t val; playlist_t* p_playlist = NULL; dbus_error_init( &error ); dbus_message_get_args( p_from, &error, DBUS_TYPE_BOOLEAN, &b_loop, DBUS_TYPE_INVALID ); if( dbus_error_is_set( &error ) ) { msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } val.b_bool = ( b_loop == TRUE ) ? true : false ; p_playlist = pl_Yield( (vlc_object_t*) p_this ); var_Set ( p_playlist, "loop", val ); pl_Release( ((vlc_object_t*) p_this) ); REPLY_SEND;}DBUS_METHOD( Repeat ){ REPLY_INIT; OUT_ARGUMENTS; DBusError error; dbus_bool_t b_repeat; vlc_value_t val; playlist_t* p_playlist = NULL; dbus_error_init( &error ); dbus_message_get_args( p_from, &error, DBUS_TYPE_BOOLEAN, &b_repeat, DBUS_TYPE_INVALID ); if( dbus_error_is_set( &error ) ) { msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } val.b_bool = ( b_repeat == TRUE ) ? true : false ; p_playlist = pl_Yield( (vlc_object_t*) p_this ); var_Set ( p_playlist, "repeat", val ); pl_Release( ((vlc_object_t*) p_this) ); REPLY_SEND;}DBUS_METHOD( SetRandom ){ REPLY_INIT; OUT_ARGUMENTS; DBusError error; dbus_bool_t b_random; vlc_value_t val; playlist_t* p_playlist = NULL; dbus_error_init( &error ); dbus_message_get_args( p_from, &error, DBUS_TYPE_BOOLEAN, &b_random, DBUS_TYPE_INVALID ); if( dbus_error_is_set( &error ) ) { msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n", error.message ); dbus_error_free( &error ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } val.b_bool = ( b_random == TRUE ) ? true : false ; p_playlist = pl_Yield( (vlc_object_t*) p_this ); var_Set ( p_playlist, "random", val ); pl_Release( ((vlc_object_t*) p_this) ); REPLY_SEND;}/***************************************************************************** * Introspection method *****************************************************************************/DBUS_METHOD( handle_introspect_root ){ /* handles introspection of root object */ VLC_UNUSED(p_this); REPLY_INIT; OUT_ARGUMENTS; ADD_STRING( &psz_introspection_xml_data_root ); REPLY_SEND;}DBUS_METHOD( handle_introspect_player ){ VLC_UNUSED(p_this); REPLY_INIT; OUT_ARGUMENTS; ADD_STRING( &psz_introspection_xml_data_player ); REPLY_SEND;}DBUS_METHOD( handle_introspect_tracklist ){ VLC_UNUSED(p_this); REPLY_INIT; OUT_ARGUMENTS; ADD_STRING( &psz_introspection_xml_data_tracklist ); REPLY_SEND;}/***************************************************************************** * handle_*: answer to incoming messages *****************************************************************************/#define METHOD_FUNC( method, function ) \ else if( dbus_message_is_method_call( p_from, MPRIS_DBUS_INTERFACE, method ) )\ return function( p_conn, p_from, p_this )DBUS_METHOD( handle_root ){ if( dbus_message_is_method_call( p_from, DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) ) return handle_introspect_root( p_conn, p_from, p_this ); /* here D-Bus method's names are associated to an handler */ METHOD_FUNC( "Identity", Identity ); METHOD_FUNC( "MprisVersion", MprisVersion ); METHOD_FUNC( "Quit", Quit ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;}DBUS_METHOD( handle_player ){ if( dbus_message_is_method_call( p_from, DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) ) return handle_introspect_player( p_conn, p_from, p_this ); /* here D-Bus method's names are associated to an handler */ METHOD_FUNC( "Prev", Prev ); METHOD_FUNC( "Next", Next ); METHOD_FUNC( "Stop", Stop ); METHOD_FUNC( "Play", Play ); METHOD_FUNC( "Pause", Pause ); METHOD_FUNC( "Repeat", Repeat ); METHOD_FUNC( "VolumeSet", VolumeSet ); METHOD_FUNC( "VolumeGet", VolumeGet ); METHOD_FUNC( "PositionSet", PositionSet ); METHOD_FUNC( "PositionGet", PositionGet ); METHOD_FUNC( "GetStatus", GetStatus ); METHOD_FUNC( "GetMetadata", GetCurrentMetadata ); METHOD_FUNC( "GetCaps", GetCaps ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;}DBUS_METHOD( handle_tracklist ){ if( dbus_message_is_method_call( p_from, DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) ) return handle_introspect_tracklist( p_conn, p_from, p_this ); /* here D-Bus method's names are associated to an handler */ METHOD_FUNC( "GetMetadata", GetMetadata ); METHOD_FUNC( "GetCurrentTrack", GetCurrentTrack ); METHOD_FUNC( "GetLength", GetLength ); METHOD_FUNC( "AddTrack", AddTrack ); METHOD_FUNC( "DelTrack", DelTrack ); METHOD_FUNC( "SetLoop", SetLoop ); METHOD_FUNC( "SetRandom", SetRandom ); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;}/***************************************************************************** * Open: initialize interface *****************************************************************************/static int Open( vlc_object_t *p_this ){ /* initialisation of the connection */ intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) ); playlist_t *p_playlist; DBusConnection *p_conn; DBusError error; if( !p_sys ) return VLC_ENOMEM; p_sys->b_meta_read = false; p_sys->i_caps = CAPS_NONE; dbus_error_init( &error ); /* connect to the session bus */ p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error ); if( !p_conn ) { msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s", error.message ); dbus_error_free( &error ); free( p_sys ); return VLC_EGENERIC; } /* register a well-known name on the bus */ dbus_bus_request_name( p_conn, VLC_MPRIS_DBUS_SERVICE, 0, &error ); if( dbus_error_is_set( &error ) ) { msg_Err( p_this, "Error requesting service " VLC_MPRIS_DBUS_SERVICE ": %s", error.message ); dbus_error_free( &error ); free( p_sys ); return VLC_EGENERIC; } /* we register the objects */ dbus_connection_register_object_path( p_conn, MPRIS_DBUS_ROOT_PATH, &vlc_dbus_root_vtable, p_this ); dbus_connection_register_object_path( p_conn, MPRIS_DBUS_PLAYER_PATH, &vlc_dbus_player_vtable, p_this ); dbus_connection_register_object_path( p_conn, MPRIS_DBUS_TRACKLIST_PATH, &vlc_dbus_tracklist_vtable, p_this ); dbus_connection_flush( p_conn ); p_playlist = pl_Yield( p_intf ); PL_LOCK; var_AddCallback( p_playlist, "playlist-current", TrackChange, p_intf ); var_AddCallback( p_playlist, "intf-change", TrackListChangeEmit, p_intf ); var_AddCallback( p_playlist, "item-append", TrackListChangeEmit, p_intf ); var_AddCallback( p_playlist, "item-deleted", TrackListChangeEmit, p_intf ); var_AddCallback( p_playlist, "random", StatusChangeEmit, p_intf ); var_AddCallback( p_playlist, "repeat", StatusChangeEmit, p_intf ); var_AddCallback( p_playlist, "loop", StatusChangeEmit, p_intf ); PL_UNLOCK; pl_Release( p_intf ); p_intf->pf_run = Run; p_intf->p_sys = p_sys; p_sys->p_conn = p_conn; UpdateCaps( p_intf, false ); return VLC_SUCCESS;}/***************************************************************************** * Close: destroy interface *****************************************************************************/static void Close ( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t*) p_this; playlist_t *p_playlist = pl_Yield( p_intf );; input_thread_t *p_input; p_this->b_dead = true; PL_LOCK; var_DelCallback( p_playlist, "playlist-current", TrackChange, p_intf ); var_DelCallback( p_playlist, "intf-change", TrackListChangeEmit, p_intf );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -