aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-modem-messaging.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-10-01 21:34:58 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-10-02 14:45:37 +0200
commit6ac9460543300ae66d3429031dabeaae2053a68a (patch)
tree327fdfe7fd716e84a7f2b8cfe3c5a8d635d6da63 /libmm-glib/mm-modem-messaging.c
parent45172e39b4b902e4c68bd810fccf3cafa5283477 (diff)
libmm-glib,messaging: `MMModemMessaging' is now a real object
Not just a typedef of the gdbus-codegen generated `MmGdbusModemMessaging'.
Diffstat (limited to 'libmm-glib/mm-modem-messaging.c')
-rw-r--r--libmm-glib/mm-modem-messaging.c257
1 files changed, 204 insertions, 53 deletions
diff --git a/libmm-glib/mm-modem-messaging.c b/libmm-glib/mm-modem-messaging.c
index 0b66c043..ccc6947e 100644
--- a/libmm-glib/mm-modem-messaging.c
+++ b/libmm-glib/mm-modem-messaging.c
@@ -17,6 +17,7 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
* Copyright (C) 2012 Google, Inc.
*/
@@ -26,6 +27,28 @@
#include "mm-modem-messaging.h"
/**
+ * SECTION: mm-modem-messaging
+ * @title: MMModemMessaging
+ * @short_description: The Messaging interface
+ *
+ * The #MMModemMessaging is an object providing access to the methods, signals and
+ * properties of the Messaging interface.
+ *
+ * The Messaging interface is exposed whenever a modem has messaging capabilities.
+ */
+
+G_DEFINE_TYPE (MMModemMessaging, mm_modem_messaging, MM_GDBUS_TYPE_MODEM_MESSAGING_PROXY)
+
+struct _MMModemMessagingPrivate {
+ /* Supported Storage */
+ GMutex supported_storages_mutex;
+ guint supported_storages_id;
+ GArray *supported_storages;
+};
+
+/*****************************************************************************/
+
+/**
* mm_modem_messaging_get_path:
* @self: A #MMModemMessaging.
*
@@ -36,7 +59,7 @@
const gchar *
mm_modem_messaging_get_path (MMModemMessaging *self)
{
- g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
@@ -55,7 +78,7 @@ mm_modem_messaging_dup_path (MMModemMessaging *self)
{
gchar *value;
- g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), NULL);
g_object_get (G_OBJECT (self),
"g-object-path", &value,
@@ -63,30 +86,118 @@ mm_modem_messaging_dup_path (MMModemMessaging *self)
RETURN_NON_EMPTY_STRING (value);
}
+/*****************************************************************************/
+
+static void
+supported_storages_updated (MMModemMessaging *self,
+ GParamSpec *pspec)
+{
+ g_mutex_lock (&self->priv->supported_storages_mutex);
+ {
+ GVariant *dictionary;
+
+ if (self->priv->supported_storages)
+ g_array_unref (self->priv->supported_storages);
+
+ dictionary = mm_gdbus_modem_messaging_get_supported_storages (MM_GDBUS_MODEM_MESSAGING (self));
+ self->priv->supported_storages = (dictionary ?
+ mm_common_sms_storages_variant_to_garray (dictionary) :
+ NULL);
+ }
+ g_mutex_unlock (&self->priv->supported_storages_mutex);
+}
+
+static void
+ensure_internal_supported_storages (MMModemMessaging *self,
+ GArray **dup)
+{
+ g_mutex_lock (&self->priv->supported_storages_mutex);
+ {
+ /* If this is the first time ever asking for the array, setup the
+ * update listener and the initial array, if any. */
+ if (!self->priv->supported_storages_id) {
+ GVariant *dictionary;
+
+ dictionary = mm_gdbus_modem_messaging_dup_supported_storages (MM_GDBUS_MODEM_MESSAGING (self));
+ if (dictionary) {
+ self->priv->supported_storages = mm_common_sms_storages_variant_to_garray (dictionary);
+ g_variant_unref (dictionary);
+ }
+
+ /* No need to clear this signal connection when freeing self */
+ self->priv->supported_storages_id =
+ g_signal_connect (self,
+ "notify::supported-storages",
+ G_CALLBACK (supported_storages_updated),
+ NULL);
+ }
+
+ if (dup && self->priv->supported_storages)
+ *dup = g_array_ref (self->priv->supported_storages);
+ }
+ g_mutex_unlock (&self->priv->supported_storages_mutex);
+}
+
/**
* mm_modem_messaging_get_supported_storages:
* @self: A #MMModem.
- * @storages: (out): Return location for the array of #MMSmsStorage values.
+ * @storages: (out) (array length=n_storages): Return location for the array of #MMSmsStorage values. The returned array should be freed with g_free() when no longer needed.
* @n_storages: (out): Return location for the number of values in @storages.
*
* Gets the list of SMS storages supported by the #MMModem.
+ *
+ * Returns: %TRUE if @storages and @n_storages are set, %FALSE otherwise.
*/
-void
+gboolean
mm_modem_messaging_get_supported_storages (MMModemMessaging *self,
MMSmsStorage **storages,
guint *n_storages)
{
GArray *array;
- g_return_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self));
- g_return_if_fail (storages != NULL);
- g_return_if_fail (n_storages != NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
+ g_return_val_if_fail (storages != NULL, FALSE);
+ g_return_val_if_fail (n_storages != NULL, FALSE);
+
+ ensure_internal_supported_storages (self, &array);
+ if (!array)
+ return FALSE;
- array = mm_common_sms_storages_variant_to_garray (mm_gdbus_modem_messaging_get_supported_storages (self));
*n_storages = array->len;
*storages = (MMSmsStorage *)g_array_free (array, FALSE);
+ return TRUE;
+}
+
+/**
+ * mm_modem_messaging_peek_supported_storages:
+ * @self: A #MMModem.
+ * @storages: (out): Return location for the array of #MMSmsStorage values. Do not free the returned array, it is owned by @self.
+ * @n_storages: (out): Return location for the number of values in @storages.
+ *
+ * Gets the list of SMS storages supported by the #MMModem.
+ *
+ * Returns: %TRUE if @storages and @n_storages are set, %FALSE otherwise.
+ */
+gboolean
+mm_modem_messaging_peek_supported_storages (MMModemMessaging *self,
+ const MMSmsStorage **storages,
+ guint *n_storages)
+{
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
+ g_return_val_if_fail (storages != NULL, FALSE);
+ g_return_val_if_fail (n_storages != NULL, FALSE);
+
+ ensure_internal_supported_storages (self, NULL);
+ if (!self->priv->supported_storages)
+ return FALSE;
+
+ *n_storages = self->priv->supported_storages->len;
+ *storages = (MMSmsStorage *)self->priv->supported_storages->data;
+ return TRUE;
}
+/*****************************************************************************/
+
/**
* mm_modem_messaging_get_default_storage:
* @self: A #MMModem.
@@ -98,11 +209,13 @@ mm_modem_messaging_get_supported_storages (MMModemMessaging *self,
MMSmsStorage
mm_modem_messaging_get_default_storage (MMModemMessaging *self)
{
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), MM_SMS_STORAGE_UNKNOWN);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), MM_SMS_STORAGE_UNKNOWN);
- return (MMSmsStorage)mm_gdbus_modem_messaging_get_default_storage (self);
+ return (MMSmsStorage)mm_gdbus_modem_messaging_get_default_storage (MM_GDBUS_MODEM_MESSAGING (self));
}
+/*****************************************************************************/
+
typedef struct {
MMModemMessaging *self;
GSimpleAsyncResult *result;
@@ -140,7 +253,7 @@ list_sms_context_complete_and_free (ListSmsContext *ctx)
*
* Finishes an operation started with mm_modem_messaging_list().
*
- * Returns: (transfer-full): The list of #MMSms objects, or %NULL if either none found or if @error is set.
+ * Returns: (element-type MM.Sms) (transfer full): A list of #MMSms objects, or #NULL if either not found or @error is set. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify function.
*/
GList *
mm_modem_messaging_list_finish (MMModemMessaging *self,
@@ -149,7 +262,7 @@ mm_modem_messaging_list_finish (MMModemMessaging *self,
{
GList *list;
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), FALSE);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
@@ -206,7 +319,7 @@ list_ready (MMModemMessaging *self,
{
GError *error = NULL;
- mm_gdbus_modem_messaging_call_list_finish (self, &ctx->sms_paths, res, &error);
+ mm_gdbus_modem_messaging_call_list_finish (MM_GDBUS_MODEM_MESSAGING (self), &ctx->sms_paths, res, &error);
if (error) {
g_simple_async_result_take_error (ctx->result, error);
list_sms_context_complete_and_free (ctx);
@@ -252,7 +365,7 @@ mm_modem_messaging_list (MMModemMessaging *self,
{
ListSmsContext *ctx;
- g_return_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self));
+ g_return_if_fail (MM_IS_MODEM_MESSAGING (self));
ctx = g_slice_new0 (ListSmsContext);
ctx->self = g_object_ref (self);
@@ -263,7 +376,7 @@ mm_modem_messaging_list (MMModemMessaging *self,
if (cancellable)
ctx->cancellable = g_object_ref (cancellable);
- mm_gdbus_modem_messaging_call_list (self,
+ mm_gdbus_modem_messaging_call_list (MM_GDBUS_MODEM_MESSAGING (self),
cancellable,
(GAsyncReadyCallback)list_ready,
ctx);
@@ -280,7 +393,7 @@ mm_modem_messaging_list (MMModemMessaging *self,
* The calling thread is blocked until a reply is received. See mm_modem_messaging_list()
* for the asynchronous version of this method.
*
- * Returns: (transfer-full): The list of #MMSms objects, or %NULL if either none found or if @error is set.
+ * Returns: (element-type MM.Sms) (transfer full): A list of #MMSms objects, or #NULL if either not found or @error is set. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify function.
*/
GList *
mm_modem_messaging_list_sync (MMModemMessaging *self,
@@ -291,9 +404,9 @@ mm_modem_messaging_list_sync (MMModemMessaging *self,
gchar **sms_paths = NULL;
guint i;
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), NULL);
- if (!mm_gdbus_modem_messaging_call_list_sync (self,
+ if (!mm_gdbus_modem_messaging_call_list_sync (MM_GDBUS_MODEM_MESSAGING (self),
&sms_paths,
cancellable,
error))
@@ -326,6 +439,8 @@ mm_modem_messaging_list_sync (MMModemMessaging *self,
return sms_objects;
}
+/*****************************************************************************/
+
typedef struct {
GSimpleAsyncResult *result;
GCancellable *cancellable;
@@ -349,14 +464,14 @@ create_sms_context_complete_and_free (CreateSmsContext *ctx)
*
* Finishes an operation started with mm_modem_messaging_create().
*
- * Returns: (transfer-full): A newly created #MMSms, or %NULL if @error is set.
+ * Returns: (transfer full): A newly created #MMSms, or %NULL if @error is set. The returned value should be freed with g_object_unref().
*/
MMSms *
mm_modem_messaging_create_finish (MMModemMessaging *self,
GAsyncResult *res,
GError **error)
{
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
@@ -391,7 +506,7 @@ create_sms_ready (MMModemMessaging *self,
GError *error = NULL;
gchar *sms_path = NULL;
- if (!mm_gdbus_modem_messaging_call_create_finish (self,
+ if (!mm_gdbus_modem_messaging_call_create_finish (MM_GDBUS_MODEM_MESSAGING (self),
&sms_path,
res,
&error)) {
@@ -435,7 +550,7 @@ mm_modem_messaging_create (MMModemMessaging *self,
CreateSmsContext *ctx;
GVariant *dictionary;
- g_return_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self));
+ g_return_if_fail (MM_IS_MODEM_MESSAGING (self));
ctx = g_slice_new0 (CreateSmsContext);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
@@ -447,7 +562,7 @@ mm_modem_messaging_create (MMModemMessaging *self,
dictionary = (mm_sms_properties_get_dictionary (properties));
mm_gdbus_modem_messaging_call_create (
- self,
+ MM_GDBUS_MODEM_MESSAGING (self),
dictionary,
cancellable,
(GAsyncReadyCallback)create_sms_ready,
@@ -468,7 +583,7 @@ mm_modem_messaging_create (MMModemMessaging *self,
* The calling thread is blocked until a reply is received. See mm_modem_messaging_create()
* for the asynchronous version of this method.
*
- * Returns: (transfer-full): A newly created #MMSms, or %NULL if @error is set.
+ * Returns: (transfer full): A newly created #MMSms, or %NULL if @error is set. The returned value should be freed with g_object_unref().
*/
MMSms *
mm_modem_messaging_create_sync (MMModemMessaging *self,
@@ -480,10 +595,10 @@ mm_modem_messaging_create_sync (MMModemMessaging *self,
gchar *sms_path = NULL;
GVariant *dictionary;
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), NULL);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), NULL);
dictionary = (mm_sms_properties_get_dictionary (properties));
- mm_gdbus_modem_messaging_call_create_sync (self,
+ mm_gdbus_modem_messaging_call_create_sync (MM_GDBUS_MODEM_MESSAGING (self),
dictionary,
&sms_path,
cancellable,
@@ -502,6 +617,28 @@ mm_modem_messaging_create_sync (MMModemMessaging *self,
return sms;
}
+/*****************************************************************************/
+
+/**
+ * mm_modem_messaging_delete_finish:
+ * @self: A #MMModemMessaging.
+ * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_messaging_delete().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with mm_modem_messaging_delete().
+ *
+ * Returns: %TRUE if the sms was deleted, %FALSE if @error is set.
+ */
+gboolean
+mm_modem_messaging_delete_finish (MMModemMessaging *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
+
+ return mm_gdbus_modem_messaging_call_delete_finish (MM_GDBUS_MODEM_MESSAGING (self), res, error);
+}
+
/**
* mm_modem_messaging_delete:
* @self: A #MMModemMessaging.
@@ -524,9 +661,9 @@ mm_modem_messaging_delete (MMModemMessaging *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- g_return_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self));
+ g_return_if_fail (MM_IS_MODEM_MESSAGING (self));
- mm_gdbus_modem_messaging_call_delete (self,
+ mm_gdbus_modem_messaging_call_delete (MM_GDBUS_MODEM_MESSAGING (self),
sms,
cancellable,
callback,
@@ -534,28 +671,6 @@ mm_modem_messaging_delete (MMModemMessaging *self,
}
/**
- * mm_modem_messaging_delete_finish:
- * @self: A #MMModemMessaging.
- * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_messaging_delete().
- * @error: Return location for error or %NULL.
- *
- * Finishes an operation started with mm_modem_messaging_delete().
- *
- * Returns: (skip): %TRUE if the sms was deleted, %FALSE if @error is set.
- */
-gboolean
-mm_modem_messaging_delete_finish (MMModemMessaging *self,
- GAsyncResult *res,
- GError **error)
-{
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), FALSE);
-
- return mm_gdbus_modem_messaging_call_delete_finish (self,
- res,
- error);
-}
-
-/**
* mm_modem_messaging_delete_sync:
* @self: A #MMModemMessaging.
* @sms: Path of the #MMSms to delete.
@@ -567,7 +682,7 @@ mm_modem_messaging_delete_finish (MMModemMessaging *self,
* The calling thread is blocked until a reply is received. See mm_modem_messaging_delete()
* for the asynchronous version of this method.
*
- * Returns: (skip): %TRUE if the SMS was deleted, %FALSE if @error is set.
+ * Returns: %TRUE if the SMS was deleted, %FALSE if @error is set.
*/
gboolean
mm_modem_messaging_delete_sync (MMModemMessaging *self,
@@ -575,10 +690,46 @@ mm_modem_messaging_delete_sync (MMModemMessaging *self,
GCancellable *cancellable,
GError **error)
{
- g_return_val_if_fail (MM_GDBUS_IS_MODEM_MESSAGING (self), FALSE);
+ g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE);
- return mm_gdbus_modem_messaging_call_delete_sync (self,
+ return mm_gdbus_modem_messaging_call_delete_sync (MM_GDBUS_MODEM_MESSAGING (self),
sms,
cancellable,
error);
}
+
+/*****************************************************************************/
+
+static void
+mm_modem_messaging_init (MMModemMessaging *self)
+{
+ /* Setup private data */
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ MM_TYPE_MODEM_MESSAGING,
+ MMModemMessagingPrivate);
+ g_mutex_init (&self->priv->supported_storages_mutex);
+}
+
+static void
+finalize (GObject *object)
+{
+ MMModemMessaging *self = MM_MODEM_MESSAGING (object);
+
+ g_mutex_clear (&self->priv->supported_storages_mutex);
+
+ if (self->priv->supported_storages)
+ g_array_unref (self->priv->supported_storages);
+
+ G_OBJECT_CLASS (mm_modem_messaging_parent_class)->finalize (object);
+}
+
+static void
+mm_modem_messaging_class_init (MMModemMessagingClass *modem_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
+
+ g_type_class_add_private (object_class, sizeof (MMModemMessagingPrivate));
+
+ /* Virtual methods */
+ object_class->finalize = finalize;
+}