mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 08:48:07 +02:00
modem: don't use GAsyncResult pattern for disconnecting modem
We should not use GAsyncResult. At least, not for internal API. It's more cumbersome then helpful, in my opinion. It requires this awkward async_finish() pattern. Instead, let the caller pass a suitable callback of the right type.
This commit is contained in:
parent
fadcc16b26
commit
9b935fad9b
9 changed files with 190 additions and 210 deletions
|
|
@ -14537,30 +14537,25 @@ ip6_managed_setup (NMDevice *self)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deactivate_async_ready (NMDevice *self,
|
deactivate_async_ready (NMDevice *self,
|
||||||
GAsyncResult *res,
|
GError *error,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
NMDeviceStateReason reason = GPOINTER_TO_UINT (user_data);
|
NMDeviceStateReason reason = GPOINTER_TO_UINT (user_data);
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
NM_DEVICE_GET_CLASS (self)->deactivate_async_finish (self, res, &error);
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
|
_LOGD (LOGD_DEVICE, "Deactivation cancelled");
|
||||||
/* If operation cancelled, just return */
|
return;
|
||||||
if ( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)
|
|
||||||
|| (priv->deactivating_cancellable && g_cancellable_is_cancelled (priv->deactivating_cancellable))) {
|
|
||||||
_LOGW (LOGD_DEVICE, "Deactivation cancelled");
|
|
||||||
} else {
|
|
||||||
/* In every other case, transition to the DISCONNECTED state */
|
|
||||||
if (error) {
|
|
||||||
_LOGW (LOGD_DEVICE, "Deactivation failed: %s",
|
|
||||||
error->message);
|
|
||||||
}
|
|
||||||
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_object (&priv->deactivating_cancellable);
|
g_clear_object (&priv->deactivating_cancellable);
|
||||||
g_clear_error (&error);
|
|
||||||
|
/* In every other case, transition to the DISCONNECTED state */
|
||||||
|
if (error) {
|
||||||
|
_LOGW (LOGD_DEVICE, "Deactivation failed: %s",
|
||||||
|
error->message);
|
||||||
|
}
|
||||||
|
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -14580,14 +14575,13 @@ deactivate_dispatcher_complete (guint call_id, gpointer user_data)
|
||||||
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
|
priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
|
||||||
|
|
||||||
if (nm_clear_g_cancellable (&priv->deactivating_cancellable))
|
if (nm_clear_g_cancellable (&priv->deactivating_cancellable))
|
||||||
g_warn_if_reached ();
|
nm_assert_not_reached ();
|
||||||
|
|
||||||
if ( NM_DEVICE_GET_CLASS (self)->deactivate_async
|
if (NM_DEVICE_GET_CLASS (self)->deactivate_async) {
|
||||||
&& NM_DEVICE_GET_CLASS (self)->deactivate_async_finish) {
|
|
||||||
priv->deactivating_cancellable = g_cancellable_new ();
|
priv->deactivating_cancellable = g_cancellable_new ();
|
||||||
NM_DEVICE_GET_CLASS (self)->deactivate_async (self,
|
NM_DEVICE_GET_CLASS (self)->deactivate_async (self,
|
||||||
priv->deactivating_cancellable,
|
priv->deactivating_cancellable,
|
||||||
(GAsyncReadyCallback) deactivate_async_ready,
|
deactivate_async_ready,
|
||||||
GUINT_TO_POINTER (reason));
|
GUINT_TO_POINTER (reason));
|
||||||
} else
|
} else
|
||||||
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
|
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
|
||||||
|
|
@ -14644,8 +14638,8 @@ _set_state_full (NMDevice *self,
|
||||||
queued_state_clear (self);
|
queued_state_clear (self);
|
||||||
|
|
||||||
dispatcher_cleanup (self);
|
dispatcher_cleanup (self);
|
||||||
if (priv->deactivating_cancellable)
|
|
||||||
g_cancellable_cancel (priv->deactivating_cancellable);
|
nm_clear_g_cancellable (&priv->deactivating_cancellable);
|
||||||
|
|
||||||
/* Cache the activation request for the dispatcher */
|
/* Cache the activation request for the dispatcher */
|
||||||
req = nm_g_object_ref (priv->act_request.obj);
|
req = nm_g_object_ref (priv->act_request.obj);
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,10 @@ typedef enum { /*< skip >*/
|
||||||
NM_DEVICE_CHECK_DEV_AVAILABLE_ALL = (1L << 1) - 1,
|
NM_DEVICE_CHECK_DEV_AVAILABLE_ALL = (1L << 1) - 1,
|
||||||
} NMDeviceCheckDevAvailableFlags;
|
} NMDeviceCheckDevAvailableFlags;
|
||||||
|
|
||||||
|
typedef void (*NMDeviceDeactivateCallback) (NMDevice *self,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
typedef struct _NMDeviceClass {
|
typedef struct _NMDeviceClass {
|
||||||
NMDBusObjectClass parent;
|
NMDBusObjectClass parent;
|
||||||
|
|
||||||
|
|
@ -354,11 +358,8 @@ typedef struct _NMDeviceClass {
|
||||||
/* Async deactivating (in the DEACTIVATING phase) */
|
/* Async deactivating (in the DEACTIVATING phase) */
|
||||||
void (* deactivate_async) (NMDevice *self,
|
void (* deactivate_async) (NMDevice *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
NMDeviceDeactivateCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean (* deactivate_async_finish) (NMDevice *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void (* deactivate_reset_hw_addr) (NMDevice *self);
|
void (* deactivate_reset_hw_addr) (NMDevice *self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,10 @@ cleanup_association_attempt (NMDeviceIwd *self, gboolean disconnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
reset_mode (NMDeviceIwd *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
reset_mode (NMDeviceIwd *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
|
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
|
@ -454,7 +457,9 @@ reset_mode (NMDeviceIwd *self, GCancellable *cancellable, GAsyncReadyCallback ca
|
||||||
"Mode",
|
"Mode",
|
||||||
g_variant_new_string ("station")),
|
g_variant_new_string ("station")),
|
||||||
G_DBUS_CALL_FLAGS_NONE, 2000,
|
G_DBUS_CALL_FLAGS_NONE, 2000,
|
||||||
cancellable, callback, user_data);
|
cancellable,
|
||||||
|
callback,
|
||||||
|
user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -473,43 +478,53 @@ deactivate (NMDevice *device)
|
||||||
reset_mode (self, NULL, NULL, NULL);
|
reset_mode (self, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
deactivate_async_finish (NMDevice *device, GAsyncResult *res, GError **error)
|
|
||||||
{
|
|
||||||
return g_task_propagate_boolean (G_TASK (res), error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_cb (GObject *source, GAsyncResult *res, gpointer user_data)
|
disconnect_cb (GObject *source, GAsyncResult *res, gpointer user_data)
|
||||||
{
|
{
|
||||||
GTask *task = user_data;
|
gs_unref_object NMDeviceIwd *self = NULL;
|
||||||
|
NMDeviceDeactivateCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
gs_unref_variant GVariant *variant = NULL;
|
gs_unref_variant GVariant *variant = NULL;
|
||||||
GError *error = NULL;
|
gs_free_error GError *error = NULL;
|
||||||
|
|
||||||
|
nm_utils_user_data_unpack (user_data, &self, &callback, &callback_user_data);
|
||||||
|
|
||||||
variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
|
variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
|
||||||
if (variant)
|
callback (NM_DEVICE (self), error, callback_user_data);
|
||||||
g_task_return_boolean (task, TRUE);
|
}
|
||||||
else
|
|
||||||
g_task_return_error (task, error);
|
|
||||||
|
|
||||||
g_object_unref (task);
|
static void
|
||||||
|
disconnect_cb_on_idle (gpointer user_data,
|
||||||
|
GCancellable *cancellable)
|
||||||
|
{
|
||||||
|
gs_unref_object NMDeviceIwd *self = NULL;
|
||||||
|
NMDeviceDeactivateCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
|
gs_free_error GError *cancelled_error = NULL;
|
||||||
|
|
||||||
|
nm_utils_user_data_unpack (user_data, &self, &callback, &callback_user_data);
|
||||||
|
|
||||||
|
g_cancellable_set_error_if_cancelled (cancellable, &cancelled_error);
|
||||||
|
callback (NM_DEVICE (self), cancelled_error, callback_user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deactivate_async (NMDevice *device,
|
deactivate_async (NMDevice *device,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
NMDeviceDeactivateCallback callback,
|
||||||
gpointer user_data)
|
gpointer callback_user_data)
|
||||||
{
|
{
|
||||||
NMDeviceIwd *self = NM_DEVICE_IWD (device);
|
NMDeviceIwd *self = NM_DEVICE_IWD (device);
|
||||||
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
|
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
|
||||||
GTask *task;
|
gpointer user_data;
|
||||||
|
|
||||||
task = g_task_new (self, cancellable, callback, user_data);
|
nm_assert (G_IS_CANCELLABLE (cancellable));
|
||||||
|
nm_assert (callback);
|
||||||
|
|
||||||
|
user_data = nm_utils_user_data_pack (g_object_ref (self), callback, callback_user_data);
|
||||||
|
|
||||||
if (!priv->dbus_obj) {
|
if (!priv->dbus_obj) {
|
||||||
g_task_return_boolean (task, TRUE);
|
nm_utils_invoke_on_idle (disconnect_cb_on_idle, user_data, cancellable);
|
||||||
g_object_unref (task);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -517,10 +532,16 @@ deactivate_async (NMDevice *device,
|
||||||
priv->act_mode_switch = FALSE;
|
priv->act_mode_switch = FALSE;
|
||||||
|
|
||||||
if (priv->dbus_station_proxy) {
|
if (priv->dbus_station_proxy) {
|
||||||
g_dbus_proxy_call (priv->dbus_station_proxy, "Disconnect", g_variant_new ("()"),
|
g_dbus_proxy_call (priv->dbus_station_proxy,
|
||||||
G_DBUS_CALL_FLAGS_NONE, -1, cancellable, disconnect_cb, task);
|
"Disconnect",
|
||||||
|
g_variant_new ("()"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
cancellable,
|
||||||
|
disconnect_cb,
|
||||||
|
user_data);
|
||||||
} else
|
} else
|
||||||
reset_mode (self, cancellable, disconnect_cb, task);
|
reset_mode (self, cancellable, disconnect_cb, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -2540,7 +2561,6 @@ nm_device_iwd_class_init (NMDeviceIwdClass *klass)
|
||||||
device_class->get_configured_mtu = get_configured_mtu;
|
device_class->get_configured_mtu = get_configured_mtu;
|
||||||
device_class->deactivate = deactivate;
|
device_class->deactivate = deactivate;
|
||||||
device_class->deactivate_async = deactivate_async;
|
device_class->deactivate_async = deactivate_async;
|
||||||
device_class->deactivate_async_finish = deactivate_async_finish;
|
|
||||||
device_class->can_reapply_change = can_reapply_change;
|
device_class->can_reapply_change = can_reapply_change;
|
||||||
|
|
||||||
device_class->state_changed = device_state_changed;
|
device_class->state_changed = device_state_changed;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ global:
|
||||||
nm_modem_complete_connection;
|
nm_modem_complete_connection;
|
||||||
nm_modem_deactivate;
|
nm_modem_deactivate;
|
||||||
nm_modem_deactivate_async;
|
nm_modem_deactivate_async;
|
||||||
nm_modem_deactivate_async_finish;
|
|
||||||
nm_modem_device_state_changed;
|
nm_modem_device_state_changed;
|
||||||
nm_modem_get_capabilities;
|
nm_modem_get_capabilities;
|
||||||
nm_modem_get_configured_mtu;
|
nm_modem_get_configured_mtu;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ struct _NMDeviceModemClass {
|
||||||
|
|
||||||
G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
|
G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
|
||||||
|
|
||||||
#define NM_DEVICE_MODEM_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceModem, NM_IS_DEVICE_MODEM)
|
#define NM_DEVICE_MODEM_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceModem, NM_IS_DEVICE_MODEM, NMDevice)
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
@ -483,44 +483,35 @@ deactivate (NMDevice *device)
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
|
||||||
deactivate_async_finish (NMDevice *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_deactivate_async_ready (NMModem *modem,
|
modem_deactivate_async_cb (NMModem *modem,
|
||||||
GAsyncResult *res,
|
GError *error,
|
||||||
GSimpleAsyncResult *simple)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
gs_unref_object NMDevice *self = NULL;
|
||||||
|
NMDeviceDeactivateCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
|
|
||||||
if (!nm_modem_deactivate_async_finish (modem, res, &error))
|
nm_utils_user_data_unpack (user_data, &self, &callback, &callback_user_data);
|
||||||
g_simple_async_result_take_error (simple, error);
|
callback (self, error, callback_user_data);
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deactivate_async (NMDevice *self,
|
deactivate_async (NMDevice *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
NMDeviceDeactivateCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
nm_assert (G_IS_CANCELLABLE (cancellable));
|
||||||
|
nm_assert (callback);
|
||||||
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (self),
|
nm_modem_deactivate_async (NM_DEVICE_MODEM_GET_PRIVATE (self)->modem,
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
deactivate_async);
|
|
||||||
nm_modem_deactivate_async (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) self)->modem,
|
|
||||||
self,
|
self,
|
||||||
cancellable,
|
cancellable,
|
||||||
(GAsyncReadyCallback) modem_deactivate_async_ready,
|
modem_deactivate_async_cb,
|
||||||
simple);
|
nm_utils_user_data_pack (g_object_ref (self),
|
||||||
|
callback,
|
||||||
|
user_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
@ -805,7 +796,6 @@ nm_device_modem_class_init (NMDeviceModemClass *klass)
|
||||||
device_class->check_connection_available = check_connection_available;
|
device_class->check_connection_available = check_connection_available;
|
||||||
device_class->complete_connection = complete_connection;
|
device_class->complete_connection = complete_connection;
|
||||||
device_class->deactivate_async = deactivate_async;
|
device_class->deactivate_async = deactivate_async;
|
||||||
device_class->deactivate_async_finish = deactivate_async_finish;
|
|
||||||
device_class->deactivate = deactivate;
|
device_class->deactivate = deactivate;
|
||||||
device_class->act_stage1_prepare = act_stage1_prepare;
|
device_class->act_stage1_prepare = act_stage1_prepare;
|
||||||
device_class->act_stage2_config = act_stage2_config;
|
device_class->act_stage2_config = act_stage2_config;
|
||||||
|
|
|
||||||
|
|
@ -1098,91 +1098,90 @@ stage3_ip6_config_request (NMModem *modem, NMDeviceStateReason *out_failure_reas
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
NMModemBroadband *self;
|
NMModemBroadband *self;
|
||||||
GSimpleAsyncResult *result;
|
_NMModemDisconnectCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
gboolean warn;
|
gboolean warn;
|
||||||
} DisconnectContext;
|
} DisconnectContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_context_complete (DisconnectContext *ctx)
|
disconnect_context_complete (DisconnectContext *ctx, GError *error)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
if (ctx->callback)
|
||||||
if (ctx->cancellable)
|
ctx->callback (NM_MODEM (ctx->self), error, ctx->callback_user_data);
|
||||||
g_object_unref (ctx->cancellable);
|
nm_g_object_unref (ctx->cancellable);
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->self);
|
g_object_unref (ctx->self);
|
||||||
g_slice_free (DisconnectContext, ctx);
|
g_slice_free (DisconnectContext, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
disconnect_finish (NMModem *self,
|
disconnect_context_complete_on_idle (gpointer user_data,
|
||||||
GAsyncResult *res,
|
GCancellable *cancellable)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
DisconnectContext *ctx = NULL;
|
||||||
|
gs_free_error GError *cancelled_error = NULL;
|
||||||
|
|
||||||
|
g_cancellable_set_error_if_cancelled (cancellable, &cancelled_error);
|
||||||
|
disconnect_context_complete (ctx, cancelled_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
simple_disconnect_ready (MMModemSimple *modem_iface,
|
simple_disconnect_ready (GObject *source_object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DisconnectContext *ctx)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
MMModemSimple *modem_iface = MM_MODEM_SIMPLE (source_object);
|
||||||
|
DisconnectContext *ctx = user_data;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!mm_modem_simple_disconnect_finish (modem_iface, res, &error)) {
|
if (!mm_modem_simple_disconnect_finish (modem_iface, res, &error)) {
|
||||||
if (ctx->warn && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) {
|
if ( ctx->warn
|
||||||
|
&& !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) {
|
||||||
NMModemBroadband *self = ctx->self;
|
NMModemBroadband *self = ctx->self;
|
||||||
|
|
||||||
_LOGW ("failed to disconnect modem: %s",
|
_LOGW ("failed to disconnect modem: %s",
|
||||||
error->message);
|
error->message);
|
||||||
}
|
}
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect_context_complete (ctx);
|
disconnect_context_complete (ctx, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect (NMModem *modem,
|
disconnect (NMModem *modem,
|
||||||
gboolean warn,
|
gboolean warn,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
_NMModemDisconnectCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMModemBroadband *self = NM_MODEM_BROADBAND (modem);
|
NMModemBroadband *self = NM_MODEM_BROADBAND (modem);
|
||||||
DisconnectContext *ctx;
|
DisconnectContext *ctx;
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
connect_context_clear (self);
|
connect_context_clear (self);
|
||||||
ctx = g_slice_new (DisconnectContext);
|
|
||||||
ctx->cancellable = NULL;
|
ctx = g_slice_new0 (DisconnectContext);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
ctx->cancellable = nm_g_object_ref (cancellable);
|
||||||
callback,
|
ctx->callback = callback;
|
||||||
user_data,
|
ctx->callback_user_data = user_data;
|
||||||
disconnect);
|
|
||||||
/* Don't bother warning on FAILED since the modem is already gone */
|
/* Don't bother warning on FAILED since the modem is already gone */
|
||||||
ctx->warn = warn;
|
ctx->warn = warn;
|
||||||
|
|
||||||
/* Already cancelled? */
|
/* Already cancelled or no simple-iface? We are done. */
|
||||||
if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
|
if ( !ctx->self->_priv.simple_iface
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|| g_cancellable_is_cancelled (cancellable)) {
|
||||||
disconnect_context_complete (ctx);
|
nm_utils_invoke_on_idle (disconnect_context_complete_on_idle,
|
||||||
return;
|
ctx,
|
||||||
}
|
cancellable);
|
||||||
|
|
||||||
/* If no simple iface, we're done */
|
|
||||||
if (!ctx->self->_priv.simple_iface) {
|
|
||||||
disconnect_context_complete (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGD ("notifying ModemManager about the modem disconnection");
|
_LOGD ("notifying ModemManager about the modem disconnection");
|
||||||
ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
mm_modem_simple_disconnect (self->_priv.simple_iface,
|
||||||
mm_modem_simple_disconnect (ctx->self->_priv.simple_iface,
|
|
||||||
NULL, /* bearer path; if NULL given ALL get disconnected */
|
NULL, /* bearer path; if NULL given ALL get disconnected */
|
||||||
cancellable,
|
cancellable,
|
||||||
(GAsyncReadyCallback) simple_disconnect_ready,
|
simple_disconnect_ready,
|
||||||
ctx);
|
ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1468,7 +1467,6 @@ nm_modem_broadband_class_init (NMModemBroadbandClass *klass)
|
||||||
modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start;
|
modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start;
|
||||||
modem_class->stage3_ip6_config_request = stage3_ip6_config_request;
|
modem_class->stage3_ip6_config_request = stage3_ip6_config_request;
|
||||||
modem_class->disconnect = disconnect;
|
modem_class->disconnect = disconnect;
|
||||||
modem_class->disconnect_finish = disconnect_finish;
|
|
||||||
modem_class->deactivate_cleanup = deactivate_cleanup;
|
modem_class->deactivate_cleanup = deactivate_cleanup;
|
||||||
modem_class->set_mm_enabled = set_mm_enabled;
|
modem_class->set_mm_enabled = set_mm_enabled;
|
||||||
modem_class->get_user_pass = get_user_pass;
|
modem_class->get_user_pass = get_user_pass;
|
||||||
|
|
|
||||||
|
|
@ -146,30 +146,36 @@ update_modem_state (NMModemOfono *self)
|
||||||
/* Disconnect */
|
/* Disconnect */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
NMModemOfono *self;
|
NMModemOfono *self;
|
||||||
GSimpleAsyncResult *result;
|
_NMModemDisconnectCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
gboolean warn;
|
gboolean warn;
|
||||||
} DisconnectContext;
|
} DisconnectContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_context_complete (DisconnectContext *ctx)
|
disconnect_context_complete (DisconnectContext *ctx, GError *error)
|
||||||
{
|
{
|
||||||
if (ctx->cancellable)
|
if (ctx->callback)
|
||||||
g_object_unref (ctx->cancellable);
|
ctx->callback (NM_MODEM (ctx->self), error, ctx->callback_user_data);
|
||||||
if (ctx->result) {
|
nm_g_object_unref (ctx->cancellable);
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
}
|
|
||||||
g_object_unref (ctx->self);
|
g_object_unref (ctx->self);
|
||||||
g_slice_free (DisconnectContext, ctx);
|
g_slice_free (DisconnectContext, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
disconnect_finish (NMModem *self,
|
disconnect_context_complete_on_idle (gpointer user_data,
|
||||||
GAsyncResult *result,
|
GCancellable *cancellable)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
|
DisconnectContext *ctx = NULL;
|
||||||
|
gs_free_error GError *error = NULL;
|
||||||
|
|
||||||
|
if (!g_cancellable_set_error_if_cancelled (cancellable, &error)) {
|
||||||
|
g_set_error_literal (&error,
|
||||||
|
NM_UTILS_ERROR,
|
||||||
|
NM_UTILS_ERROR_UNKNOWN,
|
||||||
|
("modem is currently not connected"));
|
||||||
|
}
|
||||||
|
disconnect_context_complete (ctx, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -177,16 +183,14 @@ disconnect_done (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
DisconnectContext *ctx = (DisconnectContext*) user_data;
|
DisconnectContext *ctx = user_data;
|
||||||
NMModemOfono *self = ctx->self;
|
NMModemOfono *self = ctx->self;
|
||||||
gs_free_error GError *error = NULL;
|
gs_free_error GError *error = NULL;
|
||||||
gs_unref_variant GVariant *v = NULL;
|
gs_unref_variant GVariant *v = NULL;
|
||||||
|
|
||||||
v = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
v = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
if (ctx->result)
|
disconnect_context_complete (ctx, error);
|
||||||
g_simple_async_result_take_error (ctx->result, g_steal_pointer (&error));
|
|
||||||
disconnect_context_complete (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,21 +200,21 @@ disconnect_done (GObject *source,
|
||||||
_LOGD ("modem disconnected");
|
_LOGD ("modem disconnected");
|
||||||
|
|
||||||
update_modem_state (self);
|
update_modem_state (self);
|
||||||
disconnect_context_complete (ctx);
|
disconnect_context_complete (ctx, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect (NMModem *modem,
|
disconnect (NMModem *modem,
|
||||||
gboolean warn,
|
gboolean warn,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
_NMModemDisconnectCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMModemOfono *self = NM_MODEM_OFONO (modem);
|
NMModemOfono *self = NM_MODEM_OFONO (modem);
|
||||||
NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self);
|
NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self);
|
||||||
DisconnectContext *ctx;
|
DisconnectContext *ctx;
|
||||||
NMModemState state = nm_modem_get_state (NM_MODEM (self));
|
NMModemState state = nm_modem_get_state (NM_MODEM (self));
|
||||||
GError *error = NULL;
|
gs_free_error GError *error = NULL;
|
||||||
|
|
||||||
_LOGD ("warn: %s modem_state: %s",
|
_LOGD ("warn: %s modem_state: %s",
|
||||||
warn ? "TRUE" : "FALSE",
|
warn ? "TRUE" : "FALSE",
|
||||||
|
|
@ -218,36 +222,18 @@ disconnect (NMModem *modem,
|
||||||
|
|
||||||
ctx = g_slice_new0 (DisconnectContext);
|
ctx = g_slice_new0 (DisconnectContext);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->warn = warn;
|
|
||||||
if (callback) {
|
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
disconnect);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state != NM_MODEM_STATE_CONNECTED) {
|
|
||||||
if (ctx->result) {
|
|
||||||
g_set_error_literal (&error,
|
|
||||||
NM_UTILS_ERROR,
|
|
||||||
NM_UTILS_ERROR_UNKNOWN,
|
|
||||||
("modem is currently not connected"));
|
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|
||||||
}
|
|
||||||
disconnect_context_complete (ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
|
|
||||||
if (ctx->result)
|
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
|
||||||
else
|
|
||||||
g_clear_error (&error);
|
|
||||||
disconnect_context_complete (ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->cancellable = nm_g_object_ref (cancellable);
|
ctx->cancellable = nm_g_object_ref (cancellable);
|
||||||
|
ctx->warn = warn;
|
||||||
|
ctx->callback = callback;
|
||||||
|
ctx->callback_user_data = user_data;
|
||||||
|
|
||||||
|
if ( state != NM_MODEM_STATE_CONNECTED
|
||||||
|
|| g_cancellable_is_cancelled (cancellable)) {
|
||||||
|
nm_utils_invoke_on_idle (disconnect_context_complete_on_idle,
|
||||||
|
ctx,
|
||||||
|
cancellable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nm_modem_set_state (NM_MODEM (self),
|
nm_modem_set_state (NM_MODEM (self),
|
||||||
NM_MODEM_STATE_DISCONNECTING,
|
NM_MODEM_STATE_DISCONNECTING,
|
||||||
|
|
@ -1319,7 +1305,6 @@ nm_modem_ofono_class_init (NMModemOfonoClass *klass)
|
||||||
|
|
||||||
modem_class->get_capabilities = get_capabilities;
|
modem_class->get_capabilities = get_capabilities;
|
||||||
modem_class->disconnect = disconnect;
|
modem_class->disconnect = disconnect;
|
||||||
modem_class->disconnect_finish = disconnect_finish;
|
|
||||||
modem_class->deactivate_cleanup = deactivate_cleanup;
|
modem_class->deactivate_cleanup = deactivate_cleanup;
|
||||||
modem_class->check_connection_compatible_with_modem = check_connection_compatible_with_modem;
|
modem_class->check_connection_compatible_with_modem = check_connection_compatible_with_modem;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1169,7 +1169,8 @@ typedef struct {
|
||||||
NMModem *self;
|
NMModem *self;
|
||||||
NMDevice *device;
|
NMDevice *device;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
GSimpleAsyncResult *result;
|
NMModemDeactivateCallback callback;
|
||||||
|
gpointer callback_user_data;
|
||||||
DeactivateContextStep step;
|
DeactivateContextStep step;
|
||||||
NMPPPManager *ppp_manager;
|
NMPPPManager *ppp_manager;
|
||||||
NMPPPManagerStopHandle *ppp_stop_handle;
|
NMPPPManagerStopHandle *ppp_stop_handle;
|
||||||
|
|
@ -1177,7 +1178,7 @@ typedef struct {
|
||||||
} DeactivateContext;
|
} DeactivateContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deactivate_context_complete (DeactivateContext *ctx)
|
deactivate_context_complete (DeactivateContext *ctx, GError *error)
|
||||||
{
|
{
|
||||||
if (ctx->ppp_stop_handle)
|
if (ctx->ppp_stop_handle)
|
||||||
nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle);
|
nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle);
|
||||||
|
|
@ -1185,41 +1186,29 @@ deactivate_context_complete (DeactivateContext *ctx)
|
||||||
nm_assert (!ctx->ppp_stop_handle);
|
nm_assert (!ctx->ppp_stop_handle);
|
||||||
nm_assert (ctx->ppp_stop_cancellable_id == 0);
|
nm_assert (ctx->ppp_stop_cancellable_id == 0);
|
||||||
|
|
||||||
if (ctx->ppp_manager)
|
if (ctx->callback)
|
||||||
g_object_unref (ctx->ppp_manager);
|
ctx->callback (ctx->self, error, ctx->callback_user_data);
|
||||||
if (ctx->cancellable)
|
nm_g_object_unref (ctx->ppp_manager);
|
||||||
g_object_unref (ctx->cancellable);
|
nm_g_object_unref (ctx->cancellable);
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->device);
|
g_object_unref (ctx->device);
|
||||||
g_object_unref (ctx->self);
|
g_object_unref (ctx->self);
|
||||||
g_slice_free (DeactivateContext, ctx);
|
g_slice_free (DeactivateContext, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_modem_deactivate_async_finish (NMModem *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deactivate_step (DeactivateContext *ctx);
|
static void deactivate_step (DeactivateContext *ctx);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_ready (NMModem *self,
|
disconnect_ready (NMModem *self,
|
||||||
GAsyncResult *res,
|
GError *error,
|
||||||
DeactivateContext *ctx)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
DeactivateContext *ctx = user_data;
|
||||||
|
|
||||||
if (!NM_MODEM_GET_CLASS (self)->disconnect_finish (self, res, &error)) {
|
if (error) {
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
deactivate_context_complete (ctx, error);
|
||||||
deactivate_context_complete (ctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go on */
|
|
||||||
ctx->step++;
|
ctx->step++;
|
||||||
deactivate_step (ctx);
|
deactivate_step (ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -1265,8 +1254,8 @@ deactivate_step (DeactivateContext *ctx)
|
||||||
|
|
||||||
/* Check cancellable in each step */
|
/* Check cancellable in each step */
|
||||||
if (g_cancellable_set_error_if_cancelled (ctx->cancellable, &error)) {
|
if (g_cancellable_set_error_if_cancelled (ctx->cancellable, &error)) {
|
||||||
g_simple_async_result_take_error (ctx->result, error);
|
deactivate_context_complete (ctx, error);
|
||||||
deactivate_context_complete (ctx);
|
g_error_free (error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1304,13 +1293,13 @@ deactivate_step (DeactivateContext *ctx)
|
||||||
NM_MODEM_GET_CLASS (self)->disconnect (self,
|
NM_MODEM_GET_CLASS (self)->disconnect (self,
|
||||||
FALSE,
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback) disconnect_ready,
|
disconnect_ready,
|
||||||
ctx);
|
ctx);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case DEACTIVATE_CONTEXT_STEP_LAST:
|
case DEACTIVATE_CONTEXT_STEP_LAST:
|
||||||
_LOGD ("modem deactivation finished");
|
_LOGD ("modem deactivation finished");
|
||||||
deactivate_context_complete (ctx);
|
deactivate_context_complete (ctx, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1321,25 +1310,27 @@ void
|
||||||
nm_modem_deactivate_async (NMModem *self,
|
nm_modem_deactivate_async (NMModem *self,
|
||||||
NMDevice *device,
|
NMDevice *device,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
NMModemDeactivateCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
DeactivateContext *ctx;
|
DeactivateContext *ctx;
|
||||||
|
|
||||||
|
g_return_if_fail (NM_IS_MODEM (self));
|
||||||
|
g_return_if_fail (NM_IS_DEVICE (device));
|
||||||
|
g_return_if_fail (G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
ctx = g_slice_new0 (DeactivateContext);
|
ctx = g_slice_new0 (DeactivateContext);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->device = g_object_ref (device);
|
ctx->device = g_object_ref (device);
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
ctx->cancellable = g_object_ref (cancellable);
|
||||||
callback,
|
ctx->callback = callback;
|
||||||
user_data,
|
ctx->callback_user_data = user_data;
|
||||||
nm_modem_deactivate_async);
|
|
||||||
/* FIXME(shutdown): we always require a cancellable, otherwise we cannot
|
|
||||||
* do a coordinated shutdown. */
|
|
||||||
ctx->cancellable = nm_g_object_ref (cancellable);
|
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
ctx->step = DEACTIVATE_CONTEXT_STEP_FIRST;
|
ctx->step = DEACTIVATE_CONTEXT_STEP_FIRST;
|
||||||
deactivate_step (ctx);
|
deactivate_step (ctx);
|
||||||
|
|
||||||
|
/* FIXME: never invoke the callback syncronously. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,10 @@ struct _NMModem {
|
||||||
|
|
||||||
typedef struct _NMModem NMModem;
|
typedef struct _NMModem NMModem;
|
||||||
|
|
||||||
|
typedef void (*_NMModemDisconnectCallback) (NMModem *modem,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GObjectClass parent;
|
GObjectClass parent;
|
||||||
|
|
||||||
|
|
@ -149,11 +153,8 @@ typedef struct {
|
||||||
void (*disconnect) (NMModem *self,
|
void (*disconnect) (NMModem *self,
|
||||||
gboolean warn,
|
gboolean warn,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
_NMModemDisconnectCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean (*disconnect_finish) (NMModem *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void (*deactivate_cleanup) (NMModem *self, NMDevice *device);
|
void (*deactivate_cleanup) (NMModem *self, NMDevice *device);
|
||||||
|
|
||||||
|
|
@ -236,14 +237,15 @@ void nm_modem_get_secrets (NMModem *modem,
|
||||||
|
|
||||||
void nm_modem_deactivate (NMModem *modem, NMDevice *device);
|
void nm_modem_deactivate (NMModem *modem, NMDevice *device);
|
||||||
|
|
||||||
|
typedef void (*NMModemDeactivateCallback) (NMModem *self,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
void nm_modem_deactivate_async (NMModem *self,
|
void nm_modem_deactivate_async (NMModem *self,
|
||||||
NMDevice *device,
|
NMDevice *device,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
NMModemDeactivateCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean nm_modem_deactivate_async_finish (NMModem *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
void nm_modem_device_state_changed (NMModem *modem,
|
void nm_modem_device_state_changed (NMModem *modem,
|
||||||
NMDeviceState new_state,
|
NMDeviceState new_state,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue