X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fservices_discovery%2Fhal.c;h=a8241bd85a5941ac9e23680e3673e42733b819f5;hb=da8ac5627f3cc9a99a9b8945ab71107843afd684;hp=3d6c32e4283345ab3ac59f8255af878bb0e0ed87;hpb=c6d9fff0be9732e0e2bc116525c115e20acd0b13;p=vlc diff --git a/modules/services_discovery/hal.c b/modules/services_discovery/hal.c index 3d6c32e428..a8241bd85a 100644 --- a/modules/services_discovery/hal.c +++ b/modules/services_discovery/hal.c @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -59,13 +60,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 +80,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 () /***************************************************************************** @@ -102,13 +103,12 @@ static int Open( vlc_object_t *p_this ) return VLC_ENOMEM; DBusError dbus_error; - DBusConnection *p_connection; + DBusConnection *p_connection = NULL; p_sd_global = p_sd; 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 ); @@ -124,32 +124,34 @@ static int Open( vlc_object_t *p_this ) if( dbus_error_is_set( &dbus_error ) ) { msg_Err( p_sd, "unable to connect to DBUS: %s", dbus_error.message ); - dbus_error_free( &dbus_error ); - free( p_sys ); - return VLC_EGENERIC; + goto error; } libhal_ctx_set_dbus_connection( p_sys->p_ctx, p_connection ); p_sys->p_connection = p_connection; 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: + if( p_connection ) + dbus_connection_unref( p_connection ); + dbus_error_free( &dbus_error ); + libhal_ctx_free( p_sys->p_ctx ); + free( p_sys ); + return VLC_EGENERIC; } /***************************************************************************** @@ -160,6 +162,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; @@ -173,6 +178,8 @@ static void Close( vlc_object_t *p_this ) } p_sys->pp_devices = NULL; + libhal_ctx_free( p_sys->p_ctx ); + free( p_sys ); } @@ -295,11 +302,12 @@ 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 */ @@ -310,6 +318,7 @@ static void Run( services_discovery_t *p_sd ) ParseDevice( p_sd, devices[ i ] ); libhal_free_string( devices[ i ] ); } + free( devices ); } /* FIXME: Totally lame. There are DBus watch functions to do this properly. @@ -321,6 +330,7 @@ static void Run( services_discovery_t *p_sd ) /* 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 )