<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 28, 2017 at 10:59 PM, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
plugins/wavecom/mm-broadband-<wbr>modem-wavecom.c | 655 ++++++++++++---------------<br>
1 file changed, 282 insertions(+), 373 deletions(-)<br>
<br>
diff --git a/plugins/wavecom/mm-<wbr>broadband-modem-wavecom.c b/plugins/wavecom/mm-<wbr>broadband-modem-wavecom.c<br>
index 6e0f4f6f..edb3aa8c 100644<br>
--- a/plugins/wavecom/mm-<wbr>broadband-modem-wavecom.c<br>
+++ b/plugins/wavecom/mm-<wbr>broadband-modem-wavecom.c<br>
@@ -89,35 +89,30 @@ static const WavecomBand3G bands_3g[] = {<br>
/* Load supported modes (Modem interface) */<br>
<br>
static GArray *<br>
-load_supported_modes_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+load_supported_modes_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- if (g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))<br>
- return NULL;<br>
-<br>
- return g_array_ref (g_simple_async_result_get_op_<wbr>res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));<br>
+ return g_task_propagate_pointer (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
-supported_ms_classes_query_<wbr>ready (MMBaseModem *self,<br>
+supported_ms_classes_query_<wbr>ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *simple)<br>
+ GTask *task)<br>
{<br>
- GArray *all;<br>
- GArray *combinations;<br>
- GArray *filtered;<br>
- const gchar *response;<br>
- GError *error = NULL;<br>
- MMModemModeCombination mode;<br>
- MMModemMode mode_all;<br>
+ GArray *all;<br>
+ GArray *combinations;<br>
+ GArray *filtered;<br>
+ const gchar *response;<br>
+ GError *error = NULL;<br>
+ MMModemModeCombination mode;<br>
+ MMModemMode mode_all;<br>
<br>
response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
if (!response) {<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (simple, error);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -134,13 +129,10 @@ supported_ms_classes_query_<wbr>ready (MMBaseModem *self,<br>
<br>
/* If none received, error */<br>
if (mode_all == MM_MODEM_MODE_NONE) {<br>
- g_simple_async_result_set_<wbr>error (simple,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Couldn't get supported mobile station classes: '%s'",<br>
- response);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Couldn't get supported mobile station classes: '%s'",<br>
+ response);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -186,26 +178,26 @@ supported_ms_classes_query_<wbr>ready (MMBaseModem *self,<br>
g_array_unref (all);<br>
g_array_unref (combinations);<br>
<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (simple, filtered, (GDestroyNotify) g_array_unref);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_pointer (task, filtered, (GDestroyNotify) g_array_unref);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-load_supported_modes (MMIfaceModem *self,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+load_supported_modes (MMIfaceModem *self,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
+ GTask *task;<br>
+<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
+<br>
mm_base_modem_at_command (<br>
MM_BASE_MODEM (self),<br>
"+CGCLASS=?",<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)<wbr>supported_ms_classes_query_<wbr>ready,<br>
- g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- load_supported_modes));<br>
+ task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
@@ -217,45 +209,45 @@ typedef struct {<br>
} LoadCurrentModesResult;<br>
<br>
static gboolean<br>
-load_current_modes_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- MMModemMode *allowed,<br>
- MMModemMode *preferred,<br>
- GError **error)<br>
+load_current_modes_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ MMModemMode *allowed,<br>
+ MMModemMode *preferred,<br>
+ GError **error)<br>
{<br>
LoadCurrentModesResult *result;<br>
<br>
- if (g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))<br>
+ result = g_task_propagate_pointer (G_TASK (res), error);<br>
+ if (!result)<br>
return FALSE;<br>
<br>
- result = g_simple_async_result_get_op_<wbr>res_gpointer (G_SIMPLE_ASYNC_RESULT (res));<br>
-<br>
- *allowed = result->allowed;<br>
+ *allowed = result->allowed;<br>
*preferred = result->preferred;<br>
+ g_free (result);<br>
return TRUE;<br>
}<br>
<br>
static void<br>
-wwsm_read_ready (MMBaseModem *self,<br>
+wwsm_read_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *simple)<br>
+ GTask *task)<br>
{<br>
- GRegex *r;<br>
- GMatchInfo *match_info = NULL;<br>
- LoadCurrentModesResult result;<br>
- const gchar *response;<br>
- GError *error = NULL;<br>
+ GRegex *r;<br>
+ GMatchInfo *match_info = NULL;<br>
+ LoadCurrentModesResult *result;<br>
+ const gchar *response;<br>
+ GError *error = NULL;<br>
<br>
response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
if (!response) {<br>
- g_simple_async_result_take_<wbr>error (simple, error);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
- result.allowed = MM_MODEM_MODE_NONE;<br>
- result.preferred = MM_MODEM_MODE_NONE;<br>
+ result = g_new0 (LoadCurrentModesResult, 1);<br>
+ result->allowed = MM_MODEM_MODE_NONE;<br>
+ result->preferred = MM_MODEM_MODE_NONE;<br>
<br>
/* Possible responses:<br>
* +WWSM: 0 (2G only)<br>
@@ -273,29 +265,29 @@ wwsm_read_ready (MMBaseModem *self,<br>
if (mm_get_uint_from_match_info (match_info, 1, &allowed)) {<br>
switch (allowed) {<br>
case 0:<br>
- result.allowed = MM_MODEM_MODE_2G;<br>
- result.preferred = MM_MODEM_MODE_NONE;<br>
+ result->allowed = MM_MODEM_MODE_2G;<br>
+ result->preferred = MM_MODEM_MODE_NONE;<br>
break;<br>
case 1:<br>
- result.allowed = MM_MODEM_MODE_3G;<br>
- result.preferred = MM_MODEM_MODE_NONE;<br>
+ result->allowed = MM_MODEM_MODE_3G;<br>
+ result->preferred = MM_MODEM_MODE_NONE;<br>
break;<br>
case 2: {<br>
guint preferred = 0;<br>
<br>
- result.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);<br>
+ result->allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);<br>
<br>
/* 3, to avoid the comma */<br>
if (mm_get_uint_from_match_info (match_info, 3, &preferred)) {<br>
switch (preferred) {<br>
case 0:<br>
- result.preferred = MM_MODEM_MODE_NONE;<br>
+ result->preferred = MM_MODEM_MODE_NONE;<br>
break;<br>
case 1:<br>
- result.preferred = MM_MODEM_MODE_2G;<br>
+ result->preferred = MM_MODEM_MODE_2G;<br>
break;<br>
case 2:<br>
- result.preferred = MM_MODEM_MODE_3G;<br>
+ result->preferred = MM_MODEM_MODE_3G;<br>
break;<br>
default:<br>
g_warn_if_reached ();<br>
@@ -311,16 +303,13 @@ wwsm_read_ready (MMBaseModem *self,<br>
}<br>
}<br>
<br>
- if (result.allowed == MM_MODEM_MODE_NONE)<br>
- g_simple_async_result_set_<wbr>error (simple,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Unknown wireless data service reply: '%s'",<br>
- response);<br>
+ if (result->allowed == MM_MODEM_MODE_NONE)<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Unknown wireless data service reply: '%s'",<br>
+ response);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (simple, &result, NULL);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_pointer (task, result, g_free);<br>
+ g_object_unref (task);<br>
<br>
g_regex_unref (r);<br>
if (match_info)<br>
@@ -328,19 +317,18 @@ wwsm_read_ready (MMBaseModem *self,<br>
}<br>
<br>
static void<br>
-current_ms_class_ready (MMBaseModem *self,<br>
+current_ms_class_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *simple)<br>
+ GTask *task)<br>
{<br>
- LoadCurrentModesResult result;<br>
- const gchar *response;<br>
- GError *error = NULL;<br>
+ LoadCurrentModesResult result;<br>
+ const gchar *response;<br>
+ GError *error = NULL;<br>
<br>
- response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
+ response = mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
if (!response) {<br>
- g_simple_async_result_take_<wbr>error (simple, error);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -351,12 +339,12 @@ current_ms_class_ready (MMBaseModem *self,<br>
strlen (WAVECOM_MS_CLASS_A_IDSTR)) == 0) {<br>
mm_dbg ("Modem configured as a Class A mobile station");<br>
/* For 3G devices, query WWSM status */<br>
- mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
+ mm_base_modem_at_command (self,<br>
"+WWSM?",<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)wwsm_<wbr>read_ready,<br>
- simple);<br>
+ task);<br>
return;<br>
}<br>
<br>
@@ -384,101 +372,90 @@ current_ms_class_ready (MMBaseModem *self,<br>
}<br>
<br>
if (result.allowed == MM_MODEM_MODE_NONE)<br>
- g_simple_async_result_set_<wbr>error (simple,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Unknown mobile station class: '%s'",<br>
- response);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br></blockquote><div><br></div><div>not sure about the convention, should 'task' and 'MM_CORE_ERROR, MM_CORE_ERROR_FAILED' on separate line? otherwise lgtm</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ "Unknown mobile station class: '%s'",<br>
+ response);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (simple, &result, NULL);<br>
- g_simple_async_result_complete (simple);<br>
- g_object_unref (simple);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-load_current_modes (MMIfaceModem *self,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+load_current_modes (MMIfaceModem *self,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
- GSimpleAsyncResult *result;<br>
+ GTask *task;<br>
<br>
- result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- load_current_modes);<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
<br>
mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
"+CGCLASS?",<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)current_<wbr>ms_class_ready,<br>
- result);<br>
+ task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* Set allowed modes (Modem interface) */<br>
<br>
typedef struct {<br>
- MMBroadbandModemWavecom *self;<br>
- GSimpleAsyncResult *result;<br>
gchar *cgclass_command;<br>
gchar *wwsm_command;<br>
} SetCurrentModesContext;<br>
<br>
static void<br>
-set_current_modes_context_<wbr>complete_and_free (SetCurrentModesContext *ctx)<br>
+set_current_modes_context_<wbr>free (SetCurrentModesContext *ctx)<br>
{<br>
- g_simple_async_result_<wbr>complete_in_idle (ctx->result);<br>
- g_object_unref (ctx->result);<br>
- g_object_unref (ctx->self);<br>
g_free (ctx->cgclass_command);<br>
g_free (ctx->wwsm_command);<br>
g_free (ctx);<br>
}<br>
<br>
static gboolean<br>
-set_current_modes_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+set_current_modes_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- return !g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);<br>
+ return g_task_propagate_boolean (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
-wwsm_update_ready (MMBaseModem *self,<br>
+wwsm_update_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- SetCurrentModesContext *ctx)<br>
+ GTask *task)<br>
{<br>
GError *error = NULL;<br>
<br>
- mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
+ mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
if (error)<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
+ g_task_return_error (task, error);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gboolean (ctx->result, TRUE);<br>
-<br>
- set_current_modes_context_<wbr>complete_and_free (ctx);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-cgclass_update_ready (MMBaseModem *self,<br>
+cgclass_update_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- SetCurrentModesContext *ctx)<br>
+ GTask *task)<br>
{<br>
- GError *error = NULL;<br>
+ SetCurrentModesContext *ctx;<br>
+ GError *error = NULL;<br>
+<br>
+ ctx = g_task_get_task_data (task);<br>
<br>
mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
if (error) {<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
- set_current_modes_context_<wbr>complete_and_free (ctx);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
if (!ctx->wwsm_command) {<br>
- g_simple_async_result_set_op_<wbr>res_gboolean (ctx->result, TRUE);<br>
- set_current_modes_context_<wbr>complete_and_free (ctx);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -487,24 +464,23 @@ cgclass_update_ready (MMBaseModem *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)wwsm_<wbr>update_ready,<br>
- ctx);<br>
+ task);<br>
}<br>
<br>
static void<br>
-set_current_modes (MMIfaceModem *self,<br>
- MMModemMode allowed,<br>
- MMModemMode preferred,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+set_current_modes (MMIfaceModem *self,<br>
+ MMModemMode allowed,<br>
+ MMModemMode preferred,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
+ GTask *task;<br>
SetCurrentModesContext *ctx;<br>
<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
+<br>
ctx = g_new0 (SetCurrentModesContext, 1);<br>
- ctx->self = g_object_ref (self);<br>
- ctx->result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- set_current_modes);<br>
+ g_task_set_task_data (task, ctx, (GDestroyNotify) set_current_modes_context_<wbr>free);<br>
<br>
/* Handle ANY/NONE */<br>
if (allowed == MM_MODEM_MODE_ANY && preferred == MM_MODEM_MODE_NONE) {<br>
@@ -545,17 +521,13 @@ set_current_modes (MMIfaceModem *self,<br>
<br>
allowed_str = mm_modem_mode_build_string_<wbr>from_mask (allowed);<br>
preferred_str = mm_modem_mode_build_string_<wbr>from_mask (preferred);<br>
- g_simple_async_result_set_<wbr>error (ctx->result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Requested mode (allowed: '%s', preferred: '%s') not "<br>
- "supported by the modem.",<br>
- allowed_str,<br>
- preferred_str);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Requested mode (allowed: '%s', preferred: '%s') not "<br>
+ "supported by the modem.",<br>
+ allowed_str, preferred_str);<br>
+ g_object_unref (task);<br>
g_free (allowed_str);<br>
g_free (preferred_str);<br>
-<br>
- set_current_modes_context_<wbr>complete_and_free (ctx);<br>
return;<br>
}<br>
<br>
@@ -564,34 +536,29 @@ set_current_modes (MMIfaceModem *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)cgclass_<wbr>update_ready,<br>
- ctx);<br>
+ task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* Load supported bands (Modem interface) */<br>
<br>
static GArray *<br>
-load_supported_bands_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+load_supported_bands_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- /* Never fails */<br>
- return (GArray *) g_array_ref (g_simple_async_result_get_op_<wbr>res_gpointer (<br>
- G_SIMPLE_ASYNC_RESULT (res)));<br>
+ return g_task_propagate_pointer (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
-load_supported_bands (MMIfaceModem *self,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+load_supported_bands (MMIfaceModem *self,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
- GSimpleAsyncResult *result;<br>
+ GTask *task;<br>
GArray *bands;<br>
<br>
- result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- load_supported_bands);<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
<br>
/* We do assume that we already know if the modem is 2G-only, 3G-only or<br>
* 2G+3G. This is checked quite before trying to load supported bands. */<br>
@@ -624,44 +591,35 @@ load_supported_bands (MMIfaceModem *self,<br>
_g_array_insert_enum (bands, 3, MMModemBand, MM_MODEM_BAND_G850);<br>
}<br>
<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (result,<br>
- bands,<br>
- (GDestroyNotify)g_array_unref)<wbr>;<br>
- g_simple_async_result_<wbr>complete_in_idle (result);<br>
- g_object_unref (result);<br>
+ g_task_return_pointer (task, bands, (GDestroyNotify) g_array_unref);<br>
+ g_object_unref (task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* Load current bands (Modem interface) */<br>
<br>
static GArray *<br>
-load_current_bands_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+load_current_bands_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- if (g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))<br>
- return NULL;<br>
-<br>
- return (GArray *) g_array_ref (g_simple_async_result_get_op_<wbr>res_gpointer (<br>
- G_SIMPLE_ASYNC_RESULT (res)));<br>
+ return g_task_propagate_pointer (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
-get_2g_band_ready (MMBroadbandModemWavecom *self,<br>
+get_2g_band_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *operation_result)<br>
+ GTask *task)<br>
{<br>
const gchar *response;<br>
const gchar *p;<br>
- GError *error = NULL;<br>
- GArray *bands_array = NULL;<br>
+ GError *error = NULL;<br>
+ GArray *bands_array = NULL;<br>
<br>
response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
if (!response) {<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (operation_result, error);<br>
- g_simple_async_result_complete (operation_result);<br>
- g_object_unref (operation_result);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -683,37 +641,29 @@ get_2g_band_ready (MMBroadbandModemWavecom *self,<br>
}<br>
<br>
if (!bands_array)<br>
- g_simple_async_result_set_<wbr>error (operation_result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Couldn't parse current bands reply: '%s'",<br>
- response);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Couldn't parse current bands reply: '%s'",<br>
+ response);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (operation_result,<br>
- bands_array,<br>
- (GDestroyNotify)g_array_unref)<wbr>;<br>
-<br>
- g_simple_async_result_complete (operation_result);<br>
- g_object_unref (operation_result);<br>
+ g_task_return_pointer (task, bands_array, (GDestroyNotify)g_array_unref)<wbr>;<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-get_3g_band_ready (MMBroadbandModemWavecom *self,<br>
+get_3g_band_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *operation_result)<br>
+ GTask *task)<br>
{<br>
const gchar *response;<br>
const gchar *p;<br>
- GError *error = NULL;<br>
- GArray *bands_array = NULL;<br>
- guint32 wavecom_band;<br>
+ GError *error = NULL;<br>
+ GArray *bands_array = NULL;<br>
+ guint32 wavecom_band;<br>
<br>
- response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
+ response = mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
if (!response) {<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (operation_result, error);<br>
- g_simple_async_result_complete (operation_result);<br>
- g_object_unref (operation_result);<br>
+ g_task_return_error (task, error);<br>
+ g_object_unref (task);<br>
return;<br>
}<br>
<br>
@@ -742,18 +692,12 @@ get_3g_band_ready (MMBroadbandModemWavecom *self,<br>
}<br>
<br>
if (!bands_array)<br>
- g_simple_async_result_set_<wbr>error (operation_result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Couldn't parse current bands reply: '%s'",<br>
- response);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Couldn't parse current bands reply: '%s'",<br>
+ response);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gpointer (operation_result,<br>
- bands_array,<br>
- (GDestroyNotify)g_array_unref)<wbr>;<br>
-<br>
- g_simple_async_result_complete (operation_result);<br>
- g_object_unref (operation_result);<br>
+ g_task_return_pointer (task, bands_array, (GDestroyNotify)g_array_unref)<wbr>;<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
@@ -761,12 +705,9 @@ load_current_bands (MMIfaceModem *self,<br>
GAsyncReadyCallback callback,<br>
gpointer user_data)<br>
{<br>
- GSimpleAsyncResult *result;<br>
+ GTask *task;<br>
<br>
- result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- load_current_bands);<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
<br>
if (mm_iface_modem_is_3g (self))<br>
mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
@@ -774,54 +715,53 @@ load_current_bands (MMIfaceModem *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)get_3g_<wbr>band_ready,<br>
- result);<br>
+ task);<br>
else<br>
mm_base_modem_at_command (MM_BASE_MODEM (self),<br>
"AT+WMBS?",<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)get_2g_<wbr>band_ready,<br>
- result);<br>
+ task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* Set current_bands (Modem interface) */<br>
<br>
static gboolean<br>
-set_current_bands_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+set_current_bands_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- return !g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);<br>
+ return g_task_propagate_boolean (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
-wmbs_set_ready (MMBaseModem *self,<br>
+wmbs_set_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- GSimpleAsyncResult *operation_result)<br>
+ GTask *task)<br>
{<br>
GError *error = NULL;<br>
<br>
if (!mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error))<br>
- /* Let the error be critical */<br>
- g_simple_async_result_take_<wbr>error (operation_result, error);<br>
+ g_task_return_error (task, error);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gboolean (operation_result, TRUE);<br>
-<br>
- g_simple_async_result_complete (operation_result);<br>
- g_object_unref (operation_result);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-set_bands_3g (MMIfaceModem *self,<br>
- GArray *bands_array,<br>
- GSimpleAsyncResult *result)<br>
+set_bands_3g (GTask *task,<br>
+ GArray *bands_array)<br>
{<br>
- GArray *bands_array_final;<br>
- guint wavecom_band = 0;<br>
- guint i;<br>
- gchar *bands_string;<br>
- gchar *cmd;<br>
+ MMBroadbandModemWavecom *self;<br>
+ GArray *bands_array_final;<br>
+ guint wavecom_band = 0;<br>
+ guint i;<br>
+ gchar *bands_string;<br>
+ gchar *cmd;<br>
+<br>
+ self = g_task_get_source_object (task);<br>
<br>
/* The special case of ANY should be treated separately. */<br>
if (bands_array->len == 1 &&<br>
@@ -851,13 +791,10 @@ set_bands_3g (MMIfaceModem *self,<br>
g_array_unref (bands_array_final);<br>
<br>
if (wavecom_band == 0) {<br>
- g_simple_async_result_set_<wbr>error (result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_UNSUPPORTED,<br>
- "The given band combination is not supported: '%s'",<br>
- bands_string);<br>
- g_simple_async_result_<wbr>complete_in_idle (result);<br>
- g_object_unref (result);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,<br>
+ "The given band combination is not supported: '%s'",<br>
+ bands_string);<br>
+ g_object_unref (task);<br>
g_free (bands_string);<br>
return;<br>
}<br>
@@ -869,21 +806,23 @@ set_bands_3g (MMIfaceModem *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)wmbs_set_<wbr>ready,<br>
- result);<br>
+ task);<br>
g_free (cmd);<br>
g_free (bands_string);<br>
}<br>
<br>
static void<br>
-set_bands_2g (MMIfaceModem *self,<br>
- GArray *bands_array,<br>
- GSimpleAsyncResult *result)<br>
+set_bands_2g (GTask *task,<br>
+ GArray *bands_array)<br>
{<br>
- GArray *bands_array_final;<br>
- gchar wavecom_band = '\0';<br>
- guint i;<br>
- gchar *bands_string;<br>
- gchar *cmd;<br>
+ MMBroadbandModemWavecom *self;<br>
+ GArray *bands_array_final;<br>
+ gchar wavecom_band = '\0';<br>
+ guint i;<br>
+ gchar *bands_string;<br>
+ gchar *cmd;<br>
+<br>
+ self = g_task_get_source_object (task);<br>
<br>
/* If the iface properly checked the given list against the supported bands,<br>
* it's not possible to get an array longer than 4 here. */<br>
@@ -923,13 +862,10 @@ set_bands_2g (MMIfaceModem *self,<br>
g_array_unref (bands_array_final);<br>
<br>
if (wavecom_band == '\0') {<br>
- g_simple_async_result_set_<wbr>error (result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_UNSUPPORTED,<br>
- "The given band combination is not supported: '%s'",<br>
- bands_string);<br>
- g_simple_async_result_<wbr>complete_in_idle (result);<br>
- g_object_unref (result);<br>
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,<br>
+ "The given band combination is not supported: '%s'",<br>
+ bands_string);<br>
+ g_object_unref (task);<br>
g_free (bands_string);<br>
return;<br>
}<br>
@@ -941,19 +877,19 @@ set_bands_2g (MMIfaceModem *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)wmbs_set_<wbr>ready,<br>
- result);<br>
+ task);<br>
<br>
g_free (cmd);<br>
g_free (bands_string);<br>
}<br>
<br>
static void<br>
-set_current_bands (MMIfaceModem *self,<br>
- GArray *bands_array,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+set_current_bands (MMIfaceModem *self,<br>
+ GArray *bands_array,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
- GSimpleAsyncResult *result;<br>
+ GTask *task;<br>
<br>
/* The bands that we get here are previously validated by the interface, and<br>
* that means that ALL the bands given here were also given in the list of<br>
@@ -961,15 +897,12 @@ set_current_bands (MMIfaceModem *self,<br>
* will end up being valid, as not all combinations are possible. E.g,<br>
* Wavecom modems supporting only 2G have specific combinations allowed.<br>
*/<br>
- result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- set_current_bands);<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
<br>
if (mm_iface_modem_is_3g (self))<br>
- set_bands_3g (self, bands_array, result);<br>
+ set_bands_3g (task, bands_array);<br>
else<br>
- set_bands_2g (self, bands_array, result);<br>
+ set_bands_2g (task, bands_array);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
@@ -1050,65 +983,52 @@ load_access_technologies (MMIfaceModem *self,<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* Register in network (3GPP interface) */<br>
<br>
-typedef struct {<br>
- MMBroadbandModemWavecom *self;<br>
- GSimpleAsyncResult *result;<br>
- GCancellable *cancellable;<br>
- gchar *operator_id;<br>
-} RegisterInNetworkContext;<br>
-<br>
-static void<br>
-register_in_network_context_<wbr>complete_and_free (RegisterInNetworkContext *ctx)<br>
-{<br>
- g_simple_async_result_complete (ctx->result);<br>
- g_object_unref (ctx->result);<br>
- g_object_unref (ctx->self);<br>
- if (ctx->cancellable)<br>
- g_object_unref (ctx->cancellable);<br>
- g_free (ctx->operator_id);<br>
- g_slice_free (RegisterInNetworkContext, ctx);<br>
-}<br>
-<br>
static gboolean<br>
-register_in_network_finish (MMIfaceModem3gpp *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+register_in_network_finish (MMIfaceModem3gpp *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- return !g_simple_async_result_<wbr>propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);<br>
+ return g_task_propagate_boolean (G_TASK (res), error);<br>
}<br>
<br>
static void<br>
parent_registration_ready (MMIfaceModem3gpp *self,<br>
- GAsyncResult *res,<br>
- RegisterInNetworkContext *ctx)<br>
+ GAsyncResult *res,<br>
+ GTask *task)<br>
{<br>
GError *error = NULL;<br>
<br>
if (!iface_modem_3gpp_parent-><wbr>register_in_network_finish (self, res, &error))<br>
- g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
+ g_task_return_error (task, error);<br>
else<br>
- g_simple_async_result_set_op_<wbr>res_gboolean (ctx->result, TRUE);<br>
- register_in_network_context_<wbr>complete_and_free (ctx);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-run_parent_registration (RegisterInNetworkContext *ctx)<br>
+run_parent_registration (GTask *task)<br>
{<br>
+ MMBroadbandModemWavecom *self;<br>
+ const gchar *operator_id;<br>
+<br>
+ self = g_task_get_source_object (task);<br>
+ operator_id = g_task_get_task_data (task);<br>
+<br>
iface_modem_3gpp_parent-><wbr>register_in_network (<br>
- MM_IFACE_MODEM_3GPP (ctx->self),<br>
- ctx->operator_id,<br>
- ctx->cancellable,<br>
+ MM_IFACE_MODEM_3GPP (self),<br>
+ operator_id,<br>
+ g_task_get_cancellable (task),<br>
(GAsyncReadyCallback)parent_<wbr>registration_ready,<br>
- ctx);<br>
+ task);<br>
}<br>
<br>
static gboolean<br>
parse_network_registration_<wbr>mode (const gchar *reply,<br>
- guint *mode)<br>
+ guint *mode)<br>
{<br>
- GRegex *r;<br>
+ GRegex *r;<br>
GMatchInfo *match_info;<br>
- gboolean parsed = FALSE;<br>
+ gboolean parsed = FALSE;<br>
<br>
g_assert (mode != NULL);<br>
<br>
@@ -1130,61 +1050,54 @@ parse_network_registration_<wbr>mode (const gchar *reply,<br>
}<br>
<br>
static void<br>
-cops_ready (MMBaseModem *self,<br>
+cops_ready (MMBaseModem *self,<br>
GAsyncResult *res,<br>
- RegisterInNetworkContext *ctx)<br>
+ GTask *task)<br>
{<br>
const gchar *response;<br>
- GError *error = NULL;<br>
- guint mode;<br>
+ GError *error = NULL;<br>
+ guint mode;<br>
<br>
- response = mm_base_modem_at_command_<wbr>finish (MM_BASE_MODEM (self), res, &error);<br>
- if (!response) {<br>
- /* Let the error be critical. */<br>
- g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
- register_in_network_context_<wbr>complete_and_free (ctx);<br>
- return;<br>
- }<br>
+ response = mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
+ if (!response)<br>
+ goto out;<br>
<br>
if (!parse_network_registration_<wbr>mode (response, &mode)) {<br>
- g_simple_async_result_set_<wbr>error (ctx->result,<br>
- MM_CORE_ERROR,<br>
- MM_CORE_ERROR_FAILED,<br>
- "Couldn't parse current network registration mode");<br>
- register_in_network_context_<wbr>complete_and_free (ctx);<br>
- return;<br>
+ error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Couldn't parse current network registration mode: '%s'",<br>
+ response);<br>
+ goto out;<br>
}<br>
<br>
- /* If the modem is already configured for automatic registration, don't do<br>
- * anything else */<br>
- if (mode == 0) {<br>
- mm_dbg ("Device is already in automatic registration mode, not requesting it again");<br>
- g_simple_async_result_set_op_<wbr>res_gboolean (ctx->result, TRUE);<br>
- register_in_network_context_<wbr>complete_and_free (ctx);<br>
+ /* If the modem is not configured for automatic registration, run parent */<br>
+ if (mode != 0) {<br>
+ run_parent_registration (task);<br>
return;<br>
}<br>
<br>
- /* Otherwise, run parent's implementation */<br>
- run_parent_registration (ctx);<br>
+ mm_dbg ("Device is already in automatic registration mode, not requesting it again");<br>
+<br>
+out:<br>
+ if (error)<br>
+ g_task_return_error (task, error);<br>
+ else<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
}<br>
<br>
static void<br>
-register_in_network (MMIfaceModem3gpp *self,<br>
- const gchar *operator_id,<br>
- GCancellable *cancellable,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+register_in_network (MMIfaceModem3gpp *self,<br>
+ const gchar *operator_id,<br>
+ GCancellable *cancellable,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
- RegisterInNetworkContext *ctx;<br>
+ GTask *task;<br>
<br>
- ctx = g_slice_new0 (RegisterInNetworkContext);<br>
- ctx->self = g_object_ref (self);<br>
- ctx->result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- register_in_network);<br>
- ctx->operator_id = g_strdup (operator_id);<br>
- ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;<br>
+ task = g_task_new (self, cancellable, callback, user_data);<br>
+<br>
+ /* Store operator id as task data */<br>
+ g_task_set_task_data (task, g_strdup (operator_id), g_free);<br>
<br>
/* If requesting automatic registration, we first need to query what the<br>
* current mode is. We must NOT send +COPS=0 if it already is in 0 mode,<br>
@@ -1196,49 +1109,45 @@ register_in_network (MMIfaceModem3gpp *self,<br>
3,<br>
FALSE,<br>
(GAsyncReadyCallback)cops_<wbr>ready,<br>
- ctx);<br>
+ task);<br>
return;<br>
}<br>
<br>
/* Otherwise, run parent's implementation right away */<br>
- run_parent_registration (ctx);<br>
+ run_parent_registration (task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* After SIM unlock (Modem interface) */<br>
<br>
static gboolean<br>
-modem_after_sim_unlock_finish (MMIfaceModem *self,<br>
- GAsyncResult *res,<br>
- GError **error)<br>
+modem_after_sim_unlock_finish (MMIfaceModem *self,<br>
+ GAsyncResult *res,<br>
+ GError **error)<br>
{<br>
- return TRUE;<br>
+ return g_task_propagate_boolean (G_TASK (res), error);<br>
}<br>
<br>
static gboolean<br>
-after_sim_unlock_wait_cb (GSimpleAsyncResult *result)<br>
+after_sim_unlock_wait_cb (GTask *task)<br>
{<br>
- g_simple_async_result_complete (result);<br>
- g_object_unref (result);<br>
+ g_task_return_boolean (task, TRUE);<br>
+ g_object_unref (task);<br>
return G_SOURCE_REMOVE;<br>
}<br>
<br>
static void<br>
-modem_after_sim_unlock (MMIfaceModem *self,<br>
- GAsyncReadyCallback callback,<br>
- gpointer user_data)<br>
+modem_after_sim_unlock (MMIfaceModem *self,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
{<br>
- GSimpleAsyncResult *result;<br>
+ GTask *task;<br>
<br>
/* A short wait is necessary for SIM to become ready, otherwise reloading<br>
* facility lock states may fail with a +CME ERROR: 515 error.<br>
*/<br>
- result = g_simple_async_result_new (G_OBJECT (self),<br>
- callback,<br>
- user_data,<br>
- modem_after_sim_unlock);<br>
-<br>
- g_timeout_add_seconds (5, (GSourceFunc)after_sim_unlock_<wbr>wait_cb, result);<br>
+ task = g_task_new (self, NULL, callback, user_data);<br>
+ g_timeout_add_seconds (5, (GSourceFunc)after_sim_unlock_<wbr>wait_cb, task);<br>
}<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
2.14.1<br>
<br>
</font></span></blockquote></div><br></div></div>