diff options
Diffstat (limited to 'src/mm-iface-modem.c')
-rw-r--r-- | src/mm-iface-modem.c | 179 |
1 files changed, 118 insertions, 61 deletions
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index bb6c71d0..5e98261e 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2267,6 +2267,7 @@ mm_iface_modem_update_subsystem_state (MMIfaceModem *self, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; gboolean enable; } HandleEnableContext; @@ -2274,6 +2275,9 @@ typedef struct { static void handle_enable_context_free (HandleEnableContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); g_object_unref (ctx->self); @@ -2309,13 +2313,14 @@ enable_ready (MMBaseModem *self, } static void -handle_enable_auth_ready (MMBaseModem *self, - GAsyncResult *res, +handle_enable_auth_ready (MMBaseModem *self, + GAsyncResult *res, HandleEnableContext *ctx) { GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_enable_context_free (ctx); return; @@ -2329,13 +2334,13 @@ handle_enable_auth_ready (MMBaseModem *self, if (ctx->enable) { mm_obj_info (self, "processing user request to enable modem..."); mm_base_modem_enable (self, - MM_BASE_MODEM_OPERATION_LOCK_REQUIRED, + MM_BASE_MODEM_OPERATION_LOCK_ALREADY_ACQUIRED, (GAsyncReadyCallback)enable_ready, ctx); } else { mm_obj_info (self, "processing user request to disable modem..."); mm_base_modem_disable (self, - MM_BASE_MODEM_OPERATION_LOCK_REQUIRED, + MM_BASE_MODEM_OPERATION_LOCK_ALREADY_ACQUIRED, (GAsyncReadyCallback)enable_ready, ctx); } @@ -2354,12 +2359,15 @@ handle_enable (MmGdbusModem *skeleton, ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); ctx->enable = enable; - - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_enable_auth_ready, - ctx); + ctx->operation_id = -1; + + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + enable ? "enable" : "disable", + (GAsyncReadyCallback)handle_enable_auth_ready, + ctx); return TRUE; } @@ -2368,6 +2376,7 @@ handle_enable (MmGdbusModem *skeleton, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; MMModemPowerState power_state; gboolean disable_after_update; @@ -2377,6 +2386,9 @@ typedef struct { static void handle_set_power_state_context_free (HandleSetPowerStateContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_assert (!ctx->saved_error); g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); @@ -2411,7 +2423,7 @@ disable_after_low (MMIfaceModem *self, { mm_obj_info (self, "automatically disable modem after low-power mode..."); mm_base_modem_disable (MM_BASE_MODEM (self), - MM_BASE_MODEM_OPERATION_LOCK_REQUIRED, + MM_BASE_MODEM_OPERATION_LOCK_ALREADY_ACQUIRED, (GAsyncReadyCallback)disable_after_low_ready, ctx); } @@ -2452,23 +2464,13 @@ handle_set_power_state_auth_ready (MMBaseModem *self, MMModemState modem_state; GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_set_power_state_context_free (ctx); return; } - /* Only 'off', 'low' or 'up' expected */ - if (ctx->power_state != MM_MODEM_POWER_STATE_LOW && - ctx->power_state != MM_MODEM_POWER_STATE_ON && - ctx->power_state != MM_MODEM_POWER_STATE_OFF) { - mm_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, - "Unknown power state: '%s'", - mm_modem_power_state_get_string (ctx->power_state)); - handle_set_power_state_context_free (ctx); - return; - } - modem_state = MM_MODEM_STATE_UNKNOWN; g_object_get (self, MM_IFACE_MODEM_STATE, &modem_state, @@ -2517,18 +2519,33 @@ handle_set_power_state (MmGdbusModem *skeleton, MMIfaceModem *self) { HandleSetPowerStateContext *ctx; + g_autofree gchar *operation_name = NULL; ctx = g_slice_new0 (HandleSetPowerStateContext); ctx->skeleton = g_object_ref (skeleton); ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); ctx->power_state = (MMModemPowerState)power_state; + ctx->operation_id = -1; - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_set_power_state_auth_ready, - ctx); + /* Only 'off', 'low' or 'up' expected */ + if (ctx->power_state != MM_MODEM_POWER_STATE_LOW && + ctx->power_state != MM_MODEM_POWER_STATE_ON && + ctx->power_state != MM_MODEM_POWER_STATE_OFF) { + mm_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Unknown power state: %u", ctx->power_state); + handle_set_power_state_context_free (ctx); + return TRUE; + } + + operation_name = g_strdup_printf ("set-power-state-%s", mm_modem_power_state_get_string (ctx->power_state)); + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + operation_name, + (GAsyncReadyCallback)handle_set_power_state_auth_ready, + ctx); return TRUE; } @@ -2537,12 +2554,16 @@ handle_set_power_state (MmGdbusModem *skeleton, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; } HandleResetContext; static void handle_reset_context_free (HandleResetContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); g_object_unref (ctx->self); @@ -2574,7 +2595,8 @@ handle_reset_auth_ready (MMBaseModem *self, { GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_reset_context_free (ctx); return; @@ -2605,12 +2627,15 @@ handle_reset (MmGdbusModem *skeleton, ctx->skeleton = g_object_ref (skeleton); ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); + ctx->operation_id = -1; - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_reset_auth_ready, - ctx); + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + "reset", + (GAsyncReadyCallback)handle_reset_auth_ready, + ctx); return TRUE; } @@ -2620,6 +2645,7 @@ handle_reset (MmGdbusModem *skeleton, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; gchar *code; } HandleFactoryResetContext; @@ -2627,6 +2653,9 @@ typedef struct { static void handle_factory_reset_context_free (HandleFactoryResetContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); g_object_unref (ctx->self); @@ -2659,7 +2688,8 @@ handle_factory_reset_auth_ready (MMBaseModem *self, { GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_factory_reset_context_free (ctx); return; @@ -2693,12 +2723,15 @@ handle_factory_reset (MmGdbusModem *skeleton, ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); ctx->code = g_strdup (code); + ctx->operation_id = -1; - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_factory_reset_auth_ready, - ctx); + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + "factory-reset", + (GAsyncReadyCallback)handle_factory_reset_auth_ready, + ctx); return TRUE; } @@ -2714,6 +2747,7 @@ handle_factory_reset (MmGdbusModem *skeleton, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; MMModemCapability capabilities; gchar *capabilities_str; @@ -2722,6 +2756,9 @@ typedef struct { static void handle_set_current_capabilities_context_free (HandleSetCurrentCapabilitiesContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_free (ctx->capabilities_str); g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); @@ -2759,7 +2796,8 @@ handle_set_current_capabilities_auth_ready (MMBaseModem gboolean matched = FALSE; guint i; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_set_current_capabilities_context_free (ctx); return; @@ -2830,12 +2868,15 @@ handle_set_current_capabilities (MmGdbusModem *skeleton, ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); ctx->capabilities = capabilities; - - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_set_current_capabilities_auth_ready, - ctx); + ctx->operation_id = -1; + + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + "set-current-capabilities", + (GAsyncReadyCallback)handle_set_current_capabilities_auth_ready, + ctx); return TRUE; } @@ -3196,6 +3237,7 @@ mm_iface_modem_set_current_bands (MMIfaceModem *self, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; GVariant *bands; gchar *bands_str; @@ -3204,6 +3246,9 @@ typedef struct { static void handle_set_current_bands_context_free (HandleSetCurrentBandsContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_free (ctx->bands_str); g_variant_unref (ctx->bands); g_object_unref (ctx->skeleton); @@ -3240,7 +3285,8 @@ handle_set_current_bands_auth_ready (MMBaseModem *self, g_autoptr(GArray) bands_array = NULL; GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_set_current_bands_context_free (ctx); return; @@ -3274,12 +3320,15 @@ handle_set_current_bands (MmGdbusModem *skeleton, ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); ctx->bands = g_variant_ref (bands_variant); - - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_set_current_bands_auth_ready, - ctx); + ctx->operation_id = -1; + + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + "set-current-bands", + (GAsyncReadyCallback)handle_set_current_bands_auth_ready, + ctx); return TRUE; } @@ -3591,6 +3640,7 @@ mm_iface_modem_set_current_modes (MMIfaceModem *self, typedef struct { MmGdbusModem *skeleton; GDBusMethodInvocation *invocation; + gssize operation_id; MMIfaceModem *self; MMModemMode allowed; MMModemMode preferred; @@ -3601,6 +3651,9 @@ typedef struct { static void handle_set_current_modes_context_free (HandleSetCurrentModesContext *ctx) { + if (ctx->operation_id >= 0) + mm_base_modem_operation_unlock (MM_BASE_MODEM (ctx->self), ctx->operation_id); + g_free (ctx->preferred_str); g_free (ctx->allowed_str); g_object_unref (ctx->skeleton); @@ -3638,7 +3691,8 @@ handle_set_current_modes_auth_ready (MMBaseModem *self, { GError *error = NULL; - if (!mm_base_modem_authorize_finish (self, res, &error)) { + ctx->operation_id = mm_base_modem_authorize_and_operation_lock_finish (self, res, &error); + if (ctx->operation_id < 0) { mm_dbus_method_invocation_take_error (ctx->invocation, error); handle_set_current_modes_context_free (ctx); return; @@ -3672,17 +3726,20 @@ handle_set_current_modes (MmGdbusModem *skeleton, ctx->skeleton = g_object_ref (skeleton); ctx->invocation = g_object_ref (invocation); ctx->self = g_object_ref (self); + ctx->operation_id = -1; g_variant_get (variant, "(uu)", &ctx->allowed, &ctx->preferred); - mm_base_modem_authorize (MM_BASE_MODEM (self), - invocation, - MM_AUTHORIZATION_DEVICE_CONTROL, - (GAsyncReadyCallback)handle_set_current_modes_auth_ready, - ctx); + mm_base_modem_authorize_and_operation_lock (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + MM_BASE_MODEM_OPERATION_PRIORITY_DEFAULT, + "set-current-modes", + (GAsyncReadyCallback)handle_set_current_modes_auth_ready, + ctx); return TRUE; } |