iface-modem-3gpp-ussd: port mm_iface_modem_3gpp_ussd_initialize to use GTask
This commit is contained in:

committed by
Aleksander Morgado

parent
3d800c2f49
commit
e8a647ddee
@@ -745,7 +745,7 @@ mm_iface_modem_3gpp_ussd_enable (MMIfaceModem3gppUssd *self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
typedef struct _InitializationContext InitializationContext;
|
typedef struct _InitializationContext InitializationContext;
|
||||||
static void interface_initialization_step (InitializationContext *ctx);
|
static void interface_initialization_step (GTask *task);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
INITIALIZATION_STEP_FIRST,
|
INITIALIZATION_STEP_FIRST,
|
||||||
@@ -755,18 +755,13 @@ typedef enum {
|
|||||||
} InitializationStep;
|
} InitializationStep;
|
||||||
|
|
||||||
struct _InitializationContext {
|
struct _InitializationContext {
|
||||||
MMIfaceModem3gppUssd *self;
|
|
||||||
MmGdbusModem3gppUssd *skeleton;
|
MmGdbusModem3gppUssd *skeleton;
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
InitializationStep step;
|
InitializationStep step;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initialization_context_complete_and_free (InitializationContext *ctx)
|
initialization_context_free (InitializationContext *ctx)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (ctx->result);
|
|
||||||
g_object_unref (ctx->self);
|
|
||||||
g_object_unref (ctx->result);
|
|
||||||
g_object_unref (ctx->skeleton);
|
g_object_unref (ctx->skeleton);
|
||||||
g_free (ctx);
|
g_free (ctx);
|
||||||
}
|
}
|
||||||
@@ -774,8 +769,9 @@ initialization_context_complete_and_free (InitializationContext *ctx)
|
|||||||
static void
|
static void
|
||||||
check_support_ready (MMIfaceModem3gppUssd *self,
|
check_support_ready (MMIfaceModem3gppUssd *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
InitializationContext *ctx)
|
GTask *task)
|
||||||
{
|
{
|
||||||
|
InitializationContext *ctx;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support_finish (self,
|
if (!MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support_finish (self,
|
||||||
@@ -794,13 +790,20 @@ check_support_ready (MMIfaceModem3gppUssd *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Go on to next step */
|
/* Go on to next step */
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
ctx->step++;
|
ctx->step++;
|
||||||
interface_initialization_step (ctx);
|
interface_initialization_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
interface_initialization_step (InitializationContext *ctx)
|
interface_initialization_step (GTask *task)
|
||||||
{
|
{
|
||||||
|
MMIfaceModem3gppUssd *self;
|
||||||
|
InitializationContext *ctx;
|
||||||
|
|
||||||
|
self = g_task_get_source_object (task);
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
switch (ctx->step) {
|
switch (ctx->step) {
|
||||||
case INITIALIZATION_STEP_FIRST:
|
case INITIALIZATION_STEP_FIRST:
|
||||||
/* Setup quarks if we didn't do it before */
|
/* Setup quarks if we didn't do it before */
|
||||||
@@ -815,23 +818,23 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
ctx->step++;
|
ctx->step++;
|
||||||
|
|
||||||
case INITIALIZATION_STEP_CHECK_SUPPORT:
|
case INITIALIZATION_STEP_CHECK_SUPPORT:
|
||||||
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (ctx->self),
|
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self),
|
||||||
support_checked_quark))) {
|
support_checked_quark))) {
|
||||||
/* Set the checked flag so that we don't run it again */
|
/* Set the checked flag so that we don't run it again */
|
||||||
g_object_set_qdata (G_OBJECT (ctx->self),
|
g_object_set_qdata (G_OBJECT (self),
|
||||||
support_checked_quark,
|
support_checked_quark,
|
||||||
GUINT_TO_POINTER (TRUE));
|
GUINT_TO_POINTER (TRUE));
|
||||||
/* Initially, assume we don't support it */
|
/* Initially, assume we don't support it */
|
||||||
g_object_set_qdata (G_OBJECT (ctx->self),
|
g_object_set_qdata (G_OBJECT (self),
|
||||||
supported_quark,
|
supported_quark,
|
||||||
GUINT_TO_POINTER (FALSE));
|
GUINT_TO_POINTER (FALSE));
|
||||||
|
|
||||||
if (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support &&
|
if (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support &&
|
||||||
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support_finish) {
|
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support_finish) {
|
||||||
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support (
|
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support (
|
||||||
ctx->self,
|
self,
|
||||||
(GAsyncReadyCallback)check_support_ready,
|
(GAsyncReadyCallback)check_support_ready,
|
||||||
ctx);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -843,13 +846,13 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
ctx->step++;
|
ctx->step++;
|
||||||
|
|
||||||
case INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED:
|
case INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED:
|
||||||
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (ctx->self),
|
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self),
|
||||||
supported_quark))) {
|
supported_quark))) {
|
||||||
g_simple_async_result_set_error (ctx->result,
|
g_task_return_new_error (task,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_UNSUPPORTED,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"USSD not supported");
|
"USSD not supported");
|
||||||
initialization_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,22 +866,22 @@ interface_initialization_step (InitializationContext *ctx)
|
|||||||
g_signal_connect (ctx->skeleton,
|
g_signal_connect (ctx->skeleton,
|
||||||
"handle-initiate",
|
"handle-initiate",
|
||||||
G_CALLBACK (handle_initiate),
|
G_CALLBACK (handle_initiate),
|
||||||
ctx->self);
|
self);
|
||||||
g_signal_connect (ctx->skeleton,
|
g_signal_connect (ctx->skeleton,
|
||||||
"handle-respond",
|
"handle-respond",
|
||||||
G_CALLBACK (handle_respond),
|
G_CALLBACK (handle_respond),
|
||||||
ctx->self);
|
self);
|
||||||
g_signal_connect (ctx->skeleton,
|
g_signal_connect (ctx->skeleton,
|
||||||
"handle-cancel",
|
"handle-cancel",
|
||||||
G_CALLBACK (handle_cancel),
|
G_CALLBACK (handle_cancel),
|
||||||
ctx->self);
|
self);
|
||||||
|
|
||||||
/* Finally, export the new interface */
|
/* Finally, export the new interface */
|
||||||
mm_gdbus_object_skeleton_set_modem3gpp_ussd (MM_GDBUS_OBJECT_SKELETON (ctx->self),
|
mm_gdbus_object_skeleton_set_modem3gpp_ussd (MM_GDBUS_OBJECT_SKELETON (self),
|
||||||
MM_GDBUS_MODEM3GPP_USSD (ctx->skeleton));
|
MM_GDBUS_MODEM3GPP_USSD (ctx->skeleton));
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
initialization_context_complete_and_free (ctx);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,7 +893,7 @@ mm_iface_modem_3gpp_ussd_initialize_finish (MMIfaceModem3gppUssd *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -900,6 +903,7 @@ mm_iface_modem_3gpp_ussd_initialize (MMIfaceModem3gppUssd *self,
|
|||||||
{
|
{
|
||||||
InitializationContext *ctx;
|
InitializationContext *ctx;
|
||||||
MmGdbusModem3gppUssd *skeleton = NULL;
|
MmGdbusModem3gppUssd *skeleton = NULL;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
/* Did we already create it? */
|
/* Did we already create it? */
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
@@ -921,15 +925,13 @@ mm_iface_modem_3gpp_ussd_initialize (MMIfaceModem3gppUssd *self,
|
|||||||
/* Perform async initialization here */
|
/* Perform async initialization here */
|
||||||
|
|
||||||
ctx = g_new0 (InitializationContext, 1);
|
ctx = g_new0 (InitializationContext, 1);
|
||||||
ctx->self = g_object_ref (self);
|
|
||||||
ctx->result = g_simple_async_result_new (G_OBJECT (self),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
mm_iface_modem_3gpp_ussd_initialize);
|
|
||||||
ctx->step = INITIALIZATION_STEP_FIRST;
|
ctx->step = INITIALIZATION_STEP_FIRST;
|
||||||
ctx->skeleton = skeleton;
|
ctx->skeleton = skeleton;
|
||||||
|
|
||||||
interface_initialization_step (ctx);
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
|
g_task_set_task_data (task, ctx, (GDestroyNotify)initialization_context_free);
|
||||||
|
|
||||||
|
interface_initialization_step (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user