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.
This commit is contained in:
Thomas Haller
2016-12-16 13:06:19 +01:00
parent 3b95cf68e2
commit bd89c8a924
6 changed files with 37 additions and 6 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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,

View File

@@ -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))

View File

@@ -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,

View File

@@ -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,