diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-02-08 14:26:13 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:15:01 +0100 |
commit | 470d9b933ef3a324195b1cd15edd10aba57c564d (patch) | |
tree | 322c39e7ee09feece669ff62ecc2a8986636ec76 | |
parent | fb02fbf7a0f303ea685fe1db1af9810a4234ff84 (diff) |
sms: handle message storing and sending actions from DBus
-rw-r--r-- | src/mm-sms.c | 127 | ||||
-rw-r--r-- | src/mm-sms.h | 17 |
2 files changed, 142 insertions, 2 deletions
diff --git a/src/mm-sms.c b/src/mm-sms.c index 038cc337..54fa4dbd 100644 --- a/src/mm-sms.c +++ b/src/mm-sms.c @@ -71,6 +71,123 @@ struct _MMSmsPrivate { /*****************************************************************************/ +typedef struct { + MMSms *self; + GDBusMethodInvocation *invocation; +} DbusCallContext; + +static void +dbus_call_context_free (DbusCallContext *ctx) +{ + g_object_unref (ctx->invocation); + g_object_unref (ctx->self); + g_free (ctx); +} + +static DbusCallContext * +dbus_call_context_new (MMSms *self, + GDBusMethodInvocation *invocation) +{ + DbusCallContext *ctx; + + ctx = g_new0 (DbusCallContext, 1); + ctx->self = g_object_ref (self); + ctx->invocation = g_object_ref (invocation); + return ctx; +} + +/*****************************************************************************/ +/* Store SMS (DBus call handling) */ + +static void +handle_store_ready (MMSms *self, + GAsyncResult *res, + DbusCallContext *ctx) +{ + GError *error = NULL; + + MM_SMS_GET_CLASS (self)->store_finish (self, res, &error); + if (error) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_sms_complete_store (MM_GDBUS_SMS (ctx->self), ctx->invocation); + dbus_call_context_free (ctx); +} + +static gboolean +sms_is_stored (MMSms *self) +{ + GList *l; + + for (l = self->priv->parts; l; l = g_list_next (l)) { + if (mm_sms_part_get_index ((MMSmsPart *)l->data) == SMS_PART_INVALID_INDEX) + return FALSE; + } + + return TRUE; +} + +static gboolean +handle_store (MMSms *self, + GDBusMethodInvocation *invocation) +{ + /* First of all, check if we already have the SMS stored. */ + if (sms_is_stored (self)) + mm_gdbus_sms_complete_store (MM_GDBUS_SMS (self), invocation); + /* If not stored, check if we do support doing it */ + else if (MM_SMS_GET_CLASS (self)->store && + MM_SMS_GET_CLASS (self)->store_finish) + MM_SMS_GET_CLASS (self)->store (self, + (GAsyncReadyCallback)handle_store_ready, + dbus_call_context_new (self, + invocation)); + else + g_dbus_method_invocation_return_error (invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Storing SMS is not supported by this modem"); + return TRUE; +} + +/*****************************************************************************/ +/* Send SMS (DBus call handling) */ + +static void +handle_send_ready (MMSms *self, + GAsyncResult *res, + DbusCallContext *ctx) +{ + GError *error = NULL; + + MM_SMS_GET_CLASS (self)->send_finish (self, res, &error); + if (error) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_sms_complete_send (MM_GDBUS_SMS (ctx->self), ctx->invocation); + dbus_call_context_free (ctx); +} + +static gboolean +handle_send (MMSms *self, + GDBusMethodInvocation *invocation) +{ + /* Check if we do support doing it */ + if (MM_SMS_GET_CLASS (self)->send && + MM_SMS_GET_CLASS (self)->send_finish) + MM_SMS_GET_CLASS (self)->send (self, + (GAsyncReadyCallback)handle_send_ready, + dbus_call_context_new (self, + invocation)); + else + g_dbus_method_invocation_return_error (invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Sending SMS is not supported by this modem"); + return TRUE; +} + +/*****************************************************************************/ + void mm_sms_export (MMSms *self) { @@ -91,7 +208,15 @@ mm_sms_dbus_export (MMSms *self) { GError *error = NULL; - /* TODO: Handle method invocations */ + /* Handle method invocations */ + g_signal_connect (self, + "handle-store", + G_CALLBACK (handle_store), + NULL); + g_signal_connect (self, + "handle-send", + G_CALLBACK (handle_send), + NULL); if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self), self->priv->connection, diff --git a/src/mm-sms.h b/src/mm-sms.h index 89e83551..cb551147 100644 --- a/src/mm-sms.h +++ b/src/mm-sms.h @@ -52,6 +52,22 @@ struct _MMSms { struct _MMSmsClass { MmGdbusSmsSkeletonClass parent; + /* Store the SMS */ + void (* store) (MMSms *self, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (* store_finish) (MMSms *self, + GAsyncResult *res, + GError **error); + + /* Send the SMS */ + void (* send) (MMSms *self, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (* send_finish) (MMSms *self, + GAsyncResult *res, + GError **error); + /* Delete the SMS */ void (* delete) (MMSms *self, GAsyncReadyCallback callback, @@ -96,7 +112,6 @@ guint mm_sms_get_multipart_reference (MMSms *self); gboolean mm_sms_multipart_is_complete (MMSms *self); gboolean mm_sms_multipart_is_assembled (MMSms *self); - void mm_sms_delete (MMSms *self, GAsyncReadyCallback callback, gpointer user_data); |