diff options
author | Dan Winship <danw@gnome.org> | 2014-09-29 10:58:16 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-10 12:40:19 -0400 |
commit | 6f3d1f95262abbf5101d6f88ecfa292d575e0d4f (patch) | |
tree | bffa6c50529d46377f71da8907dcd734a8e7a366 /examples | |
parent | c1f1e9618126e618e9f10d9a5ce74b2ef7101e76 (diff) | |
download | NetworkManager-6f3d1f95262abbf5101d6f88ecfa292d575e0d4f.tar.gz |
libnm: merge NMRemoteSettings into NMClient
Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/C/glib/add-connection-libnm.c | 25 | ||||
-rw-r--r-- | examples/C/glib/list-connections-libnm.c | 25 |
2 files changed, 22 insertions, 28 deletions
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c index c680f420ff..1288e79c51 100644 --- a/examples/C/glib/add-connection-libnm.c +++ b/examples/C/glib/add-connection-libnm.c @@ -31,7 +31,7 @@ #include <NetworkManager.h> static void -added_cb (GObject *settings, +added_cb (GObject *client, GAsyncResult *result, gpointer user_data) { @@ -42,8 +42,7 @@ added_cb (GObject *settings, /* NM responded to our request; either handle the resulting error or * print out the object path of the connection we just added. */ - remote = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (settings), - result, &error); + remote = nm_client_add_connection_finish (NM_CLIENT (client), result, &error); if (error) { g_print ("Error adding connection: %s", error->message); @@ -58,7 +57,7 @@ added_cb (GObject *settings, } static void -add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name) +add_connection (NMClient *client, GMainLoop *loop, const char *con_name) { NMConnection *connection; NMSettingConnection *s_con; @@ -94,7 +93,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam /* Ask the settings service to add the new connection; we'll quit the * mainloop and exit when the callback is called. */ - nm_remote_settings_add_connection_async (settings, connection, TRUE, NULL, added_cb, loop); + nm_client_add_connection_async (client, connection, TRUE, NULL, added_cb, loop); g_object_unref (connection); } @@ -102,7 +101,7 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam int main (int argc, char *argv[]) { - NMRemoteSettings *settings; + NMClient *client; GMainLoop *loop; GError *error = NULL; @@ -113,21 +112,21 @@ main (int argc, char *argv[]) loop = g_main_loop_new (NULL, FALSE); - /* Create our proxy for NetworkManager's settings service */ - settings = nm_remote_settings_new (NULL, &error); - if (!settings) { - g_message ("Error: Could not get system settings: %s.", error->message); + /* Connect to NetworkManager */ + client = nm_client_new (NULL, &error); + if (!client) { + g_message ("Error: Could not connect to NetworkManager: %s.", error->message); g_error_free (error); return 1; } - /* Ask the settings service to add the new connection */ - add_connection (settings, loop, "__Test connection__"); + /* Ask NM to add the new connection */ + add_connection (client, loop, "__Test connection__"); /* Wait for the connection to be added */ g_main_loop_run (loop); /* Clean up */ - g_object_unref (settings); + g_object_unref (client); return 0; } diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index bebeeb8a23..f761bfd77f 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -18,9 +18,9 @@ */ /* - * 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. + * The example shows how to list connections. 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 @@ -65,8 +65,7 @@ show_connection (gpointer data, gpointer user_data) int main (int argc, char *argv[]) { - NMRemoteSettings *settings; - gboolean settings_running; + NMClient *client; GError *error = NULL; GSList *connections; @@ -75,30 +74,26 @@ main (int argc, char *argv[]) g_type_init (); #endif - /* Get system settings */ - if (!(settings = nm_remote_settings_new (NULL, &error))) { - g_message ("Error: Could not get system settings: %s.", error->message); + if (!(client = nm_client_new (NULL, &error))) { + g_message ("Error: Could not connect to NetworkManager: %s.", error->message); g_error_free (error); return EXIT_FAILURE; } - /* Find out whether setting service is running */ - g_object_get (settings, NM_REMOTE_SETTINGS_NM_RUNNING, &settings_running, NULL); - - if (!settings_running) { - g_message ("Error: Can't obtain connections: settings service is not running."); + if (!nm_client_get_nm_running (client)) { + g_message ("Error: Can't obtain connections: NetworkManager is not running."); return EXIT_FAILURE; } /* Now the connections can be listed. */ - connections = nm_remote_settings_list_connections (settings); + connections = nm_client_list_connections (client); printf ("Connections:\n===================\n"); g_slist_foreach (connections, show_connection, NULL); g_slist_free (connections); - g_object_unref (settings); + g_object_unref (client); return EXIT_SUCCESS; } |