[gnome-session] gsm-app: port to GDBus
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gsm-app: port to GDBus
- Date: Fri, 12 Dec 2014 15:16:01 +0000 (UTC)
commit dfd907801332a96d8673ebbc75a5a126e4f61ac4
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Oct 25 18:30:11 2014 -0700
gsm-app: port to GDBus
https://bugzilla.gnome.org/show_bug.cgi?id=622924
gnome-session/Makefile.am | 15 +++++--
gnome-session/gsm-app.c | 109 ++++++++++++++++++++++++++++----------------
gnome-session/gsm-app.h | 11 -----
3 files changed, 80 insertions(+), 55 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index c6c1c9e..cff3026 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -153,8 +153,14 @@ org.gnome.SessionManager.ClientPrivate.h: org.gnome.SessionManager.ClientPrivate
org.gnome.SessionManager.ClientPrivate.c: org.gnome.SessionManager.ClientPrivate.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
+org.gnome.SessionManager.App.h: org.gnome.SessionManager.App.xml Makefile.am
+ $(AM_V_GEN) gdbus-codegen --interface-prefix org.gnome.SessionManager.App. \
+ --generate-c-code org.gnome.SessionManager.App \
+ --c-namespace Gsm \
+ --annotate "org.gnome.SessionManager.App" "org.gtk.GDBus.C.Name" ExportedApp \
+ $(srcdir)/org.gnome.SessionManager.App.xml
+org.gnome.SessionManager.App.c: org.gnome.SessionManager.App.h
+ @: # generated as a side-effect
gsm-inhibitor-glue.h: org.gnome.SessionManager.Inhibitor.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_inhibitor --mode=glib-server --output=gsm-inhibitor-glue.h
$(srcdir)/org.gnome.SessionManager.Inhibitor.xml
@@ -163,6 +169,8 @@ 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.App.h \
+ org.gnome.SessionManager.App.c \
org.gnome.SessionManager.Client.h \
org.gnome.SessionManager.Client.c \
org.gnome.SessionManager.ClientPrivate.h \
@@ -170,8 +178,7 @@ BUILT_SOURCES = \
org.gnome.SessionManager.h \
org.gnome.SessionManager.c \
gsm-presence-glue.h \
- gsm-inhibitor-glue.h \
- gsm-app-glue.h
+ gsm-inhibitor-glue.h
EXTRA_DIST = \
README \
diff --git a/gnome-session/gsm-app.c b/gnome-session/gsm-app.c
index 68a9f1f..1d4b4ff 100644
--- a/gnome-session/gsm-app.c
+++ b/gnome-session/gsm-app.c
@@ -25,7 +25,7 @@
#include <string.h>
#include "gsm-app.h"
-#include "gsm-app-glue.h"
+#include "org.gnome.SessionManager.App.h"
#define GSM_APP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_APP, GsmAppPrivate))
@@ -40,7 +40,8 @@ struct _GsmAppPrivate
char *startup_id;
gboolean ever_started;
GTimeVal last_restart_time;
- DBusGConnection *connection;
+ GDBusConnection *connection;
+ GsmExportedApp *skeleton;
};
@@ -77,6 +78,41 @@ gsm_app_error_quark (void)
}
+static gboolean
+gsm_app_get_app_id (GsmExportedApp *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmApp *app)
+{
+ const gchar *id;
+
+ id = GSM_APP_GET_CLASS (app)->impl_get_app_id (app);
+ gsm_exported_app_complete_get_app_id (skeleton, invocation, id);
+
+ return TRUE;
+}
+
+static gboolean
+gsm_app_get_startup_id (GsmExportedApp *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmApp *app)
+{
+ const gchar *id;
+
+ id = g_strdup (app->priv->startup_id);
+ gsm_exported_app_complete_get_startup_id (skeleton, invocation, id);
+
+ return TRUE;
+}
+
+static gboolean
+gsm_app_get_phase (GsmExportedApp *skeleton,
+ GDBusMethodInvocation *invocation,
+ GsmApp *app)
+{
+ gsm_exported_app_complete_get_phase (skeleton, invocation, app->priv->phase);
+ return TRUE;
+}
+
static guint32
get_next_app_serial (void)
{
@@ -95,18 +131,34 @@ static gboolean
register_app (GsmApp *app)
{
GError *error;
+ GsmExportedApp *skeleton;
error = NULL;
- app->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (app->priv->connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting session bus: %s", error->message);
- g_error_free (error);
- }
+ app->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (error != NULL) {
+ g_critical ("error getting session bus: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ skeleton = gsm_exported_app_skeleton_new ();
+ app->priv->skeleton = skeleton;
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
+ app->priv->connection, app->priv->id,
+ &error);
+
+ if (error != NULL) {
+ g_critical ("error registering app on session bus: %s", error->message);
+ g_error_free (error);
return FALSE;
}
- dbus_g_connection_register_g_object (app->priv->connection, app->priv->id, G_OBJECT (app));
+ g_signal_connect (skeleton, "handle-get-app-id",
+ G_CALLBACK (gsm_app_get_app_id), app);
+ g_signal_connect (skeleton, "handle-get-phase",
+ G_CALLBACK (gsm_app_get_phase), app);
+ g_signal_connect (skeleton, "handle-get-startup-id",
+ G_CALLBACK (gsm_app_get_startup_id), app);
return TRUE;
}
@@ -231,6 +283,14 @@ gsm_app_dispose (GObject *object)
g_free (app->priv->id);
app->priv->id = NULL;
+ if (app->priv->skeleton != NULL) {
+ g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON
(app->priv->skeleton),
+ app->priv->connection);
+ g_clear_object (&app->priv->skeleton);
+ }
+
+ g_clear_object (&app->priv->connection);
+
G_OBJECT_CLASS (gsm_app_parent_class)->dispose (object);
}
@@ -302,7 +362,6 @@ gsm_app_class_init (GsmAppClass *klass)
0);
g_type_class_add_private (klass, sizeof (GsmAppPrivate));
- dbus_g_object_type_install_info (GSM_TYPE_APP, &dbus_glib_gsm_app_object_info);
}
const char *
@@ -482,33 +541,3 @@ gsm_app_died (GsmApp *app,
g_signal_emit (app, signals[DIED], 0, signal);
}
-
-gboolean
-gsm_app_get_app_id (GsmApp *app,
- char **id,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_APP (app), FALSE);
- *id = g_strdup (GSM_APP_GET_CLASS (app)->impl_get_app_id (app));
- return TRUE;
-}
-
-gboolean
-gsm_app_get_startup_id (GsmApp *app,
- char **id,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_APP (app), FALSE);
- *id = g_strdup (app->priv->startup_id);
- return TRUE;
-}
-
-gboolean
-gsm_app_get_phase (GsmApp *app,
- guint *phase,
- GError **error)
-{
- g_return_val_if_fail (GSM_IS_APP (app), FALSE);
- *phase = app->priv->phase;
- return TRUE;
-}
diff --git a/gnome-session/gsm-app.h b/gnome-session/gsm-app.h
index 6de21d4..ddaadb8 100644
--- a/gnome-session/gsm-app.h
+++ b/gnome-session/gsm-app.h
@@ -120,17 +120,6 @@ gboolean gsm_app_has_autostart_condition (GsmApp *app,
const char *condition);
void gsm_app_registered (GsmApp *app);
-/* exported to bus */
-gboolean gsm_app_get_app_id (GsmApp *app,
- char **id,
- GError **error);
-gboolean gsm_app_get_startup_id (GsmApp *app,
- char **id,
- GError **error);
-gboolean gsm_app_get_phase (GsmApp *app,
- guint *phase,
- GError **error);
-
G_END_DECLS
#endif /* __GSM_APP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]