summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2012-05-03 17:54:59 +0200
committerRay Strode <rstrode@redhat.com>2012-07-17 03:38:10 -0400
commit20cf9b2302fbdf94e5322b0bb1521c9437cd7087 (patch)
tree77437dc1e4cbed5e82b507bf69d1e43ff7e5b841 /common
parent560e530559810154189b3aa4a496e2b2330f7d7f (diff)
downloadgdm-20cf9b2302fbdf94e5322b0bb1521c9437cd7087.tar.gz
common: Use GDBus for GdmSettings
GdmSettings is a system bus service provided by GDM so that greeters can read custom.conf without parsing the file themselves. This commit changes GdmSettings to use gdbus instead of dbus-glib. https://bugzilla.gnome.org/show_bug.cgi?id=622888
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am14
-rw-r--r--common/gdm-settings-client.c107
-rw-r--r--common/gdm-settings.c87
-rw-r--r--common/test-settings-server.c114
4 files changed, 144 insertions, 178 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 34920416..11cd473d 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -49,8 +49,12 @@ gdm_crash_logger_CPPFLAGS = \
$(NULL)
gdm_crash_logger_LDADD = $(GTHREAD_LIBS)
-gdm-settings-glue.h: gdm-settings.xml Makefile.am
- dbus-binding-tool --prefix=gdm_settings --mode=glib-server --output=gdm-settings-glue.h $(srcdir)/gdm-settings.xml
+gdm-settings-glue.c gdm-settings-glue.h : gdm-settings.xml Makefile.am
+ $(AM_V_GEN)gdbus-codegen \
+ --c-namespace=GdmDBus \
+ --interface-prefix=org.gnome.DisplayManager \
+ --generate-c-code=gdm-settings-glue \
+ $(srcdir)/gdm-settings.xml
if MKDTEMP_MISSING
MKDTEMP_FILES = mkdtemp.c mkdtemp.h
@@ -89,6 +93,11 @@ libgdmcommon_la_SOURCES = \
$(MKDTEMP_FILES) \
$(NULL)
+nodist_libgdmcommon_la_SOURCES = \
+ gdm-settings-glue.h \
+ gdm-settings-glue.c \
+ $(NULL)
+
libgdmcommon_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
@@ -139,6 +148,7 @@ test_settings_client_LDADD = \
$(NULL)
CLEANFILES = \
+ gdm-settings-glue.c \
$(BUILT_SOURCES) \
$(NULL)
diff --git a/common/gdm-settings-client.c b/common/gdm-settings-client.c
index 70a79997..22fb2f41 100644
--- a/common/gdm-settings-client.c
+++ b/common/gdm-settings-client.c
@@ -29,17 +29,15 @@
#include <sys/stat.h>
#include <sys/types.h>
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glib-object.h>
+#include <gio/gio.h>
#include "gdm-settings-client.h"
#include "gdm-settings-utils.h"
+#include "gdm-settings-glue.h"
#define SETTINGS_DBUS_NAME "org.gnome.DisplayManager"
#define SETTINGS_DBUS_PATH "/org/gnome/DisplayManager/Settings"
@@ -47,8 +45,7 @@
static GHashTable *notifiers = NULL;
static GHashTable *schemas = NULL;
-static DBusGProxy *settings_proxy = NULL;
-static DBusGConnection *connection = NULL;
+static GdmDBusSettings *settings_proxy = NULL;
static guint32 id_serial = 0;
typedef struct {
@@ -94,27 +91,19 @@ set_value (const char *key,
/* FIXME: check cache */
- g_debug ("Setting %s=%s", key, value);
error = NULL;
- res = dbus_g_proxy_call (settings_proxy,
- "SetValue",
- &error,
- G_TYPE_STRING, key,
- G_TYPE_STRING, value,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (! res) {
- if (error != NULL) {
- /*g_debug ("Failed to get value for %s: %s", key, error->message);*/
- g_error_free (error);
- } else {
- /*g_debug ("Failed to get value for %s", key);*/
- }
- return FALSE;
+ res = gdm_dbus_settings_call_set_value_sync (settings_proxy,
+ key,
+ value,
+ NULL,
+ &error);
+ if (! res) {
+ g_debug ("Failed to set value for %s: %s", key, error->message);
+ g_error_free (error);
}
- return TRUE;
+ return res;
}
static gboolean
@@ -122,37 +111,23 @@ get_value (const char *key,
char **value)
{
GError *error;
- char *str;
gboolean res;
/* FIXME: check cache */
error = NULL;
- res = dbus_g_proxy_call (settings_proxy,
- "GetValue",
- &error,
- G_TYPE_STRING, key,
- G_TYPE_INVALID,
- G_TYPE_STRING, &str,
- G_TYPE_INVALID);
- if (! res) {
- if (error != NULL) {
- /*g_debug ("Failed to get value for %s: %s", key, error->message);*/
- g_error_free (error);
- } else {
- /*g_debug ("Failed to get value for %s", key);*/
- }
-
- return FALSE;
- }
- if (value != NULL) {
- *value = g_strdup (str);
+ res = gdm_dbus_settings_call_get_value_sync (settings_proxy,
+ key,
+ value,
+ NULL,
+ &error);
+ if (! res) {
+ g_debug ("Failed to get value for %s: %s", key, error->message);
+ g_error_free (error);
}
- g_free (str);
-
- return TRUE;
+ return res;
}
static void
@@ -467,11 +442,11 @@ send_notification (gpointer key,
}
static void
-on_value_changed (DBusGProxy *proxy,
- const char *key,
- const char *old_value,
- const char *new_value,
- gpointer data)
+on_value_changed (GdmDBusSettings *proxy,
+ const char *key,
+ const char *old_value,
+ const char *new_value,
+ gpointer data)
{
GdmSettingsEntry *entry;
@@ -502,21 +477,16 @@ gdm_settings_client_init (const char *file,
g_assert (schemas == NULL);
error = NULL;
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (connection == NULL) {
- if (error != NULL) {
- g_warning ("error getting system bus: %s", error->message);
- g_error_free (error);
- }
- return FALSE;
- }
- settings_proxy = dbus_g_proxy_new_for_name (connection,
- SETTINGS_DBUS_NAME,
- SETTINGS_DBUS_PATH,
- SETTINGS_DBUS_INTERFACE);
+ settings_proxy = GDM_DBUS_SETTINGS (gdm_dbus_settings_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ SETTINGS_DBUS_NAME,
+ SETTINGS_DBUS_PATH,
+ NULL,
+ &error));
if (settings_proxy == NULL) {
- g_warning ("Unable to connect to settings server");
+ g_warning ("Unable to connect to settings server: %s", error->message);
+ g_error_free (error);
return FALSE;
}
@@ -532,14 +502,7 @@ gdm_settings_client_init (const char *file,
schemas = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)gdm_settings_entry_free);
g_slist_foreach (list, (GFunc)hashify_list, NULL);
- dbus_g_proxy_add_signal (settings_proxy, "ValueChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (settings_proxy,
- "ValueChanged",
- G_CALLBACK (on_value_changed),
- NULL,
- NULL);
-
-
+ g_signal_connect (settings_proxy, "value-changed", G_CALLBACK (on_value_changed), NULL);
return TRUE;
}
diff --git a/common/gdm-settings.c b/common/gdm-settings.c
index 0395681b..e6a658b3 100644
--- a/common/gdm-settings.c
+++ b/common/gdm-settings.c
@@ -33,9 +33,7 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glib-object.h>
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include "gdm-settings.h"
#include "gdm-settings-glue.h"
@@ -50,7 +48,8 @@
struct GdmSettingsPrivate
{
- DBusGConnection *connection;
+ GDBusConnection *connection;
+ GdmDBusSettings *skeleton;
GdmSettingsBackend *backend;
};
@@ -139,12 +138,58 @@ gdm_settings_set_value (GdmSettings *settings,
}
static gboolean
+handle_get_value (GdmDBusSettings *settings,
+ GDBusMethodInvocation *invocation,
+ const char *key,
+ gpointer user_data)
+{
+ GdmSettings *self = GDM_SETTINGS (user_data);
+ GError *error = NULL;
+ char *value = NULL;
+
+ gdm_settings_get_value (self, key, &value, &error);
+ if (error) {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ return TRUE;
+ }
+
+ gdm_dbus_settings_complete_get_value (settings, invocation,
+ value);
+ g_free (value);
+
+ return TRUE;
+}
+
+static gboolean
+handle_set_value (GdmDBusSettings *settings,
+ GDBusMethodInvocation *invocation,
+ const char *key,
+ const char *value,
+ gpointer user_data)
+{
+ GdmSettings *self = GDM_SETTINGS (user_data);
+ GError *error = NULL;
+
+ gdm_settings_set_value (self, key, value, &error);
+ if (error) {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ return TRUE;
+ }
+
+ gdm_dbus_settings_complete_set_value (settings, invocation);
+
+ return TRUE;
+}
+
+static gboolean
register_settings (GdmSettings *settings)
{
GError *error = NULL;
error = NULL;
- settings->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ settings->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (settings->priv->connection == NULL) {
if (error != NULL) {
g_critical ("error getting system bus: %s", error->message);
@@ -153,7 +198,22 @@ register_settings (GdmSettings *settings)
exit (1);
}
- dbus_g_connection_register_g_object (settings->priv->connection, GDM_SETTINGS_DBUS_PATH, G_OBJECT (settings));
+ settings->priv->skeleton = GDM_DBUS_SETTINGS (gdm_dbus_settings_skeleton_new ());
+ g_signal_connect_object (settings->priv->skeleton,
+ "handle-get-value",
+ G_CALLBACK (handle_get_value),
+ settings,
+ 0);
+ g_signal_connect_object (settings->priv->skeleton,
+ "handle-set-value",
+ G_CALLBACK (handle_set_value),
+ settings,
+ 0);
+
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (settings->priv->skeleton),
+ settings->priv->connection,
+ GDM_SETTINGS_DBUS_PATH,
+ NULL);
return TRUE;
}
@@ -184,8 +244,6 @@ gdm_settings_class_init (GdmSettingsClass *klass)
G_TYPE_STRING);
g_type_class_add_private (klass, sizeof (GdmSettingsPrivate));
-
- dbus_g_object_type_install_info (GDM_TYPE_SETTINGS, &dbus_glib_gdm_settings_object_info);
}
static void
@@ -196,13 +254,12 @@ backend_value_changed (GdmSettingsBackend *backend,
GdmSettings *settings)
{
g_debug ("Emitting value-changed %s %s %s", key, old_value, new_value);
- /* just proxy it */
- g_signal_emit (settings,
- signals [VALUE_CHANGED],
- 0,
- key,
- old_value,
- new_value);
+
+ /* proxy it to internal listeners */
+ g_signal_emit (settings, signals [VALUE_CHANGED], 0, key, old_value, new_value);
+
+ /* and to dbus */
+ gdm_dbus_settings_emit_value_changed (settings->priv->skeleton, key, old_value, new_value);
}
static void
diff --git a/common/test-settings-server.c b/common/test-settings-server.c
index a7fe7918..bf7ab0ee 100644
--- a/common/test-settings-server.c
+++ b/common/test-settings-server.c
@@ -30,10 +30,7 @@
#include <locale.h>
#include <glib.h>
-
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include "gdm-settings.h"
@@ -41,76 +38,14 @@
static GdmSettings *settings = NULL;
-static gboolean
-acquire_name_on_proxy (DBusGProxy *bus_proxy)
-{
- GError *error;
- guint result;
- gboolean res;
- gboolean ret;
-
- ret = FALSE;
-
- if (bus_proxy == NULL) {
- goto out;
- }
-
- error = NULL;
- res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- &error,
- G_TYPE_STRING, GDM_DBUS_NAME,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID);
- if (! res) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", GDM_DBUS_NAME);
- }
- goto out;
- }
-
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", GDM_DBUS_NAME);
- }
- goto out;
- }
-
- ret = TRUE;
-
- out:
- return ret;
-}
-
-static DBusGProxy *
-get_bus_proxy (DBusGConnection *connection)
-{
- DBusGProxy *bus_proxy;
-
- bus_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- return bus_proxy;
-}
-
-static DBusGConnection *
+static GDBusConnection *
get_system_bus (void)
{
GError *error;
- DBusGConnection *bus;
- DBusConnection *connection;
+ GDBusConnection *bus;
error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s",
error->message);
@@ -118,19 +53,29 @@ get_system_bus (void)
goto out;
}
- connection = dbus_g_connection_get_connection (bus);
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
+ g_dbus_connection_set_exit_on_close (bus, FALSE);
out:
return bus;
}
+static void
+on_name_acquired (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ settings = gdm_settings_new ();
+ if (settings == NULL) {
+ g_warning ("Unable to initialize settings");
+ exit (1);
+ }
+}
+
int
main (int argc, char **argv)
{
GMainLoop *main_loop;
- DBusGConnection *connection;
- DBusGProxy *bus_proxy;
+ GDBusConnection *connection;
g_type_init ();
@@ -139,22 +84,13 @@ main (int argc, char **argv)
goto out;
}
- bus_proxy = get_bus_proxy (connection);
- if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy object; bailing out");
- goto out;
- }
-
- if (! acquire_name_on_proxy (bus_proxy) ) {
- g_warning ("Could not acquire name; bailing out");
- goto out;
- }
-
- settings = gdm_settings_new ();
- if (settings == NULL) {
- g_warning ("Unable to initialize settings");
- exit (1);
- }
+ g_bus_own_name (G_BUS_TYPE_SYSTEM,
+ GDM_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, /* bus acquired */
+ on_name_acquired,
+ NULL, /* name lost */
+ NULL, NULL);
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);