api: Sms.Store() now requires the specific memory storage where to store the SMS

... or MM_SMS_STORAGE_UNKNOWN to store it in the default storage.
This commit is contained in:
Aleksander Morgado
2012-09-10 14:18:00 +02:00
parent 96928909b9
commit 667026f0c8
7 changed files with 96 additions and 30 deletions

View File

@@ -238,6 +238,7 @@ get_sms_ready (GObject *source,
/* Requesting to store the SMS? */
if (store_flag) {
mm_sms_store (ctx->sms,
MM_SMS_STORAGE_UNKNOWN,
ctx->cancellable,
(GAsyncReadyCallback)store_ready,
NULL);
@@ -302,6 +303,7 @@ mmcli_sms_run_synchronous (GDBusConnection *connection)
gboolean operation_result;
operation_result = mm_sms_store_sync (ctx->sms,
MM_SMS_STORAGE_UNKNOWN,
NULL,
&error);
store_process_reply (operation_result, error);

View File

@@ -30,8 +30,15 @@
Store:
Store the message in the device if not already done.
This method requires a <link linkend="MMSmsStorage">MMSmsStorage</link>
value, describing the storage where this message is to be kept; or
<link linkend="MM-SMS-STORAGE-UNKNOWN:CAPS"><constant>MM_SMS_STORAGE_UNKNOWN</constant></link>
if the default storage should be used.
-->
<method name="Store" />
<method name="Store">
<arg name="storage" type="u" direction="in" />
</method>
<!--
State:

View File

@@ -347,6 +347,7 @@ mm_sms_send_sync (MMSms *self,
/**
* mm_sms_store:
* @self: A #MMSms.
* @storage: A #MMSmsStorage specifying where to store the SMS, or #MM_SMS_STORAGE_UNKNOWN to use the default.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
@@ -360,6 +361,7 @@ mm_sms_send_sync (MMSms *self,
*/
void
mm_sms_store (MMSms *self,
MMSmsStorage storage,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -367,6 +369,7 @@ mm_sms_store (MMSms *self,
g_return_if_fail (MM_GDBUS_IS_SMS (self));
mm_gdbus_sms_call_store (self,
storage,
cancellable,
callback,
user_data);
@@ -395,6 +398,7 @@ mm_sms_store_finish (MMSms *self,
/**
* mm_sms_store_sync:
* @self: A #MMSms.
* @storage: A #MMSmsStorage specifying where to store the SMS, or #MM_SMS_STORAGE_UNKNOWN to use the default.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
@@ -407,12 +411,14 @@ mm_sms_store_finish (MMSms *self,
*/
gboolean
mm_sms_store_sync (MMSms *self,
MMSmsStorage storage,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_GDBUS_IS_SMS (self), FALSE);
return mm_gdbus_sms_call_store_sync (self,
storage,
cancellable,
error);
}

View File

@@ -61,6 +61,7 @@ gboolean mm_sms_send_sync (MMSms *self,
GError **error);
void mm_sms_store (MMSms *self,
MMSmsStorage storage,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -68,6 +69,7 @@ gboolean mm_sms_store_finish (MMSms *self,
GAsyncResult *res,
GError **error);
gboolean mm_sms_store_sync (MMSms *self,
MMSmsStorage storage,
GCancellable *cancellable,
GError **error);

View File

@@ -192,6 +192,7 @@ sms_store_next_part (SmsStoreContext *ctx)
static void
sms_store (MMSms *self,
MMSmsStorage storage,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -212,12 +213,10 @@ sms_store (MMSms *self,
sms_store);
ctx->self = g_object_ref (self);
ctx->client = g_object_ref (client);
ctx->storage = storage;
g_object_get (self,
MM_SMS_MODEM, &ctx->modem,
NULL);
g_object_get (ctx->modem,
MM_IFACE_MODEM_MESSAGING_SMS_MEM2_STORAGE, &ctx->storage,
NULL);
ctx->current = mm_sms_get_parts (self);
sms_store_next_part (ctx);

View File

@@ -25,6 +25,7 @@
#include <ModemManager.h>
#include <libmm-common.h>
#include "mm-broadband-modem.h"
#include "mm-iface-modem.h"
#include "mm-iface-modem-messaging.h"
#include "mm-sms.h"
@@ -77,6 +78,7 @@ typedef struct {
MMSms *self;
MMBaseModem *modem;
GDBusMethodInvocation *invocation;
MMSmsStorage storage;
} HandleStoreContext;
static void
@@ -98,13 +100,7 @@ handle_store_ready (MMSms *self,
if (!MM_SMS_GET_CLASS (self)->store_finish (self, res, &error))
g_dbus_method_invocation_take_error (ctx->invocation, error);
else {
MMSmsStorage storage = MM_SMS_STORAGE_UNKNOWN;
/* We'll set now the proper storage, taken from the default mem2 one */
g_object_get (self->priv->modem,
MM_IFACE_MODEM_MESSAGING_SMS_MEM2_STORAGE, &storage,
NULL);
mm_gdbus_sms_set_storage (MM_GDBUS_SMS (ctx->self), storage);
mm_gdbus_sms_set_storage (MM_GDBUS_SMS (ctx->self), ctx->storage);
/* Transition from Unknown->Stored for SMS which were created by the user */
if (mm_gdbus_sms_get_state (MM_GDBUS_SMS (ctx->self)) == MM_SMS_STATE_UNKNOWN)
@@ -116,19 +112,6 @@ handle_store_ready (MMSms *self,
handle_store_context_free (ctx);
}
static gboolean
sms_is_stored (MMSms *self)
{
GList *l;
for (l = self->priv->parts; l; l = g_list_next (l)) {
if (mm_sms_part_get_index ((MMSmsPart *)l->data) == SMS_PART_INVALID_INDEX)
return FALSE;
}
return TRUE;
}
static void
handle_store_auth_ready (MMBaseModem *modem,
GAsyncResult *res,
@@ -143,8 +126,28 @@ handle_store_auth_ready (MMBaseModem *modem,
}
/* First of all, check if we already have the SMS stored. */
if (sms_is_stored (ctx->self)) {
mm_gdbus_sms_complete_store (MM_GDBUS_SMS (ctx->self), ctx->invocation);
if (mm_sms_get_storage (ctx->self) != MM_SMS_STORAGE_UNKNOWN) {
/* Check if SMS stored in some other storage */
if (mm_sms_get_storage (ctx->self) == ctx->storage)
/* Good, same storage */
mm_gdbus_sms_complete_store (MM_GDBUS_SMS (ctx->self), ctx->invocation);
else
g_dbus_method_invocation_return_error (
ctx->invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"SMS is already stored in storage '%s', cannot store it in storage '%s'",
mm_sms_storage_get_string (mm_sms_get_storage (ctx->self)),
mm_sms_storage_get_string (ctx->storage));
handle_store_context_free (ctx);
return;
}
/* Check if the requested storage is allowed for storing */
if (!mm_iface_modem_messaging_is_storage_supported_for_storing (MM_IFACE_MODEM_MESSAGING (ctx->modem),
ctx->storage,
&error)) {
g_dbus_method_invocation_take_error (ctx->invocation, error);
handle_store_context_free (ctx);
return;
}
@@ -161,13 +164,15 @@ handle_store_auth_ready (MMBaseModem *modem,
}
MM_SMS_GET_CLASS (ctx->self)->store (ctx->self,
ctx->storage,
(GAsyncReadyCallback)handle_store_ready,
ctx);
}
static gboolean
handle_store (MMSms *self,
GDBusMethodInvocation *invocation)
GDBusMethodInvocation *invocation,
guint32 storage)
{
HandleStoreContext *ctx;
@@ -177,6 +182,15 @@ handle_store (MMSms *self,
g_object_get (self,
MM_SMS_MODEM, &ctx->modem,
NULL);
ctx->storage = (MMSmsStorage)storage;
if (ctx->storage == MM_SMS_STORAGE_UNKNOWN) {
/* We'll set now the proper storage, taken from the default mem2 one */
g_object_get (self->priv->modem,
MM_IFACE_MODEM_MESSAGING_SMS_MEM2_STORAGE, &ctx->storage,
NULL);
g_assert (ctx->storage != MM_SMS_STORAGE_UNKNOWN);
}
mm_base_modem_authorize (ctx->modem,
invocation,
@@ -473,6 +487,8 @@ typedef struct {
MMSms *self;
MMBaseModem *modem;
GSimpleAsyncResult *result;
MMSmsStorage storage;
gboolean need_unlock;
gboolean use_pdu_mode;
GList *current;
gchar *msg_data;
@@ -481,8 +497,11 @@ typedef struct {
static void
sms_store_context_complete_and_free (SmsStoreContext *ctx)
{
g_simple_async_result_complete_in_idle (ctx->result);
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
/* Unlock storages if we had the lock */
if (ctx->need_unlock)
mm_broadband_modem_unlock_sms_storages (MM_BROADBAND_MODEM (ctx->modem));
g_object_unref (ctx->modem);
g_object_unref (ctx->self);
g_free (ctx->msg_data);
@@ -601,8 +620,31 @@ sms_store_next_part (SmsStoreContext *ctx)
g_free (cmd);
}
static void
store_lock_sms_storages_ready (MMBroadbandModem *modem,
GAsyncResult *res,
SmsStoreContext *ctx)
{
GError *error = NULL;
if (!mm_broadband_modem_lock_sms_storages_finish (modem, res, &error)) {
g_simple_async_result_take_error (ctx->result, error);
sms_store_context_complete_and_free (ctx);
return;
}
/* We are now locked. Whatever result we have here, we need to make sure
* we unlock the storages before finishing. */
ctx->need_unlock = TRUE;
/* Go on to store the parts */
ctx->current = ctx->self->priv->parts;
sms_store_next_part (ctx);
}
static void
sms_store (MMSms *self,
MMSmsStorage storage,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -616,14 +658,21 @@ sms_store (MMSms *self,
sms_store);
ctx->self = g_object_ref (self);
ctx->modem = g_object_ref (self->priv->modem);
ctx->storage = storage;
/* Different ways to do it if on PDU or text mode */
g_object_get (self->priv->modem,
MM_IFACE_MODEM_MESSAGING_SMS_PDU_MODE, &ctx->use_pdu_mode,
NULL);
ctx->current = self->priv->parts;
sms_store_next_part (ctx);
/* First, lock storage to use */
g_assert (MM_IS_BROADBAND_MODEM (self->priv->modem));
mm_broadband_modem_lock_sms_storages (
MM_BROADBAND_MODEM (self->priv->modem),
MM_SMS_STORAGE_UNKNOWN, /* none required for mem1 */
ctx->storage,
(GAsyncReadyCallback)store_lock_sms_storages_ready,
ctx);
}
/*****************************************************************************/

View File

@@ -54,6 +54,7 @@ struct _MMSmsClass {
/* Store the SMS */
void (* store) (MMSms *self,
MMSmsStorage storage,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* store_finish) (MMSms *self,