iface-modem-messaging: load initial parts from all available storages

This commit is contained in:
Aleksander Morgado
2012-02-10 15:43:34 +01:00
parent cd184f33f9
commit 9e3f66393f
3 changed files with 108 additions and 14 deletions

View File

@@ -4162,16 +4162,23 @@ sms_pdu_part_list_ready (MMBroadbandModem *self,
}
static void
modem_messaging_load_initial_sms_parts (MMIfaceModemMessaging *self,
GAsyncReadyCallback callback,
gpointer user_data)
list_parts_storage_ready (MMBroadbandModem *self,
GAsyncResult *res,
GSimpleAsyncResult *simple)
{
GSimpleAsyncResult *result;
GError *error = NULL;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_messaging_load_initial_sms_parts);
if (!mm_iface_modem_messaging_set_preferred_storages_finish (
MM_IFACE_MODEM_MESSAGING (self),
res,
&error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
return;
}
/* Storage now set */
/* Get SMS parts from ALL types.
* Different command to be used if we are on Text or PDU mode */
@@ -4185,7 +4192,32 @@ modem_messaging_load_initial_sms_parts (MMIfaceModemMessaging *self,
(GAsyncReadyCallback) (MM_BROADBAND_MODEM (self)->priv->modem_messaging_sms_pdu_mode ?
sms_pdu_part_list_ready :
sms_text_part_list_ready),
result);
simple);
}
static void
modem_messaging_load_initial_sms_parts (MMIfaceModemMessaging *self,
MMSmsStorage storage,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_messaging_load_initial_sms_parts);
mm_dbg ("Listing SMS parts in storage '%s'",
mm_sms_storage_get_string (storage));
/* First, request to set the proper storage to read from */
mm_iface_modem_messaging_set_preferred_storages (self,
storage,
MM_SMS_STORAGE_UNKNOWN,
MM_SMS_STORAGE_UNKNOWN,
(GAsyncReadyCallback)list_parts_storage_ready,
result);
}
/*****************************************************************************/

View File

@@ -317,6 +317,10 @@ is_storage_supported (GArray *supported,
{
guint i;
/* We do allow setting UNKNOWN here, so that we set the *default* storage */
if (preferred == MM_SMS_STORAGE_UNKNOWN)
return TRUE;
for (i = 0; i < supported->len; i++) {
if (preferred == g_array_index (supported, MMSmsStorage, i))
return TRUE;
@@ -537,6 +541,8 @@ struct _EnablingContext {
EnablingStep step;
GSimpleAsyncResult *result;
MmGdbusModemMessaging *skeleton;
guint mem1_storage_index;
};
static EnablingContext *
@@ -604,7 +610,63 @@ mm_iface_modem_messaging_enable_finish (MMIfaceModemMessaging *self,
VOID_REPLY_READY_FN (setup_sms_format)
VOID_REPLY_READY_FN (setup_unsolicited_events)
VOID_REPLY_READY_FN (load_initial_sms_parts)
static void load_initial_sms_parts_from_storages (EnablingContext *ctx);
static void
load_initial_sms_parts_ready (MMIfaceModemMessaging *self,
GAsyncResult *res,
EnablingContext *ctx)
{
GError *error = NULL;
MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->load_initial_sms_parts_finish (self, res, &error);
if (error) {
g_simple_async_result_take_error (ctx->result, error);
enabling_context_complete_and_free (ctx);
return;
}
/* Go on with the storage iteration */
ctx->mem1_storage_index++;
load_initial_sms_parts_from_storages (ctx);
}
static void
load_initial_sms_parts_from_storages (EnablingContext *ctx)
{
gboolean all_loaded = FALSE;
StorageContext *storage_ctx;
storage_ctx = get_storage_context (ctx->self);
if (ctx->mem1_storage_index >= storage_ctx->supported_mem1->len)
all_loaded = TRUE;
/* We'll skip the 'MT' storage, as that is a combination of 'SM' and 'ME' */
else if (g_array_index (storage_ctx->supported_mem1,
MMSmsStorage,
ctx->mem1_storage_index) == MM_SMS_STORAGE_MT) {
ctx->mem1_storage_index++;
if (ctx->mem1_storage_index >= storage_ctx->supported_mem1->len)
all_loaded = TRUE;
}
if (all_loaded) {
/* Go on with next step */
ctx->step++;
interface_enabling_step (ctx);
return;
}
MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->load_initial_sms_parts (
ctx->self,
g_array_index (storage_ctx->supported_mem1,
MMSmsStorage,
ctx->mem1_storage_index),
(GAsyncReadyCallback)load_initial_sms_parts_ready,
ctx);
return;
}
static void
interface_enabling_step (EnablingContext *ctx)
@@ -664,10 +726,7 @@ interface_enabling_step (EnablingContext *ctx)
/* Allow loading the initial list of SMS parts */
if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->load_initial_sms_parts &&
MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->load_initial_sms_parts_finish) {
MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->load_initial_sms_parts (
ctx->self,
(GAsyncReadyCallback)load_initial_sms_parts_ready,
ctx);
load_initial_sms_parts_from_storages (ctx);
return;
}
/* Fall down to next step */
@@ -872,6 +931,8 @@ interface_initialization_step (InitializationContext *ctx)
initialization_context_complete_and_free (ctx);
return;
}
/* Fall down to next step */
ctx->step++;
case INITIALIZATION_STEP_LOAD_SUPPORTED_STORAGES:
if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (ctx->self)->load_supported_storages &&

View File

@@ -101,6 +101,7 @@ struct _MMIfaceModemMessaging {
/* Load initial SMS parts (async).
* Found parts need to be reported with take_part() */
void (* load_initial_sms_parts) (MMIfaceModemMessaging *self,
MMSmsStorage storage,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*load_initial_sms_parts_finish) (MMIfaceModemMessaging *self,