base-sms,iface-modem-messaging: move lock/unlock logic into the interface
Allows us to test things that rely on MMBaseSms more easily.. Signed-off-by: Dan Williams <dan@ioncontrol.co>
This commit is contained in:
+34
-24
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "mm-base-sms.h"
|
||||
#include "mm-broadband-modem.h"
|
||||
#include "mm-auth-provider.h"
|
||||
#include "mm-iface-modem.h"
|
||||
#include "mm-iface-modem-messaging.h"
|
||||
#include "mm-sms-part-3gpp.h"
|
||||
@@ -848,8 +849,11 @@ static void
|
||||
sms_store_context_free (SmsStoreContext *ctx)
|
||||
{
|
||||
/* Unlock mem2 storage if we had the lock */
|
||||
if (ctx->need_unlock)
|
||||
mm_broadband_modem_unlock_sms_storages (MM_BROADBAND_MODEM (ctx->modem), FALSE, TRUE);
|
||||
if (ctx->need_unlock) {
|
||||
mm_iface_modem_messaging_unlock_storages (MM_IFACE_MODEM_MESSAGING (ctx->modem),
|
||||
FALSE,
|
||||
TRUE);
|
||||
}
|
||||
g_object_unref (ctx->port);
|
||||
g_object_unref (ctx->modem);
|
||||
g_free (ctx->msg_data);
|
||||
@@ -986,7 +990,7 @@ sms_store_next_part (GTask *task)
|
||||
}
|
||||
|
||||
static void
|
||||
store_lock_sms_storages_ready (MMBroadbandModem *modem,
|
||||
store_lock_sms_storages_ready (MMIfaceModemMessaging *messaging,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
@@ -994,7 +998,7 @@ store_lock_sms_storages_ready (MMBroadbandModem *modem,
|
||||
SmsStoreContext *ctx;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_broadband_modem_lock_sms_storages_finish (modem, res, &error)) {
|
||||
if (!mm_iface_modem_messaging_lock_storages_finish (messaging, res, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
@@ -1040,15 +1044,15 @@ sms_store (MMBaseSms *self,
|
||||
ctx->storage = storage;
|
||||
|
||||
/* Different ways to do it if on PDU or text mode */
|
||||
g_assert (MM_IS_IFACE_MODEM_MESSAGING (self->priv->modem));
|
||||
g_object_get (self->priv->modem,
|
||||
MM_IFACE_MODEM_MESSAGING_SMS_PDU_MODE, &ctx->use_pdu_mode,
|
||||
NULL);
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)sms_store_context_free);
|
||||
|
||||
/* 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_iface_modem_messaging_lock_storages (
|
||||
MM_IFACE_MODEM_MESSAGING (self->priv->modem),
|
||||
MM_SMS_STORAGE_UNKNOWN, /* none required for mem1 */
|
||||
ctx->storage,
|
||||
(GAsyncReadyCallback)store_lock_sms_storages_ready,
|
||||
@@ -1072,8 +1076,11 @@ static void
|
||||
sms_send_context_free (SmsSendContext *ctx)
|
||||
{
|
||||
/* Unlock mem2 storage if we had the lock */
|
||||
if (ctx->need_unlock)
|
||||
mm_broadband_modem_unlock_sms_storages (MM_BROADBAND_MODEM (ctx->modem), FALSE, TRUE);
|
||||
if (ctx->need_unlock) {
|
||||
mm_iface_modem_messaging_unlock_storages (MM_IFACE_MODEM_MESSAGING (ctx->modem),
|
||||
FALSE,
|
||||
TRUE);
|
||||
}
|
||||
g_object_unref (ctx->port);
|
||||
g_object_unref (ctx->modem);
|
||||
g_free (ctx->msg_data);
|
||||
@@ -1290,15 +1297,15 @@ sms_send_next_part (GTask *task)
|
||||
}
|
||||
|
||||
static void
|
||||
send_lock_sms_storages_ready (MMBroadbandModem *modem,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
send_lock_sms_storages_ready (MMIfaceModemMessaging *messaging,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
MMBaseSms *self;
|
||||
SmsSendContext *ctx;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_broadband_modem_lock_sms_storages_finish (modem, res, &error)) {
|
||||
if (!mm_iface_modem_messaging_lock_storages_finish (messaging, res, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
@@ -1346,9 +1353,9 @@ sms_send (MMBaseSms *self,
|
||||
ctx->from_storage = (mm_base_sms_get_storage (self) != MM_SMS_STORAGE_UNKNOWN);
|
||||
if (ctx->from_storage) {
|
||||
/* When sending from storage, 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),
|
||||
g_assert (MM_IS_IFACE_MODEM_MESSAGING (self->priv->modem));
|
||||
mm_iface_modem_messaging_lock_storages (
|
||||
MM_IFACE_MODEM_MESSAGING (self->priv->modem),
|
||||
MM_SMS_STORAGE_UNKNOWN, /* none required for mem1 */
|
||||
mm_base_sms_get_storage (self),
|
||||
(GAsyncReadyCallback)send_lock_sms_storages_ready,
|
||||
@@ -1377,8 +1384,11 @@ static void
|
||||
sms_delete_parts_context_free (SmsDeletePartsContext *ctx)
|
||||
{
|
||||
/* Unlock mem1 storage if we had the lock */
|
||||
if (ctx->need_unlock)
|
||||
mm_broadband_modem_unlock_sms_storages (MM_BROADBAND_MODEM (ctx->modem), TRUE, FALSE);
|
||||
if (ctx->need_unlock) {
|
||||
mm_iface_modem_messaging_unlock_storages (MM_IFACE_MODEM_MESSAGING (ctx->modem),
|
||||
TRUE,
|
||||
FALSE);
|
||||
}
|
||||
g_object_unref (ctx->modem);
|
||||
g_slice_free (SmsDeletePartsContext, ctx);
|
||||
}
|
||||
@@ -1456,15 +1466,15 @@ delete_next_part (GTask *task)
|
||||
}
|
||||
|
||||
static void
|
||||
delete_lock_sms_storages_ready (MMBroadbandModem *modem,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
delete_lock_sms_storages_ready (MMIfaceModemMessaging *messaging,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
MMBaseSms *self;
|
||||
SmsDeletePartsContext *ctx;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_broadband_modem_lock_sms_storages_finish (modem, res, &error)) {
|
||||
if (!mm_iface_modem_messaging_lock_storages_finish (messaging, res, &error)) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
@@ -1504,8 +1514,8 @@ sms_delete (MMBaseSms *self,
|
||||
}
|
||||
|
||||
/* Select specific storage to delete from */
|
||||
mm_broadband_modem_lock_sms_storages (
|
||||
MM_BROADBAND_MODEM (self->priv->modem),
|
||||
mm_iface_modem_messaging_lock_storages (
|
||||
MM_IFACE_MODEM_MESSAGING (self->priv->modem),
|
||||
mm_base_sms_get_storage (self),
|
||||
MM_SMS_STORAGE_UNKNOWN, /* none required for mem2 */
|
||||
(GAsyncReadyCallback)delete_lock_sms_storages_ready,
|
||||
|
||||
+42
-36
@@ -7185,11 +7185,13 @@ modem_messaging_init_current_storages (MMIfaceModemMessaging *self,
|
||||
* the default one if needed.
|
||||
*/
|
||||
|
||||
void
|
||||
mm_broadband_modem_unlock_sms_storages (MMBroadbandModem *self,
|
||||
gboolean mem1,
|
||||
gboolean mem2)
|
||||
static void
|
||||
modem_messaging_unlock_storages (MMIfaceModemMessaging *_self,
|
||||
gboolean mem1,
|
||||
gboolean mem2)
|
||||
{
|
||||
MMBroadbandModem *self = MM_BROADBAND_MODEM (_self);
|
||||
|
||||
if (mem1) {
|
||||
g_assert (self->priv->mem1_storage_locked);
|
||||
self->priv->mem1_storage_locked = FALSE;
|
||||
@@ -7201,10 +7203,10 @@ mm_broadband_modem_unlock_sms_storages (MMBroadbandModem *self,
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_broadband_modem_lock_sms_storages_finish (MMBroadbandModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
static gboolean
|
||||
modem_messaging_lock_storages_finish (MMIfaceModemMessaging *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_boolean (G_TASK (res), error);
|
||||
}
|
||||
@@ -7246,13 +7248,14 @@ lock_storages_cpms_set_ready (MMBaseModem *_self,
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
void
|
||||
mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self,
|
||||
MMSmsStorage mem1, /* reading/listing/deleting */
|
||||
MMSmsStorage mem2, /* storing/sending */
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
static void
|
||||
modem_messaging_lock_storages (MMIfaceModemMessaging *_self,
|
||||
MMSmsStorage mem1, /* reading/listing/deleting */
|
||||
MMSmsStorage mem2, /* storing/sending */
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBroadbandModem *self = MM_BROADBAND_MODEM (_self);
|
||||
LockSmsStoragesContext *ctx;
|
||||
GTask *task;
|
||||
gchar *cmd = NULL;
|
||||
@@ -7267,7 +7270,7 @@ mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self,
|
||||
self,
|
||||
callback,
|
||||
user_data,
|
||||
mm_broadband_modem_lock_sms_storages,
|
||||
modem_messaging_lock_storages,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_RETRY,
|
||||
"SMS storage currently locked, try again later");
|
||||
@@ -7547,7 +7550,7 @@ sms_part_ready (MMBroadbandModem *self,
|
||||
GError *error = NULL;
|
||||
|
||||
/* Always always always unlock mem1 storage. Warned you've been. */
|
||||
mm_broadband_modem_unlock_sms_storages (self, TRUE, FALSE);
|
||||
mm_iface_modem_messaging_unlock_storages (MM_IFACE_MODEM_MESSAGING (self), TRUE, FALSE);
|
||||
|
||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||
if (error) {
|
||||
@@ -7589,15 +7592,15 @@ sms_part_ready (MMBroadbandModem *self,
|
||||
}
|
||||
|
||||
static void
|
||||
indication_lock_storages_ready (MMBroadbandModem *self,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
indication_lock_storages_ready (MMIfaceModemMessaging *messaging,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
SmsPartContext *ctx;
|
||||
gchar *command;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_broadband_modem_lock_sms_storages_finish (self, res, &error)) {
|
||||
if (!mm_iface_modem_messaging_lock_storages_finish (messaging, res, &error)) {
|
||||
/* TODO: we should either make this lock() never fail, by automatically
|
||||
* retrying after some time, or otherwise retry here. */
|
||||
g_task_return_error (task, error);
|
||||
@@ -7610,7 +7613,7 @@ indication_lock_storages_ready (MMBroadbandModem *self,
|
||||
/* Retrieve the message */
|
||||
ctx = g_task_get_task_data (task);
|
||||
command = g_strdup_printf ("+CMGR=%d", ctx->idx);
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (messaging),
|
||||
command,
|
||||
10,
|
||||
FALSE,
|
||||
@@ -7658,11 +7661,11 @@ cmti_received (MMPortSerialAt *port,
|
||||
g_task_set_task_data (task, ctx, g_free);
|
||||
|
||||
/* First, request to set the proper storage to read from */
|
||||
mm_broadband_modem_lock_sms_storages (self,
|
||||
storage,
|
||||
MM_SMS_STORAGE_UNKNOWN,
|
||||
(GAsyncReadyCallback)indication_lock_storages_ready,
|
||||
task);
|
||||
mm_iface_modem_messaging_lock_storages (MM_IFACE_MODEM_MESSAGING (self),
|
||||
storage,
|
||||
MM_SMS_STORAGE_UNKNOWN,
|
||||
(GAsyncReadyCallback)indication_lock_storages_ready,
|
||||
task);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -8120,7 +8123,7 @@ sms_pdu_part_list_ready (MMBroadbandModem *self,
|
||||
GList *l;
|
||||
|
||||
/* Always always always unlock mem1 storage. Warned you've been. */
|
||||
mm_broadband_modem_unlock_sms_storages (self, TRUE, FALSE);
|
||||
mm_iface_modem_messaging_unlock_storages (MM_IFACE_MODEM_MESSAGING (self), TRUE, FALSE);
|
||||
|
||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||
if (error) {
|
||||
@@ -8164,13 +8167,13 @@ sms_pdu_part_list_ready (MMBroadbandModem *self,
|
||||
}
|
||||
|
||||
static void
|
||||
list_parts_lock_storages_ready (MMBroadbandModem *self,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
list_parts_lock_storages_ready (MMIfaceModemMessaging *self,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_broadband_modem_lock_sms_storages_finish (self, res, &error)) {
|
||||
if (!mm_iface_modem_messaging_lock_storages_finish (self, res, &error)) {
|
||||
/* TODO: we should either make this lock() never fail, by automatically
|
||||
* retrying after some time, or otherwise retry here. */
|
||||
g_task_return_error (task, error);
|
||||
@@ -8212,11 +8215,11 @@ modem_messaging_load_initial_sms_parts (MMIfaceModemMessaging *self,
|
||||
mm_obj_dbg (self, "listing SMS parts in storage '%s'", mm_sms_storage_get_string (storage));
|
||||
|
||||
/* First, request to set the proper storage to read from */
|
||||
mm_broadband_modem_lock_sms_storages (MM_BROADBAND_MODEM (self),
|
||||
storage,
|
||||
MM_SMS_STORAGE_UNKNOWN,
|
||||
(GAsyncReadyCallback)list_parts_lock_storages_ready,
|
||||
task);
|
||||
mm_iface_modem_messaging_lock_storages (self,
|
||||
storage,
|
||||
MM_SMS_STORAGE_UNKNOWN,
|
||||
(GAsyncReadyCallback)list_parts_lock_storages_ready,
|
||||
task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -14541,6 +14544,9 @@ iface_modem_messaging_init (MMIfaceModemMessagingInterface *iface)
|
||||
iface->create_sms = modem_messaging_create_sms;
|
||||
iface->init_current_storages = modem_messaging_init_current_storages;
|
||||
iface->init_current_storages_finish = modem_messaging_init_current_storages_finish;
|
||||
iface->lock_storages = modem_messaging_lock_storages;
|
||||
iface->lock_storages_finish = modem_messaging_lock_storages_finish;
|
||||
iface->unlock_storages = modem_messaging_unlock_storages;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -126,18 +126,6 @@ gchar *mm_broadband_modem_create_device_identifier (MMBroadbandModem *self,
|
||||
const gchar *ati1,
|
||||
GError **error);
|
||||
|
||||
/* Locking/unlocking SMS storages */
|
||||
void mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self,
|
||||
MMSmsStorage mem1, /* reading/listing/deleting */
|
||||
MMSmsStorage mem2, /* storing/sending */
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean mm_broadband_modem_lock_sms_storages_finish (MMBroadbandModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
void mm_broadband_modem_unlock_sms_storages (MMBroadbandModem *self,
|
||||
gboolean mem1,
|
||||
gboolean mem2);
|
||||
/* Helper to update SIM hot swap */
|
||||
gboolean mm_broadband_modem_sim_hot_swap_ports_context_init (MMBroadbandModem *self,
|
||||
GError **error);
|
||||
|
||||
@@ -101,6 +101,49 @@ mm_iface_modem_messaging_create_sms (MMIfaceModemMessaging *self)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
mm_iface_modem_messaging_lock_storages (MMIfaceModemMessaging *self,
|
||||
MMSmsStorage mem1,
|
||||
MMSmsStorage mem2,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_assert (MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->lock_storages != NULL);
|
||||
|
||||
MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->lock_storages (self,
|
||||
mem1,
|
||||
mem2,
|
||||
callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_iface_modem_messaging_lock_storages_finish (MMIfaceModemMessaging *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
|
||||
{
|
||||
g_assert (MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->lock_storages_finish != NULL);
|
||||
|
||||
return MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->lock_storages_finish (self,
|
||||
res,
|
||||
error);
|
||||
}
|
||||
|
||||
void
|
||||
mm_iface_modem_messaging_unlock_storages (MMIfaceModemMessaging *self,
|
||||
gboolean mem1,
|
||||
gboolean mem2)
|
||||
{
|
||||
g_assert (MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->unlock_storages != NULL);
|
||||
|
||||
MM_IFACE_MODEM_MESSAGING_GET_IFACE (self)->unlock_storages (self,
|
||||
mem1,
|
||||
mem2);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
GArray *supported_mem1;
|
||||
GArray *supported_mem2;
|
||||
|
||||
@@ -78,6 +78,21 @@ struct _MMIfaceModemMessagingInterface {
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
/* Lock storages (async) */
|
||||
void (*lock_storages) (MMIfaceModemMessaging *self,
|
||||
MMSmsStorage mem1, /* reading/listing/deleting */
|
||||
MMSmsStorage mem2, /* storing/sending */
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean (*lock_storages_finish) (MMIfaceModemMessaging *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
/* Unlock storages */
|
||||
void (*unlock_storages) (MMIfaceModemMessaging *self,
|
||||
gboolean mem1,
|
||||
gboolean mem2);
|
||||
|
||||
/* Setup SMS format (async) */
|
||||
void (* setup_sms_format) (MMIfaceModemMessaging *self,
|
||||
GAsyncReadyCallback callback,
|
||||
@@ -182,6 +197,19 @@ gboolean mm_iface_modem_messaging_is_storage_supported_for_receiving (MMIfaceMod
|
||||
/* SMS creation */
|
||||
MMBaseSms *mm_iface_modem_messaging_create_sms (MMIfaceModemMessaging *self);
|
||||
|
||||
/* Locking/unlocking SMS storages */
|
||||
void mm_iface_modem_messaging_lock_storages (MMIfaceModemMessaging *self,
|
||||
MMSmsStorage mem1,
|
||||
MMSmsStorage mem2,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean mm_iface_modem_messaging_lock_storages_finish (MMIfaceModemMessaging *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
void mm_iface_modem_messaging_unlock_storages (MMIfaceModemMessaging *self,
|
||||
gboolean mem1,
|
||||
gboolean mem2);
|
||||
|
||||
/* Look for a new valid multipart reference */
|
||||
guint8 mm_iface_modem_messaging_get_local_multipart_reference (MMIfaceModemMessaging *self,
|
||||
const gchar *number,
|
||||
|
||||
Reference in New Issue
Block a user