summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dkp-daemon.c187
-rw-r--r--src/dkp-device.c8
-rw-r--r--src/org.freedesktop.DeviceKit.Power.xml153
3 files changed, 160 insertions, 188 deletions
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>