[evolution-data-server] Add E_DBUS_SERVER_EXIT_RELOAD.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add E_DBUS_SERVER_EXIT_RELOAD.
- Date: Wed, 11 Apr 2012 01:34:42 +0000 (UTC)
commit 0b4a5952ecd10dfaca13aedce909b3887cf3ec3e
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Apr 10 21:17:54 2012 -0400
Add E_DBUS_SERVER_EXIT_RELOAD.
EDBusServer now responds to SIGHUP by calling
e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD)
However EDataFactory (a subclass of EDBusServer) does not support
reloading at present, so it must intercept the RELOAD request and
stop the quit() emission.
This feature will be used in the upcoming source registry service.
libebackend/e-backend-enums.h | 9 ++++++++-
libebackend/e-data-factory.c | 20 ++++++++++++++++++++
libebackend/e-dbus-server.c | 22 ++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletions(-)
---
diff --git a/libebackend/e-backend-enums.h b/libebackend/e-backend-enums.h
index 40c92a7..4d06518 100644
--- a/libebackend/e-backend-enums.h
+++ b/libebackend/e-backend-enums.h
@@ -25,13 +25,20 @@
* The server's run state is unchanged.
* @E_DBUS_SERVER_EXIT_NORMAL:
* Normal termination. The process itself may now terminate.
+ * @E_DBUS_SERVER_EXIT_RELOAD:
+ * The server should reload its configuration and start again.
+ * Servers that do not support reloading may wish to intercept
+ * this exit code and stop the #EDBusServer::quit-server emission.
*
* Exit codes submitted to e_dbus_server_quit() and returned by
* e_dbus_server_run().
+ *
+ * Since: 3.6
**/
typedef enum {
E_DBUS_SERVER_EXIT_NONE,
- E_DBUS_SERVER_EXIT_NORMAL
+ E_DBUS_SERVER_EXIT_NORMAL,
+ E_DBUS_SERVER_EXIT_RELOAD
} EDBusServerExitCode;
#endif /* E_BACKEND_ENUMS_H */
diff --git a/libebackend/e-data-factory.c b/libebackend/e-data-factory.c
index 93ee067..207cbeb 100644
--- a/libebackend/e-data-factory.c
+++ b/libebackend/e-data-factory.c
@@ -196,9 +196,26 @@ data_factory_initable_init (GInitable *initable,
}
static void
+data_factory_quit_server (EDBusServer *server,
+ EDBusServerExitCode exit_code)
+{
+ /* EDataFactory does not support reloading, so stop the signal
+ * emission and return without chaining up to prevent quitting. */
+ if (exit_code == E_DBUS_SERVER_EXIT_RELOAD) {
+ g_signal_stop_emission_by_name (server, "quit-server");
+ return;
+ }
+
+ /* Chain up to parent's quit_server() method. */
+ E_DBUS_SERVER_CLASS (e_data_factory_parent_class)->
+ quit_server (server, exit_code);
+}
+
+static void
e_data_factory_class_init (EDataFactoryClass *class)
{
GObjectClass *object_class;
+ EDBusServerClass *dbus_server_class;
g_type_class_add_private (class, sizeof (EDataFactoryPrivate));
@@ -208,6 +225,9 @@ e_data_factory_class_init (EDataFactoryClass *class)
object_class->dispose = data_factory_dispose;
object_class->finalize = data_factory_finalize;
+ dbus_server_class = E_DBUS_SERVER_CLASS (class);
+ dbus_server_class->quit_server = data_factory_quit_server;
+
g_object_class_install_property (
object_class,
PROP_ONLINE,
diff --git a/libebackend/e-dbus-server.c b/libebackend/e-dbus-server.c
index 02bdd74..3e70e4f 100644
--- a/libebackend/e-dbus-server.c
+++ b/libebackend/e-dbus-server.c
@@ -43,6 +43,7 @@
struct _EDBusServerPrivate {
GMainLoop *main_loop;
guint bus_owner_id;
+ guint hang_up_id;
guint terminate_id;
guint inactivity_timeout_id;
@@ -103,6 +104,15 @@ dbus_server_inactivity_timeout_cb (EDBusServer *server)
#ifdef G_OS_UNIX
static gboolean
+dbus_server_hang_up_cb (EDBusServer *server)
+{
+ g_print ("Received hang up signal.\n");
+ e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD);
+
+ return FALSE;
+}
+
+static gboolean
dbus_server_terminate_cb (EDBusServer *server)
{
g_print ("Received terminate signal.\n");
@@ -124,6 +134,9 @@ dbus_server_finalize (GObject *object)
if (priv->bus_owner_id > 0)
g_bus_unown_name (priv->bus_owner_id);
+ if (priv->hang_up_id > 0)
+ g_source_remove (priv->hang_up_id);
+
if (priv->terminate_id > 0)
g_source_remove (priv->terminate_id);
@@ -204,6 +217,13 @@ static void
dbus_server_quit_server (EDBusServer *server,
EDBusServerExitCode code)
{
+ /* If we're reloading, voluntarily relinquish our bus
+ * name to avoid triggering a "bus-name-lost" signal. */
+ if (code == E_DBUS_SERVER_EXIT_RELOAD) {
+ g_bus_unown_name (server->priv->bus_owner_id);
+ server->priv->bus_owner_id = 0;
+ }
+
server->priv->exit_code = code;
g_main_loop_quit (server->priv->main_loop);
}
@@ -319,6 +339,8 @@ e_dbus_server_init (EDBusServer *server)
server->priv->wait_for_client = FALSE;
#ifdef G_OS_UNIX
+ server->priv->hang_up_id = g_unix_signal_add (
+ SIGHUP, (GSourceFunc) dbus_server_hang_up_cb, server);
server->priv->terminate_id = g_unix_signal_add (
SIGTERM, (GSourceFunc) dbus_server_terminate_cb, server);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]