]> git.sesse.net Git - vlc/blobdiff - src/playlist/services_discovery.c
Qt: efficient iconView browsing demands a specialized playlist event
[vlc] / src / playlist / services_discovery.c
index aaa46688b63709a1d3848a2f412248f80a49858d..355dffb7f1483b9d7d60c697bbc0e50147a6e537 100644 (file)
 #include "vlc_playlist.h"
 #include "vlc_events.h"
 #include <vlc_services_discovery.h>
+#include <vlc_probe.h>
 #include "playlist_internal.h"
 #include "../libvlc.h"
 
+typedef struct
+{
+    char *name;
+    char *longname;
+} vlc_sd_probe_t;
 
-/*
- * Services discovery
- * Basically you just listen to Service discovery event through the
- * sd's event manager.
- * That's how the playlist get's Service Discovery information
- */
+int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name,
+                      const char *longname)
+{
+    vlc_sd_probe_t names = { strdup(name), strdup(longname) };
+
+    if (unlikely (names.name == NULL || names.longname == NULL
+               || vlc_probe_add (probe, &names, sizeof (names))))
+    {
+        free (names.name);
+        free (names.longname);
+        return VLC_ENOMEM;
+    }
+    return VLC_PROBE_CONTINUE;
+}
+
+#undef vlc_sd_GetNames
 
 /**
  * Gets the list of available services discovery plugins.
  */
-char **vlc_sd_GetNames( char ***pppsz_longnames )
+char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames)
 {
-    return module_GetModulesNamesForCapability( "services_discovery",
-                                                pppsz_longnames );
+    size_t count;
+    vlc_sd_probe_t *tab = vlc_probe (obj, "services probe", &count);
+
+    if (count == 0)
+    {
+        free (tab);
+        return NULL;
+    }
+
+    char **names = malloc (sizeof(char *) * (count + 1));
+    char **longnames = malloc (sizeof(char *) * (count + 1));
+
+    if (unlikely (names == NULL || longnames == NULL))
+        abort();
+    for( size_t i = 0; i < count; i++ )
+    {
+        names[i] = tab[i].name;
+        longnames[i] = tab[i].longname;
+    }
+    free (tab);
+    names[count] = longnames[count] = NULL;
+    *pppsz_longnames = longnames;
+    return names;
 }
 
+
+struct vlc_sd_internal_t
+{
+    /* the playlist items for category and onelevel */
+    playlist_item_t      *p_cat;
+    playlist_item_t      *p_one;
+    services_discovery_t *p_sd; /**< Loaded service discovery modules */
+    char                 *psz_name;
+};
+
+static void services_discovery_Destructor ( vlc_object_t *p_obj );
+
+/*
+ * Services discovery
+ * Basically you just listen to Service discovery event through the
+ * sd's event manager.
+ * That's how the playlist get's Service Discovery information
+ */
+
 /***********************************************************************
  * Create
  ***********************************************************************/
@@ -71,6 +127,7 @@ services_discovery_t *vlc_sd_Create( vlc_object_t *p_super )
     vlc_event_manager_register_event_type( &p_sd->event_manager,
             vlc_ServicesDiscoveryEnded );
 
+    vlc_object_set_destructor( p_sd, services_discovery_Destructor );
     vlc_object_attach( p_sd, p_super );
 
     return p_sd;
@@ -113,6 +170,16 @@ void vlc_sd_Stop ( services_discovery_t * p_sd )
     p_sd->p_module = NULL;
 }
 
+/***********************************************************************
+ * Destructor
+ ***********************************************************************/
+static void services_discovery_Destructor ( vlc_object_t *p_obj )
+{
+    services_discovery_t * p_sd = (services_discovery_t *)p_obj;
+    assert(!p_sd->p_module); /* Forgot to call Stop */
+    vlc_event_manager_fini( &p_sd->event_manager );
+}
+
 /***********************************************************************
  * GetLocalizedName
  ***********************************************************************/
@@ -243,8 +310,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modul
     }
 
     /* Free in playlist_ServicesDiscoveryRemove */
-    struct playlist_services_discovery_support_t * p_sds;
-    p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
+    vlc_sd_internal_t * p_sds = malloc( sizeof(*p_sds) );
     if( !p_sds )
     {
         vlc_sd_Destroy( p_sd );
@@ -302,7 +368,7 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
                                       const char *psz_name )
 {
     playlist_private_t *priv = pl_priv( p_playlist );
-    struct playlist_services_discovery_support_t * p_sds = NULL;
+    vlc_sd_internal_t * p_sds = NULL;
 
     PL_LOCK;
     for( int i = 0; i < priv->i_sds; i++ )