diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2019-01-25 11:24:41 +0100 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2019-01-25 11:24:41 +0100 |
| commit | bbae86d3d2997a853ca0365e8eb7a3ca7489ee09 (patch) | |
| tree | 1f7fa49b47ab13aea3effbe839559d221f6323b4 /libnm/nm-client.c | |
| parent | 404ebe62622150e77e311777dff8617eb974e834 (diff) | |
New upstream version 1.15.2
Diffstat (limited to 'libnm/nm-client.c')
| -rw-r--r-- | libnm/nm-client.c | 151 |
1 files changed, 140 insertions, 11 deletions
diff --git a/libnm/nm-client.c b/libnm/nm-client.c index 1da22540..e2522229 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -1163,18 +1163,20 @@ add_activate_cb (GObject *object, GAsyncResult *result, gpointer user_data) { - GSimpleAsyncResult *simple = user_data; + gs_unref_object GSimpleAsyncResult *simple = user_data; + gs_unref_variant GVariant *result_data = NULL; NMActiveConnection *ac; GError *error = NULL; - ac = nm_manager_add_and_activate_connection_finish (NM_MANAGER (object), result, &error); - if (ac) - g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref); - else + ac = nm_manager_add_and_activate_connection_finish (NM_MANAGER (object), result, &result_data, &error); + if (ac) { + g_simple_async_result_set_op_res_gpointer (simple, + _nm_activate_result_new (ac, result_data), + (GDestroyNotify) _nm_activate_result_free); + } else g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); - g_object_unref (simple); } /** @@ -1233,8 +1235,14 @@ nm_client_add_and_activate_connection_async (NMClient *client, if (cancellable) g_simple_async_result_set_check_cancellable (simple, cancellable); nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, - partial, device, specific_object, - cancellable, add_activate_cb, simple); + partial, + device, + specific_object, + NULL, + FALSE, + cancellable, + add_activate_cb, + simple); } /** @@ -1257,6 +1265,7 @@ nm_client_add_and_activate_connection_finish (NMClient *client, GError **error) { GSimpleAsyncResult *simple; + _NMActivateResult *r; g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); @@ -1264,8 +1273,128 @@ nm_client_add_and_activate_connection_finish (NMClient *client, simple = G_SIMPLE_ASYNC_RESULT (result); if (g_simple_async_result_propagate_error (simple, error)) return NULL; - else - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); + r = g_simple_async_result_get_op_res_gpointer (simple); + return g_object_ref (r->active); +} + +/** + * nm_client_add_and_activate_connection2: + * @client: a #NMClient + * @partial: (allow-none): an #NMConnection to add; the connection may be + * partially filled (or even %NULL) and will be completed by NetworkManager + * using the given @device and @specific_object before being added + * @device: the #NMDevice + * @specific_object: (allow-none): the object path of a connection-type-specific + * object this activation should use. This parameter is currently ignored for + * wired and mobile broadband connections, and the value of %NULL should be used + * (ie, no specific object). For Wi-Fi or WiMAX connections, pass the object + * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can + * get using nm_object_get_path(), and which will be used to complete the + * details of the newly added connection. + * @options: a #GVariant containing a dictionary with options, or %NULL + * @cancellable: a #GCancellable, or %NULL + * @callback: callback to be called when the activation has started + * @user_data: caller-specific data passed to @callback + * + * Adds a new connection using the given details (if any) as a template, + * automatically filling in missing settings with the capabilities of the given + * device and specific object. The new connection is then asynchronously + * activated as with nm_client_activate_connection_async(). Cannot be used for + * VPN connections at this time. + * + * Note that the callback is invoked when NetworkManager has started activating + * the new connection, not when it finishes. You can used the returned + * #NMActiveConnection object (in particular, #NMActiveConnection:state) to + * track the activation to its completion. + * + * This is identitcal to nm_client_add_and_activate_connection_async() but takes + * a further @options parameter. Currently the following options are supported + * by the daemon: + * * "persist": A string describing how the connection should be stored. + * The default is "disk", but it can be modified to "memory" (until + * the daemon quits) or "volatile" (will be deleted on disconnect). + * * "bind-activation": Bind the connection lifetime to something. The default is "none", + * meaning an explicit disconnect is needed. The value "dbus-client" + * means the connection will automatically be deactivated when the calling + * DBus client disappears from the system bus. + * + * Since: 1.16 + **/ +void +nm_client_add_and_activate_connection2 (NMClient *client, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GVariant *options, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GError *error = NULL; + + g_return_if_fail (NM_IS_CLIENT (client)); + g_return_if_fail (NM_IS_DEVICE (device)); + if (partial) + g_return_if_fail (NM_IS_CONNECTION (partial)); + + if (!_nm_client_check_nm_running (client, &error)) { + g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); + return; + } + + simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, + nm_client_add_and_activate_connection2); + if (cancellable) + g_simple_async_result_set_check_cancellable (simple, cancellable); + nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, + partial, + device, + specific_object, + options, + TRUE, + cancellable, + add_activate_cb, + simple); +} + +/** + * nm_client_add_and_activate_connection2_finish: + * @client: an #NMClient + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * @out_result: (allow-none): (transfer full): the output result + * of type "a{sv}" returned by D-Bus' AddAndActivate2 call. Currently no + * output is implemented yet. + * + * Gets the result of a call to nm_client_add_and_activate_connection2(). + * + * You can call nm_active_connection_get_connection() on the returned + * #NMActiveConnection to find the path of the created #NMConnection. + * + * Returns: (transfer full): the new #NMActiveConnection on success, %NULL on + * failure, in which case @error will be set. + **/ +NMActiveConnection * +nm_client_add_and_activate_connection2_finish (NMClient *client, + GAsyncResult *result, + GVariant **out_result, + GError **error) +{ + GSimpleAsyncResult *simple; + _NMActivateResult *r; + + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) { + NM_SET_OUT (out_result, NULL); + return NULL; + } + r = g_simple_async_result_get_op_res_gpointer (simple); + NM_SET_OUT (out_result, nm_g_variant_ref (r->add_and_activate_output)); + return g_object_ref (r->active); } /** @@ -2470,7 +2599,7 @@ proxy_type (GDBusObjectManagerClient *manager, const char *interface_name, gpointer user_data) { - /* ObjectManager asks us for an object proxy. Unfortunatelly, we can't + /* ObjectManager asks us for an object proxy. Unfortunately, we can't * decide that by interface name and GDBusObjectManager doesn't allow * us to look at the known interface list. Thus we need to create a * generic GDBusObject and only couple a NMObject subclass later. */ |