libmm-glib: provide accessors for the 'Data' property in the SMS interface

This commit is contained in:
Aleksander Morgado
2012-09-12 13:08:36 +02:00
parent a66f971a7c
commit 8e6a603578
2 changed files with 89 additions and 18 deletions

View File

@@ -20,6 +20,8 @@
* Copyright (C) 2012 Google, Inc.
*/
#include "string.h"
#include "mm-helpers.h"
#include "mm-sms.h"
#include "mm-modem.h"
@@ -99,6 +101,71 @@ mm_sms_dup_text (MMSms *self)
mm_gdbus_sms_dup_text (self));
}
/**
* mm_sms_get_data:
* @self: A #MMSms.
* @data_len: (out) Size of the output data, if any given.
*
* TODO
*
* Returns: (transfer none): The data, or %NULL if it couldn't be retrieved. The returned value should be freed with g_free().
*/
const guint8 *
mm_sms_get_data (MMSms *self,
gsize *data_len)
{
GVariant *data;
g_return_val_if_fail (MM_GDBUS_IS_SMS (self), NULL);
data = mm_gdbus_sms_get_data (MM_GDBUS_SMS (self));
return (data ?
g_variant_get_fixed_array (
mm_gdbus_sms_get_data (MM_GDBUS_SMS (self)),
data_len,
sizeof (guchar)):
NULL);
}
/**
* mm_sms_dup_data:
* @self: A #MMSms.
* @data_len: (out) Size of the output data, if any given.
*
* TODO
*
* Returns: (transfer full): The data, or %NULL if it couldn't be retrieved. The returned value should be freed with g_free().
*/
guint8 *
mm_sms_dup_data (MMSms *self,
gsize *data_len)
{
guint8 *out;
GVariant *data_variant;
const guint8 *orig_data;
gsize orig_data_len = 0;
g_return_val_if_fail (MM_GDBUS_IS_SMS (self), NULL);
/* Get a ref to ensure the variant is valid as long as we use it */
data_variant = mm_gdbus_sms_dup_data (MM_GDBUS_SMS (self));
if (!data_variant)
return NULL;
orig_data = (g_variant_get_fixed_array (
mm_gdbus_sms_get_data (MM_GDBUS_SMS (self)),
&orig_data_len,
sizeof (guchar)));
out = g_new (guint8, orig_data_len);
memcpy (out, orig_data, orig_data_len);
g_variant_unref (data_variant);
if (data_len)
*data_len = orig_data_len;
return out;
}
/**
* mm_sms_get_number:
* @self: A #MMSms.

View File

@@ -73,24 +73,28 @@ gboolean mm_sms_store_sync (MMSms *self,
GCancellable *cancellable,
GError **error);
const gchar *mm_sms_get_text (MMSms *self);
gchar *mm_sms_dup_text (MMSms *self);
const gchar *mm_sms_get_number (MMSms *self);
gchar *mm_sms_dup_number (MMSms *self);
const gchar *mm_sms_get_smsc (MMSms *self);
gchar *mm_sms_dup_smsc (MMSms *self);
const gchar *mm_sms_get_timestamp (MMSms *self);
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);
guint mm_sms_get_class (MMSms *self);
guint mm_sms_get_message_reference (MMSms *self);
gboolean mm_sms_get_delivery_report_request (MMSms *self);
guint mm_sms_get_delivery_state (MMSms *self);
MMSmsState mm_sms_get_state (MMSms *self);
MMSmsStorage mm_sms_get_storage (MMSms *self);
MMSmsPduType mm_sms_get_pdu_type (MMSms *self);
const gchar *mm_sms_get_text (MMSms *self);
gchar *mm_sms_dup_text (MMSms *self);
const guint8 *mm_sms_get_data (MMSms *self,
gsize *data_len);
guint8 *mm_sms_dup_data (MMSms *self,
gsize *data_len);
const gchar *mm_sms_get_number (MMSms *self);
gchar *mm_sms_dup_number (MMSms *self);
const gchar *mm_sms_get_smsc (MMSms *self);
gchar *mm_sms_dup_smsc (MMSms *self);
const gchar *mm_sms_get_timestamp (MMSms *self);
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);
guint mm_sms_get_class (MMSms *self);
guint mm_sms_get_message_reference (MMSms *self);
gboolean mm_sms_get_delivery_report_request (MMSms *self);
guint mm_sms_get_delivery_state (MMSms *self);
MMSmsState mm_sms_get_state (MMSms *self);
MMSmsStorage mm_sms_get_storage (MMSms *self);
MMSmsPduType mm_sms_get_pdu_type (MMSms *self);
G_END_DECLS