aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-01-23 11:44:06 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:56 +0100
commite491dc2b9c18f48261b42bbe6cc01eb1ae309e60 (patch)
treeb6503a3e2014520b1b390646dc8b6b5c0fbe7af9 /src
parenta54226a0dda5666b9df5324fbfbc5208795308d8 (diff)
iface-modem-3gpp-ussd: check if USSD supported
Diffstat (limited to 'src')
-rw-r--r--src/mm-iface-modem-3gpp-ussd.c85
-rw-r--r--src/mm-iface-modem-3gpp-ussd.h8
2 files changed, 93 insertions, 0 deletions
diff --git a/src/mm-iface-modem-3gpp-ussd.c b/src/mm-iface-modem-3gpp-ussd.c
index 7642a48b..6e4acffb 100644
--- a/src/mm-iface-modem-3gpp-ussd.c
+++ b/src/mm-iface-modem-3gpp-ussd.c
@@ -25,6 +25,12 @@
#include "mm-modem-helpers.h"
#include "mm-log.h"
+#define SUPPORT_CHECKED_TAG "3gpp-ussd-support-checked-tag"
+#define SUPPORTED_TAG "3gpp-ussd-supported-tag"
+
+static GQuark support_checked_quark;
+static GQuark supported_quark;
+
/*****************************************************************************/
void
@@ -217,6 +223,8 @@ static void interface_initialization_step (InitializationContext *ctx);
typedef enum {
INITIALIZATION_STEP_FIRST,
+ INITIALIZATION_STEP_CHECK_SUPPORT,
+ INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED,
INITIALIZATION_STEP_LAST
} InitializationStep;
@@ -263,10 +271,87 @@ initialization_context_complete_and_free (InitializationContext *ctx)
}
static void
+check_support_ready (MMIfaceModem3gppUssd *self,
+ GAsyncResult *res,
+ InitializationContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->check_support_finish (self,
+ res,
+ &error)) {
+ if (error) {
+ /* This error shouldn't be treated as critical */
+ mm_dbg ("USSD support check failed: '%s'", error->message);
+ g_error_free (error);
+ }
+ } else {
+ /* USSD is supported! */
+ g_object_set_qdata (G_OBJECT (self),
+ supported_quark,
+ GUINT_TO_POINTER (TRUE));
+ }
+
+ /* Go on to next step */
+ ctx->step++;
+ interface_initialization_step (ctx);
+}
+
+static void
interface_initialization_step (InitializationContext *ctx)
{
switch (ctx->step) {
case INITIALIZATION_STEP_FIRST:
+ /* Setup quarks if we didn't do it before */
+ if (G_UNLIKELY (!support_checked_quark))
+ support_checked_quark = (g_quark_from_static_string (
+ SUPPORT_CHECKED_TAG));
+ if (G_UNLIKELY (!supported_quark))
+ supported_quark = (g_quark_from_static_string (
+ SUPPORTED_TAG));
+
+ /* Fall down to next step */
+ ctx->step++;
+
+ case INITIALIZATION_STEP_CHECK_SUPPORT:
+ if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (ctx->self),
+ support_checked_quark))) {
+ /* Set the checked flag so that we don't run it again */
+ g_object_set_qdata (G_OBJECT (ctx->self),
+ support_checked_quark,
+ GUINT_TO_POINTER (TRUE));
+ /* Initially, assume we don't support it */
+ g_object_set_qdata (G_OBJECT (ctx->self),
+ supported_quark,
+ GUINT_TO_POINTER (FALSE));
+
+ if (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support &&
+ MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support_finish) {
+ MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->check_support (
+ ctx->self,
+ (GAsyncReadyCallback)check_support_ready,
+ ctx);
+ return;
+ }
+
+ /* If there is no implementation to check support, assume we DON'T
+ * support it. */
+ }
+
+ /* Fall down to next step */
+ ctx->step++;
+
+ case INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED:
+ if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (ctx->self),
+ supported_quark))) {
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "USSD not supported");
+ initialization_context_complete_and_free (ctx);
+ return;
+ }
+
/* Fall down to next step */
ctx->step++;
diff --git a/src/mm-iface-modem-3gpp-ussd.h b/src/mm-iface-modem-3gpp-ussd.h
index c46cc871..868136ec 100644
--- a/src/mm-iface-modem-3gpp-ussd.h
+++ b/src/mm-iface-modem-3gpp-ussd.h
@@ -34,6 +34,14 @@ typedef struct _MMIfaceModem3gppUssd MMIfaceModem3gppUssd;
struct _MMIfaceModem3gppUssd {
GTypeInterface g_iface;
+
+ /* Check for USSD support (async) */
+ void (* check_support) (MMIfaceModem3gppUssd *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*check_support_finish) (MMIfaceModem3gppUssd *self,
+ GAsyncResult *res,
+ GError **error);
};
GType mm_iface_modem_3gpp_ussd_get_type (void);