diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index 5294647..a97d2f7 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -33,6 +33,7 @@ #include "up-backend.h" #include "up-daemon.h" #include "up-device.h" +#include "up-device-kbd-backlight.h" #include "up-enumerator-udev.h" @@ -419,11 +420,18 @@ up_device_disconnected_cb (GObject *gobject, "native-path", &path, "disconnected", &disconnected, NULL); + + g_warning ("Disconnect signal received %s", path); if (disconnected) { g_debug("Device %s became disconnected, hiding device", path); - if (up_device_is_registered (UP_DEVICE (gobject))) { - g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject); - up_device_unregister (UP_DEVICE (gobject)); + if (UP_IS_DEVICE (gobject)) { + if (up_device_is_registered (UP_DEVICE (gobject))) { + g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject); + up_device_unregister (UP_DEVICE (gobject)); + } + } else if (UP_IS_DEVICE_KBD_BACKLIGHT (gobject)){ + g_warning ("Unregister LED"); + up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (gobject)); } } else { g_debug ("Device %s became connected, showing device", path); @@ -441,16 +449,20 @@ udev_device_added_cb (UpBackend *backend, GObject *device) if (UP_IS_DEVICE (device)) { if (update_added_duplicate_device (backend, UP_DEVICE (device))) g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device); - } else { + } else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)){ g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device); + } else { + g_warning ("Unknown device type"); } } static void -udev_device_removed_cb (UpBackend *backend, UpDevice *device) +udev_device_removed_cb (UpBackend *backend, GObject *device) { g_debug ("Removing device from udev enumerator: %p", device); - update_removed_duplicate_device (backend, device); + + if (UP_IS_DEVICE (device)) + update_removed_duplicate_device (backend, UP_DEVICE (device)); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, device); } @@ -785,7 +797,7 @@ up_backend_class_init (UpBackendClass *klass) G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UpBackendClass, device_removed), NULL, NULL, NULL, - G_TYPE_NONE, 1, UP_TYPE_DEVICE); + G_TYPE_NONE, 1, G_TYPE_OBJECT); } static void diff --git a/src/linux/up-enumerator-udev.c b/src/linux/up-enumerator-udev.c index f9b0783..1e221b3 100644 --- a/src/linux/up-enumerator-udev.c +++ b/src/linux/up-enumerator-udev.c @@ -386,6 +386,12 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self, g_debug ("removing device for path %s", g_udev_device_get_sysfs_path (device)); + if (is_kbd_backlight) { + g_debug ("uevent KDB backlight remove."); + g_signal_emit_by_name (self, "device-removed", obj); + return; + } + parent_id = g_object_get_data (obj, "udev-parent-id"); /* Remove from siblings table. */ diff --git a/src/linux/up-kbd-backlight.c b/src/linux/up-kbd-backlight.c index 1faa078..fb8cfba 100644 --- a/src/linux/up-kbd-backlight.c +++ b/src/linux/up-kbd-backlight.c @@ -233,9 +233,10 @@ up_kbd_backlight_finalize (GObject *object) /* close file */ if (kbd_backlight->priv->fd >= 0) close (kbd_backlight->priv->fd); +#endif G_OBJECT_CLASS (up_kbd_backlight_parent_class)->finalize (object); -#endif + } /** @@ -255,7 +256,6 @@ up_kbd_backlight_class_init (UpKbdBacklightClass *klass) dev_kbd_klass->set_brightness = up_kbd_backlight_set_brightness; } - /** * up_kbd_backlight_init: **/ diff --git a/src/up-daemon.c b/src/up-daemon.c index 29090f0..1ed1bec 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -1075,16 +1075,24 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae const gchar *object_path; UpDaemonPrivate *priv = daemon->priv; + g_return_if_fail (UP_IS_DAEMON (daemon)); - g_return_if_fail (UP_IS_DEVICE (device)); + g_return_if_fail (UP_IS_DEVICE (device) || UP_IS_DEVICE_KBD_BACKLIGHT (device)); g_signal_handlers_disconnect_by_data (device, daemon); - /* remove from list (device remains valid during the function call) */ - up_device_list_remove (priv->power_devices, device); - /* emit */ - object_path = up_device_get_object_path (device); + if (UP_IS_DEVICE (device)) { + /* remove from list (device remains valid during the function call) */ + up_device_list_remove (priv->power_devices, device); + object_path = up_device_get_object_path (device); + } else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) { + /* remove from list (device remains valid during the function call) */ + up_device_list_remove (priv->kbd_backlight_devices, device); + object_path = up_device_kbd_backlight_get_object_path (UP_DEVICE_KBD_BACKLIGHT (device)); + } else { + return; + } /* don't crash the session */ if (object_path == NULL) { @@ -1095,6 +1103,10 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae g_debug ("emitting device-removed: %s", object_path); up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path); + /* Unregister keyboard backlight dbus path */ + if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) + up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (device)); + /* In case a battery was removed */ up_daemon_refresh_battery_devices (daemon); up_daemon_update_warning_level (daemon); diff --git a/src/up-device-kbd-backlight.c b/src/up-device-kbd-backlight.c index fd71eb0..ba6331c 100644 --- a/src/up-device-kbd-backlight.c +++ b/src/up-device-kbd-backlight.c @@ -36,12 +36,12 @@ typedef struct { - UpDaemon *daemon; + UpDaemon *daemon; /* native == NULL implies display device */ - GObject *native; + GObject *native; - gint fd_hw_changed; - GIOChannel *channel_hw_changed; + gint fd_hw_changed; + GIOChannel *channel_hw_changed; } UpDeviceKbdBacklightPrivate; static void up_device_kbd_backlight_initable_iface_init (GInitableIface *iface); @@ -61,7 +61,6 @@ enum { #define UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH "/org/freedesktop/UPower/KbdBacklight" static GParamSpec *properties[N_PROPS]; - /** * up_kbd_backlight_emit_change: **/ @@ -140,6 +139,8 @@ up_kbd_backlight_get_max_brightness (UpExportedKbdBacklight *skeleton, /** * up_kbd_backlight_set_brightness: + * + * Sets the kbd backlight LED brightness. **/ static gboolean up_kbd_backlight_set_brightness (UpExportedKbdBacklight *skeleton, @@ -186,8 +187,8 @@ static gchar * up_device_kbd_backlight_compute_object_path (UpDeviceKbdBacklight *device) { UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device); - gchar *basename; - gchar *id; + g_autofree gchar *basename = NULL; + g_autofree gchar *id = NULL; gchar *object_path; const gchar *native_path; guint i; @@ -213,13 +214,9 @@ up_device_kbd_backlight_compute_object_path (UpDeviceKbdBacklight *device) } object_path = g_build_filename (UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH, id, NULL); - g_free (basename); - g_free (id); - return object_path; } - static void up_device_kbd_backlight_export_skeleton (UpDeviceKbdBacklight *device, const gchar *object_path) @@ -238,7 +235,6 @@ up_device_kbd_backlight_export_skeleton (UpDeviceKbdBacklight *device, } } - gboolean up_device_kbd_backlight_register (UpDeviceKbdBacklight *device) { @@ -252,6 +248,19 @@ up_device_kbd_backlight_register (UpDeviceKbdBacklight *device) return TRUE; } +void +up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device) +{ + g_autofree char *object_path = NULL; + + object_path = g_strdup (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device))); + if (object_path != NULL) { + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (device)); + g_debug ("Unexported UpDeviceKbdBacklight with path %s", object_path); + } +} + + const gchar * up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device) { @@ -268,8 +277,6 @@ up_device_kbd_backlight_set_property (GObject *object, UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (object); UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device); - g_debug ("kbd property set"); - switch (prop_id) { case PROP_DAEMON: @@ -277,7 +284,6 @@ up_device_kbd_backlight_set_property (GObject *object, break; case PROP_NATIVE: - g_debug ("Set kbd native"); priv->native = g_value_dup_object (value); if (priv->native == NULL) g_warning ("KBD native is NULL"); @@ -297,8 +303,6 @@ up_device_kbd_backlight_get_property (GObject *object, UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (object); UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device); - return; - switch (prop_id) { default: @@ -315,7 +319,7 @@ up_device_kbd_backlight_initable_init (GInitable *initable, UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (initable); UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device); - const gchar *native_path = "KbdDevice"; + const gchar *native_path = NULL; UpDeviceKbdBacklightClass *klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (device); int ret; @@ -380,6 +384,9 @@ up_device_kbd_backlight_finalize (GObject *object) g_return_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (object)); kbd_backlight = UP_DEVICE_KBD_BACKLIGHT (object); + + g_warning ("KBD LED Finalize"); + //kbd_backlight->priv = up_device_kbd_backlight_get_instance_private (kbd_backlight); //if (kbd_backlight->priv->channel_hw_changed) { diff --git a/src/up-device-kbd-backlight.h b/src/up-device-kbd-backlight.h index 8119a53..2796948 100644 --- a/src/up-device-kbd-backlight.h +++ b/src/up-device-kbd-backlight.h @@ -44,13 +44,14 @@ struct _UpDeviceKbdBacklightClass }; -GType up_device_kbd_backlight_get_type (void); +GType up_device_kbd_backlight_get_type (void); -const gchar * up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device); -GObject * up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device); +const gchar * up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device); +GObject * up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device); UpDeviceKbdBacklight *up_device_kbd_backlight_new (UpDaemon *daemon, GObject *native); gboolean up_device_kbd_backlight_register (UpDeviceKbdBacklight *device); +void up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device); #if 0 @@ -67,7 +68,7 @@ void up_device_sibling_discovered (UpDevice *device, GObject *sibling); gboolean up_device_refresh_internal (UpDevice *device, UpRefreshReason reason); -void up_device_unregister (UpDevice *device); + gboolean up_device_is_registered (UpDevice *device); #endif