From 4f53efcd79f5ec188a5a0f453c37c475f94b78d0 Mon Sep 17 00:00:00 2001 From: iain Date: Mon, 17 Oct 2011 17:47:32 +0100 Subject: Add a no autoterminate option By default Gypsy terminates 10 seconds after the last client has quit. A --no-autoterminate option stops this --- src/gypsy-server.c | 16 ++++++++++++++-- src/gypsy-server.h | 2 +- src/main.c | 4 +++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gypsy-server.c b/src/gypsy-server.c index e2e3c1c..f82a527 100644 --- a/src/gypsy-server.c +++ b/src/gypsy-server.c @@ -46,6 +46,8 @@ enum { typedef struct _GypsyServerPrivate { DBusGConnection *connection; GHashTable *connections; + + gboolean auto_terminate; int client_count; /* When client_count returns to 0, we quit the daemon after TERMINATE_TIMEOUT */ guint32 terminate_id; @@ -176,7 +178,7 @@ gypsy_server_shutdown (GypsyServer *gps, device_name)); } else { if (--priv->client_count == 0) { - if (priv->terminate_id == 0) { + if (priv->auto_terminate && priv->terminate_id == 0) { priv->terminate_id = g_timeout_add (TERMINATE_TIMEOUT, gypsy_terminate, gps); @@ -294,4 +296,14 @@ gypsy_server_remove_clients (GypsyServer *gps, g_hash_table_remove (priv->connections, prev_owner); } } - + +GypsyServer * +gypsy_server_new (gboolean auto_terminate) +{ + GypsyServer *server = g_object_new (GYPSY_TYPE_SERVER, NULL); + GypsyServerPrivate *priv = GET_PRIVATE (server); + + priv->auto_terminate = auto_terminate; + + return server; +} diff --git a/src/gypsy-server.h b/src/gypsy-server.h index 465f18e..c53df51 100644 --- a/src/gypsy-server.h +++ b/src/gypsy-server.h @@ -50,7 +50,7 @@ typedef struct _GypsyServerClass { } GypsyServerClass; GType gypsy_server_get_type (void); - +GypsyServer *gypsy_server_new (gboolean auto_terminate); void gypsy_server_remove_clients (GypsyServer *gps, const char *prev_owner); G_END_DECLS diff --git a/src/main.c b/src/main.c index dbf3942..3e8a794 100644 --- a/src/main.c +++ b/src/main.c @@ -127,6 +127,7 @@ main (int argc, GypsyServer *gypsy; GypsyDiscovery *discovery; gboolean become_daemon = FALSE; + gboolean auto_terminate = TRUE; char *pidfile = NULL; char *user_pidfile = NULL; const char *env_string; @@ -136,6 +137,7 @@ main (int argc, { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &become_daemon, "Don't become a daemon", NULL }, { "pid-file", 0, 0, G_OPTION_ARG_FILENAME, &user_pidfile, "Specify the location of a PID file", "FILE" }, { "gypsy-debug", 0, 0, G_OPTION_ARG_CALLBACK, gypsy_arg_debug_cb, "Gypsy debugging flags to set", "FLAGS" }, + { "no-auto-terminate", 0, 0, G_OPTION_ARG_NONE, &auto_terminate, "Don't terminate after last connection closes", NULL }, { NULL } }; @@ -213,7 +215,7 @@ main (int argc, return 1; } - gypsy = g_object_new (GYPSY_TYPE_SERVER, NULL); + gypsy = gypsy_server_new (auto_terminate); g_signal_connect (G_OBJECT (gypsy), "terminate", G_CALLBACK (gypsy_terminate), NULL); -- cgit v1.2.3