summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-05-15 14:25:07 -0400
committerDan Winship <danw@gnome.org>2014-08-01 14:34:40 -0400
commit258e74eb0c191cdd86719ad65864ab3c27ada80c (patch)
tree29d5a0d72ca94d1ea7daaa6c19ef745db31806fd /examples
parent8ca2998d81ca7534c59262b10f5bf3c480177b88 (diff)
downloadNetworkManager-258e74eb0c191cdd86719ad65864ab3c27ada80c.tar.gz
libnm: make the the use of GInitable mandatory
Remove _nm_object_ensure_inited(), etc; objects that implement GInitable are now mandatory-to-init(). Remove constructor() implementations that sometimes return NULL; do all the relevant checking in init() instead. Make nm_client_new() and nm_remote_settings_new() take a GCancellable and a GError**.
Diffstat (limited to 'examples')
-rw-r--r--examples/C/glib/add-connection-libnm.c15
-rw-r--r--examples/C/glib/get-ap-info-libnm.c6
-rw-r--r--examples/C/glib/list-connections-libnm.c10
-rwxr-xr-xexamples/python/gi/device-state-ip4config.py2
-rwxr-xr-xexamples/python/gi/get-active-connections.py2
-rwxr-xr-xexamples/python/gi/get_ips.py2
-rwxr-xr-xexamples/python/gi/show-wifi-networks.py2
7 files changed, 21 insertions, 18 deletions
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c
index 1b19b4fa94..5bddf9f21f 100644
--- a/examples/C/glib/add-connection-libnm.c
+++ b/examples/C/glib/add-connection-libnm.c
@@ -24,7 +24,7 @@
* because libnm handles much of the low-level stuff for you.
*
* Compile with:
- * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` add-connection-libnm.c -o add-connection-libnm
+ * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` add-connection-libnm.c -o add-connection-libnm
*/
#include <glib.h>
@@ -106,9 +106,9 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam
int main (int argc, char *argv[])
{
- DBusGConnection *bus;
NMRemoteSettings *settings;
GMainLoop *loop;
+ GError *error = NULL;
#if !GLIB_CHECK_VERSION (2, 35, 0)
/* Initialize GType system */
@@ -117,11 +117,13 @@ int main (int argc, char *argv[])
loop = g_main_loop_new (NULL, FALSE);
- /* Get system bus */
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
-
/* Create our proxy for NetworkManager's settings service */
- settings = nm_remote_settings_new (bus);
+ settings = nm_remote_settings_new (NULL, &error);
+ if (!settings) {
+ g_message ("Error: Could not get system settings: %s.", error->message);
+ g_error_free (error);
+ return 1;
+ }
/* Ask the settings service to add the new connection */
if (add_connection (settings, loop, "__Test connection__")) {
@@ -132,7 +134,6 @@ int main (int argc, char *argv[])
/* Clean up */
g_object_unref (settings);
- dbus_g_connection_unref (bus);
return 0;
}
diff --git a/examples/C/glib/get-ap-info-libnm.c b/examples/C/glib/get-ap-info-libnm.c
index 1921811412..4c550ed6ab 100644
--- a/examples/C/glib/get-ap-info-libnm.c
+++ b/examples/C/glib/get-ap-info-libnm.c
@@ -197,6 +197,7 @@ int main (int argc, char *argv[])
NMClient *client;
const GPtrArray *devices;
int i;
+ GError *error = NULL;
#if !GLIB_CHECK_VERSION (2, 35, 0)
/* Initialize GType system */
@@ -204,9 +205,10 @@ int main (int argc, char *argv[])
#endif
/* Get NMClient object */
- client = nm_client_new ();
+ client = nm_client_new (NULL, &error);
if (!client) {
- g_message ("Error: Could not create NMClient.");
+ g_message ("Error: Could not create NMClient: %s.", error->message);
+ g_error_free (error);
return EXIT_FAILURE;
}
diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c
index 216cf06a2e..a3ad2c5f10 100644
--- a/examples/C/glib/list-connections-libnm.c
+++ b/examples/C/glib/list-connections-libnm.c
@@ -21,11 +21,10 @@
* (that wraps direct D-Bus calls).
*
* Compile with:
- * gcc -Wall `pkg-config --libs --cflags glib-2.0 dbus-glib-1 libnm` list-connections-libnm.c -o list-connections-libnm
+ * gcc -Wall `pkg-config --libs --cflags glib-2.0 libnm` list-connections-libnm.c -o list-connections-libnm
*/
#include <glib.h>
-#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@@ -119,13 +118,14 @@ get_connections_cb (NMRemoteSettings *settings, gpointer user_data)
static gboolean
list_connections (gpointer data)
{
- DBusGConnection *bus = (DBusGConnection *) data;
NMRemoteSettings *settings;
gboolean settings_running;
+ GError *error = NULL;
/* Get system settings */
- if (!(settings = nm_remote_settings_new (bus))) {
- g_message ("Error: Could not get system settings.");
+ if (!(settings = nm_remote_settings_new (NULL, &error))) {
+ g_message ("Error: Could not get system settings: %s.", error->message);
+ g_error_free (error);
result = EXIT_FAILURE;
g_main_loop_quit (loop);
return FALSE;
diff --git a/examples/python/gi/device-state-ip4config.py b/examples/python/gi/device-state-ip4config.py
index faf0ef9422..1a6f7dece9 100755
--- a/examples/python/gi/device-state-ip4config.py
+++ b/examples/python/gi/device-state-ip4config.py
@@ -51,7 +51,7 @@ if __name__ == "__main__":
sys.exit('Usage: %s <interface>' % sys.argv[0])
dev_iface = sys.argv[1]
- c = NM.Client.new()
+ c = NM.Client.new(None)
dev = c.get_device_by_iface(dev_iface)
if dev is None:
sys.exit('Device \'%s\' not found' % dev_iface)
diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py
index a295be3038..55ba2d81cd 100755
--- a/examples/python/gi/get-active-connections.py
+++ b/examples/python/gi/get-active-connections.py
@@ -24,7 +24,7 @@
from gi.repository import GLib, NM
if __name__ == "__main__":
- client = NM.Client.new()
+ client = NM.Client.new(None)
acons = client.get_active_connections()
for ac in acons:
print "%s (%s) - %s" % (ac.get_id(), ac.get_uuid(), ac.get_connection_type())
diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py
index 9f1853f17e..1d110bfd41 100755
--- a/examples/python/gi/get_ips.py
+++ b/examples/python/gi/get_ips.py
@@ -124,7 +124,7 @@ if __name__ == "__main__":
sys.exit('Usage: %s <interface>' % sys.argv[0])
dev_iface = sys.argv[1]
- c = NM.Client.new()
+ c = NM.Client.new(None)
dev = c.get_device_by_iface(dev_iface)
if dev is None:
sys.exit('Device \'%s\' not found' % dev_iface)
diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py
index 8f61cfcbe8..c76d1c4cb9 100755
--- a/examples/python/gi/show-wifi-networks.py
+++ b/examples/python/gi/show-wifi-networks.py
@@ -62,7 +62,7 @@ def print_ap_info(ap):
print
if __name__ == "__main__":
- nmc = NM.Client.new()
+ nmc = NM.Client.new(None)
devs = nmc.get_devices()
for dev in devs: