[gnome-screensaver] consolidate DBus name, path, interface definitions



commit 8b3ebfc52ff7fcdc915d2fdf1bde218af2d478f2
Author: Saleem Abdulrasool <compnerd compnerd org>
Date:   Mon Dec 27 11:24:38 2010 -0800

    consolidate DBus name, path, interface definitions
    
    Multiple things use the same interface and path definitions.  Rather than having
    the definitions duplicated in the various locations, use a single header to
    define them.  This also helps keep the naming the same across all the entire
    codebase.

 src/Makefile.am                 |    3 ++
 src/bus.h                       |   50 +++++++++++++++++++++++++++++++++++++++
 src/gnome-screensaver-command.c |    6 +---
 src/gs-listener-dbus.c          |   47 ++++++++++++++----------------------
 src/gs-watcher-x11.c            |   14 ++++++----
 5 files changed, 81 insertions(+), 39 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9e55a50..4dd7184 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,6 +55,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
 gnome_screensaver_command_SOURCES = 	\
+	bus.h				\
 	gnome-screensaver-command.c	\
 	$(NULL)
 
@@ -91,6 +92,7 @@ test_passwd_LDADD =			\
 	$(NULL)
 
 test_watcher_SOURCES =			\
+	bus.h				\
 	test-watcher.c			\
 	gs-watcher.h			\
 	gs-watcher-x11.c		\
@@ -159,6 +161,7 @@ gs-marshal.h: gs-marshal.list
 	@GLIB_GENMARSHAL@ $< --prefix=gs_marshal --header > $@
 
 gnome_screensaver_SOURCES =	\
+	bus.h			\
 	gnome-screensaver.c	\
 	gnome-screensaver.h	\
 	gs-monitor.c		\
diff --git a/src/bus.h b/src/bus.h
new file mode 100644
index 0000000..d04ce72
--- /dev/null
+++ b/src/bus.h
@@ -0,0 +1,50 @@
+/* vim: set noet ts=8 sts=8 sw=8 :
+ *
+ * Copyright © 2010 Saleem Abdulrasool <compnerd compnerd org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#ifndef bus_h
+#define bus_h
+
+/* ConsoleKit */
+#define CK_SERVICE                      "org.freedesktop.ConsoleKit"
+#define CK_PATH                         "/org/freedesktop/ConsoleKit"
+#define CK_INTERFACE                    "org.freedesktop.ConsoleKit"
+
+#define CK_MANAGER_PATH                 CK_PATH "/Manager"
+#define CK_MANAGER_INTERFACE            CK_INTERFACE ".Manager"
+
+#define CK_SESSION_PATH                 CK_PATH "/Session"
+#define CK_SESSION_INTERFACE            CK_INTERFACE ".Session"
+
+/* Gnome Screensaver */
+#define GS_SERVICE                      "org.gnome.ScreenSaver"
+#define GS_PATH                         "/org/gnome/ScreenSaver"
+#define GS_INTERFACE                    "org.gnome.ScreenSaver"
+
+/* Gnome Session Manager */
+#define GSM_SERVICE                     "org.gnome.SessionManager"
+#define GSM_PATH                        "/org/gnome/SesionManager"
+#define GSM_INTERFACE                   "org.gnome.SessionManager"
+
+#define GSM_PRESENCE_PATH               GSM_PATH "/Presence"
+#define GSM_PRESENCE_INTERFACE          GSM_INTERFACE ".Presence"
+
+#endif
+
diff --git a/src/gnome-screensaver-command.c b/src/gnome-screensaver-command.c
index 280567a..62cadaf 100644
--- a/src/gnome-screensaver-command.c
+++ b/src/gnome-screensaver-command.c
@@ -28,15 +28,13 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#include "bus.h"
+
 #define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#define GS_SERVICE   "org.gnome.ScreenSaver"
-#define GS_PATH      "/org/gnome/ScreenSaver"
-#define GS_INTERFACE "org.gnome.ScreenSaver"
-
 /* this is for dbus < 0.3 */
 #if ((DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR < 30))
 #define dbus_bus_name_has_owner(connection, name, err) dbus_bus_service_exists(connection, name, err)
diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c
index e11c7fc..a9720be 100644
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -36,6 +36,8 @@
 #include "gs-marshal.h"
 #include "gs-debug.h"
 
+#include "bus.h"
+
 /* this is for dbus < 0.3 */
 #if ((DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR < 30))
 #define dbus_bus_name_has_owner(connection, name, err)      dbus_bus_service_exists(connection, name, err)
@@ -53,22 +55,9 @@ static DBusHandlerResult gs_listener_message_handler    (DBusConnection  *connec
                                                          DBusMessage     *message,
                                                          void            *user_data);
 
-#define GS_LISTENER_SERVICE   "org.gnome.ScreenSaver"
-#define GS_LISTENER_PATH      "/org/gnome/ScreenSaver"
-#define GS_LISTENER_INTERFACE "org.gnome.ScreenSaver"
-
 #define HAL_DEVICE_INTERFACE "org.freedesktop.Hal.Device"
 
-#define CK_NAME              "org.freedesktop.ConsoleKit"
-#define CK_MANAGER_PATH      "/org/freedesktop/ConsoleKit/Manager"
-#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
-#define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session"
-
-#define SESSION_NAME         "org.gnome.SessionManager"
-#define SESSION_PATH         "/org/gnome/SessionManager"
-#define SESSION_INTERFACE    "org.gnome.SessionManager"
-
-#define TYPE_MISMATCH_ERROR GS_LISTENER_INTERFACE ".TypeMismatch"
+#define TYPE_MISMATCH_ERROR  GS_INTERFACE ".TypeMismatch"
 
 #define GS_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GS_TYPE_LISTENER, GSListenerPrivate))
 
@@ -165,8 +154,8 @@ send_dbus_boolean_signal (GSListener *listener,
 
         g_return_if_fail (listener != NULL);
 
-        message = dbus_message_new_signal (GS_LISTENER_PATH,
-                                           GS_LISTENER_SERVICE,
+        message = dbus_message_new_signal (GS_PATH,
+                                           GS_SERVICE,
                                            name);
 
         dbus_message_iter_init_append (message, &iter);
@@ -383,7 +372,7 @@ raise_syntax (DBusConnection *connection,
               const char     *method_name)
 {
         raise_error (connection, in_reply_to,
-                     GS_LISTENER_SERVICE ".SyntaxError",
+                     GS_SERVICE ".SyntaxError",
                      "There is a syntax error in the invocation of the method %s",
                      method_name);
 }
@@ -617,7 +606,7 @@ do_introspect (DBusConnection *connection,
 
         /* ScreenSaver interface */
         xml = g_string_append (xml,
-                               "  <interface name=\"org.gnome.ScreenSaver\">\n"
+                               "  <interface name=\""GS_INTERFACE"\">\n"
                                "    <method name=\"Lock\">\n"
                                "    </method>\n"
                                "    <method name=\"SimulateUserActivity\">\n"
@@ -708,27 +697,27 @@ listener_dbus_handle_session_message (DBusConnection *connection,
         g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
         g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
 
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Lock")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "Lock")) {
                 g_signal_emit (listener, signals [LOCK], 0);
                 return send_success_reply (connection, message);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "Quit")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "Quit")) {
                 g_signal_emit (listener, signals [QUIT], 0);
                 return send_success_reply (connection, message);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SetActive")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "SetActive")) {
                 return listener_set_property (listener, connection, message, PROP_ACTIVE);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActive")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "GetActive")) {
                 return listener_get_property (listener, connection, message, PROP_ACTIVE);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "GetActiveTime")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "GetActiveTime")) {
                 return listener_get_active_time (listener, connection, message);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "ShowMessage")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "ShowMessage")) {
                 return listener_show_message (listener, connection, message);
         }
-        if (dbus_message_is_method_call (message, GS_LISTENER_SERVICE, "SimulateUserActivity")) {
+        if (dbus_message_is_method_call (message, GS_SERVICE, "SimulateUserActivity")) {
                 g_signal_emit (listener, signals [SIMULATE_USER_ACTIVITY], 0);
                 return DBUS_HANDLER_RESULT_HANDLED;
         }
@@ -1157,7 +1146,7 @@ screensaver_is_running (DBusConnection *connection)
         g_return_val_if_fail (connection != NULL, FALSE);
 
         dbus_error_init (&error);
-        exists = dbus_bus_name_has_owner (connection, GS_LISTENER_SERVICE, &error);
+        exists = dbus_bus_name_has_owner (connection, GS_SERVICE, &error);
         if (dbus_error_is_set (&error)) {
                 dbus_error_free (&error);
         }
@@ -1206,7 +1195,7 @@ gs_listener_acquire (GSListener *listener,
         dbus_error_init (&buserror);
 
         if (dbus_connection_register_object_path (listener->priv->connection,
-                                                  GS_LISTENER_PATH,
+                                                  GS_PATH,
                                                   &gs_listener_vtable,
                                                   listener) == FALSE) {
                 g_critical ("out of memory registering object path");
@@ -1214,7 +1203,7 @@ gs_listener_acquire (GSListener *listener,
         }
 
         res = dbus_bus_request_name (listener->priv->connection,
-                                     GS_LISTENER_SERVICE,
+                                     GS_SERVICE,
                                      DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                      &buserror);
         if (dbus_error_is_set (&buserror)) {
@@ -1293,7 +1282,7 @@ query_session_id (GSListener *listener)
 
         dbus_error_init (&error);
 
-        message = dbus_message_new_method_call (CK_NAME, CK_MANAGER_PATH, CK_MANAGER_INTERFACE, "GetCurrentSession");
+        message = dbus_message_new_method_call (CK_SERVICE, CK_MANAGER_PATH, CK_MANAGER_INTERFACE, "GetCurrentSession");
         if (message == NULL) {
                 gs_debug ("Couldn't allocate the dbus message");
                 return NULL;
diff --git a/src/gs-watcher-x11.c b/src/gs-watcher-x11.c
index f3d611d..8dc7d14 100644
--- a/src/gs-watcher-x11.c
+++ b/src/gs-watcher-x11.c
@@ -37,6 +37,8 @@
 #include "gs-marshal.h"
 #include "gs-debug.h"
 
+#include "bus.h"
+
 static void     gs_watcher_class_init (GSWatcherClass *klass);
 static void     gs_watcher_init       (GSWatcher      *watcher);
 static void     gs_watcher_finalize   (GObject        *object);
@@ -407,9 +409,9 @@ connect_presence_watcher (GSWatcher *watcher)
         }
 
         watcher->priv->presence_proxy = dbus_g_proxy_new_for_name (bus,
-                                                                   "org.gnome.SessionManager",
-                                                                   "/org/gnome/SessionManager/Presence",
-                                                                   "org.gnome.SessionManager.Presence");
+                                                                   GSM_SERVICE,
+                                                                   GSM_PRESENCE_PATH,
+                                                                   GSM_PRESENCE_INTERFACE);
 
         dbus_g_proxy_add_signal (watcher->priv->presence_proxy,
                                  "StatusChanged",
@@ -432,7 +434,7 @@ connect_presence_watcher (GSWatcher *watcher)
 
         proxy = dbus_g_proxy_new_from_proxy (watcher->priv->presence_proxy,
                                              "org.freedesktop.DBus.Properties",
-                                             "/org/gnome/SessionManager/Presence");
+                                             GSM_PRESENCE_PATH);
 
         status = 0;
         status_text = NULL;
@@ -441,7 +443,7 @@ connect_presence_watcher (GSWatcher *watcher)
         dbus_g_proxy_call (proxy,
                            "Get",
                            &error,
-                           G_TYPE_STRING, "org.gnome.SessionManager.Presence",
+                           G_TYPE_STRING, GSM_PRESENCE_INTERFACE,
                            G_TYPE_STRING, "status",
                            G_TYPE_INVALID,
                            G_TYPE_VALUE, &value,
@@ -461,7 +463,7 @@ connect_presence_watcher (GSWatcher *watcher)
         dbus_g_proxy_call (proxy,
                            "Get",
                            &error,
-                           G_TYPE_STRING, "org.gnome.SessionManager.Presence",
+                           G_TYPE_STRING, GSM_PRESENCE_INTERFACE,
                            G_TYPE_STRING, "status-text",
                            G_TYPE_INVALID,
                            G_TYPE_VALUE, &value,



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