diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-20 11:55:29 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-30 09:45:32 +0200 |
commit | 850bb30a7fb660f6c30f80d89a53b01d555f86be (patch) | |
tree | c58d8a6e48bffad0e23fdf1fcff2d8e9e1e71927 | |
parent | 0f205be359d813369defe3f0d72022657b90fdf1 (diff) | |
download | telepathy-glib-850bb30a7fb660f6c30f80d89a53b01d555f86be.tar.gz |
ExampleEcho2Channel: add a simple implementation of SMS.GetSMSLength()
-rw-r--r-- | examples/cm/echo-message-parts/chan.c | 40 | ||||
-rw-r--r-- | 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 610c0e42d..591692ca4 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 <string.h> + #include <telepathy-glib/telepathy-glib.h> #include <telepathy-glib/channel-iface.h> +#include <telepathy-glib/message-internal.h> #include <telepathy-glib/svc-channel.h> static void destroyable_iface_init (gpointer iface, gpointer data); @@ -375,7 +378,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 06ae70c12..8a420cac7 100644 --- a/examples/cm/echo-message-parts/chan.h +++ b/examples/cm/echo-message-parts/chan.h @@ -50,6 +50,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); |