diff options
author | Wu Xiaotian <[email protected]> | 2020-06-28 20:46:58 +0800 |
---|---|---|
committer | Wu Xiaotian <[email protected]> | 2020-10-12 20:54:18 +0800 |
commit | 8f67c75fc563ce7c828f230812681b564921fd75 (patch) | |
tree | c90672d7ca2b78d025f74746b31389044bdc4436 | |
parent | c023ea8f17138ba31e895c5e9e27fa6c592c964e (diff) | |
download | mate-settings-daemon-8f67c75fc563ce7c828f230812681b564921fd75.tar.bz2 mate-settings-daemon-8f67c75fc563ce7c828f230812681b564921fd75.tar.xz |
msd: migrate from dbus-glib to GDBus
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | mate-settings-daemon/Makefile.am | 19 | ||||
-rw-r--r-- | mate-settings-daemon/main.c | 347 | ||||
-rw-r--r-- | mate-settings-daemon/mate-settings-manager.c | 262 | ||||
-rw-r--r-- | mate-settings-daemon/mate-settings-manager.h | 25 | ||||
-rw-r--r-- | mate-settings-daemon/mate-settings-manager.xml | 1 | ||||
-rw-r--r-- | mate-settings-daemon/mate-settings-plugin-info.c | 4 |
7 files changed, 317 insertions, 348 deletions
diff --git a/configure.ac b/configure.ac index cf4f72a..76f5990 100644 --- a/configure.ac +++ b/configure.ac @@ -52,7 +52,6 @@ dnl --------------------------------------------------------------------------- dnl - Dependencies dnl --------------------------------------------------------------------------- -DBUS_GLIB_REQUIRED_VERSION=0.74 GLIB_REQUIRED_VERSION=2.50.0 GIO_REQUIRED_VERSION=2.50.0 GTK_REQUIRED_VERSION=3.22.0 @@ -68,13 +67,11 @@ PKG_CHECK_MODULES(SETTINGS_DAEMON, gio-2.0 >= $GIO_REQUIRED_VERSION gmodule-2.0 gthread-2.0 - dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION ) PKG_CHECK_MODULES(SETTINGS_PLUGIN, gtk+-3.0 >= $GTK_REQUIRED_VERSION gio-2.0 >= $GIO_REQUIRED_VERSION - dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION ) MSD_PLUGIN_LDFLAGS="-export_dynamic -module -avoid-version -no-undefined" @@ -88,6 +85,7 @@ AC_SUBST([MSD_PLUGIN_LDFLAGS]) PKG_CHECK_MODULES(DCONF, dconf >= 0.13.4) AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal) +AC_PATH_PROG(GDBUS_CODEGEN, gdbus-codegen) GLIB_GSETTINGS @@ -340,7 +338,6 @@ AC_SUBST(NSS_DATABASE) # --------------------------------------------------------------------------- POLKIT_REQUIRED=0.97 -DBUS_REQUIRED=1.10.0 # PolicyKit detection; defaults to 'auto' (use it if it's available) # @@ -356,7 +353,7 @@ if test "x$enable_polkit" = "xno" ; then HAVE_POLKIT=no else HAVE_POLKIT=no - PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLKIT_REQUIRED dbus-1 >= $DBUS_REQUIRED, HAVE_POLKIT=yes, HAVE_POLKIT=no) + PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLKIT_REQUIRED, HAVE_POLKIT=yes, HAVE_POLKIT=no) if test "x$enable_polkit" = "xyes" -a "x$HAVE_POLKIT" = "xno" ; then AC_MSG_ERROR(PolicyKit support explicity enabled but not available) diff --git a/mate-settings-daemon/Makefile.am b/mate-settings-daemon/Makefile.am index 4acc62f..7ce4e61 100644 --- a/mate-settings-daemon/Makefile.am +++ b/mate-settings-daemon/Makefile.am @@ -41,23 +41,23 @@ msddir = $(libexecdir) msd_PROGRAMS = \ mate-settings-daemon -mate-settings-manager-glue.h: mate-settings-manager.xml Makefile.am - $(AM_V_GEN) dbus-binding-tool --prefix=mate_settings_manager --mode=glib-server $< > $@ - -mate-settings-client.h: mate-settings-manager.xml Makefile.am - $(AM_V_GEN) dbus-binding-tool --prefix=mate_settings_manager --mode=glib-client $< > $@ - BUILT_SOURCES = \ - mate-settings-manager-glue.h \ - mate-settings-client.h \ + manager-dbus-generated.h \ + manager-dbus-generated.c \ $(NULL) +$(BUILT_SOURCES) : $(srcdir)/mate-settings-manager.xml + $(AM_V_GEN) $(GDBUS_CODEGEN) \ + --interface-prefix org.mate. \ + --c-namespace OrgMate \ + --generate-c-code manager-dbus-generated $< + apidir = $(includedir)/mate-settings-daemon api_DATA = \ - mate-settings-client.h \ mate-settings-plugin.h mate_settings_daemon_SOURCES = \ + $(BUILT_SOURCES) \ main.c \ mate-settings-bus.c \ mate-settings-bus.h \ @@ -88,7 +88,6 @@ mate_settings_daemon_LDADD = \ $(LIBNOTIFY_LIBS) EXTRA_DIST = \ - $(Dbusapi_DATA) \ mate-settings-manager.xml \ $(NULL) diff --git a/mate-settings-daemon/main.c b/mate-settings-daemon/main.c index 77de96f..b0581c5 100644 --- a/mate-settings-daemon/main.c +++ b/mate-settings-daemon/main.c @@ -1,4 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * vim: set ts=8 sts=8 sw=8 expandtab: * * Copyright (C) 2007 William Jon McCann <[email protected]> * @@ -30,11 +31,9 @@ #include <glib/gi18n.h> #include <glib/gstdio.h> +#include <gio/gio.h> #include <gtk/gtk.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> - #ifdef HAVE_LIBNOTIFY #include <libnotify/notify.h> #endif /* HAVE_LIBNOTIFY */ @@ -76,195 +75,63 @@ timed_exit_cb (void) return FALSE; } -static DBusGProxy * -get_bus_proxy (DBusGConnection *connection) +static void +on_session_signal (GDBusProxy *proxy G_GNUC_UNUSED, + gchar *sender_name G_GNUC_UNUSED, + gchar *signal_name G_GNUC_UNUSED, + GVariant *parameters G_GNUC_UNUSED, + gpointer user_data G_GNUC_UNUSED) { - DBusGProxy *bus_proxy; - - bus_proxy = dbus_g_proxy_new_for_name (connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - - return bus_proxy; + /* not used, see on_session_end instead */ } -static gboolean -acquire_name_on_proxy (DBusGProxy *bus_proxy) +static void +on_private_signal (GDBusProxy *proxy, + gchar *sender_name G_GNUC_UNUSED, + gchar *signal_name, + GVariant *parameters G_GNUC_UNUSED, + gpointer user_data) { - GError *error; - guint result; - gboolean res; - gboolean ret; - guint32 flags; - - ret = FALSE; - - flags = DBUS_NAME_FLAG_DO_NOT_QUEUE|DBUS_NAME_FLAG_ALLOW_REPLACEMENT; - if (replace) - flags |= DBUS_NAME_FLAG_REPLACE_EXISTING; + MateSettingsManager *manager; + GVariant *variant; + GError *error = NULL; - error = NULL; - res = dbus_g_proxy_call (bus_proxy, - "RequestName", - &error, - G_TYPE_STRING, MSD_DBUS_NAME, - G_TYPE_UINT, flags, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID); - if (! res) { - if (error != NULL) { - g_warning ("Failed to acquire %s: %s", MSD_DBUS_NAME, error->message); + manager = MATE_SETTINGS_MANAGER (user_data); + + if (g_strcmp0 (signal_name, "QueryEndSession") == 0) { + /* send response */ + variant = g_dbus_proxy_call_sync (proxy, + "EndSessionResponse", + g_variant_new ("(bs)", TRUE, NULL), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (variant == NULL) { + g_warning ("failed to send session response: %s", error->message); g_error_free (error); } else { - g_warning ("Failed to acquire %s", MSD_DBUS_NAME); + g_variant_unref (variant); } - goto out; - } - - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - if (error != NULL) { - g_warning ("Failed to acquire %s: %s", MSD_DBUS_NAME, error->message); + } else if (g_strcmp0 (signal_name, "EndSession") == 0) { + /* send response */ + variant = g_dbus_proxy_call_sync (proxy, + "EndSessionResponse", + g_variant_new ("(bs)", TRUE, NULL), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (variant == NULL) { + g_warning ("failed to send session response: %s", error->message); g_error_free (error); } else { - g_warning ("Failed to acquire %s", MSD_DBUS_NAME); + g_variant_unref (variant); } - goto out; - } - - ret = TRUE; - - out: - return ret; -} -static DBusHandlerResult -bus_message_handler (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - if (dbus_message_is_signal (message, - DBUS_INTERFACE_LOCAL, - "Disconnected")) { - gtk_main_quit (); - return DBUS_HANDLER_RESULT_HANDLED; - } - else if (dbus_message_is_signal (message, - DBUS_INTERFACE_DBUS, - "NameLost")) { - g_warning ("D-Bus name lost, quitting"); + mate_settings_manager_stop (manager); gtk_main_quit (); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static DBusGConnection * -get_session_bus (void) -{ - GError *error; - DBusGConnection *bus; - DBusConnection *connection; - - error = NULL; - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (bus == NULL) { - g_warning ("Couldn't connect to session bus: %s", - error->message); - g_error_free (error); - goto out; - } - - connection = dbus_g_connection_get_connection (bus); - dbus_connection_add_filter (connection, - (DBusHandleMessageFunction) - bus_message_handler, - NULL, NULL); - - dbus_connection_set_exit_on_disconnect (connection, FALSE); - - out: - return bus; -} - -static gboolean -bus_register (DBusGConnection *bus) -{ - DBusGProxy *bus_proxy; - gboolean ret; - - mate_settings_profile_start (NULL); - - ret = FALSE; - - bus_proxy = get_bus_proxy (bus); - - if (bus_proxy == NULL) { - g_warning ("Could not construct bus_proxy object"); - goto out; } - - ret = acquire_name_on_proxy (bus_proxy); - g_object_unref (bus_proxy); - - if (!ret) { - g_warning ("Could not acquire name"); - goto out; - } - - g_debug ("Successfully connected to D-Bus"); - - out: - mate_settings_profile_end (NULL); - - return ret; -} - -static void -on_session_over (DBusGProxy *proxy, MateSettingsManager *manager) -{ - /* not used, see on_session_end instead */ -} - -static void -on_session_query_end (DBusGProxy *proxy, guint flags, MateSettingsManager *manager) -{ - GError *error = NULL; - gboolean ret = FALSE; - - /* send response */ - ret = dbus_g_proxy_call (proxy, "EndSessionResponse", &error, - G_TYPE_BOOLEAN, TRUE /* ok */, - G_TYPE_STRING, NULL /* reason */, - G_TYPE_INVALID, - G_TYPE_INVALID); - if (!ret) { - g_warning ("failed to send session response: %s", error->message); - g_error_free (error); - } -} - -static void -on_session_end (DBusGProxy *proxy, guint flags, MateSettingsManager *manager) -{ - GError *error = NULL; - gboolean ret = FALSE; - - /* send response */ - ret = dbus_g_proxy_call (proxy, "EndSessionResponse", &error, - G_TYPE_BOOLEAN, TRUE /* ok */, - G_TYPE_STRING, NULL /* reason */, - G_TYPE_INVALID, - G_TYPE_INVALID); - if (!ret) { - g_warning ("failed to send session response: %s", error->message); - g_error_free (error); - } - - mate_settings_manager_stop (manager); - gtk_main_quit (); } static void @@ -312,79 +179,66 @@ watch_for_term_signal (MateSettingsManager *manager) } static void -set_session_over_handler (DBusGConnection *bus, MateSettingsManager *manager) +set_session_over_handler (MateSettingsManager *manager) { - DBusGProxy *session_proxy; - DBusGProxy *private_proxy; + GDBusProxy *session_proxy; + GDBusProxy *private_proxy; gchar *client_id = NULL; const char *startup_id; GError *error = NULL; - gboolean res; - - g_assert (bus != NULL); mate_settings_profile_start (NULL); - session_proxy = - dbus_g_proxy_new_for_name (bus, - MATE_SESSION_DBUS_NAME, - MATE_SESSION_DBUS_OBJECT, - MATE_SESSION_DBUS_INTERFACE); - - dbus_g_object_register_marshaller ( - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - G_TYPE_INVALID); - - dbus_g_proxy_add_signal (session_proxy, - "SessionOver", - G_TYPE_INVALID); + session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + MATE_SESSION_DBUS_NAME, + MATE_SESSION_DBUS_OBJECT, + MATE_SESSION_DBUS_INTERFACE, + NULL, + &error); + if (session_proxy == NULL) { + g_warning ("Unable to contact session manager daemon: %s\n", error->message); + g_error_free (error); + } - dbus_g_proxy_connect_signal (session_proxy, - "SessionOver", - G_CALLBACK (on_session_over), - manager, - NULL); + g_signal_connect (G_OBJECT (session_proxy), "g-signal", G_CALLBACK (on_session_signal), NULL); /* Register with mate-session */ startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (startup_id != NULL && *startup_id != '\0') { - res = dbus_g_proxy_call (session_proxy, - "RegisterClient", - &error, - G_TYPE_STRING, "mate-settings-daemon", - G_TYPE_STRING, startup_id, - G_TYPE_INVALID, - DBUS_TYPE_G_OBJECT_PATH, &client_id, - G_TYPE_INVALID); - if (!res) { - g_warning ("failed to register client '%s': %s", startup_id, error->message); + GVariant *variant; + variant = g_dbus_proxy_call_sync (session_proxy, + "RegisterClient", + g_variant_new ("(ss)", "mate-settings-daemon", startup_id), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (variant == NULL) { + g_warning ("Could not ask session manager to log out: %s", error->message); g_error_free (error); - } - else { - /* get org.gnome.SessionManager.ClientPrivate interface */ - private_proxy = dbus_g_proxy_new_for_name_owner (bus, MATE_SESSION_DBUS_NAME, - client_id, MATE_SESSION_PRIVATE_DBUS_INTERFACE, - &error); + } else { + g_variant_get (variant, "(o)", &client_id); + g_variant_unref (variant); + + private_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + MATE_SESSION_DBUS_NAME, + client_id, + MATE_SESSION_PRIVATE_DBUS_INTERFACE, + NULL, + &error); if (private_proxy == NULL) { g_warning ("DBUS error: %s", error->message); g_error_free (error); } - else { - - /* get QueryEndSession */ - dbus_g_proxy_add_signal (private_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (private_proxy, "QueryEndSession", - G_CALLBACK (on_session_query_end), - manager, NULL); - - /* get EndSession */ - dbus_g_proxy_add_signal (private_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (private_proxy, "EndSession", - G_CALLBACK (on_session_end), manager, NULL); - - } + g_signal_connect (G_OBJECT (private_proxy), + "g-signal", + G_CALLBACK (on_private_signal), + manager); g_free (client_id); } } @@ -462,7 +316,6 @@ int main (int argc, char *argv[]) { MateSettingsManager *manager; - DBusGConnection *bus; gboolean res; GError *error; GSettings *debug_settings = NULL; @@ -499,22 +352,13 @@ main (int argc, char *argv[]) g_log_set_default_handler (msd_log_default_handler, NULL); - bus = get_session_bus (); - if (bus == NULL) { - g_warning ("Could not get a connection to the bus"); - goto out; - } - - if (! bus_register (bus)) { - goto out; - } #ifdef HAVE_LIBNOTIFY notify_init ("mate-settings-daemon"); #endif /* HAVE_LIBNOTIFY */ + manager = mate_settings_manager_new (replace); mate_settings_profile_start ("mate_settings_manager_new"); - manager = mate_settings_manager_new (); mate_settings_profile_end ("mate_settings_manager_new"); if (manager == NULL) { g_warning ("Unable to register object"); @@ -525,20 +369,22 @@ main (int argc, char *argv[]) * Initialization phase. Otherwise, wait for an Awake etc. */ if (g_getenv ("DBUS_STARTER_BUS_TYPE") == NULL) { error = NULL; - res = mate_settings_manager_start (manager, PLUGIN_LOAD_INIT, &error); + mate_settings_manager_set_init_flag (manager, PLUGIN_LOAD_INIT); + res = mate_settings_manager_load (manager, &error); if (! res) { g_warning ("Unable to start: %s", error->message); g_error_free (error); } } - set_session_over_handler (bus, manager); + set_session_over_handler (manager); /* If we aren't started by dbus then load the plugins automatically after * mate-settings-daemon has registered itself. Otherwise, wait for an Awake etc. */ if (g_getenv ("DBUS_STARTER_BUS_TYPE") == NULL) { error = NULL; - res = mate_settings_manager_start (manager, PLUGIN_LOAD_DEFER, &error); + mate_settings_manager_set_init_flag (manager, PLUGIN_LOAD_DEFER); + res = mate_settings_manager_load (manager, &error); if (! res) { g_warning ("Unable to start: %s", error->message); g_error_free (error); @@ -552,12 +398,7 @@ main (int argc, char *argv[]) gtk_main (); - out: - - if (bus != NULL) { - dbus_g_connection_unref (bus); - } - +out: if (manager != NULL) { g_object_unref (manager); } diff --git a/mate-settings-daemon/mate-settings-manager.c b/mate-settings-daemon/mate-settings-manager.c index c21e80a..332e260 100644 --- a/mate-settings-daemon/mate-settings-manager.c +++ b/mate-settings-daemon/mate-settings-manager.c @@ -1,4 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * vim: set ts=8 sts=8 sw=8 expandtab: * * Copyright (C) 2007 William Jon McCann <[email protected]> * @@ -25,17 +26,13 @@ #include <unistd.h> #include <string.h> -#include <glib.h> #include <glib/gi18n.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 <gtk/gtk.h> #include "mate-settings-plugin-info.h" #include "mate-settings-manager.h" -#include "mate-settings-manager-glue.h" +#include "manager-dbus-generated.h" #include "mate-settings-profile.h" #define MSD_MANAGER_DBUS_PATH "/org/mate/SettingsDaemon" @@ -44,12 +41,21 @@ #define PLUGIN_EXT ".mate-settings-plugin" +enum { + PROP_0, + PROP_REPLACE, + PROP_INIT_FLAG, + LAST_PROP +}; + struct MateSettingsManagerPrivate { - DBusGConnection *connection; GSList *plugins; gint init_load_priority; gint load_init_flag; + OrgMateSettingsDaemon *skeleton; + guint bus_name_id; + gboolean replace; }; enum { @@ -58,9 +64,16 @@ enum { LAST_SIGNAL }; +static GParamSpec *properties[LAST_PROP] = { NULL, }; static guint signals [LAST_SIGNAL] = { 0, }; -static void mate_settings_manager_finalize (GObject *object); +static void mate_settings_manager_finalize (GObject *object); +gboolean mate_settings_manager_awake_handler (OrgMateSettingsDaemon *object, + GDBusMethodInvocation *invocation, + gpointer user_data); +gboolean mate_settings_manager_start_handler (OrgMateSettingsDaemon *object, + GDBusMethodInvocation *invocation, + gpointer user_data); G_DEFINE_TYPE_WITH_PRIVATE (MateSettingsManager, mate_settings_manager, G_TYPE_OBJECT) @@ -279,21 +292,35 @@ _load_dir (MateSettingsManager *manager, mate_settings_profile_end (NULL); } -static void -_load_all (MateSettingsManager *manager) +gboolean +mate_settings_manager_load (MateSettingsManager *manager, + GError **error) { + gboolean ret = FALSE; mate_settings_profile_start (NULL); + if (!g_module_supported ()) { + g_warning ("mate-settings-daemon is not able to initialize the plugins."); + g_set_error (error, + MATE_SETTINGS_MANAGER_ERROR, + MATE_SETTINGS_MANAGER_ERROR_GENERAL, + "Plugins not supported"); + goto out; + } /* load system plugins */ _load_dir (manager, MATE_SETTINGS_PLUGINDIR G_DIR_SEPARATOR_S); manager->priv->plugins = g_slist_sort (manager->priv->plugins, (GCompareFunc) compare_priority); g_slist_foreach (manager->priv->plugins, (GFunc) maybe_activate_plugin, manager); + ret = TRUE; +out: mate_settings_profile_end (NULL); + return ret; } static void -_unload_plugin (MateSettingsPluginInfo *info, gpointer user_data) +_unload_plugin (MateSettingsPluginInfo *info, + gpointer user_data G_GNUC_UNUSED) { if (mate_settings_plugin_info_get_enabled (info)) { mate_settings_plugin_info_deactivate (info); @@ -317,60 +344,50 @@ _unload_all (MateSettingsManager *manager) org.mate.SettingsDaemon.Awake */ gboolean -mate_settings_manager_awake (MateSettingsManager *manager, - GError **error) -{ - g_debug ("Awake called"); - return mate_settings_manager_start (manager, PLUGIN_LOAD_ALL, error); -} - -static gboolean -register_manager (MateSettingsManager *manager) +mate_settings_manager_awake_handler (OrgMateSettingsDaemon *object, + GDBusMethodInvocation *invocation, + gpointer user_data) { + gboolean ret; GError *error = NULL; + MateSettingsManager *manager; - manager->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (manager->priv->connection == NULL) { - if (error != NULL) { - g_critical ("error getting system bus: %s", error->message); - g_error_free (error); - } - return FALSE; - } - - dbus_g_connection_register_g_object (manager->priv->connection, MSD_MANAGER_DBUS_PATH, G_OBJECT (manager)); + manager = MATE_SETTINGS_MANAGER (user_data); - return TRUE; + g_debug ("Awake called"); + mate_settings_manager_set_init_flag (manager, PLUGIN_LOAD_ALL); + ret = mate_settings_manager_load (manager, &error); + if (!ret) { + g_dbus_method_invocation_return_gerror (invocation, error); + } else { + org_mate_settings_daemon_complete_awake (object, invocation); + } + return ret; } gboolean -mate_settings_manager_start (MateSettingsManager *manager, - gint load_init_flag, - GError **error) +mate_settings_manager_start_handler (OrgMateSettingsDaemon *object, + GDBusMethodInvocation *invocation, + gpointer user_data G_GNUC_UNUSED) { gboolean ret; + GError *error = NULL; + MateSettingsManager *manager; g_debug ("Starting settings manager"); - ret = FALSE; + manager = MATE_SETTINGS_MANAGER (object); mate_settings_profile_start (NULL); - if (!g_module_supported ()) { - g_warning ("mate-settings-daemon is not able to initialize the plugins."); - g_set_error (error, - MATE_SETTINGS_MANAGER_ERROR, - MATE_SETTINGS_MANAGER_ERROR_GENERAL, - "Plugins not supported"); + ret = mate_settings_manager_load (manager, &error); - goto out; + if (!ret) { + g_dbus_method_invocation_return_gerror (invocation, error); + } else { + org_mate_settings_daemon_complete_start (object, invocation); } - manager->priv->load_init_flag = load_init_flag; - _load_all (manager); - - ret = TRUE; - out: mate_settings_profile_end (NULL); return ret; @@ -397,13 +414,132 @@ mate_settings_manager_dispose (GObject *object) } static void +bus_acquired_handler_cb (GDBusConnection *connection, + const gchar *name G_GNUC_UNUSED, + gpointer user_data) +{ + MateSettingsManager *manager; + + GError *error = NULL; + gboolean exported; + + manager = MATE_SETTINGS_MANAGER (user_data); + + g_signal_connect (manager->priv->skeleton, + "handle-awake", + G_CALLBACK (mate_settings_manager_awake_handler), + manager); + g_signal_connect (manager->priv->skeleton, + "handle-start", + G_CALLBACK (mate_settings_manager_start_handler), + manager); + + exported = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton), + connection, + MSD_MANAGER_DBUS_PATH, + &error); + if (!exported) + { + g_warning ("Failed to export interface: %s", error->message); + g_error_free (error); + + gtk_main_quit (); + } +} + +static void +name_lost_handler_cb (GDBusConnection *connection G_GNUC_UNUSED, + const gchar *name G_GNUC_UNUSED, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("bus name lost\n"); + gtk_main_quit (); +} + + +static void +mate_settings_manager_constructed (GObject *object) +{ + MateSettingsManager *manager; + GBusNameOwnerFlags flags; + + manager = MATE_SETTINGS_MANAGER (object); + + G_OBJECT_CLASS (mate_settings_manager_parent_class)->constructed (object); + + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (manager->priv->replace) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + manager->priv->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, + DEFAULT_SETTINGS_PREFIX, + flags, + bus_acquired_handler_cb, NULL, + name_lost_handler_cb, manager, NULL); +} + +void +mate_settings_manager_set_init_flag (MateSettingsManager *manager, + gint load_init_flag) +{ + manager->priv->load_init_flag = load_init_flag; +} + +static void +mate_settings_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MateSettingsManager *manager; + + manager = MATE_SETTINGS_MANAGER (object); + + switch (prop_id) + { + case PROP_INIT_FLAG: + mate_settings_manager_set_init_flag (manager, g_value_get_int (value)); + break; + case PROP_REPLACE: + manager->priv->replace = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static void mate_settings_manager_class_init (MateSettingsManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->constructed = mate_settings_manager_constructed; + object_class->set_property = mate_settings_manager_set_property; + object_class->dispose = mate_settings_manager_dispose; object_class->finalize = mate_settings_manager_finalize; + properties[PROP_REPLACE] = + g_param_spec_boolean ("replace", + "replace", + "replace", + FALSE, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS); + + properties[PROP_INIT_FLAG] = + g_param_spec_int ("init-flag", + "load init flag", + "load init flag", + PLUGIN_LOAD_ALL, + PLUGIN_LOAD_DEFER, + PLUGIN_LOAD_ALL, + G_PARAM_WRITABLE); + + g_object_class_install_properties (object_class, LAST_PROP, properties); + signals [PLUGIN_ACTIVATED] = g_signal_new ("plugin-activated", G_TYPE_FROM_CLASS (object_class), @@ -424,8 +560,6 @@ mate_settings_manager_class_init (MateSettingsManagerClass *klass) g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); - - dbus_g_object_type_install_info (MATE_TYPE_SETTINGS_MANAGER, &dbus_glib_mate_settings_manager_object_info); } static void @@ -441,6 +575,8 @@ mate_settings_manager_init (MateSettingsManager *manager) settings = g_settings_new (schema); manager->priv->init_load_priority = g_settings_get_int (settings, "init-load-priority"); } + manager->priv->load_init_flag = PLUGIN_LOAD_ALL; + manager->priv->skeleton = org_mate_settings_daemon_skeleton_new (); } static void @@ -453,28 +589,36 @@ mate_settings_manager_finalize (GObject *object) manager = MATE_SETTINGS_MANAGER (object); + if (manager->priv->skeleton != NULL) + { + GDBusInterfaceSkeleton *skeleton; + + skeleton = G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton); + g_dbus_interface_skeleton_unexport (skeleton); + g_clear_object (&manager->priv->skeleton); + } + + if (manager->priv->bus_name_id > 0) + { + g_bus_unown_name (manager->priv->bus_name_id); + manager->priv->bus_name_id = 0; + } + g_return_if_fail (manager->priv != NULL); G_OBJECT_CLASS (mate_settings_manager_parent_class)->finalize (object); } MateSettingsManager * -mate_settings_manager_new (void) +mate_settings_manager_new (gboolean replace) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - gboolean res; - manager_object = g_object_new (MATE_TYPE_SETTINGS_MANAGER, + "replace", + replace, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - res = register_manager (manager_object); - if (! res) { - g_object_unref (manager_object); - return NULL; - } } return MATE_SETTINGS_MANAGER (manager_object); diff --git a/mate-settings-daemon/mate-settings-manager.h b/mate-settings-daemon/mate-settings-manager.h index 6eaf360..9a2f71e 100644 --- a/mate-settings-daemon/mate-settings-manager.h +++ b/mate-settings-daemon/mate-settings-manager.h @@ -23,9 +23,7 @@ #include <glib-object.h> -#ifdef __cplusplus -extern "C" { -#endif +G_BEGIN_DECLS #define MATE_TYPE_SETTINGS_MANAGER (mate_settings_manager_get_type ()) #define MATE_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_TYPE_SETTINGS_MANAGER, MateSettingsManager)) @@ -66,21 +64,14 @@ enum #define MATE_SETTINGS_MANAGER_ERROR mate_settings_manager_error_quark () -GQuark mate_settings_manager_error_quark (void); -GType mate_settings_manager_get_type (void); +GQuark mate_settings_manager_error_quark (void); +GType mate_settings_manager_get_type (void); -MateSettingsManager * mate_settings_manager_new (void); +MateSettingsManager* mate_settings_manager_new (gboolean replace); +void mate_settings_manager_set_init_flag (MateSettingsManager *manager, gint load_init_flag); +gboolean mate_settings_manager_load (MateSettingsManager *manager, GError **error); +void mate_settings_manager_stop (MateSettingsManager *manager); -gboolean mate_settings_manager_start (MateSettingsManager *manager, - gint load_init_flag, - GError **error); -void mate_settings_manager_stop (MateSettingsManager *manager); - -gboolean mate_settings_manager_awake (MateSettingsManager *manager, - GError **error); - -#ifdef __cplusplus -} -#endif +G_END_DECLS #endif /* __MATE_SETTINGS_MANAGER_H */ diff --git a/mate-settings-daemon/mate-settings-manager.xml b/mate-settings-daemon/mate-settings-manager.xml index b1e316f..00c9f25 100644 --- a/mate-settings-daemon/mate-settings-manager.xml +++ b/mate-settings-daemon/mate-settings-manager.xml @@ -1,7 +1,6 @@ <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> <node name="/org/mate/SettingsDaemon"> <interface name="org.mate.SettingsDaemon"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="mate_settings_manager"/> <method name="Awake"/> <method name="Start"/> <signal name="PluginActivated"> diff --git a/mate-settings-daemon/mate-settings-plugin-info.c b/mate-settings-daemon/mate-settings-plugin-info.c index 5db6e61..f9deec0 100644 --- a/mate-settings-daemon/mate-settings-plugin-info.c +++ b/mate-settings-daemon/mate-settings-plugin-info.c @@ -32,8 +32,6 @@ #include "mate-settings-plugin.h" #include "mate-settings-profile.h" -#define MATE_SETTINGS_PLUGIN_INFO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MATE_TYPE_SETTINGS_PLUGIN_INFO, MateSettingsPluginInfoPrivate)) - #define PLUGIN_GROUP "MATE Settings Plugin" #define PLUGIN_PRIORITY_MAX 1 @@ -148,7 +146,7 @@ mate_settings_plugin_info_class_init (MateSettingsPluginInfoClass *klass) static void mate_settings_plugin_info_init (MateSettingsPluginInfo *info) { - info->priv = MATE_SETTINGS_PLUGIN_INFO_GET_PRIVATE (info); + info->priv = mate_settings_plugin_info_get_instance_private (info); } static void |