api,introspection: update 'Validity' property in the SMS interface

We don't want to support only 'relative' validity, so don't assume that the
Validity property will always be a uint32 value.

Instead, we define the Validity propery as '(uv)' tuple, where the first value
(a MMSmsValidityType) specifies the type of validity, and the second value is
a variant formatted accordingly to what the validity type specifies (e.g. a
uint32 value if the type is MM_SMS_VALIDITY_TYPE_RELATIVE).
This commit is contained in:
Aleksander Morgado
2013-04-03 16:30:48 +02:00
parent 372a49bbf6
commit f9105bff87
11 changed files with 147 additions and 32 deletions

View File

@@ -181,16 +181,17 @@ print_sms_info (MMSms *sms)
g_print (" -----------------------------------\n"
" Properties | PDU type: '%s'\n"
" | state: '%s'\n"
" | smsc: '%s'\n"
" | validity: '%u'\n"
" | class: '%u'\n"
" | storage: '%s'\n",
" | smsc: '%s'\n",
mm_sms_pdu_type_get_string (pdu_type),
mm_sms_state_get_string (mm_sms_get_state (sms)),
VALIDATE (mm_sms_get_smsc (sms)),
mm_sms_get_validity (sms),
VALIDATE (mm_sms_get_smsc (sms)));
if (mm_sms_get_validity_type (sms) == MM_SMS_VALIDITY_TYPE_RELATIVE)
g_print (" | validity (relative): '%u'\n",
mm_sms_get_validity_relative (sms));
g_print (" | class: '%u'\n"
" | storage: '%s'\n",
mm_sms_get_class (sms),
mm_sms_storage_get_string (mm_sms_get_storage (sms)));

View File

@@ -27,6 +27,7 @@ MMSmsPduType
MMSmsState
MMSmsDeliveryState
MMSmsStorage
MMSmsValidityType
</SECTION>
<SECTION>

View File

@@ -885,7 +885,8 @@ mm_sms_get_smsc
mm_sms_dup_smsc
mm_sms_get_message_reference
mm_sms_get_class
mm_sms_get_validity
mm_sms_get_validity_type
mm_sms_get_validity_relative
mm_sms_get_timestamp
mm_sms_dup_timestamp
mm_sms_get_discharge_timestamp
@@ -979,6 +980,7 @@ mm_sms_pdu_type_get_string
mm_sms_state_get_string
mm_sms_delivery_state_get_string
mm_sms_storage_get_string
mm_sms_validity_type_get_string
mm_firmware_image_type_get_string
<SUBSECTION Private>
mm_modem_capability_get_string
@@ -994,6 +996,7 @@ mm_sms_pdu_type_build_string_from_mask
mm_sms_state_build_string_from_mask
mm_sms_delivery_state_build_string_from_mask
mm_sms_storage_build_string_from_mask
mm_sms_validity_type_build_string_from_mask
mm_modem_location_source_get_string
mm_modem_contacts_storage_build_string_from_mask
mm_bearer_ip_family_build_string_from_mask
@@ -1034,6 +1037,7 @@ MM_TYPE_SMS_DELIVERY_STATE
MM_TYPE_SMS_PDU_TYPE
MM_TYPE_SMS_STATE
MM_TYPE_SMS_STORAGE
MM_TYPE_SMS_VALIDITY_TYPE
mm_bearer_ip_family_get_type
mm_bearer_ip_method_get_type
mm_bearer_allowed_auth_get_type
@@ -1060,6 +1064,7 @@ mm_sms_delivery_state_get_type
mm_sms_pdu_type_get_type
mm_sms_state_get_type
mm_sms_storage_get_type
mm_sms_validity_type_get_type
</SECTION>
<SECTION>
@@ -2317,6 +2322,7 @@ mm_gdbus_sms_dup_number
mm_gdbus_sms_get_smsc
mm_gdbus_sms_dup_smsc
mm_gdbus_sms_get_validity
mm_gdbus_sms_dup_validity
mm_gdbus_sms_get_class
mm_gdbus_sms_get_timestamp
mm_gdbus_sms_dup_timestamp

View File

@@ -521,6 +521,22 @@ typedef enum { /*< underscore_name=mm_sms_storage >*/
MM_SMS_STORAGE_TA = 6,
} MMSmsStorage;
/**
* MMSmsValidityType:
* @MM_SMS_VALIDITY_TYPE_UNKNOWN: Validity type unknown.
* @MM_SMS_VALIDITY_TYPE_RELATIVE: Relative validity.
* @MM_SMS_VALIDITY_TYPE_ABSOLUTE: Absolute validity.
* @MM_SMS_VALIDITY_TYPE_ENHANCED: Enhanced validity.
*
* Type of SMS validity value.
*/
typedef enum { /*< underscore_name=mm_sms_validity_type >*/
MM_SMS_VALIDITY_TYPE_UNKNOWN = 0,
MM_SMS_VALIDITY_TYPE_RELATIVE = 1,
MM_SMS_VALIDITY_TYPE_ABSOLUTE = 2,
MM_SMS_VALIDITY_TYPE_ENHANCED = 3,
} MMSmsValidityType;
/**
* MMModemLocationSource:
* @MM_MODEM_LOCATION_SOURCE_NONE: None.

View File

@@ -99,11 +99,25 @@
<!--
Validity:
Specifies when the SMS expires in the SMSC.
Indicates when the SMS expires in the SMSC.
Always 0 for 3GPP2/CDMA.
This value is composed of a
<link linkend="MMSmsValidityType">MMSmsValidityType</link>
key, with an associated data which contains type-specific validity
information:
<variablelist>
<varlistentry><term><link linkend="MM-SMS-VALIDITY-TYPE-RELATIVE:CAPS">MM_SMS_VALIDITY_TYPE_RELATIVE</link></term>
<listitem>
<para>
The value is the length of the validity period in minutes, given
as an unsigned integer (D-Bus signature <literal>'u'</literal>).
</para>
</listitem>
</varlistentry>
</variablelist>
-->
<property name="Validity" type="u" access="read" />
<property name="Validity" type="(uv)" access="read" />
<!--
Class:

View File

@@ -375,19 +375,66 @@ mm_sms_dup_discharge_timestamp (MMSms *self)
/*****************************************************************************/
/**
* mm_sms_get_validity:
* mm_sms_get_validity_type:
* @self: A #MMSms.
*
* Gets the validity time of the SMS.
* Gets the type of validity information in the SMS.
*
* Returns: the validity time or 0 if unknown.
* Returns: the validity type or #MM_SMS_VALIDITY_TYPE_UNKNOWN.
*/
MMSmsValidityType
mm_sms_get_validity_type (MMSms *self)
{
GVariant *variant;
guint type;
GVariant *value;
g_return_val_if_fail (MM_IS_SMS (self), MM_SMS_VALIDITY_TYPE_UNKNOWN);
variant = mm_gdbus_sms_dup_validity (MM_GDBUS_SMS (self));
if (!variant)
return MM_SMS_VALIDITY_TYPE_UNKNOWN;
g_variant_get (variant, "(uv)", &type, &value);
g_variant_unref (variant);
g_variant_unref (value);
return (MMSmsValidityType)type;
}
/**
* mm_sms_get_validity_relative:
* @self: A #MMSms.
*
* Gets the length of the validity period, in minutes.
*
* Only applicable if the type of validity is #MM_SMS_VALIDITY_TYPE_RELATIVE.
*
* Returns: the length of the validity period, or 0 if unknown.
*/
guint
mm_sms_get_validity (MMSms *self)
mm_sms_get_validity_relative (MMSms *self)
{
g_return_val_if_fail (MM_IS_SMS (self), 0);
GVariant *variant;
guint type;
GVariant *value;
guint value_integer = 0;
return mm_gdbus_sms_get_validity (MM_GDBUS_SMS (self));
g_return_val_if_fail (MM_IS_SMS (self), MM_SMS_VALIDITY_TYPE_UNKNOWN);
variant = mm_gdbus_sms_dup_validity (MM_GDBUS_SMS (self));
if (!variant)
return 0;
g_variant_get (variant, "(uv)", &type, &value);
if (type == MM_SMS_VALIDITY_TYPE_RELATIVE)
value_integer = g_variant_get_uint32 (value);
g_variant_unref (variant);
g_variant_unref (value);
return value_integer;
}
/*****************************************************************************/

View File

@@ -86,7 +86,8 @@ gchar *mm_sms_dup_timestamp (MMSms *self);
const gchar *mm_sms_get_discharge_timestamp (MMSms *self);
gchar *mm_sms_dup_discharge_timestamp (MMSms *self);
guint mm_sms_get_validity (MMSms *self);
MMSmsValidityType mm_sms_get_validity_type (MMSms *self);
guint mm_sms_get_validity_relative (MMSms *self);
guint mm_sms_get_class (MMSms *self);

View File

@@ -326,7 +326,7 @@ struct _MMSmsPart {
MMSmsEncoding encoding;
GByteArray *data;
guint class;
guint validity;
guint validity_relative;
gboolean delivery_report_request;
guint message_reference;
/* NOT a MMSmsDeliveryState, which just includes the known values */
@@ -405,8 +405,8 @@ PART_GET_FUNC (MMSmsEncoding, encoding)
PART_SET_FUNC (MMSmsEncoding, encoding)
PART_GET_FUNC (guint, class)
PART_SET_FUNC (guint, class)
PART_GET_FUNC (guint, validity)
PART_SET_FUNC (guint, validity)
PART_GET_FUNC (guint, validity_relative)
PART_SET_FUNC (guint, validity_relative)
PART_GET_FUNC (gboolean, delivery_report_request)
PART_SET_FUNC (gboolean, delivery_report_request)
PART_GET_FUNC (guint, message_reference)
@@ -655,8 +655,8 @@ mm_sms_part_new_from_binary_pdu (guint index,
switch (validity_format) {
case 0x10:
mm_dbg (" validity available, format relative");
mm_sms_part_set_validity (sms_part,
relative_to_validity (pdu[offset]));
mm_sms_part_set_validity_relative (sms_part,
relative_to_validity (pdu[offset]));
offset++;
break;
case 0x08:
@@ -972,7 +972,7 @@ mm_sms_part_get_submit_pdu (MMSmsPart *part,
pdu[offset] = 0;
/* TP-VP present; format RELATIVE */
if (part->validity > 0) {
if (part->validity_relative > 0) {
mm_dbg (" adding validity to PDU...");
pdu[offset] |= 0x10;
}
@@ -1034,8 +1034,8 @@ mm_sms_part_get_submit_pdu (MMSmsPart *part,
/* ----------- TP-Validity-Period (1 byte): 4 days ----------- */
/* Only if TP-VPF was set in first byte */
if (part->validity > 0)
pdu[offset++] = validity_to_relative (part->validity);
if (part->validity_relative > 0)
pdu[offset++] = validity_to_relative (part->validity_relative);
/* ----------- TP-User-Data-Length ----------- */
/* Set to zero initially, and keep a ptr for easy access later */

View File

@@ -100,8 +100,8 @@ guint mm_sms_part_get_class (MMSmsPart *part);
void mm_sms_part_set_class (MMSmsPart *part,
guint class);
guint mm_sms_part_get_validity (MMSmsPart *part);
void mm_sms_part_set_validity (MMSmsPart *part,
guint mm_sms_part_get_validity_relative (MMSmsPart *part);
void mm_sms_part_set_validity_relative (MMSmsPart *part,
guint validity);
guint mm_sms_part_get_delivery_state (MMSmsPart *part);

View File

@@ -73,6 +73,29 @@ struct _MMSmsPrivate {
/*****************************************************************************/
static guint
get_validity_relative (GVariant *tuple)
{
guint type;
GVariant *value;
guint value_integer = 0;
if (!tuple)
return 0;
g_variant_get (tuple, "(ub)", &type, &value);
if (type == MM_SMS_VALIDITY_TYPE_RELATIVE)
value_integer = g_variant_get_uint32 (value);
else
/* Currently not supported other than relative */
g_warn_if_reached ();
g_variant_unref (value);
return value_integer;
}
static gboolean
generate_submit_pdus (MMSms *self,
GError **error)
@@ -172,7 +195,7 @@ generate_submit_pdus (MMSms *self,
mm_sms_part_set_encoding (part, encoding);
mm_sms_part_set_number (part, mm_gdbus_sms_get_number (MM_GDBUS_SMS (self)));
mm_sms_part_set_smsc (part, mm_gdbus_sms_get_smsc (MM_GDBUS_SMS (self)));
mm_sms_part_set_validity (part, mm_gdbus_sms_get_validity (MM_GDBUS_SMS (self)));
mm_sms_part_set_validity_relative (part, get_validity_relative (mm_gdbus_sms_get_validity (MM_GDBUS_SMS (self))));
mm_sms_part_set_class (part, mm_gdbus_sms_get_class (MM_GDBUS_SMS (self)));
mm_sms_part_set_delivery_report_request (part, mm_gdbus_sms_get_delivery_report_request (MM_GDBUS_SMS (self)));
@@ -1376,6 +1399,7 @@ assemble_sms (MMSms *self,
MMSmsPart **sorted_parts;
GString *fulltext;
GByteArray *fulldata;
guint validity_relative;
sorted_parts = g_new0 (MMSmsPart *, self->priv->max_parts);
@@ -1463,6 +1487,9 @@ assemble_sms (MMSms *self,
/* If we got all parts, we also have the first one always */
g_assert (sorted_parts[0] != NULL);
/* Prepare for validity tuple */
validity_relative = mm_sms_part_get_validity_relative (sorted_parts[0]);
/* If we got everything, assemble the text! */
g_object_set (self,
"pdu-type", mm_sms_part_get_pdu_type (sorted_parts[0]),
@@ -1476,7 +1503,9 @@ assemble_sms (MMSms *self,
"smsc", mm_sms_part_get_smsc (sorted_parts[0]),
"class", mm_sms_part_get_class (sorted_parts[0]),
"number", mm_sms_part_get_number (sorted_parts[0]),
"validity", mm_sms_part_get_validity (sorted_parts[0]),
"validity", (validity_relative ?
g_variant_new ("(uv)", MM_SMS_VALIDITY_TYPE_RELATIVE, g_variant_new_uint32 (validity_relative)) :
g_variant_new ("(uv)", MM_SMS_VALIDITY_TYPE_UNKNOWN, g_variant_new_boolean (FALSE))),
"timestamp", mm_sms_part_get_timestamp (sorted_parts[0]),
"discharge-timestamp", mm_sms_part_get_discharge_timestamp (sorted_parts[0]),
"delivery-state", mm_sms_part_get_delivery_state (sorted_parts[0]),

View File

@@ -536,7 +536,7 @@ common_test_create_pdu (const gchar *smsc,
mm_sms_part_set_encoding (part, encoding);
}
if (validity > 0)
mm_sms_part_set_validity (part, validity);
mm_sms_part_set_validity_relative (part, validity);
if (class > 0)
mm_sms_part_set_class (part, class);