summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriain <iain@linux.intel.com>2011-10-17 17:47:32 +0100
committeriain <iain@linux.intel.com>2011-10-17 17:47:32 +0100
commit4f53efcd79f5ec188a5a0f453c37c475f94b78d0 (patch)
treeeafb3717142ef1c9c6adf50adc1695662db8e775
parent68efbab41b9f54aaab1f8f469290eccb57bf164d (diff)
Add a no autoterminate option
By default Gypsy terminates 10 seconds after the last client has quit. A --no-autoterminate option stops this
-rw-r--r--src/gypsy-server.c16
-rw-r--r--src/gypsy-server.h2
-rw-r--r--src/main.c4
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);