* That's how the playlist get's Service Discovery information
*/
-/***********************************************************************
- * GetServicesNames
- ***********************************************************************/
-char ** __services_discovery_GetServicesNames( vlc_object_t * p_super,
- char ***pppsz_longnames )
+/**
+ * Gets the list of available services discovery plugins.
+ */
+char **vlc_sd_GetNames( char ***pppsz_longnames )
{
return module_GetModulesNamesForCapability( "services_discovery",
pppsz_longnames );
/* First make sure that if item is a node it will be deleted.
* XXX: Why don't we have a function to ensure that in the playlist code ? */
- vlc_object_lock( p_parent->p_playlist );
+ playlist_Lock( p_parent->p_playlist );
p_pl_item = playlist_ItemFindFromInputAndRoot( p_parent->p_playlist,
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, true, false );
- vlc_object_unlock( p_parent->p_playlist );
- return;
- }
-
- /* Delete the non-node item normally */
- playlist_DeleteFromInputInParent( p_parent->p_playlist, p_input->i_id,
- p_parent, pl_Locked );
+ else
+ /* Delete the non-node item normally */
+ playlist_DeleteFromInputInParent( p_parent->p_playlist, p_input,
+ p_parent, pl_Locked );
- vlc_object_unlock( p_parent->p_playlist );
+ playlist_Unlock( p_parent->p_playlist );
}
-int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modules )
+int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_module )
{
- const char *psz_parser = psz_modules ?: "";
+ /* Perform the addition */
+ msg_Dbg( p_playlist, "adding services_discovery %s...", psz_module );
+
+ services_discovery_t *p_sd = vlc_sd_Create( VLC_OBJECT(p_playlist) );
+ if( !p_sd )
+ return VLC_ENOMEM;
- for (;;)
+ module_t *m = module_find_by_shortcut( psz_module );
+ if( !m )
{
- struct playlist_services_discovery_support_t * p_sds;
- playlist_item_t * p_cat;
- playlist_item_t * p_one;
+ msg_Err( p_playlist, "No such module: %s", psz_module );
+ vlc_sd_Destroy( p_sd );
+ return VLC_EGENERIC;
+ }
- while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' )
- psz_parser++;
+ /* Free in playlist_ServicesDiscoveryRemove */
+ struct playlist_services_discovery_support_t * p_sds;
+ p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
+ if( !p_sds )
+ {
+ vlc_sd_Destroy( p_sd );
+ module_release( m );
+ return VLC_ENOMEM;
+ }
- if( *psz_parser == '\0' )
- break;
+ playlist_item_t * p_cat;
+ playlist_item_t * p_one;
- const char *psz_next = strchr( psz_parser, ':' );
- if( psz_next == NULL )
- psz_next = psz_parser + strlen( psz_parser );
+ PL_LOCK;
+ playlist_NodesPairCreate( p_playlist, module_get_name( m, true ),
+ &p_cat, &p_one, false );
+ PL_UNLOCK;
+ module_release( m );
- char psz_plugin[psz_next - psz_parser + 1];
- memcpy (psz_plugin, psz_parser, sizeof (psz_plugin) - 1);
- psz_plugin[sizeof (psz_plugin) - 1] = '\0';
- psz_parser = psz_next;
+ vlc_event_attach( services_discovery_EventManager( p_sd ),
+ vlc_ServicesDiscoveryItemAdded,
+ playlist_sd_item_added, p_one );
+
+ vlc_event_attach( services_discovery_EventManager( p_sd ),
+ vlc_ServicesDiscoveryItemAdded,
+ playlist_sd_item_added, p_cat );
- /* Perform the addition */
- msg_Dbg( p_playlist, "Add services_discovery %s", psz_plugin );
- services_discovery_t *p_sd;
+ vlc_event_attach( services_discovery_EventManager( p_sd ),
+ vlc_ServicesDiscoveryItemRemoved,
+ playlist_sd_item_removed, p_one );
- p_sd = vlc_sd_Create( (vlc_object_t*)p_playlist );
- if( !p_sd )
- return VLC_ENOMEM;
+ vlc_event_attach( services_discovery_EventManager( p_sd ),
+ vlc_ServicesDiscoveryItemRemoved,
+ playlist_sd_item_removed, p_cat );
- /* Free in playlist_ServicesDiscoveryRemove */
- p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
- if( !p_sds )
- {
- vlc_sd_Destroy( p_sd );
- return VLC_ENOMEM;
- }
+ if( !vlc_sd_Start( p_sd, psz_module ) )
+ {
+ vlc_sd_Destroy( p_sd );
+ free( p_sds );
+ return VLC_EGENERIC;
+ }
- vlc_event_attach( services_discovery_EventManager( p_sd ),
- vlc_ServicesDiscoveryItemAdded,
- playlist_sd_item_added,
- p_one );
-
- vlc_event_attach( services_discovery_EventManager( p_sd ),
- vlc_ServicesDiscoveryItemAdded,
- playlist_sd_item_added,
- p_cat );
-
- vlc_event_attach( services_discovery_EventManager( p_sd ),
- vlc_ServicesDiscoveryItemRemoved,
- playlist_sd_item_removed,
- p_one );
-
- vlc_event_attach( services_discovery_EventManager( p_sd ),
- vlc_ServicesDiscoveryItemRemoved,
- playlist_sd_item_removed,
- p_cat );
-
- if( !vlc_sd_Start( p_sd, psz_plugin ) )
- {
- vlc_sd_Destroy( p_sd );
- free( p_sds );
- return VLC_EGENERIC;
- }
-
- char *psz = services_discovery_GetLocalizedName( p_sd );
- assert( psz );
- PL_LOCK;
- playlist_NodesPairCreate( p_playlist, psz,
- &p_cat, &p_one, false );
- PL_UNLOCK;
- free( psz );
-
-
- /* We want tree-view for service directory */
- p_one->p_input->b_prefers_tree = true;
- p_sds->p_sd = p_sd;
- p_sds->p_one = p_one;
- p_sds->p_cat = p_cat;
-
- PL_LOCK;
- TAB_APPEND( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds, p_sds );
- PL_UNLOCK;
+ /* We want tree-view for service directory */
+ p_one->p_input->b_prefers_tree = true;
+ p_sds->p_sd = p_sd;
+ p_sds->p_one = p_one;
+ p_sds->p_cat = p_cat;
- }
+ PL_LOCK;
+ TAB_APPEND( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds, p_sds );
+ PL_UNLOCK;
return VLC_SUCCESS;
}