[gnome-session] gsm-client: port to GDBus
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm-client: port to GDBus
- Date: Fri, 12 Dec 2014 15:15:51 +0000 (UTC)
commit 8ce2bbb46aca488c3e63eba1504d08115d66b464
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Oct 25 16:19:56 2014 -0700
gsm-client: port to GDBus
https://bugzilla.gnome.org/show_bug.cgi?id=622924
gnome-session/Makefile.am | 17 +++-
gnome-session/gsm-client.c | 221 ++++++++++++++++++++++++--------------------
gnome-session/gsm-client.h | 20 +----
3 files changed, 134 insertions(+), 124 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index 693926f..725ea99 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -135,8 +135,14 @@ org.gnome.SessionManager.h: org.gnome.SessionManager.xml Makefile.am
org.gnome.SessionManager.c: org.gnome.SessionManager.h
@: # generated as a side-effect
-gsm-client-glue.h: org.gnome.SessionManager.Client.xml Makefile.am
- $(AM_V_GEN)dbus-binding-tool --prefix=gsm_client --mode=glib-server --output=gsm-client-glue.h
$(srcdir)/org.gnome.SessionManager.Client.xml
+org.gnome.SessionManager.Client.h: org.gnome.SessionManager.Client.xml Makefile.am
+ $(AM_V_GEN) gdbus-codegen --interface-prefix org.gnome.SessionManager.Client. \
+ --generate-c-code org.gnome.SessionManager.Client \
+ --c-namespace Gsm \
+ --annotate "org.gnome.SessionManager.Client" "org.gtk.GDBus.C.Name" ExportedClient \
+ $(srcdir)/org.gnome.SessionManager.Client.xml
+org.gnome.SessionManager.Client.c: org.gnome.SessionManager.Client.h
+ @: # generated as a side-effect
gsm-app-glue.h: org.gnome.SessionManager.App.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_app --mode=glib-server --output=gsm-app-glue.h
$(srcdir)/org.gnome.SessionManager.App.xml
@@ -148,11 +154,12 @@ gsm-presence-glue.h: org.gnome.SessionManager.Presence.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_presence --mode=glib-server --output=gsm-presence-glue.h
$(srcdir)/org.gnome.SessionManager.Presence.xml
BUILT_SOURCES = \
- org.gnome.SessionManager.h \
- org.gnome.SessionManager.c \
+ org.gnome.SessionManager.Client.h \
+ org.gnome.SessionManager.Client.c \
+ org.gnome.SessionManager.h \
+ org.gnome.SessionManager.c \
gsm-presence-glue.h \
gsm-inhibitor-glue.h \
- gsm-client-glue.h \
gsm-app-glue.h
EXTRA_DIST = \
diff --git a/gnome-session/gsm-client.c b/gnome-session/gsm-client.c
index 543d7ef..75edbbf 100644
--- a/gnome-session/gsm-client.c
+++ b/gnome-session/gsm-client.c
@@ -19,10 +19,8 @@
#include "config.h"
-#include <dbus/dbus-glib.h>
-
#include "gsm-client.h"
-#include "gsm-client-glue.h"
+#include "org.gnome.SessionManager.Client.h"
static guint32 client_serial = 1;
@@ -34,7 +32,8 @@ struct GsmClientPrivate
char *startup_id;
char *app_id;
guint status;
- DBusGConnection *connection;
+ GsmExportedClient *skeleton;
+ GDBusConnection *connection;
};
enum {
@@ -55,69 +54,145 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_ABSTRACT_TYPE (GsmClient, gsm_client, G_TYPE_OBJECT)
+#define GSM_CLIENT_DBUS_IFACE "org.gnome.SessionManager.Client"
+
+static const GDBusErrorEntry gsm_client_error_entries[] = {
+ { GSM_CLIENT_ERROR_GENERAL, GSM_CLIENT_DBUS_IFACE ".GeneralError" },
+ { GSM_CLIENT_ERROR_NOT_REGISTERED, GSM_CLIENT_DBUS_IFACE ".NotRegistered" }
+};
+
GQuark
gsm_client_error_quark (void)
{
- static GQuark ret = 0;
- if (ret == 0) {
- ret = g_quark_from_static_string ("gsm_client_error");
- }
+ static volatile gsize quark_volatile = 0;
- return ret;
+ g_dbus_error_register_error_domain ("gsm_client_error",
+ &quark_volatile,
+ gsm_client_error_entries,
+ G_N_ELEMENTS (gsm_client_error_entries));
+ return quark_volatile;
}
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+static guint32
+get_next_client_serial (void)
+{
+ guint32 serial;
+
+ serial = client_serial++;
+
+ if ((gint32)client_serial < 0) {
+ client_serial = 1;
+ }
+
+ return serial;
+}
-GType
-gsm_client_error_get_type (void)
+static gboolean
+gsm_client_get_startup_id (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
{
- static GType etype = 0;
+ gsm_exported_client_complete_get_startup_id (skeleton, invocation, client->priv->startup_id);
+ return TRUE;
+}
- if (etype == 0) {
- static const GEnumValue values[] = {
- ENUM_ENTRY (GSM_CLIENT_ERROR_GENERAL, "GeneralError"),
- ENUM_ENTRY (GSM_CLIENT_ERROR_NOT_REGISTERED, "NotRegistered"),
- { 0, 0, 0 }
- };
+static gboolean
+gsm_client_get_app_id (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
+{
+ gsm_exported_client_complete_get_app_id (skeleton, invocation, client->priv->app_id);
+ return TRUE;
+}
- g_assert (GSM_CLIENT_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
+static gboolean
+gsm_client_get_restart_style_hint (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
+{
+ guint hint;
- etype = g_enum_register_static ("GsmClientError", values);
- }
+ hint = GSM_CLIENT_GET_CLASS (client)->impl_get_restart_style_hint (client);
+ gsm_exported_client_complete_get_restart_style_hint (skeleton, invocation, hint);
+ return TRUE;
+}
- return etype;
+static gboolean
+gsm_client_get_status (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
+{
+ gsm_exported_client_complete_get_status (skeleton, invocation, client->priv->status);
+ return TRUE;
}
-static guint32
-get_next_client_serial (void)
+static gboolean
+gsm_client_get_unix_process_id (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
{
- guint32 serial;
+ guint pid;
- serial = client_serial++;
+ pid = GSM_CLIENT_GET_CLASS (client)->impl_get_unix_process_id (client);
+ gsm_exported_client_complete_get_unix_process_id (skeleton, invocation, pid);
+ return TRUE;
+}
- if ((gint32)client_serial < 0) {
- client_serial = 1;
+static gboolean
+gsm_client_stop_dbus (GsmExportedClient *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmClient *client)
+{
+ GError *error = NULL;
+ gsm_client_stop (client, &error);
+
+ if (error != NULL) {
+ g_dbus_method_invocation_take_error (invocation, error);
+ } else {
+ gsm_exported_client_complete_stop (skeleton, invocation);
}
- return serial;
+ return TRUE;
}
static gboolean
register_client (GsmClient *client)
{
- GError *error;
+ GError *error = NULL;
+ GsmExportedClient *skeleton;
- error = NULL;
- client->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ client->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (client->priv->connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting session bus: %s", error->message);
- g_error_free (error);
- }
+ g_critical ("error getting session bus: %s", error->message);
+ g_error_free (error);
return FALSE;
}
- dbus_g_connection_register_g_object (client->priv->connection, client->priv->id, G_OBJECT (client));
+ skeleton = gsm_exported_client_skeleton_new ();
+ client->priv->skeleton = skeleton;
+ g_debug ("exporting client to object path: %s", client->priv->id);
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
+ client->priv->connection,
+ client->priv->id, &error);
+
+ if (error != NULL) {
+ g_critical ("error exporting client on session bus: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_signal_connect (skeleton, "handle-get-app-id",
+ G_CALLBACK (gsm_client_get_app_id), client);
+ g_signal_connect (skeleton, "handle-get-restart-style-hint",
+ G_CALLBACK (gsm_client_get_restart_style_hint), client);
+ g_signal_connect (skeleton, "handle-get-startup-id",
+ G_CALLBACK (gsm_client_get_startup_id), client);
+ g_signal_connect (skeleton, "handle-get-status",
+ G_CALLBACK (gsm_client_get_status), client);
+ g_signal_connect (skeleton, "handle-get-unix-process-id",
+ G_CALLBACK (gsm_client_get_unix_process_id), client);
+ g_signal_connect (skeleton, "handle-stop",
+ G_CALLBACK (gsm_client_stop_dbus), client);
return TRUE;
}
@@ -167,6 +242,14 @@ gsm_client_finalize (GObject *object)
g_free (client->priv->startup_id);
g_free (client->priv->app_id);
+ if (client->priv->skeleton != NULL) {
+ g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON
(client->priv->skeleton),
+ client->priv->connection);
+ g_clear_object (&client->priv->skeleton);
+ }
+
+ g_clear_object (&client->priv->connection);
+
G_OBJECT_CLASS (gsm_client_parent_class)->finalize (object);
}
@@ -346,8 +429,6 @@ gsm_client_class_init (GsmClientClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_type_class_add_private (klass, sizeof (GsmClientPrivate));
-
- dbus_g_object_type_install_info (GSM_TYPE_CLIENT, &dbus_glib_gsm_client_object_info);
}
const char *
@@ -400,66 +481,6 @@ gsm_client_peek_restart_style_hint (GsmClient *client)
return GSM_CLIENT_GET_CLASS (client)->impl_get_restart_style_hint (client);
}
-gboolean
-gsm_client_get_startup_id (GsmClient *client,
- char **id,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_CLIENT (client), FALSE);
-
- *id = g_strdup (client->priv->startup_id);
-
- return TRUE;
-}
-
-gboolean
-gsm_client_get_app_id (GsmClient *client,
- char **id,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_CLIENT (client), FALSE);
-
- *id = g_strdup (client->priv->app_id);
-
- return TRUE;
-}
-
-gboolean
-gsm_client_get_restart_style_hint (GsmClient *client,
- guint *hint,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_CLIENT (client), FALSE);
-
- *hint = GSM_CLIENT_GET_CLASS (client)->impl_get_restart_style_hint (client);
-
- return TRUE;
-}
-
-gboolean
-gsm_client_get_status (GsmClient *client,
- guint *status,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_CLIENT (client), FALSE);
-
- *status = client->priv->status;
-
- return TRUE;
-}
-
-gboolean
-gsm_client_get_unix_process_id (GsmClient *client,
- guint *pid,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_CLIENT (client), FALSE);
-
- *pid = GSM_CLIENT_GET_CLASS (client)->impl_get_unix_process_id (client);
-
- return TRUE;
-}
-
/**
* gsm_client_get_app_name:
* @client: a #GsmClient.
diff --git a/gnome-session/gsm-client.h b/gnome-session/gsm-client.h
index 4ef5dc9..cd7c06d 100644
--- a/gnome-session/gsm-client.h
+++ b/gnome-session/gsm-client.h
@@ -102,9 +102,6 @@ typedef enum
} GsmClientError;
#define GSM_CLIENT_ERROR gsm_client_error_quark ()
-#define GSM_CLIENT_TYPE_ERROR (gsm_client_error_get_type ())
-
-GType gsm_client_error_get_type (void);
GQuark gsm_client_error_quark (void);
GType gsm_client_get_type (void) G_GNUC_CONST;
@@ -137,24 +134,9 @@ void gsm_client_disconnected (GsmClient *client)
GKeyFile *gsm_client_save (GsmClient *client,
GError **error);
-/* exported to bus */
+
gboolean gsm_client_stop (GsmClient *client,
GError **error);
-gboolean gsm_client_get_startup_id (GsmClient *client,
- char **startup_id,
- GError **error);
-gboolean gsm_client_get_app_id (GsmClient *client,
- char **app_id,
- GError **error);
-gboolean gsm_client_get_restart_style_hint (GsmClient *client,
- guint *hint,
- GError **error);
-gboolean gsm_client_get_status (GsmClient *client,
- guint *status,
- GError **error);
-gboolean gsm_client_get_unix_process_id (GsmClient *client,
- guint *pid,
- GError **error);
/* private */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]