diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-13 12:00:37 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-14 07:05:26 +0200 |
commit | e212f6b6edcd2b5678372bd0b05c70209c516f05 (patch) | |
tree | f28a596d95ed494ca667a351b78f42c50b60ab3a /src/mm-iface-modem-messaging.c | |
parent | 2da9474d0c0e22044d7ab636e3336cab1a75bc22 (diff) |
sms: create SMS parts only when storing or sending
When a user creates an SMS object, we will expose all its properties in DBus
properly, but we will not create the internal list of SMS parts.
The list of SMS parts will be created when the SMS is stored or sent, whatever
comes first. When the message is sent and it was previously stored, the list of
parts is not re-created.
If the message requires multiple parts, the multipart reference is computed as
follows:
* If the SMS was not stored and is being sent, we just use a random number.
* If the SMS is being stored, we will use a multipart reference which is not
being used already in another SMS to the same destination.
Diffstat (limited to 'src/mm-iface-modem-messaging.c')
-rw-r--r-- | src/mm-iface-modem-messaging.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/mm-iface-modem-messaging.c b/src/mm-iface-modem-messaging.c index 7a4c1f31..5861b373 100644 --- a/src/mm-iface-modem-messaging.c +++ b/src/mm-iface-modem-messaging.c @@ -31,6 +31,54 @@ static GQuark storage_context_quark; /*****************************************************************************/ +guint8 +mm_iface_modem_messaging_get_local_multipart_reference (MMIfaceModemMessaging *self, + const gchar *number, + GError **error) +{ + MMSmsList *list = NULL; + guint8 reference; + guint8 first; + + /* Start by looking for a random number */ + reference = g_random_int_range (1,255); + + /* Then, look for the given reference in user-created messages */ + g_object_get (self, + MM_IFACE_MODEM_MESSAGING_SMS_LIST, &list, + NULL); + if (!list) + return reference; + + first = reference; + do { + if (!mm_sms_list_has_local_multipart_reference (list, number, reference)) { + g_object_unref (list); + return reference; + } + + if (reference == 255) + reference = 1; + else + reference++; + } + while (reference != first); + + g_object_unref (list); + + /* We were not able to find a new valid multipart reference :/ + * return an error */ + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_TOO_MANY, + "Cannot create multipart SMS: No valid multipart reference " + "available for destination number '%s'", + number); + return 0; +} + +/*****************************************************************************/ + void mm_iface_modem_messaging_bind_simple_status (MMIfaceModemMessaging *self, MMSimpleStatus *status) |