From fdec98521ecaeee2f34128d5faa9b6dbb16dcb0a Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 20 May 2011 11:55:29 +0200 Subject: [PATCH] ExampleEcho2Channel: add a simple implementation of SMS.GetSMSLength() --- examples/cm/echo-message-parts/chan.c | 40 +++++++++++++++++++++++++++++++++ examples/cm/echo-message-parts/chan.h | 2 + 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/examples/cm/echo-message-parts/chan.c b/examples/cm/echo-message-parts/chan.c index 3c2f2c0..96aeddc 100644 --- a/examples/cm/echo-message-parts/chan.c +++ b/examples/cm/echo-message-parts/chan.c @@ -13,8 +13,11 @@ #include "chan.h" +#include + #include #include +#include #include static void destroyable_iface_init (gpointer iface, gpointer data); @@ -382,7 +385,44 @@ example_echo_2_channel_set_sms (ExampleEcho2Channel *self, } static void +sms_get_sms_length (TpSvcChannelInterfaceSMS *self, + const GPtrArray *parts, + DBusGMethodInvocation *context) +{ + TpMessage *message; + guint i; + gchar *txt; + size_t len; + + message = tp_cm_message_new ( + tp_base_channel_get_connection (TP_BASE_CHANNEL (self)), parts->len); + + for (i = 0; i < parts->len; i++) + { + tp_g_hash_table_update (g_ptr_array_index (message->parts, i), + g_ptr_array_index (parts, i), + (GBoxedCopyFunc) g_strdup, + (GBoxedCopyFunc) tp_g_value_slice_dup); + } + + txt = tp_message_to_text (message, NULL); + len = strlen (txt); + + tp_svc_channel_interface_sms_return_from_get_sms_length (context, len, + EXAMPLE_ECHO_2_CHANNEL_MAX_SMS_LENGTH - len, -1); + + g_object_unref (message); + g_free (txt); +} + +static void sms_iface_init (gpointer iface, gpointer data) { + TpSvcChannelInterfaceSMSClass *klass = iface; + +#define IMPLEMENT(x) \ + tp_svc_channel_interface_sms_implement_##x (klass, sms_##x) + IMPLEMENT (get_sms_length); +#undef IMPLEMENT } diff --git a/examples/cm/echo-message-parts/chan.h b/examples/cm/echo-message-parts/chan.h index 1df724b..0bc98ca 100644 --- a/examples/cm/echo-message-parts/chan.h +++ b/examples/cm/echo-message-parts/chan.h @@ -51,6 +51,8 @@ struct _ExampleEcho2Channel { ExampleEcho2ChannelPrivate *priv; }; +#define EXAMPLE_ECHO_2_CHANNEL_MAX_SMS_LENGTH 100 + void example_echo_2_channel_set_sms (ExampleEcho2Channel *self, gboolean sms); -- 1.7.4.1