iface-modem: setup modem charset configuration during enable

Load supported charsets, and loop trying to set the best one.
This commit is contained in:
Aleksander Morgado
2011-11-25 15:05:56 +01:00
parent c0d3bd944c
commit 781c1821fd
2 changed files with 125 additions and 0 deletions

View File

@@ -757,6 +757,8 @@ typedef enum {
ENABLING_STEP_MODEM_POWER_UP,
ENABLING_STEP_MODEM_AFTER_POWER_UP,
ENABLING_STEP_FLOW_CONTROL,
ENABLING_STEP_SUPPORTED_CHARSETS,
ENABLING_STEP_MODEM_CHARSET,
ENABLING_STEP_LAST
} EnablingStep;
@@ -765,6 +767,8 @@ struct _EnablingContext {
MMAtSerialPort *primary;
gboolean primary_open;
EnablingStep step;
MMModemCharset supported_charsets;
const MMModemCharset *current_charset;
gboolean enabled;
GSimpleAsyncResult *result;
MmGdbusModem *skeleton;
@@ -859,6 +863,46 @@ VOID_REPLY_READY_FN (modem_power_up);
VOID_REPLY_READY_FN (modem_after_power_up);
VOID_REPLY_READY_FN (modem_flow_control);
static void
load_supported_charsets_ready (MMIfaceModem *self,
GAsyncResult *res,
EnablingContext *ctx)
{
GError *error = NULL;
ctx->supported_charsets =
MM_IFACE_MODEM_GET_INTERFACE (self)->load_supported_charsets_finish (self, res, &error);
if (error) {
mm_warn ("couldn't load Supported Charsets: '%s'", error->message);
g_error_free (error);
}
/* Go on to next step */
ctx->step++;
interface_enabling_step (ctx);
}
static void
modem_charset_ready (MMIfaceModem *self,
GAsyncResult *res,
EnablingContext *ctx)
{
GError *error = NULL;
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->modem_charset_finish (self, res, &error)) {
mm_dbg ("couldn't set charset '%s': '%s'",
mm_modem_charset_to_string (*ctx->current_charset),
error->message);
g_error_free (error);
/* Will retry step with some other charset type */
} else
/* Done, Go on to next step */
ctx->step++;
interface_enabling_step (ctx);
}
static void
interface_enabling_flash_done (MMSerialPort *port,
GError *error,
@@ -877,6 +921,15 @@ interface_enabling_flash_done (MMSerialPort *port,
interface_enabling_step (ctx);
}
static const MMModemCharset best_charsets[] = {
MM_MODEM_CHARSET_UTF8,
MM_MODEM_CHARSET_UCS2,
MM_MODEM_CHARSET_8859_1,
MM_MODEM_CHARSET_IRA,
MM_MODEM_CHARSET_GSM,
MM_MODEM_CHARSET_UNKNOWN
};
static void
interface_enabling_step (EnablingContext *ctx)
{
@@ -956,6 +1009,59 @@ interface_enabling_step (EnablingContext *ctx)
/* Fall down to next step */
ctx->step++;
case ENABLING_STEP_SUPPORTED_CHARSETS:
if (MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_charsets &&
MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_charsets_finish) {
MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->load_supported_charsets (
ctx->self,
(GAsyncReadyCallback)load_supported_charsets_ready,
ctx);
return;
}
/* Fall down to next step */
ctx->step++;
case ENABLING_STEP_MODEM_CHARSET:
/* Only try to set charsets if we were able to load supported ones */
if (ctx->supported_charsets > 0 &&
MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->modem_charset &&
MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->modem_charset_finish) {
gboolean next_to_try = FALSE;
while (!next_to_try) {
if (!ctx->current_charset)
/* Switch the device's charset; we prefer UTF-8, but UCS2 will do too */
ctx->current_charset = &best_charsets[0];
else
/* Try with the next one */
ctx->current_charset++;
if (*ctx->current_charset == MM_MODEM_CHARSET_UNKNOWN)
break;
if (ctx->supported_charsets & (*ctx->current_charset))
next_to_try = TRUE;
}
if (next_to_try) {
MM_IFACE_MODEM_GET_INTERFACE (ctx->self)->modem_charset (
ctx->self,
*ctx->current_charset,
(GAsyncReadyCallback)modem_charset_ready,
ctx);
return;
}
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Failed to find a usable modem character set");
enabling_context_complete_and_free (ctx);
return;
}
/* Fall down to next step */
ctx->step++;
case ENABLING_STEP_LAST:
/* We are done without errors! */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);

View File

@@ -19,6 +19,8 @@
#include <glib-object.h>
#include <gio/gio.h>
#include "mm-charsets.h"
#define MM_TYPE_IFACE_MODEM (mm_iface_modem_get_type ())
#define MM_IFACE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_IFACE_MODEM, MMIfaceModem))
#define MM_IS_IFACE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_IFACE_MODEM))
@@ -215,6 +217,23 @@ struct _MMIfaceModem {
gboolean (*modem_flow_control_finish) (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
/* Asynchronous loading of supported charsets */
void (*load_supported_charsets) (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data);
MMModemCharset (*load_supported_charsets_finish) (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
/* Asynchronous charset setting setup */
void (*modem_charset) (MMIfaceModem *self,
MMModemCharset charset,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*modem_charset_finish) (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
};
GType mm_iface_modem_get_type (void);