On 19 March 2011 01:05, Phillip Susi <ps...@cfl.rr.com> wrote:
> I went to do a string at first, but when I got into the g-p-m code, it
> already had signals set up using an int.  In the interest of simplicity
> and conformity, I decided to stick with an int rather than parse strings
> and convert when reflecting the signal.  Attaching patches to both
> upower and g-p-m.

Sorry for the delay -- I've been caught up in other GNOME 3 stuff.
What about the attached patch?

I'm still not sure if it's a sensible thing to change the public DBus
API at this stage, as other things are using the existing signals
(notably, NetworkManager). David, Kay, any advice?

Richard.
From 50731ed2e65680617b267de7d023f96cb30af2cb Mon Sep 17 00:00:00 2001
From: Richard Hughes <rich...@hughsie.com>
Date: Wed, 30 Mar 2011 15:09:57 +0100
Subject: [PATCH] Add a sleep-kind parameter to the Sleeping() and Resuming() signals

This allows session power managers to do different actions depending on whether the user
is suspending or hibernating. This allows the session policy agent to poke other things
(for instance, the screensaver) even if another process initiated the sleep.

This is heavily based on a patch from Phillip Susi <ps...@cfl.rr.com>, many thanks.
---
 libupower-glib/up-client.c     |   12 +++++++--
 libupower-glib/up-client.h     |    1 +
 libupower-glib/up-types.c      |   52 ++++++++++++++++++++++++++++++++++++++++
 libupower-glib/up-types.h      |   16 ++++++++++++
 src/org.freedesktop.UPower.xml |   24 ++++++++++++++++++
 src/up-daemon.c                |   21 ++++++++++------
 src/up-daemon.h                |    1 +
 7 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c
index 3da75ef..41cc0f5 100644
--- a/libupower-glib/up-client.c
+++ b/libupower-glib/up-client.c
@@ -251,6 +251,7 @@ out:
 /**
  * up_client_about_to_sleep_sync:
  * @client: a #UpClient instance.
+ * @sleep_kind: a sleep type, e.g. %UP_SLEEP_KIND_SUSPEND
  * @cancellable: a #GCancellable or %NULL
  * @error: a #GError, or %NULL.
  *
@@ -259,10 +260,13 @@ out:
  *
  * Return value: TRUE if system suspended okay, FALSE other wise.
  *
- * Since: 0.9.1
+ * Since: 0.9.10
  **/
 gboolean
-up_client_about_to_sleep_sync (UpClient *client, GCancellable *cancellable, GError **error)
+up_client_about_to_sleep_sync (UpClient *client,
+			       UpSleepKind sleep_kind,
+			       GCancellable *cancellable,
+			       GError **error)
 {
 	gboolean ret;
 	GError *error_local = NULL;
@@ -271,7 +275,9 @@ up_client_about_to_sleep_sync (UpClient *client, GCancellable *cancellable, GErr
 	g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
 
 	ret = dbus_g_proxy_call (client->priv->proxy, "AboutToSleep", &error_local,
-				 G_TYPE_INVALID, G_TYPE_INVALID);
+				 G_TYPE_STRING, sleep_kind,
+				 G_TYPE_INVALID,
+				 G_TYPE_INVALID);
 	if (!ret) {
 		/* DBus might time out, which is okay */
 		if (g_error_matches (error_local, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) {
diff --git a/libupower-glib/up-client.h b/libupower-glib/up-client.h
index aa522ab..773f5be 100644
--- a/libupower-glib/up-client.h
+++ b/libupower-glib/up-client.h
@@ -87,6 +87,7 @@ gboolean	 up_client_suspend_sync			(UpClient		*client,
 							 GCancellable		*cancellable,
 							 GError			**error);
 gboolean	 up_client_about_to_sleep_sync		(UpClient		*client,
+							 UpSleepKind		 sleep_kind,
 							 GCancellable		*cancellable,
 							 GError			**error);
 gboolean	 up_client_hibernate_sync		(UpClient		*client,
diff --git a/libupower-glib/up-types.c b/libupower-glib/up-types.c
index 9109c54..4f7643f 100644
--- a/libupower-glib/up-types.c
+++ b/libupower-glib/up-types.c
@@ -300,3 +300,55 @@ up_qos_kind_from_string (const gchar *type)
 	return UP_QOS_KIND_UNKNOWN;
 }
 
+/**
+ * up_sleep_kind_to_string:
+ *
+ * Converts a #UpSleepKind to a string.
+ *
+ * Return value: identifier string
+ *
+ * Since: 0.9.10
+ **/
+const gchar *
+up_sleep_kind_to_string (UpSleepKind sleep_kind_enum)
+{
+	const gchar *sleep_kind = NULL;
+	switch (sleep_kind_enum) {
+	case UP_SLEEP_KIND_SUSPEND:
+		sleep_kind = "suspend";
+		break;
+	case UP_SLEEP_KIND_HIBERNATE:
+		sleep_kind = "hibernate";
+		break;
+	case UP_SLEEP_KIND_HYBRID:
+		sleep_kind = "hybrid";
+		break;
+	default:
+		sleep_kind = "unknown";
+		break;
+	}
+	return sleep_kind;
+}
+
+/**
+ * up_sleep_kind_from_string:
+ *
+ * Converts a string to a #UpSleepKind.
+ *
+ * Return value: enumerated value
+ *
+ * Since: 0.9.10
+ **/
+UpSleepKind
+up_sleep_kind_from_string (const gchar *sleep_kind)
+{
+	if (sleep_kind == NULL)
+		return UP_SLEEP_KIND_UNKNOWN;
+	if (g_strcmp0 (sleep_kind, "suspend") == 0)
+		return UP_SLEEP_KIND_SUSPEND;
+	if (g_strcmp0 (sleep_kind, "hibernate") == 0)
+		return UP_SLEEP_KIND_HIBERNATE;
+	if (g_strcmp0 (sleep_kind, "hybrid") == 0)
+		return UP_SLEEP_KIND_HYBRID;
+	return UP_SLEEP_KIND_UNKNOWN;
+}
diff --git a/libupower-glib/up-types.h b/libupower-glib/up-types.h
index 4e1d285..083d3d9 100644
--- a/libupower-glib/up-types.h
+++ b/libupower-glib/up-types.h
@@ -95,6 +95,19 @@ typedef enum {
 	UP_QOS_KIND_LAST
 } UpQosKind;
 
+/**
+ * UpSleepKind:
+ *
+ * The type of QOS request.
+ **/
+typedef enum {
+	UP_SLEEP_KIND_UNKNOWN,
+	UP_SLEEP_KIND_SUSPEND,
+	UP_SLEEP_KIND_HIBERNATE,
+	UP_SLEEP_KIND_HYBRID,
+	UP_SLEEP_KIND_LAST
+} UpSleepKind;
+
 const gchar	*up_device_kind_to_string		(UpDeviceKind		 type_enum);
 const gchar	*up_device_state_to_string		(UpDeviceState		 state_enum);
 const gchar	*up_device_technology_to_string		(UpDeviceTechnology	 technology_enum);
@@ -103,6 +116,9 @@ UpDeviceState	 up_device_state_from_string		(const gchar		*state);
 UpDeviceTechnology up_device_technology_from_string	(const gchar		*technology);
 const gchar	*up_qos_kind_to_string			(UpQosKind		 type);
 UpQosKind	 up_qos_kind_from_string		(const gchar		*type);
+const gchar	*up_sleep_kind_to_string		(UpSleepKind		 sleep_kind_enum);
+UpSleepKind	 up_sleep_kind_from_string		(const gchar		*sleep_kind);
+
 
 G_END_DECLS
 
diff --git a/src/org.freedesktop.UPower.xml b/src/org.freedesktop.UPower.xml
index c37d218..3e165fc 100644
--- a/src/org.freedesktop.UPower.xml
+++ b/src/org.freedesktop.UPower.xml
@@ -125,6 +125,14 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
           </doc:para>
         </doc:description>
       </doc:doc>
+      <arg name="action" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>
+            The sleep action type, e.g. <doc:tt>suspend</doc:tt>,
+            <doc:tt>hibernate</doc:tt> or <doc:tt>hybrid</doc:tt>.
+          </doc:summary>
+        </doc:doc>
+      </arg>
     </signal>
 
     <!-- ************************************************************ -->
@@ -140,6 +148,14 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
           </doc:para>
         </doc:description>
       </doc:doc>
+      <arg name="action" direction="out" type="s">
+        <doc:doc>
+          <doc:summary>
+            The sleep action type, e.g. <doc:tt>suspend</doc:tt>,
+            <doc:tt>hibernate</doc:tt> or <doc:tt>hybrid</doc:tt>.
+          </doc:summary>
+        </doc:doc>
+      </arg>
     </signal>
 
     <!-- ************************************************************ -->
@@ -168,6 +184,14 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
           </doc:para>
         </doc:description>
       </doc:doc>
+      <arg name="action" direction="in" type="s">
+        <doc:doc>
+          <doc:summary>
+            The sleep action type, e.g. <doc:tt>suspend</doc:tt> or
+            <doc:tt>hibernate</doc:tt>.
+          </doc:summary>
+        </doc:doc>
+      </arg>
     </method>
 
     <!-- ************************************************************ -->
diff --git a/src/up-daemon.c b/src/up-daemon.c
index 12bd999..1f6187c 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -95,6 +95,7 @@ struct UpDaemonPrivate
 	guint			 about_to_sleep_id;
 	guint			 conf_sleep_timeout;
 	gboolean		 conf_allow_hibernate_encrypted_swap;
+	const gchar		*sleep_kind;
 };
 
 static void	up_daemon_finalize		(GObject	*object);
@@ -315,7 +316,9 @@ up_daemon_enumerate_devices (UpDaemon *daemon, DBusGMethodInvocation *context)
  * up_daemon_about_to_sleep:
  **/
 gboolean
-up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context)
+up_daemon_about_to_sleep (UpDaemon *daemon,
+			  const gchar *sleep_kind,
+			  DBusGMethodInvocation *context)
 {
 	PolkitSubject *subject = NULL;
 	GError *error;
@@ -341,7 +344,7 @@ up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context)
 
 	/* we've told the clients we're going down */
 	g_debug ("emitting sleeping");
-	g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0);
+	g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0, sleep_kind);
 	g_timer_start (priv->about_to_sleep_timer);
 	daemon->priv->sent_sleeping_signal = TRUE;
 
@@ -387,7 +390,7 @@ up_daemon_deferred_sleep_cb (UpDaemonDeferredSleep *sleep)
 
 	/* emit signal for session components */
 	g_debug ("emitting resuming");
-	g_signal_emit (daemon, signals[SIGNAL_RESUMING], 0);
+	g_signal_emit (daemon, signals[SIGNAL_RESUMING], 0, priv->sleep_kind);
 
 	/* reset the about-to-sleep logic */
 	g_timer_reset (priv->about_to_sleep_timer);
@@ -431,7 +434,7 @@ up_daemon_deferred_sleep (UpDaemon *daemon, const gchar *command, DBusGMethodInv
 	/* we didn't use AboutToSleep() so send the signal for clients now */
 	if (!priv->sent_sleeping_signal) {
 		g_debug ("no AboutToSleep(), so emitting ::Sleeping()");
-		g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0);
+		g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0, priv->sleep_kind);
 		priv->about_to_sleep_id = g_timeout_add (priv->conf_sleep_timeout,
 							 (GSourceFunc) up_daemon_deferred_sleep_cb, sleep);
 #if GLIB_CHECK_VERSION(2,25,8)
@@ -498,6 +501,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
 	}
 
 	/* do this deferred action */
+	priv->sleep_kind = "suspend";
 	command = up_backend_get_suspend_command (priv->backend);
 	up_daemon_deferred_sleep (daemon, command, context);
 out:
@@ -622,6 +626,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
 	}
 
 	/* do this deferred action */
+	priv->sleep_kind = "hibernate";
 	command = up_backend_get_hibernate_command (priv->backend);
 	up_daemon_deferred_sleep (daemon, command, context);
 out:
@@ -1256,16 +1261,16 @@ up_daemon_class_init (UpDaemonClass *klass)
 			      G_OBJECT_CLASS_TYPE (klass),
 			      G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
 			      0, NULL, NULL,
-			      g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);
+			      g_cclosure_marshal_VOID__STRING,
+			      G_TYPE_NONE, 1, G_TYPE_STRING);
 
 	signals[SIGNAL_RESUMING] =
 		g_signal_new ("resuming",
 			      G_OBJECT_CLASS_TYPE (klass),
 			      G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
 			      0, NULL, NULL,
-			      g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);
+			      g_cclosure_marshal_VOID__STRING,
+			      G_TYPE_NONE, 1, G_TYPE_STRING);
 
 	g_object_class_install_property (object_class,
 					 PROP_DAEMON_VERSION,
diff --git a/src/up-daemon.h b/src/up-daemon.h
index 99fb9da..9c81053 100644
--- a/src/up-daemon.h
+++ b/src/up-daemon.h
@@ -96,6 +96,7 @@ gboolean	 up_daemon_get_low_battery	(UpDaemon		*daemon,
 gboolean	 up_daemon_suspend		(UpDaemon		*daemon,
 						 DBusGMethodInvocation	*context);
 gboolean	 up_daemon_about_to_sleep	(UpDaemon		*daemon,
+						 const gchar		*sleep_kind,
 						 DBusGMethodInvocation	*context);
 gboolean	 up_daemon_suspend_allowed	(UpDaemon		*daemon,
 						 DBusGMethodInvocation	*context);
-- 
1.7.4.2

_______________________________________________
devkit-devel mailing list
devkit-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/devkit-devel

Reply via email to