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:
@@ -238,6 +238,7 @@ get_sms_ready (GObject *source,
|
|||||||
/* Requesting to store the SMS? */
|
/* Requesting to store the SMS? */
|
||||||
if (store_flag) {
|
if (store_flag) {
|
||||||
mm_sms_store (ctx->sms,
|
mm_sms_store (ctx->sms,
|
||||||
|
MM_SMS_STORAGE_UNKNOWN,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(GAsyncReadyCallback)store_ready,
|
(GAsyncReadyCallback)store_ready,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -302,6 +303,7 @@ mmcli_sms_run_synchronous (GDBusConnection *connection)
|
|||||||
gboolean operation_result;
|
gboolean operation_result;
|
||||||
|
|
||||||
operation_result = mm_sms_store_sync (ctx->sms,
|
operation_result = mm_sms_store_sync (ctx->sms,
|
||||||
|
MM_SMS_STORAGE_UNKNOWN,
|
||||||
NULL,
|
NULL,
|
||||||
&error);
|
&error);
|
||||||
store_process_reply (operation_result, error);
|
store_process_reply (operation_result, error);
|
||||||
|
@@ -30,8 +30,15 @@
|
|||||||
Store:
|
Store:
|
||||||
|
|
||||||
Store the message in the device if not already done.
|
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:
|
State:
|
||||||
|
@@ -347,6 +347,7 @@ mm_sms_send_sync (MMSms *self,
|
|||||||
/**
|
/**
|
||||||
* mm_sms_store:
|
* mm_sms_store:
|
||||||
* @self: A #MMSms.
|
* @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.
|
* @cancellable: (allow-none): A #GCancellable or %NULL.
|
||||||
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
|
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
|
||||||
* @user_data: User data to pass to @callback.
|
* @user_data: User data to pass to @callback.
|
||||||
@@ -360,6 +361,7 @@ mm_sms_send_sync (MMSms *self,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
mm_sms_store (MMSms *self,
|
mm_sms_store (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
@@ -367,6 +369,7 @@ mm_sms_store (MMSms *self,
|
|||||||
g_return_if_fail (MM_GDBUS_IS_SMS (self));
|
g_return_if_fail (MM_GDBUS_IS_SMS (self));
|
||||||
|
|
||||||
mm_gdbus_sms_call_store (self,
|
mm_gdbus_sms_call_store (self,
|
||||||
|
storage,
|
||||||
cancellable,
|
cancellable,
|
||||||
callback,
|
callback,
|
||||||
user_data);
|
user_data);
|
||||||
@@ -395,6 +398,7 @@ mm_sms_store_finish (MMSms *self,
|
|||||||
/**
|
/**
|
||||||
* mm_sms_store_sync:
|
* mm_sms_store_sync:
|
||||||
* @self: A #MMSms.
|
* @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.
|
* @cancellable: (allow-none): A #GCancellable or %NULL.
|
||||||
* @error: Return location for error or %NULL.
|
* @error: Return location for error or %NULL.
|
||||||
*
|
*
|
||||||
@@ -407,12 +411,14 @@ mm_sms_store_finish (MMSms *self,
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
mm_sms_store_sync (MMSms *self,
|
mm_sms_store_sync (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (MM_GDBUS_IS_SMS (self), FALSE);
|
g_return_val_if_fail (MM_GDBUS_IS_SMS (self), FALSE);
|
||||||
|
|
||||||
return mm_gdbus_sms_call_store_sync (self,
|
return mm_gdbus_sms_call_store_sync (self,
|
||||||
|
storage,
|
||||||
cancellable,
|
cancellable,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,7 @@ gboolean mm_sms_send_sync (MMSms *self,
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
void mm_sms_store (MMSms *self,
|
void mm_sms_store (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
@@ -68,6 +69,7 @@ gboolean mm_sms_store_finish (MMSms *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean mm_sms_store_sync (MMSms *self,
|
gboolean mm_sms_store_sync (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
@@ -192,6 +192,7 @@ sms_store_next_part (SmsStoreContext *ctx)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
sms_store (MMSms *self,
|
sms_store (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -212,12 +213,10 @@ sms_store (MMSms *self,
|
|||||||
sms_store);
|
sms_store);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->client = g_object_ref (client);
|
ctx->client = g_object_ref (client);
|
||||||
|
ctx->storage = storage;
|
||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
MM_SMS_MODEM, &ctx->modem,
|
MM_SMS_MODEM, &ctx->modem,
|
||||||
NULL);
|
NULL);
|
||||||
g_object_get (ctx->modem,
|
|
||||||
MM_IFACE_MODEM_MESSAGING_SMS_MEM2_STORAGE, &ctx->storage,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
ctx->current = mm_sms_get_parts (self);
|
ctx->current = mm_sms_get_parts (self);
|
||||||
sms_store_next_part (ctx);
|
sms_store_next_part (ctx);
|
||||||
|
101
src/mm-sms.c
101
src/mm-sms.c
@@ -25,6 +25,7 @@
|
|||||||
#include <ModemManager.h>
|
#include <ModemManager.h>
|
||||||
#include <libmm-common.h>
|
#include <libmm-common.h>
|
||||||
|
|
||||||
|
#include "mm-broadband-modem.h"
|
||||||
#include "mm-iface-modem.h"
|
#include "mm-iface-modem.h"
|
||||||
#include "mm-iface-modem-messaging.h"
|
#include "mm-iface-modem-messaging.h"
|
||||||
#include "mm-sms.h"
|
#include "mm-sms.h"
|
||||||
@@ -77,6 +78,7 @@ typedef struct {
|
|||||||
MMSms *self;
|
MMSms *self;
|
||||||
MMBaseModem *modem;
|
MMBaseModem *modem;
|
||||||
GDBusMethodInvocation *invocation;
|
GDBusMethodInvocation *invocation;
|
||||||
|
MMSmsStorage storage;
|
||||||
} HandleStoreContext;
|
} HandleStoreContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -98,13 +100,7 @@ handle_store_ready (MMSms *self,
|
|||||||
if (!MM_SMS_GET_CLASS (self)->store_finish (self, res, &error))
|
if (!MM_SMS_GET_CLASS (self)->store_finish (self, res, &error))
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
else {
|
else {
|
||||||
MMSmsStorage storage = MM_SMS_STORAGE_UNKNOWN;
|
mm_gdbus_sms_set_storage (MM_GDBUS_SMS (ctx->self), ctx->storage);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
/* Transition from Unknown->Stored for SMS which were created by the user */
|
/* 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)
|
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);
|
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
|
static void
|
||||||
handle_store_auth_ready (MMBaseModem *modem,
|
handle_store_auth_ready (MMBaseModem *modem,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -143,8 +126,28 @@ handle_store_auth_ready (MMBaseModem *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* First of all, check if we already have the SMS stored. */
|
/* First of all, check if we already have the SMS stored. */
|
||||||
if (sms_is_stored (ctx->self)) {
|
if (mm_sms_get_storage (ctx->self) != MM_SMS_STORAGE_UNKNOWN) {
|
||||||
mm_gdbus_sms_complete_store (MM_GDBUS_SMS (ctx->self), ctx->invocation);
|
/* 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);
|
handle_store_context_free (ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,13 +164,15 @@ handle_store_auth_ready (MMBaseModem *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
MM_SMS_GET_CLASS (ctx->self)->store (ctx->self,
|
MM_SMS_GET_CLASS (ctx->self)->store (ctx->self,
|
||||||
|
ctx->storage,
|
||||||
(GAsyncReadyCallback)handle_store_ready,
|
(GAsyncReadyCallback)handle_store_ready,
|
||||||
ctx);
|
ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_store (MMSms *self,
|
handle_store (MMSms *self,
|
||||||
GDBusMethodInvocation *invocation)
|
GDBusMethodInvocation *invocation,
|
||||||
|
guint32 storage)
|
||||||
{
|
{
|
||||||
HandleStoreContext *ctx;
|
HandleStoreContext *ctx;
|
||||||
|
|
||||||
@@ -177,6 +182,15 @@ handle_store (MMSms *self,
|
|||||||
g_object_get (self,
|
g_object_get (self,
|
||||||
MM_SMS_MODEM, &ctx->modem,
|
MM_SMS_MODEM, &ctx->modem,
|
||||||
NULL);
|
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,
|
mm_base_modem_authorize (ctx->modem,
|
||||||
invocation,
|
invocation,
|
||||||
@@ -473,6 +487,8 @@ typedef struct {
|
|||||||
MMSms *self;
|
MMSms *self;
|
||||||
MMBaseModem *modem;
|
MMBaseModem *modem;
|
||||||
GSimpleAsyncResult *result;
|
GSimpleAsyncResult *result;
|
||||||
|
MMSmsStorage storage;
|
||||||
|
gboolean need_unlock;
|
||||||
gboolean use_pdu_mode;
|
gboolean use_pdu_mode;
|
||||||
GList *current;
|
GList *current;
|
||||||
gchar *msg_data;
|
gchar *msg_data;
|
||||||
@@ -481,8 +497,11 @@ typedef struct {
|
|||||||
static void
|
static void
|
||||||
sms_store_context_complete_and_free (SmsStoreContext *ctx)
|
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);
|
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->modem);
|
||||||
g_object_unref (ctx->self);
|
g_object_unref (ctx->self);
|
||||||
g_free (ctx->msg_data);
|
g_free (ctx->msg_data);
|
||||||
@@ -601,8 +620,31 @@ sms_store_next_part (SmsStoreContext *ctx)
|
|||||||
g_free (cmd);
|
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
|
static void
|
||||||
sms_store (MMSms *self,
|
sms_store (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -616,14 +658,21 @@ sms_store (MMSms *self,
|
|||||||
sms_store);
|
sms_store);
|
||||||
ctx->self = g_object_ref (self);
|
ctx->self = g_object_ref (self);
|
||||||
ctx->modem = g_object_ref (self->priv->modem);
|
ctx->modem = g_object_ref (self->priv->modem);
|
||||||
|
ctx->storage = storage;
|
||||||
|
|
||||||
/* Different ways to do it if on PDU or text mode */
|
/* Different ways to do it if on PDU or text mode */
|
||||||
g_object_get (self->priv->modem,
|
g_object_get (self->priv->modem,
|
||||||
MM_IFACE_MODEM_MESSAGING_SMS_PDU_MODE, &ctx->use_pdu_mode,
|
MM_IFACE_MODEM_MESSAGING_SMS_PDU_MODE, &ctx->use_pdu_mode,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
ctx->current = self->priv->parts;
|
/* First, lock storage to use */
|
||||||
sms_store_next_part (ctx);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@@ -54,6 +54,7 @@ struct _MMSmsClass {
|
|||||||
|
|
||||||
/* Store the SMS */
|
/* Store the SMS */
|
||||||
void (* store) (MMSms *self,
|
void (* store) (MMSms *self,
|
||||||
|
MMSmsStorage storage,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
gboolean (* store_finish) (MMSms *self,
|
gboolean (* store_finish) (MMSms *self,
|
||||||
|
Reference in New Issue
Block a user