From ae39f7001e5603010afc02de29787ade6d48ef14 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 16:34:34 -0500 Subject: port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%. --- src/main.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ff5997b --- /dev/null +++ b/src/main.c @@ -0,0 +1,87 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include /* exit() */ + +#include +#include + +#include "service.h" + +/*** +**** +***/ + +static gboolean replace = FALSE; + +static void +parse_command_line (int * argc, char *** argv) +{ + GError * error; + GOptionContext * option_context; + + static GOptionEntry entries[] = + { + { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace the currently-running service", NULL }, + { NULL } + }; + + error = NULL; + option_context = g_option_context_new ("- indicator-session service"); + g_option_context_add_main_entries (option_context, entries, GETTEXT_PACKAGE); + if (!g_option_context_parse (option_context, argc, argv, &error)) + { + g_print ("option parsing failed: %s\n", error->message); + g_error_free (error); + exit (EXIT_FAILURE); + } + + g_option_context_free (option_context); +} + +/*** +**** +***/ + +int +main (int argc, char ** argv) +{ + GMainLoop * loop; + IndicatorSessionService * service; + + signal (SIGPIPE, SIG_IGN); + + /* boilerplate i18n */ + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + textdomain (GETTEXT_PACKAGE); + + parse_command_line (&argc, &argv); + + /* run */ + service = indicator_session_service_new (replace); + loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (loop); + + /* cleanup */ + g_clear_object (&service); + g_main_loop_unref (loop); + return 0; +} -- cgit v1.2.3 From 066872fb191ba3b79d1387a10f0b8be948d2d488 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 18 Apr 2013 09:49:09 -0500 Subject: remove unnecessary signal (SIGPIPE, SIG_IGN) --- src/main.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index ff5997b..17b50b4 100644 --- a/src/main.c +++ b/src/main.c @@ -66,8 +66,6 @@ main (int argc, char ** argv) GMainLoop * loop; IndicatorSessionService * service; - signal (SIGPIPE, SIG_IGN); - /* boilerplate i18n */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); -- cgit v1.2.3 From 67218e58889b101ceb5a50bcb40c37045fb2855d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 18 Apr 2013 11:13:03 -0500 Subject: indicator-session-service should exit when it loses ownership of its name on the bus. --- src/main.c | 9 +++++++++ src/service.c | 23 ++++++++++++++++++++++- src/service.h | 7 +++++++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 17b50b4..4511fce 100644 --- a/src/main.c +++ b/src/main.c @@ -60,6 +60,13 @@ parse_command_line (int * argc, char *** argv) **** ***/ +static void +on_name_lost (gpointer instance, gpointer loop) +{ + g_debug ("exiting: service couldn't acquire or lost ownership of busname"); + g_main_loop_quit ((GMainLoop*)loop); +} + int main (int argc, char ** argv) { @@ -76,6 +83,8 @@ main (int argc, char ** argv) /* run */ service = indicator_session_service_new (replace); loop = g_main_loop_new (NULL, FALSE); + g_signal_connect (service, INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST, + G_CALLBACK(on_name_lost), loop); g_main_loop_run (loop); /* cleanup */ diff --git a/src/service.c b/src/service.c index 2a10290..bcd88ff 100644 --- a/src/service.c +++ b/src/service.c @@ -37,6 +37,15 @@ G_DEFINE_TYPE (IndicatorSessionService, indicator_session_service, G_TYPE_OBJECT) +/* signals enum */ +enum +{ + NAME_LOST, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + enum { PROP_0, @@ -910,9 +919,13 @@ on_name_lost (GDBusConnection * connection G_GNUC_UNUSED, const gchar * name, gpointer gself) { + IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (gself); + g_debug ("%s %s name lost %s", G_STRLOC, G_STRFUNC, name); - unexport (INDICATOR_SESSION_SERVICE (gself)); + unexport (self); + + g_signal_emit (self, signals[NAME_LOST], 0, NULL); } /*** @@ -1133,6 +1146,14 @@ indicator_session_service_class_init (IndicatorSessionServiceClass * klass) g_type_class_add_private (klass, sizeof (IndicatorSessionServicePrivate)); + signals[NAME_LOST] = g_signal_new (INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicatorSessionServiceClass, name_lost), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + properties[PROP_0] = NULL; properties[PROP_REPLACE] = g_param_spec_boolean ("replace", diff --git a/src/service.h b/src/service.h index 2a78855..3fad6bf 100644 --- a/src/service.h +++ b/src/service.h @@ -36,6 +36,9 @@ typedef struct _IndicatorSessionService IndicatorSessionService; typedef struct _IndicatorSessionServiceClass IndicatorSessionServiceClass; typedef struct _IndicatorSessionServicePrivate IndicatorSessionServicePrivate; +/* signal keys */ +#define INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST "name-lost" + /** * The Indicator Session Service. */ @@ -49,6 +52,10 @@ struct _IndicatorSessionService struct _IndicatorSessionServiceClass { GObjectClass parent_class; + + /* signals */ + + void (* name_lost)(IndicatorSessionService * self); }; /*** -- cgit v1.2.3 From fab2853f35eb108988b5ddb16cd9f6e43de79773 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Jun 2013 13:54:41 -0500 Subject: remove the --replace command-line argument and property as we're using upstart for that --- src/main.c | 42 +++++------------------------------------- src/service.c | 41 +++-------------------------------------- src/service.h | 2 +- tests/test-service.cc | 7 +------ 4 files changed, 10 insertions(+), 82 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 4511fce..8df5e60 100644 --- a/src/main.c +++ b/src/main.c @@ -29,46 +29,16 @@ **** ***/ -static gboolean replace = FALSE; - -static void -parse_command_line (int * argc, char *** argv) -{ - GError * error; - GOptionContext * option_context; - - static GOptionEntry entries[] = - { - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace the currently-running service", NULL }, - { NULL } - }; - - error = NULL; - option_context = g_option_context_new ("- indicator-session service"); - g_option_context_add_main_entries (option_context, entries, GETTEXT_PACKAGE); - if (!g_option_context_parse (option_context, argc, argv, &error)) - { - g_print ("option parsing failed: %s\n", error->message); - g_error_free (error); - exit (EXIT_FAILURE); - } - - g_option_context_free (option_context); -} - -/*** -**** -***/ - static void on_name_lost (gpointer instance, gpointer loop) { - g_debug ("exiting: service couldn't acquire or lost ownership of busname"); - g_main_loop_quit ((GMainLoop*)loop); + g_warning ("exiting: service couldn't acquire, or lost ownership of, busname"); + + g_main_loop_quit (loop); } int -main (int argc, char ** argv) +main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) { GMainLoop * loop; IndicatorSessionService * service; @@ -78,10 +48,8 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); - parse_command_line (&argc, &argv); - /* run */ - service = indicator_session_service_new (replace); + service = indicator_session_service_new (); loop = g_main_loop_new (NULL, FALSE); g_signal_connect (service, INDICATOR_SESSION_SERVICE_SIGNAL_NAME_LOST, G_CALLBACK(on_name_lost), loop); diff --git a/src/service.c b/src/service.c index 862028b..83bfeaa 100644 --- a/src/service.c +++ b/src/service.c @@ -46,7 +46,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_REPLACE, PROP_MAX_USERS, PROP_LAST }; @@ -106,8 +105,6 @@ struct _IndicatorSessionServicePrivate int rebuild_flags; GDBusConnection * conn; GCancellable * cancellable; - - gboolean replace; }; typedef IndicatorSessionServicePrivate priv_t; @@ -1013,23 +1010,10 @@ indicator_session_service_init (IndicatorSessionService * self) gp = p->keybinding_settings; g_signal_connect_swapped (gp, "changed::screensaver", G_CALLBACK(rebuild_switch_section_soon), self); -} - -static void -my_constructed (GObject * o) -{ - GBusNameOwnerFlags owner_flags; - IndicatorSessionService * self = INDICATOR_SESSION_SERVICE(o); - - /* own the name in constructed() instead of init() so that - we'll know the value of the 'replace' property */ - owner_flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; - if (self->priv->replace) - owner_flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; self->priv->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, - owner_flags, + G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, on_bus_acquired, NULL, on_name_lost, @@ -1051,10 +1035,6 @@ my_get_property (GObject * o, switch (property_id) { - case PROP_REPLACE: - g_value_set_boolean (value, self->priv->replace); - break; - case PROP_MAX_USERS: g_value_set_uint (value, self->priv->max_users); break; @@ -1074,10 +1054,6 @@ my_set_property (GObject * o, switch (property_id) { - case PROP_REPLACE: - self->priv->replace = g_value_get_boolean (value); - break; - case PROP_MAX_USERS: self->priv->max_users = g_value_get_uint (value); rebuild_switch_section_soon (self); @@ -1145,7 +1121,6 @@ indicator_session_service_class_init (IndicatorSessionServiceClass * klass) GObjectClass * object_class = G_OBJECT_CLASS (klass); object_class->dispose = my_dispose; - object_class->constructed = my_constructed; object_class->get_property = my_get_property; object_class->set_property = my_set_property; @@ -1161,14 +1136,6 @@ indicator_session_service_class_init (IndicatorSessionServiceClass * klass) properties[PROP_0] = NULL; - properties[PROP_REPLACE] = g_param_spec_boolean ("replace", - "Replace Service", - "Replace existing service", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); - properties[PROP_MAX_USERS] = g_param_spec_uint ("max-users", "Max Users", "Max visible users", @@ -1181,11 +1148,9 @@ indicator_session_service_class_init (IndicatorSessionServiceClass * klass) } IndicatorSessionService * -indicator_session_service_new (gboolean replace) +indicator_session_service_new (void) { - GObject * o = g_object_new (INDICATOR_TYPE_SESSION_SERVICE, - "replace", replace, - NULL); + GObject * o = g_object_new (INDICATOR_TYPE_SESSION_SERVICE, NULL); return INDICATOR_SESSION_SERVICE (o); } diff --git a/src/service.h b/src/service.h index 3fad6bf..fa870e5 100644 --- a/src/service.h +++ b/src/service.h @@ -64,7 +64,7 @@ struct _IndicatorSessionServiceClass GType indicator_session_service_get_type (void); -IndicatorSessionService * indicator_session_service_new (gboolean replace); +IndicatorSessionService * indicator_session_service_new (void); G_END_DECLS diff --git a/tests/test-service.cc b/tests/test-service.cc index 76dcd75..57b4221 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -161,12 +161,7 @@ class ServiceTest: public GTestDBusFixture // Start an IndicatorSessionService and wait for it to appear on the bus. // This way our calls to g_dbus_*_get() in the next paragraph won't activate // a second copy of the service... - service = indicator_session_service_new (true); - - // confirm that the property got set - gboolean replace = FALSE; - g_object_get (service, "replace", &replace, NULL); - ASSERT_TRUE (replace); + service = indicator_session_service_new (); // wait for the service to show up on the bus const guint watch_id = g_bus_watch_name_on_connection (conn, -- cgit v1.2.3 From cba24317a60a2670c0c917aaa637488b834da379 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Jul 2013 20:55:54 -0500 Subject: in main.c's on_name_lost(), silence minor 'unused parameter' compiler warning --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8df5e60..45c5394 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,7 @@ ***/ static void -on_name_lost (gpointer instance, gpointer loop) +on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop) { g_warning ("exiting: service couldn't acquire, or lost ownership of, busname"); -- cgit v1.2.3