diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-07-18 05:20:22 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-07-18 05:20:22 +0200 |
commit | 20d753122d7bea71e2f2a20915db7d29814b55c7 (patch) | |
tree | b33c031b96e44e76475aa58de75049e975ef514b | |
parent | dcc61534e74be71191a705c2e013ad5a658b7546 (diff) | |
download | connman-gnome-20d753122d7bea71e2f2a20915db7d29814b55c7.tar.gz |
Add simple test code for manager interface
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | common/Makefile.am | 4 | ||||
-rw-r--r-- | common/test-dbus.c | 116 |
3 files changed, 120 insertions, 1 deletions
@@ -27,6 +27,7 @@ po/POTFILES po/stamp-it po/.intltool-merge-cache +common/test-dbus common/test-client common/connman-demo applet/connman-applet diff --git a/common/Makefile.am b/common/Makefile.am index ff3a996..18c1eb1 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -5,13 +5,15 @@ libcommon_a_SOURCES = connman-dbus.c connman-dbus.h \ connman-client.h connman-client.c \ instance.h instance.c -noinst_PROGRAMS = connman-demo test-client +noinst_PROGRAMS = connman-demo test-client test-dbus connman_demo_SOURCES = demo.c connman_demo_LDADD = libcommon.a @GTK_LIBS@ @DBUS_LIBS@ test_client_LDADD = libcommon.a @GTK_LIBS@ @DBUS_LIBS@ +test_dbus_LDADD = @DBUS_LIBS@ + BUILT_SOURCES = marshal.h marshal.c \ connman-dbus-glue.h \ instance-glue.h diff --git a/common/test-dbus.c b/common/test-dbus.c new file mode 100644 index 0000000..0b7cebd --- /dev/null +++ b/common/test-dbus.c @@ -0,0 +1,116 @@ +/* + * + * 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> + +static GMainLoop *mainloop; +static DBusGConnection *connection; + +static void print_properties(GHashTable *hash) +{ + GValue *value; + + value = g_hash_table_lookup(hash, "State"); + if (value != NULL) + g_print("State: %s\n", g_value_get_string(value)); + + value = g_hash_table_lookup(hash, "OfflineMode"); + if (value != NULL) + g_print("OfflineMode: %d\n", g_value_get_boolean(value)); + + value = g_hash_table_lookup(hash, "Technologies"); + if (value != NULL) { + gchar **list = g_value_get_boxed(value); + guint i; + + g_print("Technologies:"); + for (i = 0; i < g_strv_length(list); i++) + g_print(" %s", *(list + i)); + g_print("\n"); + } +} + +static void properties_callback(DBusGProxy *proxy, + DBusGProxyCall *call, void *user_data) +{ + GHashTable *hash; + GError *error = NULL; + + dbus_g_proxy_end_call(proxy, call, &error, + dbus_g_type_get_map("GHashTable", + G_TYPE_STRING, G_TYPE_VALUE), + &hash, G_TYPE_INVALID); + + if (error != NULL) { + g_printerr("%s\n", error->message); + g_error_free(error); + } else + print_properties(hash); + + g_object_unref(proxy); + + g_main_loop_quit(mainloop); +} + +static void get_properties(const char *path, const char *interface) +{ + DBusGProxy *proxy; + + proxy = dbus_g_proxy_new_for_name(connection, "org.moblin.connman", + path, interface); + + if (dbus_g_proxy_begin_call_with_timeout(proxy, "GetProperties", + properties_callback, NULL, NULL, + 120 * 1000, G_TYPE_INVALID) == FALSE) { + g_printerr("Method call for retrieving properties failed\n"); + g_object_unref(proxy); + return; + } +} + +int main(int argc, char *argv[]) +{ + GError *error = NULL; + + g_type_init(); + + mainloop = g_main_loop_new(NULL, FALSE); + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error != NULL) { + g_printerr("%s\n", error->message); + g_error_free(error); + } + + get_properties("/", "org.moblin.connman.Manager"); + + g_main_loop_run(mainloop); + + dbus_g_connection_unref(connection); + + g_main_loop_unref(mainloop); + + return 0; +} |