[PATCH] sim-mbim: port MMSimMbim to use GTask
Ben Chan
benchan at chromium.org
Fri Jun 30 09:16:27 UTC 2017
---
src/mm-sim-mbim.c | 201 ++++++++++++++++++++++++------------------------------
1 file changed, 89 insertions(+), 112 deletions(-)
diff --git a/src/mm-sim-mbim.c b/src/mm-sim-mbim.c
index 3d99c99d..f112fe7d 100644
--- a/src/mm-sim-mbim.c
+++ b/src/mm-sim-mbim.c
@@ -50,12 +50,13 @@ peek_device (gpointer self,
g_object_unref (modem);
if (!port) {
- g_simple_async_report_error_in_idle (G_OBJECT (self),
- callback,
- user_data,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Couldn't peek MBIM port");
+ g_task_report_new_error (self,
+ callback,
+ user_data,
+ peek_device,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't peek MBIM port");
return FALSE;
}
@@ -71,15 +72,13 @@ load_sim_identifier_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
- return NULL;
- return g_strdup ((gchar *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void
simid_subscriber_ready_state_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
MbimMessage *response;
GError *error = NULL;
@@ -97,14 +96,13 @@ simid_subscriber_ready_state_ready (MbimDevice *device,
NULL, /* telephone_numbers_count */
NULL, /* telephone_numbers */
&error))
- g_simple_async_result_set_op_res_gpointer (simple, sim_iccid, g_free);
+ g_task_return_pointer (task, sim_iccid, g_free);
else
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
+ g_object_unref (task);
if (response)
mbim_message_unref (response);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
static void
@@ -114,12 +112,12 @@ load_sim_identifier (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, load_sim_identifier);
+ task = g_task_new (self, NULL, callback, user_data);
message = mbim_message_subscriber_ready_status_query_new (NULL);
mbim_device_command (device,
@@ -127,7 +125,7 @@ load_sim_identifier (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)simid_subscriber_ready_state_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -136,18 +134,16 @@ load_sim_identifier (MMBaseSim *self,
static gchar *
load_imsi_finish (MMBaseSim *self,
- GAsyncResult *res,
- GError **error)
+ GAsyncResult *res,
+ GError **error)
{
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
- return NULL;
- return g_strdup ((gchar *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void
imsi_subscriber_ready_state_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
MbimMessage *response;
GError *error = NULL;
@@ -165,14 +161,13 @@ imsi_subscriber_ready_state_ready (MbimDevice *device,
NULL, /* telephone_numbers_count */
NULL, /* telephone_numbers */
&error))
- g_simple_async_result_set_op_res_gpointer (simple, subscriber_id, g_free);
+ g_task_return_pointer (task, subscriber_id, g_free);
else
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
+ g_object_unref (task);
if (response)
mbim_message_unref (response);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
static void
@@ -182,12 +177,12 @@ load_imsi (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, load_imsi);
+ task = g_task_new (self, NULL, callback, user_data);
message = mbim_message_subscriber_ready_status_query_new (NULL);
mbim_device_command (device,
@@ -195,7 +190,7 @@ load_imsi (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)imsi_subscriber_ready_state_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -207,19 +202,13 @@ load_operator_identifier_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- MbimProvider *provider;
-
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
- return NULL;
-
- provider = (MbimProvider *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
- return g_strdup (provider->provider_id);
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void
load_operator_identifier_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
MbimMessage *response;
GError *error = NULL;
@@ -231,15 +220,15 @@ load_operator_identifier_ready (MbimDevice *device,
mbim_message_home_provider_response_parse (
response,
&provider,
- &error))
- g_simple_async_result_set_op_res_gpointer (simple, provider, (GDestroyNotify)mbim_provider_free);
- else
- g_simple_async_result_take_error (simple, error);
+ &error)) {
+ g_task_return_pointer (task, g_strdup (provider->provider_id), g_free);
+ mbim_provider_free (provider);
+ } else
+ g_task_return_error (task, error);
+ g_object_unref (task);
if (response)
mbim_message_unref (response);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
static void
@@ -249,12 +238,12 @@ load_operator_identifier (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, load_operator_identifier);
+ task = g_task_new (self, NULL, callback, user_data);
message = mbim_message_home_provider_query_new (NULL);
mbim_device_command (device,
@@ -262,7 +251,7 @@ load_operator_identifier (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)load_operator_identifier_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -274,19 +263,13 @@ load_operator_name_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- MbimProvider *provider;
-
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
- return NULL;
-
- provider = (MbimProvider *)g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
- return g_strdup (provider->provider_name);
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void
load_operator_name_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
MbimMessage *response;
GError *error = NULL;
@@ -298,15 +281,15 @@ load_operator_name_ready (MbimDevice *device,
mbim_message_home_provider_response_parse (
response,
&provider,
- &error))
- g_simple_async_result_set_op_res_gpointer (simple, provider, (GDestroyNotify)mbim_provider_free);
- else
- g_simple_async_result_take_error (simple, error);
+ &error)) {
+ g_task_return_pointer (task, g_strdup (provider->provider_name), g_free);
+ mbim_provider_free (provider);
+ } else
+ g_task_return_error (task, error);
+ g_object_unref (task);
if (response)
mbim_message_unref (response);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
static void
@@ -316,12 +299,12 @@ load_operator_name (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, load_operator_name);
+ task = g_task_new (self, NULL, callback, user_data);
message = mbim_message_home_provider_query_new (NULL);
mbim_device_command (device,
@@ -329,7 +312,7 @@ load_operator_name (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)load_operator_name_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -341,13 +324,13 @@ send_pin_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
pin_set_enter_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
GError *error = NULL;
MbimMessage *response;
@@ -376,11 +359,11 @@ pin_set_enter_ready (MbimDevice *device,
}
if (error)
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
else
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+
if (response)
mbim_message_unref (response);
}
@@ -393,13 +376,13 @@ send_pin (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
GError *error = NULL;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, send_pin);
+ task = g_task_new (self, NULL, callback, user_data);
mm_dbg ("Sending PIN...");
message = (mbim_message_pin_set_new (
@@ -409,9 +392,8 @@ send_pin (MMBaseSim *self,
"",
&error));
if (!message) {
- g_simple_async_result_take_error (result, error);
- g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
@@ -420,7 +402,7 @@ send_pin (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)pin_set_enter_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -432,13 +414,13 @@ send_puk_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
puk_set_enter_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
GError *error = NULL;
MbimMessage *response;
@@ -468,11 +450,11 @@ puk_set_enter_ready (MbimDevice *device,
}
if (error)
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
else
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+
if (response)
mbim_message_unref (response);
}
@@ -486,13 +468,13 @@ send_puk (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
GError *error = NULL;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, send_puk);
+ task = g_task_new (self, NULL, callback, user_data);
mm_dbg ("Sending PUK...");
message = (mbim_message_pin_set_new (
@@ -502,9 +484,8 @@ send_puk (MMBaseSim *self,
new_pin,
&error));
if (!message) {
- g_simple_async_result_take_error (result, error);
- g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
@@ -513,7 +494,7 @@ send_puk (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)puk_set_enter_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -525,13 +506,13 @@ enable_pin_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
pin_set_enable_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
GError *error = NULL;
MbimMessage *response;
@@ -550,11 +531,10 @@ pin_set_enable_ready (MbimDevice *device,
"Need to be unlocked to allow enabling/disabling PIN");
}
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
} else
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
@@ -566,13 +546,13 @@ enable_pin (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
GError *error = NULL;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, send_puk);
+ task = g_task_new (self, NULL, callback, user_data);
mm_dbg ("%s PIN ...", enabled ? "Enabling" : "Disabling");
message = (mbim_message_pin_set_new (
@@ -582,9 +562,8 @@ enable_pin (MMBaseSim *self,
"",
&error));
if (!message) {
- g_simple_async_result_take_error (result, error);
- g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
@@ -593,7 +572,7 @@ enable_pin (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)pin_set_enable_ready,
- result);
+ task);
mbim_message_unref (message);
}
@@ -605,13 +584,13 @@ change_pin_finish (MMBaseSim *self,
GAsyncResult *res,
GError **error)
{
- return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
static void
pin_set_change_ready (MbimDevice *device,
GAsyncResult *res,
- GSimpleAsyncResult *simple)
+ GTask *task)
{
GError *error = NULL;
MbimMessage *response;
@@ -630,11 +609,10 @@ pin_set_change_ready (MbimDevice *device,
"Need to be unlocked to allow changing PIN");
}
- g_simple_async_result_take_error (simple, error);
+ g_task_return_error (task, error);
} else
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
static void
@@ -646,13 +624,13 @@ change_pin (MMBaseSim *self,
{
MbimDevice *device;
MbimMessage *message;
- GSimpleAsyncResult *result;
+ GTask *task;
GError *error = NULL;
if (!peek_device (self, &device, callback, user_data))
return;
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, send_puk);
+ task = g_task_new (self, NULL, callback, user_data);
mm_dbg ("Changing PIN");
message = (mbim_message_pin_set_new (
@@ -662,9 +640,8 @@ change_pin (MMBaseSim *self,
new_pin,
&error));
if (!message) {
- g_simple_async_result_take_error (result, error);
- g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
+ g_task_return_error (task, error);
+ g_object_unref (task);
return;
}
@@ -673,7 +650,7 @@ change_pin (MMBaseSim *self,
10,
NULL,
(GAsyncReadyCallback)pin_set_change_ready,
- result);
+ task);
mbim_message_unref (message);
}
--
2.13.2
More information about the ModemManager-devel
mailing list