diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-12-22 20:41:11 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:36 +0100 |
commit | c9c94211025dd65bfec43d43019ee9366d0ec721 (patch) | |
tree | 7610e41744dbbf22ad89925603ba95756961d44a | |
parent | 937baa1a0a39aa21008224cd9c9f67b8b7f21653 (diff) |
iface-modem: allow setting allowed modes and bands internally, not just via DBus
-rw-r--r-- | src/mm-iface-modem.c | 200 | ||||
-rw-r--r-- | src/mm-iface-modem.h | 22 |
2 files changed, 170 insertions, 52 deletions
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 2f29313a..5782c338 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -17,6 +17,7 @@ #include <ModemManager.h> #include <libmm-common.h> +#include "mm-modem-helpers.h" #include "mm-iface-modem.h" #include "mm-base-modem.h" #include "mm-sim.h" @@ -563,18 +564,70 @@ handle_factory_reset (MmGdbusModem *skeleton, /*****************************************************************************/ +gboolean +mm_iface_modem_set_allowed_bands_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} + static void set_allowed_bands_ready (MMIfaceModem *self, GAsyncResult *res, - DbusCallContext *ctx) + GSimpleAsyncResult *simple) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish (self, res, &error)) + g_simple_async_result_take_error (simple, error); + else + g_simple_async_result_set_op_res_gboolean (simple, TRUE); + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +void +mm_iface_modem_set_allowed_bands (MMIfaceModem *self, + MMModemBand bands, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + + /* If setting allowed bands is not implemented, report an error */ + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands || + !MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish) { + g_simple_async_report_error_in_idle (G_OBJECT (self), + callback, + user_data, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Setting allowed bands not supported"); + return; + } + + result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_set_allowed_bands); + MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands (self, + bands, + (GAsyncReadyCallback)set_allowed_bands_ready, + result); +} + +static void +handle_set_allowed_bands_ready (MMIfaceModem *self, + GAsyncResult *res, + DbusCallContext *ctx) { GError *error = NULL; if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish (self, res, &error)) - g_dbus_method_invocation_take_error (ctx->invocation, - error); + g_dbus_method_invocation_take_error (ctx->invocation, error); else mm_gdbus_modem_complete_set_allowed_bands (ctx->skeleton, ctx->invocation); @@ -584,22 +637,11 @@ set_allowed_bands_ready (MMIfaceModem *self, static gboolean handle_set_allowed_bands (MmGdbusModem *skeleton, GDBusMethodInvocation *invocation, - guint64 arg_bands, + guint64 bands, MMIfaceModem *self) { - MMModemState modem_state; + MMModemState modem_state = MM_MODEM_STATE_UNKNOWN; - /* If setting allowed bands is not implemented, report an error */ - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands || - !MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands_finish) { - g_dbus_method_invocation_return_error (invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Setting allowed bands not supported"); - return TRUE; - } - - modem_state = MM_MODEM_STATE_UNKNOWN; g_object_get (self, MM_IFACE_MODEM_STATE, &modem_state, NULL); @@ -610,7 +652,7 @@ handle_set_allowed_bands (MmGdbusModem *skeleton, g_dbus_method_invocation_return_error (invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, - "Cannot reset the modem to factory defaults: " + "Cannot set allowed bands: " "not initialized/unlocked yet"); break; @@ -623,12 +665,12 @@ handle_set_allowed_bands (MmGdbusModem *skeleton, case MM_MODEM_STATE_DISCONNECTING: case MM_MODEM_STATE_CONNECTING: case MM_MODEM_STATE_CONNECTED: - MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_bands (self, - arg_bands, - (GAsyncReadyCallback)set_allowed_bands_ready, - dbus_call_context_new (skeleton, - invocation, - self)); + mm_iface_modem_set_allowed_bands (self, + bands, + (GAsyncReadyCallback)handle_set_allowed_bands_ready, + dbus_call_context_new (skeleton, + invocation, + self)); break; } @@ -636,19 +678,72 @@ handle_set_allowed_bands (MmGdbusModem *skeleton, } /*****************************************************************************/ +/* ALLOWED MODES */ + +gboolean +mm_iface_modem_set_allowed_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); +} static void set_allowed_modes_ready (MMIfaceModem *self, GAsyncResult *res, - DbusCallContext *ctx) + GSimpleAsyncResult *simple) { GError *error = NULL; - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish (self, - res, - &error)) - g_dbus_method_invocation_take_error (ctx->invocation, - error); + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish (self, res, &error)) + g_simple_async_result_take_error (simple, error); + else + g_simple_async_result_set_op_res_gboolean (simple, TRUE); + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +void +mm_iface_modem_set_allowed_modes (MMIfaceModem *self, + MMModemMode allowed, + MMModemMode preferred, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + + /* If setting allowed modes is not implemented, report an error */ + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes || + !MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish) { + g_simple_async_report_error_in_idle (G_OBJECT (self), + callback, + user_data, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Setting allowed modes not supported"); + return; + } + + result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_set_allowed_modes); + MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes (self, + allowed, + preferred, + (GAsyncReadyCallback)set_allowed_modes_ready, + result); +} + +static void +handle_set_allowed_modes_ready (MMIfaceModem *self, + GAsyncResult *res, + DbusCallContext *ctx) +{ + GError *error = NULL; + + if (mm_iface_modem_set_allowed_modes_finish (self, res, &error)) + g_dbus_method_invocation_take_error (ctx->invocation, error); else mm_gdbus_modem_complete_set_allowed_modes (ctx->skeleton, ctx->invocation); @@ -658,24 +753,12 @@ set_allowed_modes_ready (MMIfaceModem *self, static gboolean handle_set_allowed_modes (MmGdbusModem *skeleton, GDBusMethodInvocation *invocation, - guint arg_modes, - guint arg_preferred, + guint modes, + guint preferred, MMIfaceModem *self) { - MMModemState modem_state; + MMModemState modem_state = MM_MODEM_STATE_UNKNOWN; - /* If setting allowed modes is not implemented, report an error */ - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes || - !MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes_finish) { - g_dbus_method_invocation_return_error (invocation, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Setting allowed modes not supported"); - return TRUE; - - } - - modem_state = MM_MODEM_STATE_UNKNOWN; g_object_get (self, MM_IFACE_MODEM_STATE, &modem_state, NULL); @@ -686,7 +769,7 @@ handle_set_allowed_modes (MmGdbusModem *skeleton, g_dbus_method_invocation_return_error (invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, - "Cannot reset the modem to factory defaults: " + "Cannot set allowed modes: " "not initialized/unlocked yet"); break; @@ -699,13 +782,13 @@ handle_set_allowed_modes (MmGdbusModem *skeleton, case MM_MODEM_STATE_DISCONNECTING: case MM_MODEM_STATE_CONNECTING: case MM_MODEM_STATE_CONNECTED: - MM_IFACE_MODEM_GET_INTERFACE (self)->set_allowed_modes (self, - arg_modes, - arg_preferred, - (GAsyncReadyCallback)set_allowed_modes_ready, - dbus_call_context_new (skeleton, - invocation, - self)); + mm_iface_modem_set_allowed_modes (self, + modes, + preferred, + (GAsyncReadyCallback)handle_set_allowed_modes_ready, + dbus_call_context_new (skeleton, + invocation, + self)); break; } @@ -2187,6 +2270,19 @@ mm_iface_modem_shutdown (MMIfaceModem *self) NULL); } +/*****************************************************************************/ + +gboolean +mm_iface_modem_is_3gpp (MMIfaceModem *self) +{ + MMModemCapability capabilities = MM_MODEM_CAPABILITY_NONE; + + g_object_get (self, + MM_IFACE_MODEM_CURRENT_CAPABILITIES, &capabilities, + NULL); + + return (capabilities & MM_MODEM_CAPABILITY_3GPP); +} /*****************************************************************************/ diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 30278adf..5195497e 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -242,6 +242,9 @@ struct _MMIfaceModem { GType mm_iface_modem_get_type (void); +/* Check whether this modem has 3GPP capabilities */ +gboolean mm_iface_modem_is_3gpp (MMIfaceModem *self); + /* Initialize Modem interface (async) */ void mm_iface_modem_initialize (MMIfaceModem *self, MMAtSerialPort *port, @@ -301,4 +304,23 @@ void mm_iface_modem_update_access_tech (MMIfaceModem *self, MMModemAccessTechnology access_tech, guint32 mask); +/* Allow setting allowed modes */ +void mm_iface_modem_set_allowed_modes (MMIfaceModem *self, + MMModemMode allowed, + MMModemMode preferred, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_iface_modem_set_allowed_modes_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error); + +/* Allow setting allowed bands */ +void mm_iface_modem_set_allowed_bands (MMIfaceModem *self, + MMModemBand bands, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_iface_modem_set_allowed_bands_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error); + #endif /* MM_IFACE_MODEM_H */ |