via: port get_detailed_registration_state() to GTask
This commit is contained in:
@@ -145,22 +145,6 @@ typedef struct {
|
|||||||
MMModemCdmaRegistrationState detailed_evdo_state;
|
MMModemCdmaRegistrationState detailed_evdo_state;
|
||||||
} DetailedRegistrationStateResults;
|
} DetailedRegistrationStateResults;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
MMBroadbandModem *self;
|
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
DetailedRegistrationStateResults state;
|
|
||||||
} DetailedRegistrationStateContext;
|
|
||||||
|
|
||||||
static void
|
|
||||||
detailed_registration_state_context_complete_and_free (DetailedRegistrationStateContext *ctx)
|
|
||||||
{
|
|
||||||
/* Always not in idle! we're passing a struct in stack as result */
|
|
||||||
g_simple_async_result_complete (ctx->result);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_free (ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
get_detailed_registration_state_finish (MMIfaceModemCdma *self,
|
get_detailed_registration_state_finish (MMIfaceModemCdma *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -170,36 +154,39 @@ get_detailed_registration_state_finish (MMIfaceModemCdma *self,
|
|||||||
{
|
{
|
||||||
DetailedRegistrationStateResults *results;
|
DetailedRegistrationStateResults *results;
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
results = g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
if (!results)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
results = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
|
|
||||||
*detailed_cdma1x_state = results->detailed_cdma1x_state;
|
*detailed_cdma1x_state = results->detailed_cdma1x_state;
|
||||||
*detailed_evdo_state = results->detailed_evdo_state;
|
*detailed_evdo_state = results->detailed_evdo_state;
|
||||||
|
g_free (results);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysinfo_ready (MMIfaceModemCdma *self,
|
sysinfo_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DetailedRegistrationStateContext *ctx)
|
GTask *task)
|
||||||
|
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
DetailedRegistrationStateResults *ctx;
|
||||||
|
DetailedRegistrationStateResults *results;
|
||||||
const gchar *response;
|
const gchar *response;
|
||||||
GRegex *r;
|
GRegex *r;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
|
MMModemCdmaRegistrationState reg_state;
|
||||||
|
guint val = 0;
|
||||||
|
|
||||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
|
/* Set input detailed states as fallback */
|
||||||
|
results = g_memdup (ctx, sizeof (*ctx));
|
||||||
|
|
||||||
/* If error, leave superclass' reg state alone if AT^SYSINFO isn't supported. */
|
/* If error, leave superclass' reg state alone if AT^SYSINFO isn't supported. */
|
||||||
if (error) {
|
response = mm_base_modem_at_command_finish (self, res, NULL);
|
||||||
g_error_free (error);
|
if (!response)
|
||||||
|
goto out;
|
||||||
/* NOTE: always complete NOT in idle here */
|
|
||||||
g_simple_async_result_set_op_res_gpointer (ctx->result, &ctx->state, NULL);
|
|
||||||
detailed_registration_state_context_complete_and_free (ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
response = mm_strip_tag (response, "^SYSINFO:");
|
response = mm_strip_tag (response, "^SYSINFO:");
|
||||||
|
|
||||||
@@ -209,14 +196,11 @@ sysinfo_ready (MMIfaceModemCdma *self,
|
|||||||
g_assert (r != NULL);
|
g_assert (r != NULL);
|
||||||
|
|
||||||
/* Try to parse the results */
|
/* Try to parse the results */
|
||||||
|
|
||||||
g_regex_match (r, response, 0, &match_info);
|
g_regex_match (r, response, 0, &match_info);
|
||||||
|
|
||||||
if (g_match_info_get_match_count (match_info) < 6) {
|
if (g_match_info_get_match_count (match_info) < 6) {
|
||||||
mm_warn ("Via: failed to parse ^SYSINFO response: '%s'", response);
|
mm_warn ("Via: failed to parse ^SYSINFO response: '%s'", response);
|
||||||
} else {
|
goto out;
|
||||||
MMModemCdmaRegistrationState reg_state;
|
}
|
||||||
guint val = 0;
|
|
||||||
|
|
||||||
/* At this point the generic code already knows we've been registered */
|
/* At this point the generic code already knows we've been registered */
|
||||||
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
||||||
@@ -238,26 +222,25 @@ sysinfo_ready (MMIfaceModemCdma *self,
|
|||||||
val = 0;
|
val = 0;
|
||||||
if (mm_get_uint_from_match_info (match_info, 4, &val)) {
|
if (mm_get_uint_from_match_info (match_info, 4, &val)) {
|
||||||
if (val == 2) /* CDMA */
|
if (val == 2) /* CDMA */
|
||||||
ctx->state.detailed_cdma1x_state = reg_state;
|
results->detailed_cdma1x_state = reg_state;
|
||||||
else if (val == 4) /* HDR */
|
else if (val == 4) /* HDR */
|
||||||
ctx->state.detailed_evdo_state = reg_state;
|
results->detailed_evdo_state = reg_state;
|
||||||
else if (val == 8) { /* Hybrid */
|
else if (val == 8) { /* Hybrid */
|
||||||
ctx->state.detailed_cdma1x_state = reg_state;
|
results->detailed_cdma1x_state = reg_state;
|
||||||
ctx->state.detailed_evdo_state = reg_state;
|
results->detailed_evdo_state = reg_state;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Say we're registered to something even though sysmode parsing failed */
|
/* Say we're registered to something even though sysmode parsing failed */
|
||||||
mm_dbg ("SYSMODE parsing failed: assuming registered at least in CDMA1x");
|
mm_dbg ("SYSMODE parsing failed: assuming registered at least in CDMA1x");
|
||||||
ctx->state.detailed_cdma1x_state = reg_state;
|
results->detailed_cdma1x_state = reg_state;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_match_info_free (match_info);
|
g_match_info_free (match_info);
|
||||||
g_regex_unref (r);
|
g_regex_unref (r);
|
||||||
|
|
||||||
/* NOTE: always complete NOT in idle here */
|
out:
|
||||||
g_simple_async_result_set_op_res_gpointer (ctx->result, &ctx->state, NULL);
|
g_task_return_pointer (task, results, NULL);
|
||||||
detailed_registration_state_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -267,24 +250,23 @@ get_detailed_registration_state (MMIfaceModemCdma *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
DetailedRegistrationStateContext *ctx;
|
GTask *task;
|
||||||
|
DetailedRegistrationStateResults *ctx;
|
||||||
|
|
||||||
/* Setup context */
|
/* Setup context */
|
||||||
ctx = g_new0 (DetailedRegistrationStateContext, 1);
|
ctx = g_new0 (DetailedRegistrationStateResults, 1);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->detailed_cdma1x_state = cdma1x_state;
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
ctx->detailed_evdo_state = evdo_state;
|
||||||
callback,
|
|
||||||
user_data,
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
get_detailed_registration_state);
|
g_task_set_task_data (task, ctx, g_free);
|
||||||
ctx->state.detailed_cdma1x_state = cdma1x_state;
|
|
||||||
ctx->state.detailed_evdo_state = evdo_state;
|
|
||||||
|
|
||||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||||
"^SYSINFO",
|
"^SYSINFO",
|
||||||
3,
|
3,
|
||||||
FALSE,
|
FALSE,
|
||||||
(GAsyncReadyCallback)sysinfo_ready,
|
(GAsyncReadyCallback)sysinfo_ready,
|
||||||
ctx);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user