]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/hal.c
Restore SD human-readable names
[vlc] / modules / services_discovery / hal.c
index b45b5fdee0485db9e789c5b4fa601b05a91dddae..a4ef70320758279d6d35a35801755cb42cd5ea0c 100644 (file)
@@ -59,13 +59,13 @@ struct udi_input_id_t
 
 struct services_discovery_sys_t
 {
+    vlc_thread_t            thread;
     LibHalContext           *p_ctx;
     DBusConnection          *p_connection;
     int                     i_devices_number;
     struct udi_input_id_t   **pp_devices;
 };
-static void Run    ( services_discovery_t *p_intf );
-
+static void *Run ( void * );
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
@@ -79,15 +79,15 @@ services_discovery_t        *p_sd_global;
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_description( N_("HAL devices detection") );
-    set_category( CAT_PLAYLIST );
-    set_subcategory( SUBCAT_PLAYLIST_SD );
+vlc_module_begin ()
+    set_description( N_("HAL devices detection") )
+    set_category( CAT_PLAYLIST )
+    set_subcategory( SUBCAT_PLAYLIST_SD )
 
-    set_capability( "services_discovery", 0 );
-    set_callbacks( Open, Close );
+    set_capability( "services_discovery", 0 )
+    set_callbacks( Open, Close )
 
-vlc_module_end();
+vlc_module_end ()
 
 
 /*****************************************************************************
@@ -108,7 +108,6 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_devices_number = 0;
     p_sys->pp_devices = NULL;
 
-    p_sd->pf_run = Run;
     p_sd->p_sys  = p_sys;
 
     dbus_error_init( &dbus_error );
@@ -133,23 +132,24 @@ static int Open( vlc_object_t *p_this )
     if( !libhal_ctx_init( p_sys->p_ctx, &dbus_error ) )
     {
         msg_Err( p_sd, "hal not available : %s", dbus_error.message );
-        dbus_error_free( &dbus_error );
-        free( p_sys );
-        return VLC_EGENERIC;
+        goto error;
     }
 
     if( !libhal_ctx_set_device_added( p_sys->p_ctx, DeviceAdded ) ||
             !libhal_ctx_set_device_removed( p_sys->p_ctx, DeviceRemoved ) )
     {
         msg_Err( p_sd, "unable to add callback" );
-        dbus_error_free( &dbus_error );
-        free( p_sys );
-        return VLC_EGENERIC;
+        goto error;
     }
 
-    services_discovery_SetLocalizedName( p_sd, _("Devices") );
+    if( vlc_clone( &p_sys->thread, Run, p_this, VLC_THREAD_PRIORITY_LOW ) )
+        goto error;
 
     return VLC_SUCCESS;
+error:
+    dbus_error_free( &dbus_error );
+    free( p_sys );
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************
@@ -160,6 +160,9 @@ static void Close( vlc_object_t *p_this )
     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
     services_discovery_sys_t *p_sys  = p_sd->p_sys;
 
+    /*vlc_cancel( p_sys->thread );*/
+    vlc_object_kill( p_sd );
+    vlc_join( p_sys->thread, NULL );
     dbus_connection_unref( p_sys->p_connection );
     struct udi_input_id_t *p_udi_entry;
 
@@ -295,11 +298,13 @@ static void ParseDevice( services_discovery_t *p_sd, const char *psz_device )
 /*****************************************************************************
  * Run: main HAL thread
  *****************************************************************************/
-static void Run( services_discovery_t *p_sd )
+static void *Run( void *data )
 {
-    int i, i_devices;
+    services_discovery_t     *p_sd  = data;
+    services_discovery_sys_t *p_sys = p_sd->p_sys;
     char **devices;
-    services_discovery_sys_t    *p_sys  = p_sd->p_sys;
+    int i, i_devices;
+    int canc = vlc_savecancel();
 
     /* parse existing devices first */
     if( ( devices = libhal_get_all_devices( p_sys->p_ctx, &i_devices, NULL ) ) )
@@ -310,12 +315,17 @@ static void Run( services_discovery_t *p_sd )
             libhal_free_string( devices[ i ] );
         }
     }
+
+    /* FIXME: Totally lame. There are DBus watch functions to do this properly.
+     * -- Courmisch, 28/08/2008 */
     while( vlc_object_alive (p_sd) )
     {
         /* look for events on the bus, blocking 1 second */
         dbus_connection_read_write_dispatch( p_sys->p_connection, 1000 );
         /* HAL 0.5.8.1 can use libhal_ctx_get_dbus_connection(p_sys->p_ctx) */
     }
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 void DeviceAdded( LibHalContext *p_ctx, const char *psz_udi )