diff options
-rw-r--r-- | libdevkit-power/dkp-client.c | 270 | ||||
-rw-r--r-- | libdevkit-power/dkp-client.h | 30 | ||||
-rw-r--r-- | src/dkp-daemon.c | 187 | ||||
-rw-r--r-- | src/dkp-device.c | 8 | ||||
-rw-r--r-- | src/org.freedesktop.DeviceKit.Power.xml | 153 | ||||
-rw-r--r-- | tools/dkp-tool.c | 54 |
6 files changed, 369 insertions, 333 deletions
diff --git a/libdevkit-power/dkp-client.c b/libdevkit-power/dkp-client.c index d6db70a..dc68954 100644 --- a/libdevkit-power/dkp-client.c +++ b/libdevkit-power/dkp-client.c @@ -40,16 +40,24 @@ struct DkpClientPrivate { DBusGConnection *bus; DBusGProxy *proxy; + DBusGProxy *prop_proxy; GHashTable *hash; GPtrArray *array; + + gboolean have_properties; + + char *daemon_version; + gboolean can_suspend; + gboolean can_hibernate; + gboolean on_battery; + gboolean on_low_battery; }; enum { - DKP_CLIENT_ADDED, + DKP_CLIENT_DEVICE_ADDED, + DKP_CLIENT_DEVICE_CHANGED, + DKP_CLIENT_DEVICE_REMOVED, DKP_CLIENT_CHANGED, - DKP_CLIENT_REMOVED, - DKP_CLIENT_ON_BATTERY_CHANGED, - DKP_CLIENT_LOW_BATTERY_CHANGED, DKP_CLIENT_LAST_SIGNAL }; @@ -93,92 +101,114 @@ dkp_client_enumerate_devices (DkpClient *client, GError **error) return devices; } -/** - * dkp_client_get_on_battery - **/ -gboolean -dkp_client_get_on_battery (DkpClient *client, gboolean *on_battery, GError **error) +static void +ensure_properties (DkpClient *client) { - gboolean ret; - GError *error_local = NULL; + GError *error; + GHashTable *props; + GValue *value; - ret = dbus_g_proxy_call (client->priv->proxy, "GetOnBattery", &error_local, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &on_battery, - G_TYPE_INVALID); - if (!ret) { - egg_warning ("Couldn't get battery status: %s", error_local->message); - if (error != NULL) - *error = g_error_new (1, 0, "%s", error_local->message); - g_error_free (error_local); - } - return ret; + props = NULL; + + if (client->priv->have_properties) + goto out; + + error = NULL; + if (!dbus_g_proxy_call (client->priv->prop_proxy, + "GetAll", + &error, + G_TYPE_STRING, + "org.freedesktop.DeviceKit.Power", + G_TYPE_INVALID, + dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), + &props, + G_TYPE_INVALID)) { + g_warning ("Error invokving GetAll() to get properties: %s", error->message); + g_error_free (error); + goto out; + } + + + value = g_hash_table_lookup (props, "daemon-version"); + if (value == NULL) { + g_warning ("No 'daemon-version' property"); + goto out; + } + client->priv->daemon_version = g_strdup (g_value_get_string (value)); + + value = g_hash_table_lookup (props, "can-suspend"); + if (value == NULL) { + g_warning ("No 'can-suspend' property"); + goto out; + } + client->priv->can_suspend = g_value_get_boolean (value); + + value = g_hash_table_lookup (props, "can-hibernate"); + if (value == NULL) { + g_warning ("No 'can-hibernate' property"); + goto out; + } + client->priv->can_hibernate = g_value_get_boolean (value); + + value = g_hash_table_lookup (props, "on-battery"); + if (value == NULL) { + g_warning ("No 'on-battery' property"); + goto out; + } + client->priv->on_battery = g_value_get_boolean (value); + + value = g_hash_table_lookup (props, "on-low-battery"); + if (value == NULL) { + g_warning ("No 'on-low-battery' property"); + goto out; + } + client->priv->on_low_battery = g_value_get_boolean (value); + + client->priv->have_properties = TRUE; + + out: + if (props != NULL) + g_hash_table_unref (props); } -/** - * dkp_client_get_low_battery - **/ -gboolean -dkp_client_get_low_battery (DkpClient *client, gboolean *low_battery, GError **error) +const gchar * +dkp_client_get_daemon_version (DkpClient *client) { - gboolean ret; - GError *error_local = NULL; - - ret = dbus_g_proxy_call (client->priv->proxy, "GetLowBattery", &error_local, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &low_battery, - G_TYPE_INVALID); - if (!ret) { - egg_warning ("Couldn't get low battery status: %s", error_local->message); - if (error != NULL) - *error = g_error_new (1, 0, "%s", error_local->message); - g_error_free (error_local); - } - return ret; + g_return_val_if_fail (DKP_IS_CLIENT (client), NULL); + ensure_properties (client); + return client->priv->daemon_version; } -/** - * dkp_client_can_suspend - **/ gboolean -dkp_client_can_suspend (DkpClient *client, gboolean interactive, gboolean *can_suspend, GError **error) +dkp_client_can_hibernate (DkpClient *client) { - gboolean ret; - GError *error_local = NULL; + g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE); + ensure_properties (client); + return client->priv->can_hibernate; +} - ret = dbus_g_proxy_call (client->priv->proxy, "CanSuspend", &error_local, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &can_suspend, - G_TYPE_INVALID); - if (!ret) { - egg_warning ("Couldn't get suspend status: %s", error_local->message); - if (error != NULL) - *error = g_error_new (1, 0, "%s", error_local->message); - g_error_free (error_local); - } - return ret; +gboolean +dkp_client_can_suspend (DkpClient *client) +{ + g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE); + ensure_properties (client); + return client->priv->can_suspend; } -/** - * dkp_client_can_hibernate - **/ gboolean -dkp_client_can_hibernate (DkpClient *client, gboolean interactive, gboolean *can_hibernate, GError **error) +dkp_client_on_battery (DkpClient *client) { - gboolean ret; - GError *error_local = NULL; + g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE); + ensure_properties (client); + return client->priv->on_battery; +} - ret = dbus_g_proxy_call (client->priv->proxy, "CanHibernate", &error_local, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &can_hibernate, - G_TYPE_INVALID); - if (!ret) { - egg_warning ("Couldn't get hibernate status: %s", error_local->message); - if (error != NULL) - *error = g_error_new (1, 0, "%s", error_local->message); - g_error_free (error_local); - } - return ret; +gboolean +dkp_client_on_low_battery (DkpClient *client) +{ + g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE); + ensure_properties (client); + return client->priv->on_low_battery; } /** @@ -216,56 +246,48 @@ dkp_client_remove (DkpClient *client, DkpClientDevice *device) * dkp_client_added_cb: **/ static void -dkp_client_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) +dkp_client_device_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) { DkpClientDevice *device; /* create new device */ device = dkp_client_add (client, object_path); - g_signal_emit (client, signals [DKP_CLIENT_ADDED], 0, device); + g_signal_emit (client, signals [DKP_CLIENT_DEVICE_ADDED], 0, device); } /** * dkp_client_changed_cb: **/ static void -dkp_client_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) +dkp_client_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) { DkpClientDevice *device; device = dkp_client_get_device (client, object_path); if (device != NULL) - g_signal_emit (client, signals [DKP_CLIENT_CHANGED], 0, device); + g_signal_emit (client, signals [DKP_CLIENT_DEVICE_CHANGED], 0, device); } /** * dkp_client_removed_cb: **/ static void -dkp_client_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) +dkp_client_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client) { DkpClientDevice *device; device = dkp_client_get_device (client, object_path); if (device != NULL) - g_signal_emit (client, signals [DKP_CLIENT_REMOVED], 0, device); + g_signal_emit (client, signals [DKP_CLIENT_DEVICE_REMOVED], 0, device); dkp_client_remove (client, device); } /** - * dkp_client_on_battery_changed_cb: - **/ -static void -dkp_client_on_battery_changed_cb (DBusGProxy *proxy, gboolean on_battery, DkpClient *client) -{ - g_signal_emit (client, signals [DKP_CLIENT_ON_BATTERY_CHANGED], 0, on_battery); -} - -/** - * dkp_client_low_battery_changed_cb: + * dkp_client_changed_cb: **/ static void -dkp_client_low_battery_changed_cb (DBusGProxy *proxy, gboolean low_battery, DkpClient *client) +dkp_client_changed_cb (DBusGProxy *proxy, DkpClient *client) { - g_signal_emit (client, signals [DKP_CLIENT_LOW_BATTERY_CHANGED], 0, low_battery); + client->priv->have_properties = FALSE; + g_signal_emit (client, signals [DKP_CLIENT_CHANGED], 0); } /** @@ -278,36 +300,30 @@ dkp_client_class_init (DkpClientClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = dkp_client_finalize; - signals [DKP_CLIENT_ADDED] = - g_signal_new ("added", + signals [DKP_CLIENT_DEVICE_ADDED] = + g_signal_new ("device-added", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (DkpClientClass, added), + G_STRUCT_OFFSET (DkpClientClass, device_added), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - signals [DKP_CLIENT_REMOVED] = - g_signal_new ("removed", + signals [DKP_CLIENT_DEVICE_REMOVED] = + g_signal_new ("device-removed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (DkpClientClass, removed), + G_STRUCT_OFFSET (DkpClientClass, device_removed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - signals [DKP_CLIENT_CHANGED] = - g_signal_new ("changed", + signals [DKP_CLIENT_DEVICE_CHANGED] = + g_signal_new ("device-changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (DkpClientClass, changed), + G_STRUCT_OFFSET (DkpClientClass, device_changed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - signals [DKP_CLIENT_ON_BATTERY_CHANGED] = - g_signal_new ("on-battery-changed", - G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (DkpClientClass, changed), - NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - signals [DKP_CLIENT_LOW_BATTERY_CHANGED] = - g_signal_new ("low-battery-changed", + signals [DKP_CLIENT_CHANGED] = + g_signal_new ("changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (DkpClientClass, changed), - NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); g_type_class_add_private (klass, sizeof (DkpClientPrivate)); } @@ -346,23 +362,29 @@ dkp_client_init (DkpClient *client) goto out; } + client->priv->prop_proxy = dbus_g_proxy_new_for_name (client->priv->bus, + "org.freedesktop.DeviceKit.Power", + "/org/freedesktop/DeviceKit/Power", + "org.freedesktop.DBus.Properties"); + if (client->priv->prop_proxy == NULL) { + egg_warning ("Couldn't connect to proxy"); + goto out; + } + dbus_g_proxy_add_signal (client->priv->proxy, "DeviceAdded", G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (client->priv->proxy, "DeviceRemoved", G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (client->priv->proxy, "DeviceChanged", G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_add_signal (client->priv->proxy, "OnBatteryChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_add_signal (client->priv->proxy, "LowBatteryChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_add_signal (client->priv->proxy, "Changed", G_TYPE_INVALID); /* all callbacks */ dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceAdded", - G_CALLBACK (dkp_client_added_cb), client, NULL); + G_CALLBACK (dkp_client_device_added_cb), client, NULL); dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceRemoved", - G_CALLBACK (dkp_client_removed_cb), client, NULL); + G_CALLBACK (dkp_client_device_removed_cb), client, NULL); dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceChanged", + G_CALLBACK (dkp_client_device_changed_cb), client, NULL); + dbus_g_proxy_connect_signal (client->priv->proxy, "Changed", G_CALLBACK (dkp_client_changed_cb), client, NULL); - dbus_g_proxy_connect_signal (client->priv->proxy, "OnBatteryChanged", - G_CALLBACK (dkp_client_on_battery_changed_cb), client, NULL); - dbus_g_proxy_connect_signal (client->priv->proxy, "LowBatteryChanged", - G_CALLBACK (dkp_client_low_battery_changed_cb), client, NULL); /* coldplug */ devices = dkp_client_enumerate_devices (client, NULL); @@ -401,6 +423,14 @@ dkp_client_finalize (GObject *object) g_hash_table_unref (client->priv->hash); dbus_g_connection_unref (client->priv->bus); + if (client->priv->proxy != NULL) + g_object_unref (client->priv->proxy); + + if (client->priv->prop_proxy != NULL) + g_object_unref (client->priv->prop_proxy); + + g_free (client->priv->daemon_version); + G_OBJECT_CLASS (dkp_client_parent_class)->finalize (object); } diff --git a/libdevkit-power/dkp-client.h b/libdevkit-power/dkp-client.h index 70680d1..2582109 100644 --- a/libdevkit-power/dkp-client.h +++ b/libdevkit-power/dkp-client.h @@ -48,36 +48,26 @@ typedef struct typedef struct { GObjectClass parent_class; - void (*added) (DkpClient *client, + void (*device_added) (DkpClient *client, const DkpClientDevice *device); - void (*changed) (DkpClient *client, + void (*device_changed) (DkpClient *client, const DkpClientDevice *device); - void (*removed) (DkpClient *client, + void (*device_removed) (DkpClient *client, const DkpClientDevice *device); - void (*on_battery_changed) (DkpClient *client, + void (*changed) (DkpClient *client, gboolean on_battery); - void (*low_battery_changed) (DkpClient *client, - gboolean low_battery); } DkpClientClass; GType dkp_client_get_type (void) G_GNUC_CONST; DkpClient *dkp_client_new (void); GPtrArray *dkp_client_enumerate_devices (DkpClient *client, GError **error); -gboolean dkp_client_get_on_battery (DkpClient *client, - gboolean *on_battery, - GError **error); -gboolean dkp_client_get_low_battery (DkpClient *client, - gboolean *low_battery, - GError **error); -gboolean dkp_client_can_suspend (DkpClient *client, - gboolean interactive, - gboolean *can_suspend, - GError **error); -gboolean dkp_client_can_hibernate (DkpClient *client, - gboolean interactive, - gboolean *can_hibernate, - GError **error); + +const gchar *dkp_client_get_daemon_version (DkpClient *client); +gboolean dkp_client_can_hibernate (DkpClient *client); +gboolean dkp_client_can_suspend (DkpClient *client); +gboolean dkp_client_on_battery (DkpClient *client); +gboolean dkp_client_on_low_battery (DkpClient *client); G_END_DECLS diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c index be884e8..e72a80b 100644 --- a/src/dkp-daemon.c +++ b/src/dkp-daemon.c @@ -47,11 +47,20 @@ enum { + PROP_0, + PROP_DAEMON_VERSION, + PROP_CAN_SUSPEND, + PROP_CAN_HIBERNATE, + PROP_ON_BATTERY, + PROP_ON_LOW_BATTERY, +}; + +enum +{ DEVICE_ADDED_SIGNAL, DEVICE_REMOVED_SIGNAL, DEVICE_CHANGED_SIGNAL, - ON_BATTERY_CHANGED_SIGNAL, - LOW_BATTERY_CHANGED_SIGNAL, + CHANGED_SIGNAL, LAST_SIGNAL, }; @@ -134,6 +143,49 @@ dkp_daemon_constructor (GType type, guint n_construct_properties, GObjectConstru } /** + * dkp_daemon_get_property: + **/ +static void +dkp_daemon_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + DkpDaemon *daemon; + + daemon = DKP_DAEMON (object); + + switch (prop_id) { + + case PROP_DAEMON_VERSION: + g_value_set_string (value, PACKAGE_VERSION); + break; + + case PROP_CAN_SUSPEND: + /* TODO: for now assume we can always suspend */ + g_value_set_boolean (value, TRUE); + break; + + case PROP_CAN_HIBERNATE: + /* TODO for now assume we can always hibernate */ + g_value_set_boolean (value, TRUE); + break; + + case PROP_ON_BATTERY: + g_value_set_boolean (value, daemon->priv->on_battery); + break; + + case PROP_ON_LOW_BATTERY: + g_value_set_boolean (value, daemon->priv->on_battery && daemon->priv->low_battery); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/** * dkp_daemon_class_init: **/ static void @@ -143,6 +195,7 @@ dkp_daemon_class_init (DkpDaemonClass *klass) object_class->constructor = dkp_daemon_constructor; object_class->finalize = dkp_daemon_finalize; + object_class->get_property = dkp_daemon_get_property; g_type_class_add_private (klass, sizeof (DkpDaemonPrivate)); @@ -173,23 +226,55 @@ dkp_daemon_class_init (DkpDaemonClass *klass) g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); - signals[ON_BATTERY_CHANGED_SIGNAL] = - g_signal_new ("on-battery-changed", + signals[CHANGED_SIGNAL] = + g_signal_new ("changed", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - - signals[LOW_BATTERY_CHANGED_SIGNAL] = - g_signal_new ("low-battery-changed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + G_TYPE_NONE, 0); + + + g_object_class_install_property (object_class, + PROP_DAEMON_VERSION, + g_param_spec_string ("daemon-version", + "Daemon Version", + "The version of the running daemon", + NULL, + G_PARAM_READABLE)); + + g_object_class_install_property (object_class, + PROP_CAN_SUSPEND, + g_param_spec_boolean ("can-suspend", + "Can Suspend", + "Whether the system can suspend", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property (object_class, + PROP_CAN_SUSPEND, + g_param_spec_boolean ("can-hibernate", + "Can Hibernate", + "Whether the system can hibernate", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property (object_class, + PROP_ON_BATTERY, + g_param_spec_boolean ("on-battery", + "On Battery", + "Whether the system is running on battery", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property (object_class, + PROP_ON_LOW_BATTERY, + g_param_spec_boolean ("on-low-battery", + "On Low Battery", + "Whether the system is running on battery and if the battery is critically low", + FALSE, + G_PARAM_READABLE)); dbus_g_object_type_install_info (DKP_TYPE_DAEMON, &dbus_glib_dkp_daemon_object_info); @@ -372,28 +457,28 @@ gpk_daemon_device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesi DkpDevice *device; gboolean ret; - /* check if the on_battery and low_battery state has changed */ + /* first, change the device and add it if it doesn't exist */ + device = dkp_device_list_lookup (daemon->priv->list, d); + if (device != NULL) { + egg_debug ("changed %s", dkp_device_get_object_path (device)); + dkp_device_changed (device, d, synthesized); + } else { + egg_debug ("treating change event as add on %s", dkp_device_get_object_path (device)); + gpk_daemon_device_add (daemon, d, TRUE); + } + + /* second, check if the on_battery and low_battery state has changed */ ret = dkp_daemon_get_on_battery_local (daemon); if (ret != daemon->priv->on_battery) { daemon->priv->on_battery = ret; egg_debug ("now on_battery = %s", ret ? "yes" : "no"); - g_signal_emit (daemon, signals[ON_BATTERY_CHANGED_SIGNAL], 0, ret); + g_signal_emit (daemon, signals[CHANGED_SIGNAL], 0); } ret = dkp_daemon_get_low_battery_local (daemon); if (ret != daemon->priv->low_battery) { daemon->priv->low_battery = ret; egg_debug ("now low_battery = %s", ret ? "yes" : "no"); - g_signal_emit (daemon, signals[LOW_BATTERY_CHANGED_SIGNAL], 0, ret); - } - - /* does the device exist in the db? */ - device = dkp_device_list_lookup (daemon->priv->list, d); - if (device != NULL) { - egg_debug ("changed %s", dkp_device_get_object_path (device)); - dkp_device_changed (device, d, synthesized); - } else { - egg_debug ("treating change event as add on %s", dkp_device_get_object_path (device)); - gpk_daemon_device_add (daemon, d, TRUE); + g_signal_emit (daemon, signals[CHANGED_SIGNAL], 0); } } @@ -808,54 +893,6 @@ dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context) } /** - * dkp_daemon_get_on_battery: - **/ -gboolean -dkp_daemon_get_on_battery (DkpDaemon *daemon, DBusGMethodInvocation *context) -{ - /* this is cached as it's expensive to check all sources */ - dbus_g_method_return (context, daemon->priv->on_battery); - return TRUE; -} - -/** - * dkp_daemon_get_low_battery: - **/ -gboolean -dkp_daemon_get_low_battery (DkpDaemon *daemon, DBusGMethodInvocation *context) -{ - /* this is cached as it's expensive to check all sources */ - dbus_g_method_return (context, daemon->priv->low_battery); - return TRUE; -} - -/** - * dkp_daemon_can_suspend: - * - * TODO: Ask PolicyKit and check in DeviceKit.conf - **/ -gboolean -dkp_daemon_can_suspend (DkpDaemon *daemon, gboolean interactive, DBusGMethodInvocation *context) -{ - /* for now, assume we can suspend under all circumstances */ - dbus_g_method_return (context, TRUE); - return TRUE; -} - -/** - * dkp_daemon_can_hibernate: - * - * TODO: Ask PolicyKit and check in DeviceKit.conf - **/ -gboolean -dkp_daemon_can_hibernate (DkpDaemon *daemon, gboolean interactive, DBusGMethodInvocation *context) -{ - /* for now, assume we can hibernate under all circumstances */ - dbus_g_method_return (context, TRUE); - return TRUE; -} - -/** * dkp_daemon_suspend: **/ gboolean diff --git a/src/dkp-device.c b/src/dkp-device.c index bdd10a5..4a92f1d 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -580,9 +580,15 @@ dkp_device_emit_changed (DkpDevice *device) dkp_history_set_time_empty_data (device->priv->history, obj->time_to_empty); egg_debug ("emitting changed on %s", device->priv->obj->native_path); + + /* The order here matters; we want Device::Changed() before + * the DeviceChanged() signal on the main object; otherwise + * clients that only listens on DeviceChanged() won't be + * fully caught up... + */ + g_signal_emit (device, signals[CHANGED_SIGNAL], 0); g_signal_emit_by_name (device->priv->daemon, "device-changed", device->priv->object_path, NULL); - g_signal_emit (device, signals[CHANGED_SIGNAL], 0); } /** diff --git a/src/org.freedesktop.DeviceKit.Power.xml b/src/org.freedesktop.DeviceKit.Power.xml index 3070c30..b696364 100644 --- a/src/org.freedesktop.DeviceKit.Power.xml +++ b/src/org.freedesktop.DeviceKit.Power.xml @@ -100,88 +100,14 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2 </signal> <!-- ************************************************************ --> - <signal name="OnBatteryChanged"> - <arg name="on_battery" type="b"> - <doc:doc><doc:summary>If we are on battery power.</doc:summary></doc:doc> - </arg> - - <doc:doc> - <doc:description> - <doc:para> - Emitted when the main power source of the system has changed. - </doc:para> - </doc:description> - </doc:doc> - </signal> - - <!-- ************************************************************ --> - <signal name="LowBatteryChanged"> - <arg name="low_battery" type="b"> - <doc:doc><doc:summary>If we are critically low on battery power.</doc:summary></doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para> - Emitted when the main power source of the system is critically low in power. - </doc:para> - </doc:description> - </doc:doc> - </signal> - - <!-- ************************************************************ --> - <method name="GetOnBattery"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="on_battery" direction="out" type="b"> - <doc:doc><doc:summary>If we are on battery power.</doc:summary></doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para> - Finds out if we are using battery so we can make policy decisions, - for instance not running the indexer when we are on battery power. - </doc:para> - </doc:description> - </doc:doc> - </method> - - <!-- ************************************************************ --> - <method name="GetLowBattery"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="low_battery" direction="out" type="b"> - <doc:doc><doc:summary>If we are critically low on battery power.</doc:summary></doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para> - Finds out if we are critically low on battery so we can make policy - decisions, for instance saving documents or turning off network - connections. - </doc:para> - </doc:description> - </doc:doc> - </method> - - <!-- ************************************************************ --> - <method name="CanSuspend"> + <method name="Suspend"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="interactive" direction="in" type="b"> - <doc:doc> - <doc:summary> - If we are allowed to be interactive, and ask the user to authorise - the action. - </doc:summary> - </doc:doc> - </arg> - <arg name="can_suspend" direction="out" type="b"> - <doc:doc><doc:summary>If we can suspend.</doc:summary></doc:doc> - </arg> <doc:doc> <doc:description> <doc:para> - Returns if the computer is able to suspend. - This function should be used to decide whether to show the - Supend menu item or button in GUI programs. + Suspends the computer into a low power state. + System state is not preserved if the power is lost. </doc:para> </doc:description> </doc:doc> @@ -189,25 +115,13 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2 <!-- ************************************************************ --> - <method name="CanHibernate"> + <method name="Hibernate"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="interactive" direction="in" type="b"> - <doc:doc> - <doc:summary> - If we are allowed to be interactive, and ask the user to authorise - the action. - </doc:summary> - </doc:doc> - </arg> - <arg name="can_hibernate" direction="out" type="b"> - <doc:doc><doc:summary>If we can hibernate.</doc:summary></doc:doc> - </arg> <doc:doc> <doc:description> <doc:para> - Returns if the computer is able to hibernate. - This function should be used to decide whether to show the - Hibernate menu item or button in GUI programs. + Hibernates the computer into a low power state. + System state is preserved if the power is lost. </doc:para> </doc:description> </doc:doc> @@ -215,33 +129,48 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2 <!-- ************************************************************ --> - <method name="Suspend"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <doc:doc> - <doc:description> - <doc:para> - Suspends the computer into a low power state. - System state is not preserved if the power is lost. - </doc:para> - </doc:description> - </doc:doc> - </method> - - <!-- ************************************************************ --> - <method name="Hibernate"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <property name="daemon-version" type="s" access="read"> + <doc:doc><doc:description><doc:para> + Version of the running daemon, e.g. <doc:tt>002</doc:tt>. + </doc:para></doc:description></doc:doc> + </property> + + <property name="can-suspend" type="b" access="read"> + <doc:doc><doc:description><doc:para> + Whether the system is able to suspend. + </doc:para></doc:description></doc:doc> + </property> + + <property name="can-hibernate" type="b" access="read"> + <doc:doc><doc:description><doc:para> + Whether the system is able to hibernate. + </doc:para></doc:description></doc:doc> + </property> + + <property name="on-battery" type="b" access="read"> + <doc:doc><doc:description><doc:para> + Indicates whether the system is running on battery power. + This property is provided for convenience. + </doc:para></doc:description></doc:doc> + </property> + + <property name="on-low-battery" type="b" access="read"> + <doc:doc><doc:description><doc:para> + Indicates whether the system is running on battery power and if the battery is critically low. + This property is provided for convenience. + </doc:para></doc:description></doc:doc> + </property> + + <signal name="Changed"> <doc:doc> <doc:description> <doc:para> - Hibernates the computer into a low power state. - System state is preserved if the power is lost. + Emitted when one or more properties on the object changes. </doc:para> </doc:description> </doc:doc> - </method> - - <!-- ************************************************************ --> + </signal> </interface> diff --git a/tools/dkp-tool.c b/tools/dkp-tool.c index f35486f..b774044 100644 --- a/tools/dkp-tool.c +++ b/tools/dkp-tool.c @@ -47,6 +47,7 @@ dkp_tool_device_added_cb (DkpClient *client, const DkpClientDevice *device, gpoi g_print ("added: %s\n", dkp_client_device_get_object_path (device)); if (opt_monitor_detail) { dkp_client_device_print (device); + g_print ("\n"); } } @@ -60,6 +61,7 @@ dkp_tool_device_changed_cb (DkpClient *client, const DkpClientDevice *device, gp if (opt_monitor_detail) { /* TODO: would be nice to just show the diff */ dkp_client_device_print (device); + g_print ("\n"); } } @@ -70,6 +72,31 @@ static void dkp_tool_device_removed_cb (DkpClient *client, const DkpClientDevice *device, gpointer user_data) { g_print ("removed: %s\n", dkp_client_device_get_object_path (device)); + if (opt_monitor_detail) + g_print ("\n"); +} + +static void +dkp_client_print (DkpClient *client) +{ + g_print (" daemon-version: %s\n", dkp_client_get_daemon_version (client)); + g_print (" can-suspend: %s\n", dkp_client_can_suspend (client) ? "yes" : "no"); + g_print (" can-hibernate %s\n", dkp_client_can_hibernate (client) ? "yes" : "no"); + g_print (" on-battery: %s\n", dkp_client_on_battery (client) ? "yes" : "no"); + g_print (" on-low-battery: %s\n", dkp_client_on_low_battery (client) ? "yes" : "no"); +} + +/** + * dkp_tool_changed_cb: + **/ +static void +dkp_tool_changed_cb (DkpClient *client, gpointer user_data) +{ + g_print ("daemon changed:\n"); + if (opt_monitor_detail) { + dkp_client_print (client); + g_print ("\n"); + } } /** @@ -80,9 +107,10 @@ dkp_tool_do_monitor (DkpClient *client) { g_print ("Monitoring activity from the power daemon. Press Ctrl+C to cancel.\n"); - g_signal_connect (client, "added", G_CALLBACK (dkp_tool_device_added_cb), NULL); - g_signal_connect (client, "removed", G_CALLBACK (dkp_tool_device_removed_cb), NULL); - g_signal_connect (client, "changed", G_CALLBACK (dkp_tool_device_changed_cb), NULL); + g_signal_connect (client, "device-added", G_CALLBACK (dkp_tool_device_added_cb), NULL); + g_signal_connect (client, "device-removed", G_CALLBACK (dkp_tool_device_removed_cb), NULL); + g_signal_connect (client, "device-changed", G_CALLBACK (dkp_tool_device_changed_cb), NULL); + g_signal_connect (client, "changed", G_CALLBACK (dkp_tool_changed_cb), NULL); g_main_loop_run (loop); @@ -102,6 +130,7 @@ main (int argc, char **argv) gboolean opt_enumerate = FALSE; gboolean opt_monitor = FALSE; gchar *opt_show_info = FALSE; + gboolean opt_version = FALSE; unsigned int n; DkpClient *client; @@ -114,6 +143,7 @@ main (int argc, char **argv) { "monitor", 'm', 0, G_OPTION_ARG_NONE, &opt_monitor, _("Monitor activity from the power daemon"), NULL }, { "monitor-detail", 0, 0, G_OPTION_ARG_NONE, &opt_monitor_detail, _("Monitor with detail"), NULL }, { "show-info", 'i', 0, G_OPTION_ARG_STRING, &opt_show_info, _("Show information about object path"), NULL }, + { "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, "Print version of client and daemon", NULL }, { NULL } }; @@ -128,6 +158,15 @@ main (int argc, char **argv) loop = g_main_loop_new (NULL, FALSE); client = dkp_client_new (); + if (opt_version) { + g_print ("DeviceKit-power client version %s\n" + "DeviceKit-power daemon version %s\n", + PACKAGE_VERSION, + dkp_client_get_daemon_version (client)); + ret = 0; + goto out; + } + if (opt_enumerate || opt_dump) { GPtrArray *devices; const gchar *object_path; @@ -136,18 +175,23 @@ main (int argc, char **argv) goto out; for (n=0; n < devices->len; n++) { object_path = (const gchar *) g_ptr_array_index (devices, n); - if (opt_enumerate) + if (opt_enumerate) { g_print ("%s\n", object_path); - else { + } else { g_print ("Device: %s\n", object_path); device = dkp_client_device_new (); dkp_client_device_set_object_path (device, object_path); dkp_client_device_print (device); + g_print ("\n"); g_object_unref (device); } } g_ptr_array_foreach (devices, (GFunc) g_free, NULL); g_ptr_array_free (devices, TRUE); + if (opt_dump) { + g_print ("Daemon:\n"); + dkp_client_print (client); + } } else if (opt_monitor || opt_monitor_detail) { if (!dkp_tool_do_monitor (client)) goto out; |