diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-02-20 03:22:00 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-02-20 03:22:00 +0100 |
commit | 17b859e2650a071649bc19347491862d20288df3 (patch) | |
tree | 635d60886dc3199421088d7dec04f51bdee339d7 | |
parent | 76a3fde2204cb966efe2604e715150d2ae8a3143 (diff) | |
download | connman-gnome-17b859e2650a071649bc19347491862d20288df3.tar.gz |
Add single instance support
-rw-r--r-- | common/Makefile.am | 14 | ||||
-rw-r--r-- | common/client.c | 5 | ||||
-rw-r--r-- | common/common.h | 25 | ||||
-rw-r--r-- | common/instance.c | 101 | ||||
-rw-r--r-- | common/instance.h | 25 | ||||
-rw-r--r-- | common/instance.xml | 8 | ||||
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | properties/main.c | 12 |
8 files changed, 187 insertions, 6 deletions
diff --git a/common/Makefile.am b/common/Makefile.am index 57b99d8..2e2bcfa 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -1,12 +1,24 @@ noinst_LIBRARIES = libcommon.a -libcommon_a_SOURCES = client.h client.c +libcommon_a_SOURCES = common.h client.h client.c \ + instance.h instance.c noinst_PROGRAMS = test-client test_client_LDADD = libcommon.a @GTK_LIBS@ @DBUS_LIBS@ +BUILT_SOURCES = instance-glue.h + +nodist_libcommon_a_SOURCES = $(BUILT_SOURCES) + +CLEANFILES = $(BUILT_SOURCES) + AM_CFLAGS = @DBUS_CFLAGS@ @GTK_CFLAGS@ +EXTRA_DIST = instance.xml + MAINTAINERCLEANFILES = Makefile.in + +instance-glue.h: instance.xml + $(DBUS_BINDING_TOOL) --prefix=instance --mode=glib-server --output=$@ $< diff --git a/common/client.c b/common/client.c index 2a8a4f0..fc5d122 100644 --- a/common/client.c +++ b/common/client.c @@ -29,6 +29,7 @@ #include <gtk/gtk.h> +#include "common.h" #include "client.h" #ifndef DBYS_TYPE_G_OBJECT_PATH_ARRAY @@ -36,10 +37,6 @@ (dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH)) #endif -#define CONNMAN_SERVICE "org.freedesktop.connman" -#define CONNMAN_MANAGER CONNMAN_SERVICE ".Manager" -#define CONNMAN_INTERFACE CONNMAN_SERVICE ".Interface" - static GtkTreeStore *store = NULL; static client_state_callback state_callback = NULL; diff --git a/common/common.h b/common/common.h new file mode 100644 index 0000000..a7c5956 --- /dev/null +++ b/common/common.h @@ -0,0 +1,25 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2008 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 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 warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#define CONNMAN_SERVICE "org.freedesktop.connman" +#define CONNMAN_INSTANCE CONNMAN_SERVICE ".Instance" +#define CONNMAN_MANAGER CONNMAN_SERVICE ".Manager" +#define CONNMAN_INTERFACE CONNMAN_SERVICE ".Interface" diff --git a/common/instance.c b/common/instance.c new file mode 100644 index 0000000..b82af94 --- /dev/null +++ b/common/instance.c @@ -0,0 +1,101 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2008 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 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 warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <dbus/dbus-glib.h> + +#include <gtk/gtk.h> + +#include "common.h" +#include "instance.h" + +static DBusGConnection *connection; + +static GtkWindow *instance_window; + +static gboolean instance_present(GObject *self, GError **error) +{ + gtk_window_present(instance_window); + + return TRUE; +} + +#include "instance-glue.h" + +void instance_register(GtkWindow *window) +{ + instance_window = window; + + dbus_g_object_type_install_info(GTK_TYPE_WINDOW, + &dbus_glib_instance_object_info); + + dbus_g_connection_register_g_object(connection, "/", G_OBJECT(window)); +} + +gboolean instance_init(const gchar *name) +{ + DBusGProxy *proxy; + GError *error = NULL; + guint result; + + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_printerr("Can't get session bus: %s", error->message); + g_error_free(error); + return FALSE; + } + + proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + + if (dbus_g_proxy_call(proxy, "RequestName", NULL, + G_TYPE_STRING, name, G_TYPE_UINT, 0, G_TYPE_INVALID, + G_TYPE_UINT, &result, G_TYPE_INVALID) == FALSE) { + g_printerr("Can't get unique name on session bus"); + g_object_unref(proxy); + dbus_g_connection_unref(connection); + return FALSE; + } + + g_object_unref(proxy); + + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + proxy = dbus_g_proxy_new_for_name(connection, name, "/", + CONNMAN_SERVICE ".Instance"); + + dbus_g_proxy_call_no_reply(proxy, "Present", + G_TYPE_INVALID, G_TYPE_INVALID); + + g_object_unref(G_OBJECT(proxy)); + dbus_g_connection_unref(connection); + return FALSE; + } + + return TRUE; +} + +void instance_cleanup(void) +{ + dbus_g_connection_unref(connection); +} diff --git a/common/instance.h b/common/instance.h new file mode 100644 index 0000000..629fdfe --- /dev/null +++ b/common/instance.h @@ -0,0 +1,25 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2008 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 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 warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +gboolean instance_init(const gchar *name); +void instance_cleanup(void); + +void instance_register(GtkWindow *window); diff --git a/common/instance.xml b/common/instance.xml new file mode 100644 index 0000000..cdd73c9 --- /dev/null +++ b/common/instance.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/"> + <interface name="org.freedesktop.connman.Instance"> + <method name="Present"> + </method> + </interface> +</node> diff --git a/configure.in b/configure.in index c571912..26b8640 100644 --- a/configure.in +++ b/configure.in @@ -35,6 +35,9 @@ PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.70, dummy=yes, AC_SUBST(DBUS_CFLAGS) AC_SUBST(DBUS_LIBS) +DBUS_BINDING_TOOL="dbus-binding-tool" +AC_SUBST(DBUS_BINDING_TOOL) + PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.12, dummy=yes, AC_MSG_ERROR(gtk+ >= 2.12 is required)) AC_SUBST(GTK_CFLAGS) diff --git a/properties/main.c b/properties/main.c index 8cdaa65..b7e2fb2 100644 --- a/properties/main.c +++ b/properties/main.c @@ -30,7 +30,9 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "common.h" #include "client.h" +#include "instance.h" #include "advanced.h" static GtkWidget *interface_notebook; @@ -535,6 +537,7 @@ static void sig_term(int sig) int main(int argc, char *argv[]) { + GtkWidget *window; struct sigaction sa; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); @@ -545,9 +548,14 @@ int main(int argc, char *argv[]) gtk_window_set_default_icon_name("stock_internet"); + if (instance_init(CONNMAN_SERVICE ".properties") == FALSE) + return 0; + client_init(NULL); - create_window(); + window = create_window(); + + instance_register(GTK_WINDOW(window)); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sig_term; @@ -558,5 +566,7 @@ int main(int argc, char *argv[]) client_cleanup(); + instance_cleanup(); + return 0; } |