static BOOL hal_enumerate_devices(void) { LibHalContext *ctx; DBusError error; int i, num; char **list; if (!p_libhal_ctx_new) return FALSE; if (!(ctx = p_libhal_ctx_new())) return FALSE; p_libhal_ctx_set_dbus_connection( ctx, connection ); p_libhal_ctx_set_device_added( ctx, hal_new_device ); p_libhal_ctx_set_device_removed( ctx, hal_removed_device ); p_libhal_ctx_set_device_property_modified( ctx, hal_property_modified ); p_dbus_error_init( &error ); if (!p_libhal_ctx_init( ctx, &error )) { WARN( "HAL context init failed: %s\n", error.message ); p_dbus_error_free( &error ); return FALSE; } /* retrieve all existing devices */ if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error ); else { for (i = 0; i < num; i++) hal_new_device( ctx, list[i] ); p_libhal_free_string_array( list ); } return TRUE; }
static DWORD WINAPI hal_thread( void *arg ) { DBusError error; DBusConnection *dbc; LibHalContext *ctx; int i, num; char **list; if (!(ctx = p_libhal_ctx_new())) return 1; p_dbus_error_init( &error ); if (!(dbc = p_dbus_bus_get( DBUS_BUS_SYSTEM, &error ))) { WINE_WARN( "failed to get system dbus connection: %s\n", error.message ); p_dbus_error_free( &error ); return 1; } p_libhal_ctx_set_dbus_connection( ctx, dbc ); p_libhal_ctx_set_device_added( ctx, new_device ); p_libhal_ctx_set_device_removed( ctx, removed_device ); p_libhal_ctx_set_device_property_modified( ctx, property_modified ); if (!p_libhal_ctx_init( ctx, &error )) { WINE_WARN( "HAL context init failed: %s\n", error.message ); p_dbus_error_free( &error ); return 1; } /* retrieve all existing devices */ if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error ); else { for (i = 0; i < num; i++) new_device( ctx, list[i] ); p_libhal_free_string_array( list ); } __TRY { while (p_dbus_connection_read_write_dispatch( dbc, -1 )) /* nothing */ ; } __EXCEPT( assert_fault ) { WINE_WARN( "dbus assertion failure, disabling HAL support\n" ); return 1; } __ENDTRY; p_libhal_ctx_shutdown( ctx, &error ); p_dbus_error_free( &error ); /* just in case */ p_dbus_connection_close( dbc ); p_libhal_ctx_free( ctx ); return 0; }