diff options
author | Thomas Haller <thaller@redhat.com> | 2016-12-16 13:06:19 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-12-20 15:53:41 +0100 |
commit | bd89c8a9249657d388312d3e4ea8ce8253153ab8 (patch) | |
tree | 7845e80758e96fe572a6719987240e759ae55107 | |
parent | 3b95cf68e2c128e91a9556b10bc5f2af8895c3f5 (diff) | |
download | NetworkManager-bd89c8a9249657d388312d3e4ea8ce8253153ab8.tar.gz |
act-request: allow omitting the @self argument in nm_act_request_cancel_secrets()
Previously, we would require a @self argument and the @call_id in
nm_act_request_cancel_secrets(), although the @call_id already has
a pointer to @self.
In principle that is not necessary, but it makes the API a bit
more robust as you need to care about the lifetime of the @req
as well.
However it is a bit inconvenient, because it requires that caller to
track both the activation request and the call-id.
Now, allow nm_act_request_get_secrets() to instruct the call-id to
take an additional reference to @self. Later on, we would allow to omit
the argument during cancelling. We only allow this, if the call-id
takes a reference to @self.
-rw-r--r-- | src/devices/nm-device-ethernet.c | 3 | ||||
-rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 3 | ||||
-rw-r--r-- | src/devices/wwan/nm-modem.c | 2 | ||||
-rw-r--r-- | src/nm-act-request.c | 33 | ||||
-rw-r--r-- | src/nm-act-request.h | 1 | ||||
-rw-r--r-- | src/ppp/nm-ppp-manager.c | 1 |
6 files changed, 37 insertions, 6 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 4fc32c38f2..7454d46cf9 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -518,6 +518,7 @@ link_timeout_cb (gpointer user_data) nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); nm_act_request_get_secrets (req, + FALSE, setting_name, NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW, NULL, @@ -702,7 +703,7 @@ handle_auth_or_fail (NMDeviceEthernet *self, if (new_secrets) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; - nm_act_request_get_secrets (req, setting_name, flags, NULL, wired_secrets_cb, self); + nm_act_request_get_secrets (req, FALSE, setting_name, flags, NULL, wired_secrets_cb, self); g_object_set_data (G_OBJECT (applied_connection), WIRED_SECRETS_TRIES, GUINT_TO_POINTER (++tries)); } else diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 0ec9fe8e66..039c614fe1 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1901,6 +1901,7 @@ handle_8021x_or_psk_auth_fail (NMDeviceWifi *self, cleanup_association_attempt (self, TRUE); nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); nm_act_request_get_secrets (req, + FALSE, setting_name, NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION | NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW, @@ -2189,7 +2190,7 @@ handle_auth_or_fail (NMDeviceWifi *self, if (new_secrets) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; - nm_act_request_get_secrets (req, setting_name, flags, NULL, wifi_secrets_cb, self); + nm_act_request_get_secrets (req, FALSE, setting_name, flags, NULL, wifi_secrets_cb, self); g_object_set_data (G_OBJECT (applied_connection), WIRELESS_SECRETS_TRIES, GUINT_TO_POINTER (++tries)); ret = NM_ACT_STAGE_RETURN_POSTPONE; diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 635f20ea74..4a8e9094ad 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -820,6 +820,7 @@ nm_modem_get_secrets (NMModem *self, if (request_new) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; priv->secrets_id = nm_act_request_get_secrets (priv->act_request, + FALSE, setting_name, flags, hint, @@ -870,6 +871,7 @@ nm_modem_act_stage1_prepare (NMModem *self, flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; priv->secrets_id = nm_act_request_get_secrets (req, + FALSE, setting_name, flags, hints ? g_ptr_array_index (hints, 0) : NULL, diff --git a/src/nm-act-request.c b/src/nm-act-request.c index b68b32fce9..3a04667b3c 100644 --- a/src/nm-act-request.c +++ b/src/nm-act-request.c @@ -94,17 +94,19 @@ struct _NMActRequestGetSecretsCallId { NMActRequestSecretsFunc callback; gpointer callback_data; NMSettingsConnectionCallId call_id; + bool has_ref; }; typedef struct _NMActRequestGetSecretsCallId GetSecretsInfo; static GetSecretsInfo * -_get_secrets_info_new (NMActRequest *self, NMActRequestSecretsFunc callback, gpointer callback_data) +_get_secrets_info_new (NMActRequest *self, gboolean ref_self, NMActRequestSecretsFunc callback, gpointer callback_data) { GetSecretsInfo *info; info = g_slice_new0 (GetSecretsInfo); - info->self = self; + info->has_ref = ref_self; + info->self = ref_self ? g_object_ref (self) : self; info->callback = callback; info->callback_data = callback_data; @@ -114,6 +116,8 @@ _get_secrets_info_new (NMActRequest *self, NMActRequestSecretsFunc callback, gpo static void _get_secrets_info_free (GetSecretsInfo *info) { + if (info->has_ref) + g_object_unref (info->self); g_slice_free (GetSecretsInfo, info); } @@ -149,6 +153,8 @@ get_secrets_cb (NMSettingsConnection *connection, /** * nm_act_request_get_secrets: * @self: + * @ref_self: if %TRUE, the pending call take a reference on @self. + * It also allows you to omit the @self argument in nm_act_request_cancel_secrets(). * @setting_name: * @flags: * @hint: @@ -167,6 +173,7 @@ get_secrets_cb (NMSettingsConnection *connection, */ NMActRequestGetSecretsCallId nm_act_request_get_secrets (NMActRequest *self, + gboolean ref_self, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char *hint, @@ -187,7 +194,7 @@ nm_act_request_get_secrets (NMActRequest *self, settings_connection = nm_act_request_get_settings_connection (self); applied_connection = nm_act_request_get_applied_connection (self); - info = _get_secrets_info_new (self, callback, callback_data); + info = _get_secrets_info_new (self, ref_self, callback, callback_data); priv->secrets_calls = g_slist_append (priv->secrets_calls, info); @@ -229,14 +236,32 @@ _do_cancel_secrets (NMActRequest *self, GetSecretsInfo *info, gboolean is_dispos _get_secrets_info_free (info); } +/** + * nm_act_request_cancel_secrets: + * @self: The #NMActRequest. Note that this argument can be %NULL if, and only if + * the call_id was created with @take_ref. + * @call_id: + * + * You are only allowed to cancel the call once, and only before the callback + * is already invoked. Note that cancelling causes the callback to be invoked + * synchronously. + */ void nm_act_request_cancel_secrets (NMActRequest *self, NMActRequestGetSecretsCallId call_id) { NMActRequestPrivate *priv; - g_return_if_fail (NM_IS_ACT_REQUEST (self)); g_return_if_fail (call_id); + if (self) { + g_return_if_fail (NM_IS_ACT_REQUEST (self)); + g_return_if_fail (self == call_id->self); + } else { + g_return_if_fail (call_id->has_ref); + g_return_if_fail (NM_IS_ACT_REQUEST (call_id->self)); + self = call_id->self; + } + priv = NM_ACT_REQUEST_GET_PRIVATE (self); if (!g_slist_find (priv->secrets_calls, call_id)) diff --git a/src/nm-act-request.h b/src/nm-act-request.h index 2443633f00..47247f8910 100644 --- a/src/nm-act-request.h +++ b/src/nm-act-request.h @@ -63,6 +63,7 @@ typedef void (*NMActRequestSecretsFunc) (NMActRequest *req, gpointer user_data); NMActRequestGetSecretsCallId nm_act_request_get_secrets (NMActRequest *req, + gboolean take_ref, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char *hint, diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index e33d9fe6fc..bf24552fb3 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -346,6 +346,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; priv->secrets_id = nm_act_request_get_secrets (priv->act_req, + FALSE, priv->secrets_setting_name, flags, hints ? g_ptr_array_index (hints, 0) : NULL, |