[gnome-session] gsm-inhibitor: port to GDBus



commit f91274d2274344cdf4a18a59ec2647fa5755e66f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Oct 25 18:52:54 2014 -0700

    gsm-inhibitor: port to GDBus
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622924

 gnome-session/Makefile.am     |   15 ++-
 gnome-session/gsm-inhibitor.c |  226 +++++++++++++++++++++--------------------
 gnome-session/gsm-inhibitor.h |   21 ----
 3 files changed, 127 insertions(+), 135 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index cff3026..425d8c4 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -162,8 +162,14 @@ org.gnome.SessionManager.App.h: org.gnome.SessionManager.App.xml Makefile.am
 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
+org.gnome.SessionManager.Inhibitor.h: org.gnome.SessionManager.Inhibitor.xml Makefile.am
+       $(AM_V_GEN) gdbus-codegen --interface-prefix org.gnome.SessionManager.Inhibitor. \
+       --generate-c-code org.gnome.SessionManager.Inhibitor \
+       --c-namespace Gsm \
+        --annotate "org.gnome.SessionManager.Inhibitor" "org.gtk.GDBus.C.Name" ExportedInhibitor \
+       $(srcdir)/org.gnome.SessionManager.Inhibitor.xml
+org.gnome.SessionManager.Inhibitor.c: org.gnome.SessionManager.Inhibitor.h
+       @: # generated as a side-effect
 
 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
@@ -175,10 +181,11 @@ BUILT_SOURCES =                   \
        org.gnome.SessionManager.Client.c       \
        org.gnome.SessionManager.ClientPrivate.h        \
        org.gnome.SessionManager.ClientPrivate.c        \
+       org.gnome.SessionManager.Inhibitor.h    \
+       org.gnome.SessionManager.Inhibitor.c    \
        org.gnome.SessionManager.h      \
        org.gnome.SessionManager.c      \
-       gsm-presence-glue.h     \
-       gsm-inhibitor-glue.h
+       gsm-presence-glue.h
 
 EXTRA_DIST =                                           \
        README                                          \
diff --git a/gnome-session/gsm-inhibitor.c b/gnome-session/gsm-inhibitor.c
index 994fd91..05e3df7 100644
--- a/gnome-session/gsm-inhibitor.c
+++ b/gnome-session/gsm-inhibitor.c
@@ -24,10 +24,8 @@
 #include <time.h>
 #include <unistd.h>
 
-#include <dbus/dbus-glib.h>
-
 #include "gsm-inhibitor.h"
-#include "gsm-inhibitor-glue.h"
+#include "org.gnome.SessionManager.Inhibitor.h"
 
 #include "gsm-util.h"
 
@@ -45,7 +43,8 @@ struct GsmInhibitorPrivate
         guint flags;
         guint toplevel_xid;
         guint cookie;
-        DBusGConnection *connection;
+        GDBusConnection *connection;
+        GsmExportedInhibitor *skeleton;
 };
 
 enum {
@@ -61,37 +60,96 @@ enum {
 
 G_DEFINE_TYPE (GsmInhibitor, gsm_inhibitor, G_TYPE_OBJECT)
 
+#define GSM_INHIBITOR_DBUS_IFACE "org.gnome.SessionManager.Inhibitor"
+
+static const GDBusErrorEntry gsm_inhibitor_error_entries[] = {
+        { GSM_INHIBITOR_ERROR_GENERAL, GSM_INHIBITOR_DBUS_IFACE ".GeneralError" },
+        { GSM_INHIBITOR_ERROR_NOT_SET, GSM_INHIBITOR_DBUS_IFACE ".NotSet" }
+};
+
 GQuark
 gsm_inhibitor_error_quark (void)
 {
-        static GQuark ret = 0;
-        if (ret == 0) {
-                ret = g_quark_from_static_string ("gsm_inhibitor_error");
-        }
+        static volatile gsize quark_volatile = 0;
 
-        return ret;
+        g_dbus_error_register_error_domain ("gsm_inhibitor_error",
+                                            &quark_volatile,
+                                            gsm_inhibitor_error_entries,
+                                            G_N_ELEMENTS (gsm_inhibitor_error_entries));
+        return quark_volatile;
 }
 
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+static gboolean
+gsm_inhibitor_get_app_id (GsmExportedInhibitor  *skeleton,
+                          GDBusMethodInvocation *invocation,
+                          GsmInhibitor          *inhibitor)
+{
+        const gchar *id;
+
+        if (inhibitor->priv->app_id != NULL) {
+                id = inhibitor->priv->app_id;
+        } else {
+                id = "";
+        }
+
+        gsm_exported_inhibitor_complete_get_app_id (skeleton, invocation, id);
+
+        return TRUE;
+}
 
-GType
-gsm_inhibitor_error_get_type (void)
+static gboolean
+gsm_inhibitor_get_client_id (GsmExportedInhibitor  *skeleton,
+                             GDBusMethodInvocation *invocation,
+                             GsmInhibitor          *inhibitor)
 {
-        static GType etype = 0;
+        /* object paths are not allowed to be NULL or blank */
+        if (IS_STRING_EMPTY (inhibitor->priv->client_id)) {
+                g_dbus_method_invocation_return_error (invocation,
+                                                       GSM_INHIBITOR_ERROR,
+                                                       GSM_INHIBITOR_ERROR_NOT_SET,
+                                                       "Value is not set");
+                return TRUE;
+        }
+
+        gsm_exported_inhibitor_complete_get_client_id (skeleton, invocation, inhibitor->priv->client_id);
+        g_debug ("GsmInhibitor: getting client-id = '%s'", inhibitor->priv->client_id);
 
-        if (etype == 0) {
-                static const GEnumValue values[] = {
-                        ENUM_ENTRY (GSM_INHIBITOR_ERROR_GENERAL, "GeneralError"),
-                        ENUM_ENTRY (GSM_INHIBITOR_ERROR_NOT_SET, "NotSet"),
-                        { 0, 0, 0 }
-                };
+        return TRUE;
+}
 
-                g_assert (GSM_INHIBITOR_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
+static gboolean
+gsm_inhibitor_get_reason (GsmExportedInhibitor  *skeleton,
+                          GDBusMethodInvocation *invocation,
+                          GsmInhibitor          *inhibitor)
+{
+        const gchar *reason;
 
-                etype = g_enum_register_static ("GsmInhibitorError", values);
+        if (inhibitor->priv->reason != NULL) {
+                reason = inhibitor->priv->reason;
+        } else {
+                reason = "";
         }
 
-        return etype;
+        gsm_exported_inhibitor_complete_get_reason (skeleton, invocation, reason);
+        return TRUE;
+}
+
+static gboolean
+gsm_inhibitor_get_flags (GsmExportedInhibitor  *skeleton,
+                         GDBusMethodInvocation *invocation,
+                         GsmInhibitor          *inhibitor)
+{
+        gsm_exported_inhibitor_complete_get_flags (skeleton, invocation, inhibitor->priv->flags);
+        return TRUE;
+}
+
+static gboolean
+gsm_inhibitor_get_toplevel_xid (GsmExportedInhibitor  *skeleton,
+                                GDBusMethodInvocation *invocation,
+                                GsmInhibitor          *inhibitor)
+{
+        gsm_exported_inhibitor_complete_get_toplevel_xid (skeleton, invocation, 
inhibitor->priv->toplevel_xid);
+        return TRUE;
 }
 
 static guint32
@@ -112,18 +170,39 @@ static gboolean
 register_inhibitor (GsmInhibitor *inhibitor)
 {
         GError *error;
+        GsmExportedInhibitor *skeleton;
 
         error = NULL;
-        inhibitor->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-        if (inhibitor->priv->connection == NULL) {
-                if (error != NULL) {
-                        g_critical ("error getting session bus: %s", error->message);
-                        g_error_free (error);
-                }
+        inhibitor->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;
         }
 
-        dbus_g_connection_register_g_object (inhibitor->priv->connection, inhibitor->priv->id, G_OBJECT 
(inhibitor));
+        skeleton = gsm_exported_inhibitor_skeleton_new ();
+        inhibitor->priv->skeleton = skeleton;
+        g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
+                                          inhibitor->priv->connection,
+                                          inhibitor->priv->id, &error);
+
+        if (error != NULL) {
+                g_critical ("error exporting inhibitor on session bus: %s", error->message);
+                g_error_free (error);
+                return FALSE;
+        }
+
+        g_signal_connect (skeleton, "handle-get-app-id",
+                          G_CALLBACK (gsm_inhibitor_get_app_id), inhibitor);
+        g_signal_connect (skeleton, "handle-get-client-id",
+                          G_CALLBACK (gsm_inhibitor_get_client_id), inhibitor);
+        g_signal_connect (skeleton, "handle-get-flags",
+                          G_CALLBACK (gsm_inhibitor_get_flags), inhibitor);
+        g_signal_connect (skeleton, "handle-get-reason",
+                          G_CALLBACK (gsm_inhibitor_get_reason), inhibitor);
+        g_signal_connect (skeleton, "handle-get-toplevel-xid",
+                          G_CALLBACK (gsm_inhibitor_get_toplevel_xid), inhibitor);
 
         return TRUE;
 }
@@ -262,85 +341,6 @@ gsm_inhibitor_peek_bus_name (GsmInhibitor  *inhibitor)
         return inhibitor->priv->bus_name;
 }
 
-gboolean
-gsm_inhibitor_get_app_id (GsmInhibitor *inhibitor,
-                          char        **id,
-                          GError      **error)
-{
-        g_return_val_if_fail (GSM_IS_INHIBITOR (inhibitor), FALSE);
-
-        if (inhibitor->priv->app_id != NULL) {
-                *id = g_strdup (inhibitor->priv->app_id);
-        } else {
-                *id = g_strdup ("");
-        }
-
-        return TRUE;
-}
-
-gboolean
-gsm_inhibitor_get_client_id (GsmInhibitor *inhibitor,
-                             char        **id,
-                             GError      **error)
-{
-        g_return_val_if_fail (GSM_IS_INHIBITOR (inhibitor), FALSE);
-
-        /* object paths are not allowed to be NULL or blank */
-        if (IS_STRING_EMPTY (inhibitor->priv->client_id)) {
-                g_set_error (error,
-                             GSM_INHIBITOR_ERROR,
-                             GSM_INHIBITOR_ERROR_NOT_SET,
-                             "Value is not set");
-                return FALSE;
-        }
-
-        *id = g_strdup (inhibitor->priv->client_id);
-
-        g_debug ("GsmInhibitor: getting client-id = '%s'", *id);
-
-        return TRUE;
-}
-
-gboolean
-gsm_inhibitor_get_reason (GsmInhibitor *inhibitor,
-                          char        **reason,
-                          GError      **error)
-{
-        g_return_val_if_fail (GSM_IS_INHIBITOR (inhibitor), FALSE);
-
-        if (inhibitor->priv->reason != NULL) {
-                *reason = g_strdup (inhibitor->priv->reason);
-        } else {
-                *reason = g_strdup ("");
-        }
-
-        return TRUE;
-}
-
-gboolean
-gsm_inhibitor_get_flags (GsmInhibitor *inhibitor,
-                         guint        *flags,
-                         GError      **error)
-{
-        g_return_val_if_fail (GSM_IS_INHIBITOR (inhibitor), FALSE);
-
-        *flags = inhibitor->priv->flags;
-
-        return TRUE;
-}
-
-gboolean
-gsm_inhibitor_get_toplevel_xid (GsmInhibitor *inhibitor,
-                                guint        *xid,
-                                GError      **error)
-{
-        g_return_val_if_fail (GSM_IS_INHIBITOR (inhibitor), FALSE);
-
-        *xid = inhibitor->priv->toplevel_xid;
-
-        return TRUE;
-}
-
 const char *
 gsm_inhibitor_peek_id (GsmInhibitor *inhibitor)
 {
@@ -484,6 +484,14 @@ gsm_inhibitor_finalize (GObject *object)
         g_free (inhibitor->priv->client_id);
         g_free (inhibitor->priv->reason);
 
+        if (inhibitor->priv->skeleton != NULL) {
+                g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON 
(inhibitor->priv->skeleton),
+                                                                    inhibitor->priv->connection);
+                g_clear_object (&inhibitor->priv->skeleton);
+        }
+
+        g_clear_object (&inhibitor->priv->connection);
+
         G_OBJECT_CLASS (gsm_inhibitor_parent_class)->finalize (object);
 }
 
@@ -553,8 +561,6 @@ gsm_inhibitor_class_init (GsmInhibitorClass *klass)
                                                             0,
                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
-        dbus_g_object_type_install_info (GSM_TYPE_INHIBITOR, &dbus_glib_gsm_inhibitor_object_info);
-        dbus_g_error_domain_register (GSM_INHIBITOR_ERROR, NULL, GSM_INHIBITOR_TYPE_ERROR);
         g_type_class_add_private (klass, sizeof (GsmInhibitorPrivate));
 }
 
diff --git a/gnome-session/gsm-inhibitor.h b/gnome-session/gsm-inhibitor.h
index 63b191a..5229fe1 100644
--- a/gnome-session/gsm-inhibitor.h
+++ b/gnome-session/gsm-inhibitor.h
@@ -57,9 +57,6 @@ typedef enum
 } GsmInhibitorError;
 
 #define GSM_INHIBITOR_ERROR gsm_inhibitor_error_quark ()
-GType          gsm_inhibitor_error_get_type       (void);
-#define GSM_INHIBITOR_TYPE_ERROR (gsm_inhibitor_error_get_type ())
-
 GQuark         gsm_inhibitor_error_quark          (void);
 
 GType          gsm_inhibitor_get_type             (void) G_GNUC_CONST;
@@ -86,24 +83,6 @@ guint          gsm_inhibitor_peek_cookie          (GsmInhibitor  *inhibitor);
 guint          gsm_inhibitor_peek_flags           (GsmInhibitor  *inhibitor);
 guint          gsm_inhibitor_peek_toplevel_xid    (GsmInhibitor  *inhibitor);
 
-/* exported to bus */
-gboolean       gsm_inhibitor_get_app_id           (GsmInhibitor  *inhibitor,
-                                                   char         **id,
-                                                   GError       **error);
-gboolean       gsm_inhibitor_get_client_id        (GsmInhibitor  *inhibitor,
-                                                   char         **id,
-                                                   GError       **error);
-gboolean       gsm_inhibitor_get_reason           (GsmInhibitor  *inhibitor,
-                                                   char         **reason,
-                                                   GError       **error);
-gboolean       gsm_inhibitor_get_flags            (GsmInhibitor  *inhibitor,
-                                                   guint         *flags,
-                                                   GError       **error);
-gboolean       gsm_inhibitor_get_toplevel_xid     (GsmInhibitor  *inhibitor,
-                                                   guint         *xid,
-                                                   GError       **error);
-
-
 G_END_DECLS
 
 #endif /* __GSM_INHIBITOR_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]