diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-08 21:35:23 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-23 19:10:57 +0200 |
commit | 5dc1ba289ea0915da8608d8371128b182bb7f760 (patch) | |
tree | a95d29926fb73046f1a7cd3f65a0d2594aa7afec | |
parent | 3cd1b7c468d844f3142ee683663866f9096143cf (diff) |
iface-modem-cdma: allow implementations to fully override registration checks
Implementations of the CDMA interface can either:
* Implement run_registration_checks()
or,
* Implement the sub-steps of the generic registration checks sequence
-rw-r--r-- | src/mm-iface-modem-cdma.c | 110 | ||||
-rw-r--r-- | src/mm-iface-modem-cdma.h | 52 |
2 files changed, 117 insertions, 45 deletions
diff --git a/src/mm-iface-modem-cdma.c b/src/mm-iface-modem-cdma.c index da12bec9..2a6e1be5 100644 --- a/src/mm-iface-modem-cdma.c +++ b/src/mm-iface-modem-cdma.c @@ -406,8 +406,8 @@ mm_iface_modem_cdma_register_in_network (MMIfaceModemCdma *self, /*****************************************************************************/ -typedef struct _RunAllRegistrationChecksContext RunAllRegistrationChecksContext; -static void registration_check_step (RunAllRegistrationChecksContext *ctx); +typedef struct _RunRegistrationChecksContext RunRegistrationChecksContext; +static void registration_check_step (RunRegistrationChecksContext *ctx); typedef enum { REGISTRATION_CHECK_STEP_FIRST, @@ -425,7 +425,7 @@ typedef enum { REGISTRATION_CHECK_STEP_LAST, } RegistrationCheckStep; -struct _RunAllRegistrationChecksContext { +struct _RunRegistrationChecksContext { MMIfaceModemCdma *self; GSimpleAsyncResult *result; RegistrationCheckStep step; @@ -454,7 +454,7 @@ struct _RunAllRegistrationChecksContext { }; static void -run_registration_checks_context_complete_and_free (RunAllRegistrationChecksContext *ctx) +run_registration_checks_context_complete_and_free (RunRegistrationChecksContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->result); @@ -473,7 +473,7 @@ mm_iface_modem_cdma_run_registration_checks_finish (MMIfaceModemCdma *self, static void setup_registration_checks_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; @@ -500,7 +500,7 @@ setup_registration_checks_ready (MMIfaceModemCdma *self, static void get_call_manager_state_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; @@ -533,7 +533,7 @@ get_call_manager_state_ready (MMIfaceModemCdma *self, static void get_hdr_state_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; @@ -558,7 +558,7 @@ get_hdr_state_ready (MMIfaceModemCdma *self, } static void -parse_qcdm_results (RunAllRegistrationChecksContext *ctx) +parse_qcdm_results (RunRegistrationChecksContext *ctx) { /* Set QCDM-obtained registration info */ switch (ctx->call_manager_system_mode) { @@ -594,7 +594,7 @@ parse_qcdm_results (RunAllRegistrationChecksContext *ctx) static void get_service_status_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; gboolean has_service = FALSE; @@ -623,7 +623,7 @@ get_service_status_ready (MMIfaceModemCdma *self, static void get_cdma1x_serving_system_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; @@ -657,7 +657,7 @@ get_cdma1x_serving_system_ready (MMIfaceModemCdma *self, } static void -parse_at_results (RunAllRegistrationChecksContext *ctx) +parse_at_results (RunRegistrationChecksContext *ctx) { /* 99999 means unknown/no service */ if (ctx->cdma1x_sid == MM_MODEM_CDMA_SID_UNKNOWN && @@ -678,7 +678,7 @@ parse_at_results (RunAllRegistrationChecksContext *ctx) static void get_detailed_registration_state_ready (MMIfaceModemCdma *self, GAsyncResult *res, - RunAllRegistrationChecksContext *ctx) + RunRegistrationChecksContext *ctx) { GError *error = NULL; MMModemCdmaRegistrationState detailed_cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; @@ -704,7 +704,7 @@ get_detailed_registration_state_ready (MMIfaceModemCdma *self, } static void -registration_check_step (RunAllRegistrationChecksContext *ctx) +registration_check_step (RunRegistrationChecksContext *ctx) { switch (ctx->step) { case REGISTRATION_CHECK_STEP_FIRST: @@ -854,36 +854,84 @@ registration_check_step (RunAllRegistrationChecksContext *ctx) g_assert_not_reached (); } +static void +custom_run_registration_checks_ready (MMIfaceModemCdma *self, + GAsyncResult *res, + GSimpleAsyncResult *simple) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks_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_cdma_run_registration_checks (MMIfaceModemCdma *self, GAsyncReadyCallback callback, gpointer user_data) { - RunAllRegistrationChecksContext *ctx; + GSimpleAsyncResult *result; + gboolean cdma1x_supported; + gboolean evdo_supported; - ctx = g_new0 (RunAllRegistrationChecksContext, 1); - ctx->self = g_object_ref (self); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - mm_iface_modem_cdma_run_registration_checks); - ctx->cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; - ctx->evdo_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; - ctx->call_manager_system_mode = QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_NO_SERVICE; - ctx->hdr_session_state = QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_CLOSED; - ctx->hdr_almp_state = QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_INACTIVE; - ctx->hdr_hybrid_mode = 0; + result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_cdma_run_registration_checks); g_object_get (self, - MM_IFACE_MODEM_CDMA_EVDO_NETWORK_SUPPORTED, &ctx->evdo_supported, - MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED, &ctx->cdma1x_supported, + MM_IFACE_MODEM_CDMA_EVDO_NETWORK_SUPPORTED, &evdo_supported, + MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED, &cdma1x_supported, NULL); mm_dbg ("Running registration checks (CDMA1x: '%s', EV-DO: '%s')", - ctx->cdma1x_supported ? "yes" : "no", - ctx->evdo_supported ? "yes" : "no"); + cdma1x_supported ? "yes" : "no", + evdo_supported ? "yes" : "no"); + + if (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks && + MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks_finish) { + /* Plugins implementing full custom registration checks shouldn't implement + * sub-steps of the generic registration check sequence */ + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->setup_registration_checks != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->setup_registration_checks_finish != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_call_manager_state != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_call_manager_state_finish != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_hdr_state != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_hdr_state_finish != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_service_status != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_service_status_finish != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_cdma1x_serving_system != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_cdma1x_serving_system_finish != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_detailed_registration_state != NULL); + g_warn_if_fail (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_detailed_registration_state_finish != NULL); + + MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks ( + self, + cdma1x_supported, + evdo_supported, + (GAsyncReadyCallback)custom_run_registration_checks_ready, + result); + } else { + RunRegistrationChecksContext *ctx; + + ctx = g_new0 (RunRegistrationChecksContext, 1); + ctx->self = g_object_ref (self); + ctx->result = result; + ctx->cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; + ctx->evdo_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; + ctx->call_manager_system_mode = QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_NO_SERVICE; + ctx->hdr_session_state = QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_CLOSED; + ctx->hdr_almp_state = QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_INACTIVE; + ctx->hdr_hybrid_mode = 0; + ctx->evdo_supported = evdo_supported; + ctx->cdma1x_supported = cdma1x_supported; - registration_check_step (ctx); + registration_check_step (ctx); + } } /*****************************************************************************/ diff --git a/src/mm-iface-modem-cdma.h b/src/mm-iface-modem-cdma.h index 8164056c..8407e1b5 100644 --- a/src/mm-iface-modem-cdma.h +++ b/src/mm-iface-modem-cdma.h @@ -112,6 +112,44 @@ struct _MMIfaceModemCdma { GAsyncResult *res, GError **error); + /* Try to register in the CDMA network. This implementation is just making + * sure that the modem is registered, and if it's not it will wait until it + * is. + */ + void (* register_in_network) (MMIfaceModemCdma *self, + guint max_registration_time, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*register_in_network_finish) (MMIfaceModemCdma *self, + GAsyncResult *res, + GError **error); + + /* Run CDMA1x/EV-DO registration state checks.. + * Note that no registration state is returned, implementations should call + * mm_iface_modem_cdma_update_registration_state(). + * + * NOTE: Plugins implementing this method will NOT execute the generic + * registration check logic involving setup_registration_checks(), + * get_call_manager_state(), get_hdr_state(), get_service_status(), + * get_cdma1x_serving_system() and get_detailed_registration_state(). + * + * In other words, it is fine to leave this callback to NULL if you want + * the generic steps to run. This callback may be implemented if there + * is a completely independent way/command which can gather both CDMA1x + * and EV-DO registration states, SID and NID. + */ + void (* run_registration_checks) (MMIfaceModemCdma *self, + gboolean cdma1x_supported, + gboolean evdo_supported, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (* run_registration_checks_finish) (MMIfaceModemCdma *self, + GAsyncResult *res, + GError **error); + + /* The following steps will only be run if run_registration_checks() is NOT + * given by the object implementing the interface */ + /* Setup registration checks */ void (* setup_registration_checks) (MMIfaceModemCdma *self, GAsyncReadyCallback callback, @@ -124,7 +162,6 @@ struct _MMIfaceModemCdma { gboolean *skip_at_cdma1x_serving_system_step, gboolean *skip_detailed_registration_state, GError **error); - /* Get call manager state */ void (* get_call_manager_state) (MMIfaceModemCdma *self, GAsyncReadyCallback callback, @@ -134,7 +171,6 @@ struct _MMIfaceModemCdma { guint *operating_mode, guint *system_mode, GError **error); - /* Get HDR state */ void (* get_hdr_state) (MMIfaceModemCdma *self, GAsyncReadyCallback callback, @@ -145,7 +181,6 @@ struct _MMIfaceModemCdma { guint8 *session_state, guint8 *almp_state, GError **error); - /* Get service status */ void (* get_service_status) (MMIfaceModemCdma *self, GAsyncReadyCallback callback, @@ -154,7 +189,6 @@ struct _MMIfaceModemCdma { GAsyncResult *res, gboolean *has_cdma_service, GError **error); - /* Get CDMA1x serving system */ void (* get_cdma1x_serving_system) (MMIfaceModemCdma *self, GAsyncReadyCallback callback, @@ -166,7 +200,6 @@ struct _MMIfaceModemCdma { guint *sid, guint *nid, GError **error); - /* Get detailed registration state */ void (* get_detailed_registration_state) (MMIfaceModemCdma *self, MMModemCdmaRegistrationState cdma1x_state, @@ -178,15 +211,6 @@ struct _MMIfaceModemCdma { MMModemCdmaRegistrationState *detailed_cdma1x_state, MMModemCdmaRegistrationState *detailed_evdo_state, GError **error); - - /* Try to register in the CDMA network */ - void (* register_in_network) (MMIfaceModemCdma *self, - guint max_registration_time, - GAsyncReadyCallback callback, - gpointer user_data); - gboolean (*register_in_network_finish) (MMIfaceModemCdma *self, - GAsyncResult *res, - GError **error); }; GType mm_iface_modem_cdma_get_type (void); |