diff options
author | Dan Winship <danw@gnome.org> | 2014-09-11 16:27:13 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-25 09:29:20 -0400 |
commit | 2237ea3ddbe602446ac87a8a055a6d719c4a0f6c (patch) | |
tree | 4891a7570618c68905f9375c43f65c71bc21eb9b /examples | |
parent | 6ca10677d67c129d43b82e5563e20c4c5f2e5727 (diff) | |
download | NetworkManager-2237ea3ddbe602446ac87a8a055a6d719c4a0f6c.tar.gz |
libnm: make sync/async APIs more GLib-like
Make synchronous APIs take GCancellables, and make asynchronous APIs
use GAsyncReadyCallbacks and have names ending in "_async", with
"_finish" functions to retrieve the results.
Also, make nm_client_activate_connection_finish(),
nm_client_add_and_activate_finish(), and
nm_remote_settings_add_connection_finish() be (transfer full) rather
than (transfer none), because the refcounting semantics become
slightly confusing in some edge cases otherwise.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/C/glib/add-connection-libnm.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c index 59632955b8..c680f420ff 100644 --- a/examples/C/glib/add-connection-libnm.c +++ b/examples/C/glib/add-connection-libnm.c @@ -31,27 +31,33 @@ #include <NetworkManager.h> static void -added_cb (NMRemoteSettings *settings, - NMRemoteConnection *remote, - GError *error, +added_cb (GObject *settings, + GAsyncResult *result, gpointer user_data) { GMainLoop *loop = user_data; + NMRemoteConnection *remote; + GError *error; /* 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); - if (error) + if (error) { g_print ("Error adding connection: %s", error->message); - else + g_error_free (error); + } else { g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote))); + g_object_unref (remote); + } /* Tell the mainloop we're done and we can quit now */ g_main_loop_quit (loop); } -static gboolean +static void add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name) { NMConnection *connection; @@ -59,7 +65,6 @@ add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_nam NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; char *uuid; - gboolean success; /* Create a new connection object */ connection = nm_simple_connection_new (); @@ -89,12 +94,8 @@ 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. */ - success = nm_remote_settings_add_connection (settings, connection, TRUE, added_cb, loop); - if (!success) - g_print ("Error adding connection\n"); - + nm_remote_settings_add_connection_async (settings, connection, TRUE, NULL, added_cb, loop); g_object_unref (connection); - return success; } @@ -121,11 +122,9 @@ main (int argc, char *argv[]) } /* Ask the settings service to add the new connection */ - if (add_connection (settings, loop, "__Test connection__")) { - /* Wait for the connection to be added */ - g_main_loop_run (loop); - } else - g_print ("Error adding connection to NetworkManager\n"); + add_connection (settings, loop, "__Test connection__"); + /* Wait for the connection to be added */ + g_main_loop_run (loop); /* Clean up */ g_object_unref (settings); |