diff options
author | Dan Winship <danw@gnome.org> | 2014-08-20 10:08:18 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-04 18:19:22 -0400 |
commit | 9e5ddb58305c3f0b3041606e2a790b3cc75c92c4 (patch) | |
tree | 08d2a70319396fe04014e23b0ae70d3255e8c8a1 /examples | |
parent | 89228569f89036a5f492611cbc6c602a903b6a4e (diff) | |
download | NetworkManager-9e5ddb58305c3f0b3041606e2a790b3cc75c92c4.tar.gz |
examples: port dbus-glib-based examples to gdbus
Port the dbus-glib-based examples to GDBus.
Also, don't use libnm in them at all; there's not much point in
examples that use the D-Bus API directly if they're just going to fall
back to libnm for the hard stuff... (And also, this avoids the problem
that GDBus uses GVariant, while the libnm-core APIs currently still
use GHashTables.)
Also fix up some comment grammar and copyright style, and add emacs
modelines where missing.
Also rename the existing GDBus-based examples to have names ending in
"-gdbus", not "-GDBus", since there's no reason to gratuitously
capitalize here.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/C/glib/Makefile.am | 67 | ||||
-rw-r--r-- | examples/C/glib/add-connection-dbus-glib.c | 121 | ||||
-rw-r--r-- | examples/C/glib/add-connection-gdbus.c | 148 | ||||
-rw-r--r-- | examples/C/glib/add-connection-libnm.c | 13 | ||||
-rw-r--r-- | examples/C/glib/get-active-connections-dbus-glib.c | 218 | ||||
-rw-r--r-- | examples/C/glib/get-active-connections-gdbus.c | 272 | ||||
-rw-r--r-- | examples/C/glib/get-ap-info-libnm.c | 11 | ||||
-rw-r--r-- | examples/C/glib/list-connections-dbus-glib.c | 90 | ||||
-rw-r--r-- | examples/C/glib/list-connections-gdbus.c | 88 | ||||
-rw-r--r-- | examples/C/glib/list-connections-libnm.c | 8 | ||||
-rw-r--r-- | examples/C/glib/monitor-nm-running-dbus-glib.c | 127 | ||||
-rw-r--r-- | examples/C/glib/monitor-nm-running-gdbus.c (renamed from examples/C/glib/monitor-nm-running-GDBus.c) | 5 | ||||
-rw-r--r-- | examples/C/glib/monitor-nm-state-gdbus.c (renamed from examples/C/glib/monitor-nm-state-GDBus.c) | 8 |
13 files changed, 554 insertions, 622 deletions
diff --git a/examples/C/glib/Makefile.am b/examples/C/glib/Makefile.am index ffbc98783d..c3e9be0660 100644 --- a/examples/C/glib/Makefile.am +++ b/examples/C/glib/Makefile.am @@ -8,21 +8,19 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) noinst_PROGRAMS = \ - add-connection-dbus-glib \ + add-connection-gdbus \ add-connection-libnm \ - get-active-connections-dbus-glib \ - list-connections-dbus-glib \ - list-connections-libnm \ + get-active-connections-gdbus \ get-ap-info-libnm \ - monitor-nm-running-dbus-glib \ - monitor-nm-running-GDBus \ - monitor-nm-state-GDBus + list-connections-gdbus \ + list-connections-libnm \ + monitor-nm-running-gdbus \ + monitor-nm-state-gdbus -add_connection_dbus_glib_SOURCES = add-connection-dbus-glib.c -add_connection_dbus_glib_LDADD = \ - $(top_builddir)/libnm/libnm.la \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) +add_connection_gdbus_SOURCES = add-connection-gdbus.c +add_connection_gdbus_LDADD = \ + $(GLIB_LIBS) \ + $(UUID_LIBS) add_connection_libnm_SOURCES = add-connection-libnm.c add_connection_libnm_LDADD = \ @@ -30,51 +28,30 @@ add_connection_libnm_LDADD = \ $(DBUS_LIBS) \ $(GLIB_LIBS) -get_active_connections_dbus_glib_SOURCES = get-active-connections-dbus-glib.c -get_active_connections_dbus_glib_LDADD = \ - $(top_builddir)/libnm/libnm.la \ - $(DBUS_LIBS) \ +get_active_connections_gdbus_SOURCES = get-active-connections-gdbus.c +get_active_connections_gdbus_LDADD = \ $(GLIB_LIBS) -list_connections_dbus_glib_SOURCES = list-connections-dbus-glib.c -list_connections_dbus_glib_LDADD = \ +get_ap_info_libnm_SOURCES = get-ap-info-libnm.c +get_ap_info_libnm_LDADD = \ $(top_builddir)/libnm/libnm.la \ $(DBUS_LIBS) \ $(GLIB_LIBS) -list_connections_libnm_SOURCES = list-connections-libnm.c -list_connections_libnm_LDADD = \ - $(top_builddir)/libnm/libnm.la \ - $(DBUS_LIBS) \ +list_connections_gdbus_SOURCES = list-connections-gdbus.c +list_connections_gdbus_LDADD = \ $(GLIB_LIBS) -get_ap_info_libnm_SOURCES = get-ap-info-libnm.c -get_ap_info_libnm_LDADD = \ +list_connections_libnm_SOURCES = list-connections-libnm.c +list_connections_libnm_LDADD = \ $(top_builddir)/libnm/libnm.la \ $(DBUS_LIBS) \ $(GLIB_LIBS) -monitor_nm_running_dbus_glib_SOURCES = monitor-nm-running-dbus-glib.c -monitor_nm_running_dbus_glib_LDADD = \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) - -monitor_nm_running_GDBus_SOURCES = monitor-nm-running-GDBus.c -monitor_nm_running_GDBus_LDADD = \ +monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c +monitor_nm_running_gdbus_LDADD = \ $(GLIB_LIBS) -monitor_nm_state_GDBus_SOURCES = monitor-nm-state-GDBus.c -monitor_nm_state_GDBus_LDADD = \ +monitor_nm_state_gdbus_SOURCES = monitor-nm-state-gdbus.c +monitor_nm_state_gdbus_LDADD = \ $(GLIB_LIBS) - -EXTRA_DIST = \ - add-connection-dbus-glib.c \ - add-connection-libnm.c \ - get-active-connections-dbus-glib.c \ - list-connections-dbus-glib.c \ - list-connections-libnm.c \ - get-ap-info-libnm.c \ - monitor-nm-running-dbus-glib.c \ - monitor-nm-running-GDBus.c \ - monitor-nm-state-GDBus.c - diff --git a/examples/C/glib/add-connection-dbus-glib.c b/examples/C/glib/add-connection-dbus-glib.c deleted file mode 100644 index d4ac7be096..0000000000 --- a/examples/C/glib/add-connection-dbus-glib.c +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2011 Red Hat, Inc. - */ - -/* - * The example shows how to call AddConnection() D-Bus method to add - * a connection to system settings service. It uses dbus-glib and libnm - * libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` add-connection-glib.c -o add-connection-glib - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include <NetworkManager.h> - -#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) -#define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) - -static void -add_connection (DBusGProxy *proxy, const char *con_name) -{ - NMConnection *connection; - NMSettingConnection *s_con; - NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - char *uuid, *new_con_path = NULL; - GHashTable *hash; - GError *error = NULL; - - /* Create a new connection object */ - connection = (NMConnection *) nm_simple_connection_new (); - - /* Build up the 'connection' Setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new (); - uuid = nm_utils_uuid_generate (); - g_object_set (G_OBJECT (s_con), - NM_SETTING_CONNECTION_UUID, uuid, - NM_SETTING_CONNECTION_ID, con_name, - NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", - NULL); - g_free (uuid); - nm_connection_add_setting (connection, NM_SETTING (s_con)); - - /* Build up the 'wired' Setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new (); - nm_connection_add_setting (connection, NM_SETTING (s_wired)); - - /* Build up the 'ipv4' Setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (s_ip4), - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - - hash = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); - - /* Call AddConnection with the hash as argument */ - if (!dbus_g_proxy_call (proxy, "AddConnection", &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - G_TYPE_INVALID, - DBUS_TYPE_G_OBJECT_PATH, &new_con_path, - G_TYPE_INVALID)) { - g_print ("Error adding connection: %s %s", - dbus_g_error_get_name (error), - error->message); - g_clear_error (&error); - } else { - g_print ("Added: %s\n", new_con_path); - g_free (new_con_path); - } - - g_hash_table_destroy (hash); - g_object_unref (connection); -} - - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_INTERFACE_SETTINGS); - - /* Add a connection */ - add_connection (proxy, "__Test connection__"); - - g_object_unref (proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/add-connection-gdbus.c b/examples/C/glib/add-connection-gdbus.c new file mode 100644 index 0000000000..a7874fc51f --- /dev/null +++ b/examples/C/glib/add-connection-gdbus.c @@ -0,0 +1,148 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2011, 2014 Red Hat, Inc. + */ + +/* + * The example shows how to call the AddConnection() D-Bus method to add a + * connection to the system settings service. It uses GDBus, plus a few defines + * from the NetworkManager headers. Contrast add-connection-libnm, which is + * higher level because it uses libnm. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` -luuid add-connection-gdbus.c -o add-connection-gdbus + */ + +#include <gio/gio.h> +#include <uuid/uuid.h> +#include <NetworkManager.h> + +/* copied from libnm-core/nm-utils.c */ +char * +nm_utils_uuid_generate (void) +{ + uuid_t uuid; + char *buf; + + buf = g_malloc0 (37); + uuid_generate_random (uuid); + uuid_unparse_lower (uuid, &buf[0]); + return buf; +} + +static void +add_connection (GDBusProxy *proxy, const char *con_name) +{ + GVariantBuilder connection_builder; + GVariantBuilder setting_builder; + char *uuid; + const char *new_con_path; + GVariant *ret; + GError *error = NULL; + + /* Initialize connection GVariantBuilder */ + g_variant_builder_init (&connection_builder, G_VARIANT_TYPE ("a{sa{sv}}")); + + /* Build up the 'connection' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + + uuid = nm_utils_uuid_generate (); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_UUID, + g_variant_new_string (uuid)); + g_free (uuid); + + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_ID, + g_variant_new_string (con_name)); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_TYPE, + g_variant_new_string (NM_SETTING_WIRED_SETTING_NAME)); + + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_CONNECTION_SETTING_NAME, + &setting_builder); + + /* Add the (empty) 'wired' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_WIRED_SETTING_NAME, + &setting_builder); + + /* Build up the 'ipv4' Setting */ + g_variant_builder_init (&setting_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_IP4_CONFIG_METHOD, + g_variant_new_string (NM_SETTING_IP4_CONFIG_METHOD_AUTO)); + g_variant_builder_add (&connection_builder, "{sa{sv}}", + NM_SETTING_IP4_CONFIG_SETTING_NAME, + &setting_builder); + + /* Call AddConnection with the connection dictionary as argument. + * (g_variant_new() will consume the floating GVariant returned from + * &connection_builder, and g_dbus_proxy_call_sync() will consume the + * floating variant returned from g_variant_new(), so no cleanup is needed. + */ + ret = g_dbus_proxy_call_sync (proxy, + "AddConnection", + g_variant_new ("(a{sa{sv}})", &connection_builder), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (ret) { + g_variant_get (ret, "(&o)", &new_con_path); + g_print ("Added: %s\n", new_con_path); + g_variant_unref (ret); + } else { + g_dbus_error_strip_remote_error (error); + g_print ("Error adding connection: %s\n", error->message); + g_clear_error (&error); + } +} + +int +main (int argc, char *argv[]) +{ + GDBusProxy *proxy; + GError *error = NULL; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + NULL, &error); + if (!proxy) { + g_dbus_error_strip_remote_error (error); + g_print ("Could not create NetworkManager D-Bus proxy: %s\n", error->message); + g_error_free (error); + return 1; + } + + /* Add a connection */ + add_connection (proxy, "__Test connection__"); + + g_object_unref (proxy); + + return 0; +} diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c index f390bfa159..2b0143d35a 100644 --- a/examples/C/glib/add-connection-libnm.c +++ b/examples/C/glib/add-connection-libnm.c @@ -14,14 +14,14 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2011 Red Hat, Inc. + * Copyright 2011 Red Hat, Inc. */ /* - * The example shows how to add a new connection using libnm. - * Contrast this example with add-connection-dbus-glib.c, which is a bit lower - * level and talks directly to NM using dbus-glib. This example is simpler - * because libnm handles much of the low-level stuff for you. + * The example shows how to add a new connection using libnm. Contrast this + * example with add-connection-gdbus.c, which is a bit lower level and talks + * directly to NM using GDBus. This example is simpler because libnm handles + * much of the low-level stuff for you. * * Compile with: * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` add-connection-libnm.c -o add-connection-libnm @@ -98,7 +98,8 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam } -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { NMRemoteSettings *settings; GMainLoop *loop; diff --git a/examples/C/glib/get-active-connections-dbus-glib.c b/examples/C/glib/get-active-connections-dbus-glib.c deleted file mode 100644 index e7aaff7bb3..0000000000 --- a/examples/C/glib/get-active-connections-dbus-glib.c +++ /dev/null @@ -1,218 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2010 -2014 Red Hat, Inc. - */ - -/* - * The example shows how to call the D-Bus properties interface to get the - * list of currently active connections known to NetworkManager. It uses - * dbus-glib and libnm libraries. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` get-active-connections-dbus-glib.c -o get-active-connections-dbus-glib - */ - -#include <stdio.h> -#include <glib.h> -#include <dbus/dbus-glib.h> - -#include <NetworkManager.h> - -#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) -#define DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT)) -#define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH)) - -static void -print_connection (DBusGConnection *bus, const char *path) -{ - DBusGProxy *proxy; - GError *error = NULL; - GHashTable *hash = NULL; - NMConnection *connection = NULL; - - /* This function asks NetworkManager for the details of the connection */ - - /* Create the D-Bus proxy so we can ask it for the connection configuration details. */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - path, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION); - g_assert (proxy); - - /* Request the all the configuration of the Connection */ - if (!dbus_g_proxy_call (proxy, "GetSettings", &error, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) { - g_warning ("Failed to get active connection Connection property: %s", - error->message); - g_error_free (error); - goto out; - } - - /* Using the raw configuration, create an NMConnection object for it. This - * step also verifies that the data we got from NetworkManager are valid. */ - connection = nm_simple_connection_new_from_dbus (hash, &error); - if (!connection) { - g_warning ("Received invalid connection data: %s", error->message); - g_error_free (error); - goto out; - } - - /* And finally dump all the configuration to stdout */ - printf ("%s <=> %s\n", nm_connection_get_id (connection), path); - nm_connection_dump (connection); - -out: - if (connection) - g_object_unref (connection); - if (hash) - g_hash_table_destroy (hash); - g_object_unref (proxy); -} - -static void -get_active_connection_details (DBusGConnection *bus, const char *obj_path) -{ - DBusGProxy *props_proxy; - GValue path_value = G_VALUE_INIT; - GError *error = NULL; - const char *path = NULL; - - /* This function gets the backing Connection object that describes the - * network configuration that the ActiveConnection object is actually using. - * The ActiveConnection object contains the mapping between the configuration - * and the actual network interfaces that are using that configuration. - */ - - /* Create a D-Bus object proxy for the active connection object's properties */ - props_proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - obj_path, - DBUS_INTERFACE_PROPERTIES); - g_assert (props_proxy); - - /* Get the object path of the Connection details */ - if (!dbus_g_proxy_call (props_proxy, "Get", &error, - G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - G_TYPE_STRING, "Connection", - G_TYPE_INVALID, - G_TYPE_VALUE, &path_value, - G_TYPE_INVALID)) { - g_warning ("Failed to get active connection Connection property: %s", - error->message); - g_error_free (error); - goto out; - } - - if (!G_VALUE_HOLDS (&path_value, DBUS_TYPE_G_OBJECT_PATH)) { - g_warning ("Unexpected type returned getting Connection property: %s", - G_VALUE_TYPE_NAME (&path_value)); - goto out; - } - - path = g_value_get_boxed (&path_value); - if (!path) { - g_warning ("Missing connection path!"); - goto out; - } - - /* Print out the actual connection details */ - print_connection (bus, path); - -out: - g_value_unset (&path_value); - g_object_unref (props_proxy); -} - -static void -get_active_connections (DBusGConnection *bus, DBusGProxy *proxy) -{ - GError *error = NULL; - GValue value = G_VALUE_INIT; - GPtrArray *paths = NULL; - const char *a_path; - int i; - - /* Get the ActiveConnections property from the NM Manager object */ - if (!dbus_g_proxy_call (proxy, "Get", &error, - G_TYPE_STRING, NM_DBUS_INTERFACE, - G_TYPE_STRING, "ActiveConnections", - G_TYPE_INVALID, - G_TYPE_VALUE, &value, - G_TYPE_INVALID)) { - g_warning ("Failed to get ActiveConnections property: %s", error->message); - g_error_free (error); - return; - } - - /* Make sure the ActiveConnections property is the type we expect it to be */ - if (!G_VALUE_HOLDS (&value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) { - g_warning ("Unexpected type returned getting ActiveConnections: %s", - G_VALUE_TYPE_NAME (&value)); - goto out; - } - - /* Extract the active connections array from the GValue */ - paths = g_value_get_boxed (&value); - if (!paths) { - g_warning ("Could not retrieve active connections property"); - goto out; - } - - /* And print out the details for each active connection */ - for (i = 0; i < paths->len; i++) { - a_path = g_ptr_array_index (paths, i); - printf ("Active connection path: %s\n", a_path); - get_active_connection_details (bus, a_path); - } - -out: - g_value_unset (&value); -} - - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *props_proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy to get the object properties from the NM Manager - * object. NM_DBUS_* defines are from nm-dbus-interface.h. - */ - props_proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH, - DBUS_INTERFACE_PROPERTIES); - g_assert (props_proxy); - - /* Get active connections */ - get_active_connections (bus, props_proxy); - - g_object_unref (props_proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/get-active-connections-gdbus.c b/examples/C/glib/get-active-connections-gdbus.c new file mode 100644 index 0000000000..6a19bf895e --- /dev/null +++ b/examples/C/glib/get-active-connections-gdbus.c @@ -0,0 +1,272 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2010 -2014 Red Hat, Inc. + */ + +/* + * The example shows how to call the D-Bus properties interface to get the list + * of currently active connections known to NetworkManager. It uses GDBus, plus + * a few defines from the NetworkManager headers. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` get-active-connections-gdbus.c -o get-active-connections-gdbus + */ + +#include <string.h> +#include <gio/gio.h> +#include <NetworkManager.h> + +static void +print_setting (const char *setting_name, GVariant *setting) +{ + GVariantIter iter; + const char *property_name; + GVariant *value; + char *printed_value; + + g_print (" %s:\n", setting_name); + g_variant_iter_init (&iter, setting); + while (g_variant_iter_next (&iter, "{&sv}", &property_name, &value)) { + printed_value = g_variant_print (value, FALSE); + if (strcmp (printed_value, "[]") != 0) + g_print (" %s: %s\n", property_name, printed_value); + g_free (printed_value); + g_variant_unref (value); + } +} + +static void +print_connection (const char *path) +{ + GDBusProxy *proxy; + GError *error = NULL; + GVariant *ret, *connection = NULL, *s_con = NULL; + const char *id, *type; + gboolean found; + GVariantIter iter; + const char *setting_name; + GVariant *setting; + + /* This function asks NetworkManager for the details of the connection */ + + /* Create the D-Bus proxy so we can ask it for the connection configuration details. */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + NULL, NULL); + g_assert (proxy); + + /* Request the all the configuration of the Connection */ + ret = g_dbus_proxy_call_sync (proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get connection settings: %s\n", error->message); + g_error_free (error); + goto out; + } + + g_variant_get (ret, "(@a{sa{sv}})", &connection); + + s_con = g_variant_lookup_value (connection, NM_SETTING_CONNECTION_SETTING_NAME, NULL); + g_assert (s_con != NULL); + found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_ID, "&s", &id); + g_assert (found); + found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_TYPE, "&s", &type); + g_assert (found); + + /* Dump the configuration to stdout */ + g_print ("%s <=> %s\n", id, path); + + /* Connection setting first */ + print_setting (NM_SETTING_CONNECTION_SETTING_NAME, s_con); + + /* Then the type-specific setting */ + setting = g_variant_lookup_value (connection, type, NULL); + if (setting) { + print_setting (type, setting); + g_variant_unref (setting); + } + + g_variant_iter_init (&iter, connection); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting)) { + if ( strcmp (setting_name, NM_SETTING_CONNECTION_SETTING_NAME) != 0 + && strcmp (setting_name, type) != 0) + print_setting (setting_name, setting); + g_variant_unref (setting); + } + g_print ("\n"); + +out: + if (s_con) + g_variant_unref (s_con); + if (connection) + g_variant_unref (connection); + if (ret) + g_variant_unref (ret); + g_object_unref (proxy); +} + +static void +get_active_connection_details (const char *obj_path) +{ + GDBusProxy *props_proxy; + GVariant *ret = NULL, *path_value = NULL; + const char *path = NULL; + GError *error = NULL; + + /* This function gets the backing Connection object that describes the + * network configuration that the ActiveConnection object is actually using. + * The ActiveConnection object contains the mapping between the configuration + * and the actual network interfaces that are using that configuration. + */ + + /* Create a D-Bus object proxy for the active connection object's properties */ + props_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + obj_path, + "org.freedesktop.DBus.Properties", + NULL, NULL); + g_assert (props_proxy); + + /* Get the object path of the Connection details */ + ret = g_dbus_proxy_call_sync (props_proxy, + "Get", + g_variant_new ("(ss)", + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "Connection"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get active connection Connection property: %s\n", + error->message); + g_error_free (error); + goto out; + } + + g_variant_get (ret, "(v)", &path_value); + if (!g_variant_is_of_type (path_value, G_VARIANT_TYPE_OBJECT_PATH)) { + g_warning ("Unexpected type returned getting Connection property: %s", + g_variant_get_type_string (path_value)); + goto out; + } + + path = g_variant_get_string (path_value, NULL); + + /* Print out the actual connection details */ + print_connection (path); + +out: + if (path_value) + g_variant_unref (path_value); + if (ret) + g_variant_unref (ret); + g_object_unref (props_proxy); +} + +static void +get_active_connections (GDBusProxy *proxy) +{ + GError *error = NULL; + GVariant *ret = NULL, *value = NULL; + char **paths; + int i; + + /* Get the ActiveConnections property from the NM Manager object */ + ret = g_dbus_proxy_call_sync (proxy, + "Get", + g_variant_new ("(ss)", + NM_DBUS_INTERFACE, + "ActiveConnections"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_warning ("Failed to get ActiveConnections property: %s\n", error->message); + g_error_free (error); + return; + } + + g_variant_get (ret, "(v)", &value); + + /* Make sure the ActiveConnections property is the type we expect it to be */ + if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) { + g_warning ("Unexpected type returned getting ActiveConnections: %s", + g_variant_get_type_string (value)); + goto out; + } + + /* Extract the active connections array from the GValue */ + paths = g_variant_dup_objv (value, NULL); + if (!paths) { + g_warning ("Could not retrieve active connections property"); + goto out; + } + + /* And print out the details for each active connection */ + for (i = 0; paths[i]; i++) { + g_print ("Active connection path: %s\n", paths[i]); + get_active_connection_details (paths[i]); + } + g_strfreev (paths); + +out: + if (value) + g_variant_unref (value); + if (ret) + g_variant_unref (ret); +} + + +int +main (int argc, char *argv[]) +{ + GDBusProxy *props_proxy; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy to get the object properties from the NM Manager + * object. NM_DBUS_* defines are from nm-dbus-interface.h. + */ + props_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH, + "org.freedesktop.DBus.Properties", + NULL, NULL); + g_assert (props_proxy); + + /* Get active connections */ + get_active_connections (props_proxy); + + g_object_unref (props_proxy); + + return 0; +} diff --git a/examples/C/glib/get-ap-info-libnm.c b/examples/C/glib/get-ap-info-libnm.c index 044cec9c04..efb70bf4b8 100644 --- a/examples/C/glib/get-ap-info-libnm.c +++ b/examples/C/glib/get-ap-info-libnm.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,19 +14,18 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 Red Hat, Inc. + * Copyright 2010 Red Hat, Inc. */ /* - * The example shows how to get info about APs visible by Wi-Fi devices - * using libnm (that wraps direct D-Bus calls). + * The example shows how to get info about APs visible by Wi-Fi devices using + * libnm. * * Compile with: * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` get-ap-info-libnm.c -o get-ap-info-libnm */ #include <glib.h> -#include <dbus/dbus-glib.h> #include <stdio.h> #include <stdlib.h> @@ -188,7 +188,8 @@ show_wifi_device_info (NMDevice *device) } } -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { NMClient *client; const GPtrArray *devices; diff --git a/examples/C/glib/list-connections-dbus-glib.c b/examples/C/glib/list-connections-dbus-glib.c deleted file mode 100644 index 608c666603..0000000000 --- a/examples/C/glib/list-connections-dbus-glib.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2011 Red Hat, Inc. - */ - -/* - * The example shows how to list connections from System Settings service using direct - * D-Bus call of ListConnections method. - * The example uses dbus-glib libraries and libnm headers. - * - * Compile with: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1` `pkg-config --cflags libnm` list-connections-dbus.c -o list-connections-dbus - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <stdio.h> - -#include <NetworkManager.h> - -#define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH)) - -static void -list_connections (DBusGProxy *proxy) -{ - int i; - GError *error = NULL; - GPtrArray *con_array; - gboolean success; - - /* Call ListConnections D-Bus method */ - success = dbus_g_proxy_call (proxy, "ListConnections", &error, - /* No input arguments */ - G_TYPE_INVALID, - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, &con_array, /* Return values */ - G_TYPE_INVALID); - if (!success) { - printf ("ListConnections failed: %s", error->message); - g_error_free (error); - return; - } - - for (i = 0; con_array && i < con_array->len; i++) { - char *connection_path = g_ptr_array_index (con_array, i); - printf ("%s\n", connection_path); - g_free (connection_path); - } - g_ptr_array_free (con_array, TRUE); -} - -int main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *proxy; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_INTERFACE_SETTINGS); - - /* List connections of system settings service */ - list_connections (proxy); - - g_object_unref (proxy); - dbus_g_connection_unref (bus); - - return 0; -} diff --git a/examples/C/glib/list-connections-gdbus.c b/examples/C/glib/list-connections-gdbus.c new file mode 100644 index 0000000000..f5922582ea --- /dev/null +++ b/examples/C/glib/list-connections-gdbus.c @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2011, 2014 Red Hat, Inc. + */ + +/* + * The example shows how to list connections from the System Settings service + * using direct D-Bus calls. The example uses GDBus, plus a few defines from + * the NetworkManager headers. Contrast list-connections-libnm, which is higher + * level because it uses libnm. + * + * Compile with: + * gcc -Wall `pkg-config --cflags libnm` `pkg-config --cflags --libs gio-2.0` list-connections-gdbus.c -o list-connections-gdbus + */ + +#include <gio/gio.h> +#include <NetworkManager.h> + +static void +list_connections (GDBusProxy *proxy) +{ + int i; + GError *error = NULL; + GVariant *ret; + char **paths; + + /* Call ListConnections D-Bus method */ + ret = g_dbus_proxy_call_sync (proxy, + "ListConnections", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (!ret) { + g_dbus_error_strip_remote_error (error); + g_print ("ListConnections failed: %s\n", error->message); + g_error_free (error); + return; + } + + g_variant_get (ret, "(^ao)", &paths); + g_variant_unref (ret); + + for (i = 0; paths[i]; i++) + g_print ("%s\n", paths[i]); + g_strfreev (paths); +} + +int +main (int argc, char *argv[]) +{ + GDBusProxy *proxy; + +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + NM_DBUS_SERVICE, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + NULL, NULL); + g_assert (proxy != NULL); + + /* List connections of system settings service */ + list_connections (proxy); + + g_object_unref (proxy); + + return 0; +} diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index 1827835948..bebeeb8a23 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,12 +14,13 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2011 Red Hat, Inc. + * Copyright 2011 Red Hat, Inc. */ /* - * The example shows how to list connections from System Settings service using libnm - * (that wraps direct D-Bus calls). + * The example shows how to list connections from the System Settings service + * using libnm. Contrast this example with list-connections-gdbus.c, which is a + * bit lower level and talks directly to NM using GDBus. * * Compile with: * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` list-connections-libnm.c -o list-connections-libnm diff --git a/examples/C/glib/monitor-nm-running-dbus-glib.c b/examples/C/glib/monitor-nm-running-dbus-glib.c deleted file mode 100644 index 0b01a57f06..0000000000 --- a/examples/C/glib/monitor-nm-running-dbus-glib.c +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2012 Red Hat, Inc. - */ - -/* - * This example monitors whether NM is running by checking D-Bus - * NameOwnerChanged signal. - * It uses dbus-glib library. - * - * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1` monitor-nm-running.c -o monitor-nm-running - */ - -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-bindings.h> -#include <string.h> - -#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" - -static void -proxy_name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) -{ - gboolean *nm_running = (gboolean *) user_data; - gboolean old_good = (old_owner && strlen (old_owner)); - gboolean new_good = (new_owner && strlen (new_owner)); - gboolean new_running = FALSE; - - /* We are only interested in NetworkManager */ - if (!name || strcmp (name, NM_DBUS_SERVICE) != 0) - return; - - if (!old_good && new_good) - new_running = TRUE; - else if (old_good && !new_good) - new_running = FALSE; - - *nm_running = new_running; - - g_print ("name: '%s', old_owner: '%s', new_owner: '%s'", name, old_owner, new_owner); - g_print (" => NM is %s\n", *nm_running ? "running" : "not running"); -} - - -int -main (int argc, char *argv[]) -{ - DBusGConnection *bus; - DBusGProxy *bus_proxy; - GMainLoop *loop = NULL; - GError *err = NULL; - gboolean nm_running; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - /* Initialize GType system */ - g_type_init (); -#endif - - g_print ("Monitor 'org.freedesktop.NetworkManager' D-Bus name\n"); - g_print ("===================================================\n"); - - /* Get system bus */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - - /* Create a D-Bus proxy to D-Bus daemon */ - bus_proxy = dbus_g_proxy_new_for_name (bus, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!bus_proxy) { - g_message ("Error: Couldn't create D-Bus object proxy for org.freedesktop.DBus."); - dbus_g_connection_unref (bus); - return -1; - } - - /* Call NameHasOwner method to find out if NM is running. When NM runs it claims - * 'org.freedesktop.NetworkManager' service name on D-Bus */ - if (!org_freedesktop_DBus_name_has_owner (bus_proxy, NM_DBUS_SERVICE, &nm_running, &err)) { - g_message ("Error: NameHasOwner request failed: %s", - (err && err->message) ? err->message : "(unknown)"); - g_clear_error (&err); - g_object_unref (bus_proxy); - dbus_g_connection_unref (bus); - return -1; - } - g_print ("NM is %s\n", nm_running ? "running" : "not running"); - - - /* Connect to NameOwnerChanged signal to monitor NM running state */ - dbus_g_proxy_add_signal (bus_proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (bus_proxy, - "NameOwnerChanged", - G_CALLBACK (proxy_name_owner_changed), - &nm_running, NULL); - - loop = g_main_loop_new (NULL, FALSE); /* Create main loop */ - g_main_loop_run (loop); /* Run main loop */ - - g_object_unref (bus_proxy); - dbus_g_connection_unref (bus); - - return 0; -} - diff --git a/examples/C/glib/monitor-nm-running-GDBus.c b/examples/C/glib/monitor-nm-running-gdbus.c index 9e38d4c70d..2e1a11c0c8 100644 --- a/examples/C/glib/monitor-nm-running-GDBus.c +++ b/examples/C/glib/monitor-nm-running-gdbus.c @@ -1,5 +1,4 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2012 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. */ /* @@ -26,7 +25,7 @@ * See also http://developer.gnome.org/gio/stable/gio-Watching-Bus-Names.html * * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` monitor-nm-running-GDBus.c -o monitor-nm-running-GDBus + * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` monitor-nm-running-gdbus.c -o monitor-nm-running-gdbus */ #include <gio/gio.h> diff --git a/examples/C/glib/monitor-nm-state-GDBus.c b/examples/C/glib/monitor-nm-state-gdbus.c index 5131b8c867..05596399d9 100644 --- a/examples/C/glib/monitor-nm-state-GDBus.c +++ b/examples/C/glib/monitor-nm-state-gdbus.c @@ -1,5 +1,4 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2012 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. */ /* @@ -23,11 +22,11 @@ * "org.freedesktop.NetworkManager" object. * It uses GDBus and the libnm headers. - * You don't need to have NetworkManager devel package installed. You can just + * You don't need to have the NetworkManager devel packages installed. You can just * grab nm-dbus-interface.h and put it in the path. * * Standalone compilation: - * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` `pkg-config --cflags libnm` monitor-nm-state-GDBus.c -o monitor-nm-state-GDBus + * gcc -Wall `pkg-config --libs --cflags glib-2.0 gio-2.0` `pkg-config --cflags libnm` monitor-nm-state-gdbus.c -o monitor-nm-state-gdbus */ #include <gio/gio.h> @@ -112,6 +111,7 @@ main (int argc, char *argv[]) if (proxy == NULL) { + g_dbus_error_strip_remote_error (error); g_printerr ("Error creating D-Bus proxy: %s\n", error->message); g_error_free (error); return -1; |