X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fplaylist%2Fservices_discovery.c;h=6f3cda60de2041337b0031dbc5a83bb1bbcc67ae;hb=d666030b2349e8a710fcba4d2cabb912cc700580;hp=2dc578681da16b0c66a6aa56cfec0d76aaa6a653;hpb=f452c11004a9eddf5fa3c9342b44590c936018a1;p=vlc diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c index 2dc578681d..6f3cda60de 100644 --- a/src/playlist/services_discovery.c +++ b/src/playlist/services_discovery.c @@ -20,10 +20,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include + +#include #include "vlc_playlist.h" #include "vlc_events.h" #include "playlist_internal.h" +#include "../libvlc.h" static void RunSD( services_discovery_t *p_sd ); @@ -37,9 +43,11 @@ static void RunSD( services_discovery_t *p_sd ); /*********************************************************************** * GetServicesNames ***********************************************************************/ -char ** services_discovery_GetServicesNames( vlc_object_t * p_super ) +char ** __services_discovery_GetServicesNames( vlc_object_t * p_super, + char ***pppsz_longnames ) { - return module_GetModulesNamesForCapability( p_super, "services_discovery" ); + return module_GetModulesNamesForCapability( p_super, "services_discovery", + pppsz_longnames ); } /*********************************************************************** @@ -48,7 +56,9 @@ char ** services_discovery_GetServicesNames( vlc_object_t * p_super ) services_discovery_t * services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name ) { - services_discovery_t *p_sd = vlc_object_create( p_super, VLC_OBJECT_SD ); + services_discovery_t *p_sd; + p_sd = vlc_custom_create( p_super, sizeof( *p_sd ), VLC_OBJECT_GENERIC, + "services discovery" ); if( !p_sd ) return NULL; @@ -60,17 +70,21 @@ services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name vlc_ServicesDiscoveryItemAdded ); vlc_event_manager_register_event_type( &p_sd->event_manager, vlc_ServicesDiscoveryItemRemoved ); + vlc_event_manager_register_event_type( &p_sd->event_manager, + vlc_ServicesDiscoveryStarted ); + vlc_event_manager_register_event_type( &p_sd->event_manager, + vlc_ServicesDiscoveryEnded ); - p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module_name, VLC_TRUE ); + p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module_name, true ); if( p_sd->p_module == NULL ) { msg_Err( p_super, "no suitable services discovery module" ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); return NULL; } p_sd->psz_module = strdup( psz_module_name ); - p_sd->b_die = VLC_FALSE; /* FIXME */ + p_sd->b_die = false; /* FIXME */ vlc_object_attach( p_sd, p_super ); return p_sd; @@ -87,7 +101,7 @@ void services_discovery_Destroy ( services_discovery_t * p_sd ) free( p_sd->psz_localized_name ); vlc_object_detach( p_sd ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); } /*********************************************************************** @@ -97,10 +111,10 @@ int services_discovery_Start ( services_discovery_t * p_sd ) { if ((p_sd->pf_run != NULL) && vlc_thread_create( p_sd, "services_discovery", RunSD, - VLC_THREAD_PRIORITY_LOW, VLC_FALSE)) + VLC_THREAD_PRIORITY_LOW, false)) { msg_Err( p_sd, "cannot create services discovery thread" ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); return VLC_EGENERIC; } return VLC_SUCCESS; @@ -132,7 +146,7 @@ services_discovery_GetLocalizedName ( services_discovery_t * p_sd ) void services_discovery_SetLocalizedName ( services_discovery_t * p_sd, const char *psz ) { - if(p_sd->psz_localized_name) free( p_sd->psz_localized_name ); + free( p_sd->psz_localized_name ); p_sd->psz_localized_name = strdup(psz); } @@ -178,7 +192,15 @@ services_discovery_RemoveItem ( services_discovery_t * p_sd, input_item_t * p_it ***********************************************************************/ static void RunSD( services_discovery_t *p_sd ) { + vlc_event_t event; + + event.type = vlc_ServicesDiscoveryStarted; + vlc_event_send( &p_sd->event_manager, &event ); + p_sd->pf_run( p_sd ); + + event.type = vlc_ServicesDiscoveryEnded; + vlc_event_send( &p_sd->event_manager, &event ); return; } @@ -214,9 +236,12 @@ static void playlist_sd_item_added( const vlc_event_t * p_event, void * user_dat } p_new_item = playlist_NodeAddInput( p_parent->p_playlist, p_input, p_parent, - PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE ); - p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG; - p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG; + PLAYLIST_APPEND, PLAYLIST_END, false ); + if( p_new_item ) + { + p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG; + p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG; + } } /* A new item has been removed from a certain sd */ @@ -230,11 +255,11 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d * XXX: Why don't we have a function to ensure that in the playlist code ? */ vlc_object_lock( p_parent->p_playlist ); p_pl_item = playlist_ItemFindFromInputAndRoot( p_parent->p_playlist, - p_input->i_id, p_parent, VLC_FALSE ); + p_input->i_id, p_parent, false ); if( p_pl_item && p_pl_item->i_children > -1 ) { - playlist_NodeDelete( p_parent->p_playlist, p_pl_item, VLC_TRUE, VLC_FALSE ); + playlist_NodeDelete( p_parent->p_playlist, p_pl_item, true, false ); vlc_object_unlock( p_parent->p_playlist ); return; } @@ -242,7 +267,7 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d /* Delete the non-node item normally */ playlist_DeleteInputInParent( p_parent->p_playlist, p_input->i_id, - p_parent, VLC_FALSE ); + p_parent, false ); } int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modules ) @@ -280,20 +305,10 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu continue; char * psz = services_discovery_GetLocalizedName( p_sd ); - if( psz ) - { - playlist_NodesPairCreate( p_playlist, psz, - &p_cat, &p_one, VLC_FALSE ); - free( psz ); - } - else - { - /* No name, just add at the top of the playlist */ - PL_LOCK; - p_cat = p_playlist->p_root_category; - p_one = p_playlist->p_root_onelevel; - PL_UNLOCK; - } + assert( psz ); + playlist_NodesPairCreate( p_playlist, psz, + &p_cat, &p_one, false ); + free( psz ); vlc_event_attach( services_discovery_EventManager( p_sd ), vlc_ServicesDiscoveryItemAdded, @@ -387,8 +402,8 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, if( p_sds->p_cat != p_playlist->p_root_category && p_sds->p_one != p_playlist->p_root_onelevel ) { - playlist_NodeDelete( p_playlist, p_sds->p_cat, VLC_TRUE, VLC_FALSE ); - playlist_NodeDelete( p_playlist, p_sds->p_one, VLC_TRUE, VLC_FALSE ); + playlist_NodeDelete( p_playlist, p_sds->p_cat, true, false ); + playlist_NodeDelete( p_playlist, p_sds->p_one, true, false ); } PL_UNLOCK; @@ -397,7 +412,7 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, return VLC_SUCCESS; } -vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, +bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, const char *psz_module ) { int i; @@ -408,10 +423,10 @@ vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) ) { PL_UNLOCK; - return VLC_TRUE; + return true; } } PL_UNLOCK; - return VLC_FALSE; + return false; }