Index: src/th-device-pool.c =================================================================== RCS file: /cvsroot/thoggen/thoggen/src/th-device-pool.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -p -r1.4 -r1.5 --- src/th-device-pool.c 6 Jan 2005 20:23:47 -0000 1.4 +++ src/th-device-pool.c 4 Apr 2005 13:06:20 -0000 1.5 @@ -88,23 +88,33 @@ static void dp_hal_device_prop dbus_bool_t is_removed, dbus_bool_t is_added); +#ifndef USE_NEW_DBUS_HAL_API + static void dp_hal_device_condition_cb (LibHalContext *ctx, const char *udi, const char *cond_name, DBusMessage *msg); +#else + +static void dp_hal_device_condition_cb (LibHalContext *ctx, + const char *udi, + const char *cond_name, + const char *cond_detail); + +#endif /* variables */ static GObjectClass *dp_parent_class; /* NULL */ - /*************************************************************************** * * disc_drive_hal_cb_funcs * ***************************************************************************/ +#ifndef USE_NEW_DBUS_HAL_API static const LibHalFunctions disc_drive_hal_cb_funcs = { dp_hal_main_loop_hook_cb, /* main loop integration */ @@ -115,6 +125,7 @@ static const LibHalFunctions disc_drive_ dp_hal_device_prop_mod_cb, /* device property modified */ dp_hal_device_condition_cb /* device condiiton */ }; +#endif /* USE_NEW_DBUS_HAL_API */ /*************************************************************************** * @@ -194,8 +205,38 @@ device_pool_instance_init (ThDevicePool pool->priv = g_new0 (ThDevicePoolPrivate, 1); +#ifdef USE_NEW_DBUS_HAL_API + new_hal_ctx = libhal_ctx_new(); + libhal_ctx_set_cache (new_hal_ctx, TRUE); + libhal_ctx_set_device_added (new_hal_ctx, dp_hal_device_added_cb); + libhal_ctx_set_device_removed (new_hal_ctx, dp_hal_device_removed_cb); + libhal_ctx_set_device_new_capability (new_hal_ctx, dp_hal_device_new_cap_cb); + libhal_ctx_set_device_lost_capability (new_hal_ctx, dp_hal_device_lost_cap_cb); + libhal_ctx_set_device_property_modified (new_hal_ctx, dp_hal_device_prop_mod_cb); + libhal_ctx_set_device_condition (new_hal_ctx, dp_hal_device_condition_cb); + + { + DBusConnection *conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) + { + g_warning ("dbus_bus_get(DBUS_BUS_SYSTEM) failed at %s!\n", G_STRLOC); + } + else + { + libhal_ctx_set_dbus_connection (new_hal_ctx, conn); + dp_hal_main_loop_hook_cb (new_hal_ctx, conn); + } + } + + if (!libhal_ctx_init (new_hal_ctx, NULL)) + g_warning ("libhal_ctx_init() failed at %s!\n", G_STRLOC); + +#else + new_hal_ctx = hal_initialize (&disc_drive_hal_cb_funcs, TRUE); +#endif /* USE_NEW_DBUS_HAL_API */ + /* we will get a NULL context if libhal cannot connect * to the dbus message bus. we will get a valid context @@ -236,8 +277,14 @@ device_pool_finalize (GObject *object) if (pool->priv->hal_ctx) { +#ifndef USE_NEW_DBUS_HAL_API if (hal_shutdown (pool->priv->hal_ctx) != 0) - g_printerr ("ThDevicePool: hal_shutdown() problem!?\n"); + g_printerr ("ThDevicePool: hal_shutdown() problem!\n"); +#else + if (!libhal_ctx_shutdown (pool->priv->hal_ctx, NULL)) + g_printerr ("ThDevicePool: libhal_ctx_shutdown() problem!\n"); + libhal_ctx_free (pool->priv->hal_ctx); +#endif } for (l = pool->priv->trackers; l; l = l->next) @@ -312,7 +359,34 @@ dp_reconnect_to_hal_cb (ThDevicePool *po g_message ("Trying to reconnect to HAL..."); +#ifdef USE_NEW_DBUS_HAL_API + new_hal_ctx = libhal_ctx_new(); + libhal_ctx_set_cache (new_hal_ctx, TRUE); + libhal_ctx_set_device_added (new_hal_ctx, dp_hal_device_added_cb); + libhal_ctx_set_device_removed (new_hal_ctx, dp_hal_device_removed_cb); + libhal_ctx_set_device_new_capability (new_hal_ctx, dp_hal_device_new_cap_cb); + libhal_ctx_set_device_lost_capability (new_hal_ctx, dp_hal_device_lost_cap_cb); + libhal_ctx_set_device_property_modified (new_hal_ctx, dp_hal_device_prop_mod_cb); + libhal_ctx_set_device_condition (new_hal_ctx, dp_hal_device_condition_cb); + + { + DBusConnection *conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) + { + g_warning ("dbus_bus_get(DBUS_BUS_SYSTEM) failed at %s!\n", G_STRLOC); + } + else + { + libhal_ctx_set_dbus_connection (new_hal_ctx, conn); + dp_hal_main_loop_hook_cb (new_hal_ctx, conn); + } + } + + if (!libhal_ctx_init (new_hal_ctx, NULL)) + g_warning ("libhal_ctx_init() failed at %s!\n", G_STRLOC); +#else new_hal_ctx = hal_initialize (&disc_drive_hal_cb_funcs, TRUE); +#endif if (new_hal_ctx) { @@ -517,6 +591,8 @@ dp_hal_device_prop_mod_cb (LibHalContext * ***************************************************************************/ +#ifndef USE_NEW_DBUS_HAL_API + static void dp_hal_device_condition_cb (LibHalContext *ctx, const char *udi, const char *cond_name, DBusMessage *msg) { @@ -534,6 +610,27 @@ dp_hal_device_condition_cb (LibHalContex } } +#else /* USE_NEW_DBUS_HAL_API */ + +static void +dp_hal_device_condition_cb (LibHalContext *ctx, const char *udi, const char *cond_name, const char *msg_detail) +{ + ThDevicePool *pool; + GList *l; + + pool = hal_ctx_get_device_pool (ctx); + g_return_if_fail (TH_IS_DEVICE_POOL (pool)); + + for (l = pool->priv->trackers; l; l = l->next) + { + ThDeviceTracker *tracker = TH_DEVICE_TRACKER (l->data); + + th_device_tracker_dev_condition (tracker, udi, cond_name, msg_detail); + } +} + +#endif /* USE_NEW_DBUS_HAL_API */ + /*************************************************************************** * * device_pool_device_is_volume Index: src/th-device-tracker.c =================================================================== RCS file: /cvsroot/thoggen/thoggen/src/th-device-tracker.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -p -r1.1.1.1 -r1.2 --- src/th-device-tracker.c 25 Nov 2004 18:06:32 -0000 1.1.1.1 +++ src/th-device-tracker.c 4 Apr 2005 13:06:21 -0000 1.2 @@ -196,6 +196,8 @@ th_device_tracker_prop_mod (ThDeviceTrac * ***************************************************************************/ +#ifndef USE_NEW_DBUS_HAL_API + void th_device_tracker_dev_condition (ThDeviceTracker *tracker, const gchar *udi, @@ -211,4 +213,21 @@ th_device_tracker_dev_condition (ThDevic TH_DEVICE_TRACKER_GET_IFACE (tracker)->dev_condition (tracker, udi, cond_name, msg); } +#else + +void +th_device_tracker_dev_condition (ThDeviceTracker *tracker, + const gchar *udi, + const gchar *cond_name, + const gchar *cond_detail) +{ + g_return_if_fail (TH_IS_DEVICE_TRACKER (tracker)); + g_return_if_fail (udi != NULL); + g_return_if_fail (cond_name != NULL); + + if (TH_DEVICE_TRACKER_GET_IFACE (tracker)->dev_condition != NULL) + TH_DEVICE_TRACKER_GET_IFACE (tracker)->dev_condition (tracker, udi, cond_name, cond_detail); +} + +#endif /* USE_NEW_DBUS_HAL_API */ Index: src/th-device-tracker.h =================================================================== RCS file: /cvsroot/thoggen/thoggen/src/th-device-tracker.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -p -r1.1.1.1 -r1.2 --- src/th-device-tracker.h 25 Nov 2004 18:06:32 -0000 1.1.1.1 +++ src/th-device-tracker.h 4 Apr 2005 13:06:21 -0000 1.2 @@ -21,6 +21,39 @@ #include #include +#include +/* dbus-glib >= 0.30 */ +#ifdef DBUS_TYPE_PENDING_CALL +# define USE_NEW_DBUS_HAL_API +# warning **************************************************************** +# warning * +# warning * It seems like you are using dbus >= 0.30 and hal >= 0.5.0 +# warning * +# warning * Please be advised that this code has not been tested with +# warning * this configuration yet, it has just been fixed to compile. +# warning * +# warning * Please let me know whether DVD drive detection works on +# warning * your system, and please do send the log as well (so I +# warning * can see whether the drives were actually detected via +# warning * HAL or using the backup methods). Thanks! +# warning * +# warning **************************************************************** +#endif + +#ifdef USE_NEW_DBUS_HAL_API +# define hal_ctx_get_user_data(ctx) libhal_ctx_get_user_data(ctx) +# define hal_ctx_set_user_data(ctx,user_data) libhal_ctx_set_user_data(ctx,user_data) +# define hal_device_exists(ctx,udi) libhal_device_exists(ctx,udi,NULL) +# define hal_device_property_exists(ctx,udi,key) libhal_device_property_exists(ctx,udi,key,NULL) +# define hal_device_get_property_string(ctx,udi,key) libhal_device_get_property_string(ctx,udi,key,NULL) +# define hal_device_get_property_uint64(ctx,udi,key) libhal_device_get_property_uint64(ctx,udi,key,NULL) +# define hal_device_get_property_bool(ctx,udi,key) libhal_device_get_property_bool(ctx,udi,key,NULL) +# define hal_free_string(s) libhal_free_string(s) +# define hal_free_string_array(str_arr) libhal_free_string_array(str_arr) +# define hal_get_all_devices(ctx,p_num_devices) libhal_get_all_devices(ctx,p_num_devices,NULL) +# define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL DBUS_INTERFACE_LOCAL +#endif + #define TH_TYPE_DEVICE_TRACKER (th_device_tracker_get_type ()) #define TH_DEVICE_TRACKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TH_TYPE_DEVICE_TRACKER, ThDeviceTracker)) #define TH_IS_DEVICE_TRACKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TH_TYPE_DEVICE_TRACKER)) @@ -50,10 +83,20 @@ struct _ThDeviceTrackerIface gboolean is_removed, gboolean is_added); +#ifndef USE_NEW_DBUS_HAL_API + void (*dev_condition) (ThDeviceTracker *tracker, const gchar *udi, const gchar *cond_name, DBusMessage *msg); +#else + + void (*dev_condition) (ThDeviceTracker *tracker, + const gchar *udi, + const gchar *cond_name, + const gchar *cond_detail); + +#endif /* USE_NEW_DBUS_HAL_API */ }; GType th_device_tracker_get_type (void) G_GNUC_CONST; @@ -81,10 +124,20 @@ void th_device_tracker_prop_mod ( gboolean is_removed, gboolean is_added); +#ifndef USE_NEW_DBUS_HAL_API + void th_device_tracker_dev_condition (ThDeviceTracker *tracker, const gchar *udi, const gchar *cond_name, DBusMessage *msg); +#else + +void th_device_tracker_dev_condition (ThDeviceTracker *tracker, + const gchar *udi, + const gchar *cond_name, + const gchar *cond_detail); + +#endif /* USE_NEW_DBUS_HAL_API */ #endif /* _th_device_tracker_h_included_ */ Index: src/th-disc-drive-pool.c =================================================================== RCS file: /cvsroot/thoggen/thoggen/src/th-disc-drive-pool.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -p -r1.11 -r1.12 --- src/th-disc-drive-pool.c 16 Mar 2005 16:00:23 -0000 1.11 +++ src/th-disc-drive-pool.c 4 Apr 2005 13:06:21 -0000 1.12 @@ -119,11 +119,21 @@ static void disc_pool_device_p gboolean is_removed, gboolean is_added); +#ifndef USE_NEW_DBUS_HAL_API + static void disc_pool_device_condition (ThDeviceTracker *tracker, const char *udi, const char *cond_name, DBusMessage *msg); +#else + +static void disc_pool_device_condition (ThDeviceTracker *tracker, + const char *udi, + const char *cond_name, + const gchar *cond_detail); +#endif + /* variables */ static guint ddp_signals[NUM_SIGNALS]; /* all 0 */ @@ -892,7 +902,11 @@ static void disc_pool_device_condition (ThDeviceTracker *tracker, const gchar *udi, const gchar *cond_name, +#ifndef USE_NEW_DBUS_HAL_API DBusMessage *msg) +#else + const gchar *cond_detail) +#endif { ThDiscDrivePool *disc_pool;