diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | util/Makefile.am | 4 | ||||
-rw-r--r-- | util/wait-for-name.c | 96 |
3 files changed, 102 insertions, 3 deletions
@@ -79,5 +79,6 @@ test/twisted/tools/missioncontrol-*.log test/twisted/tools/tmp-session-bus.conf /test/twisted/tools/*.service /test/twisted/tmp-*/ -util/mc-account-convert -util/mc-tool +/util/mc-account-convert +/util/mc-tool +/util/mc-wait-for-name diff --git a/util/Makefile.am b/util/Makefile.am index 4f2514e2..5b066905 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,9 +1,11 @@ INCLUDES = $(GCONF_CFLAGS) $(TELEPATHY_CFLAGS) -I$(top_srcdir) -bin_PROGRAMS = mc-account-convert mc-tool +bin_PROGRAMS = mc-account-convert mc-tool mc-wait-for-name mc_account_convert_SOURCES = mc-account-convert.c mc_account_convert_LDADD = $(GCONF_LIBS) $(TELEPATHY_LIBS) $(top_builddir)/libmcclient/libmcclient.la mc_tool_SOURCES = mc-tool.c mc_tool_LDADD = $(GCONF_LIBS) $(TELEPATHY_LIBS) $(top_builddir)/libmcclient/libmcclient.la +mc_wait_for_name_SOURCES = wait-for-name.c +mc_wait_for_name_LDADD = $(TELEPATHY_LIBS) diff --git a/util/wait-for-name.c b/util/wait-for-name.c new file mode 100644 index 00000000..dd737879 --- /dev/null +++ b/util/wait-for-name.c @@ -0,0 +1,96 @@ +/* + * Run until a bus name appears. This can be used as a service-activation + * helper for a bus name that is not directly activatable, but will be provided + * automatically (after a while) by the desktop session. + * + * Usage, in + * $XDG_DATA_DIRS/dbus-1/services/org.freedesktop.Client.Something.service: + * + * [D-BUS Service] + * Name=org.freedesktop.Telepathy.Client.Something + * Exec=/usr/lib/mission-control/mc-wait-for-name org.freedesktop.Telepathy.Client.Something + * + * Copyright (C) 2009 Nokia Corporation + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include <glib.h> +#include <telepathy-glib/dbus.h> + +static gboolean +quit (gpointer data) +{ + g_main_loop_quit (data); + g_main_loop_unref (data); + return FALSE; +} + +static void +noc_cb (TpDBusDaemon *bus_daemon, + const gchar *name, + const gchar *new_owner, + gpointer data) +{ + if (new_owner[0] == '\0') + { + g_debug ("Waiting for %s", name); + } + else + { + g_debug ("%s now owned by %s", name, new_owner); + g_idle_add (quit, g_main_loop_ref (data)); + } +} + +int +main (int argc, + char **argv) +{ + TpDBusDaemon *bus_daemon; + GMainLoop *loop; + GError *error = NULL; + + g_set_prgname ("mc-wait-for-name"); + + if (argc != 2) + { + g_message ("Usage: mc-wait-for-name com.example.SomeBusName"); + return 2; + } + + g_type_init (); + bus_daemon = tp_dbus_daemon_dup (NULL); + + if (bus_daemon == NULL) + { + g_message ("%s", error->message); + g_error_free (error); + return 1; + } + + loop = g_main_loop_new (NULL, FALSE); + tp_dbus_daemon_watch_name_owner (bus_daemon, argv[1], + noc_cb, g_main_loop_ref (loop), (GDestroyNotify) g_main_loop_unref); + g_main_loop_run (loop); + + g_main_loop_unref (loop); + g_object_unref (bus_daemon); + + return 0; +} |