From 74051189c8499c75cfc2d928eb86ec6411d5420e Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 20 May 2011 10:31:48 +0200 Subject: [PATCH] ExampleEcho2Channel: implement SMS interface --- examples/cm/echo-message-parts/chan.c | 114 ++++++++++++++++++++++++++++++++- examples/cm/echo-message-parts/chan.h | 6 ++ 2 files changed, 119 insertions(+), 1 deletions(-) diff --git a/examples/cm/echo-message-parts/chan.c b/examples/cm/echo-message-parts/chan.c index 4f63390..3c2f2c0 100644 --- a/examples/cm/echo-message-parts/chan.c +++ b/examples/cm/echo-message-parts/chan.c @@ -18,6 +18,7 @@ #include static void destroyable_iface_init (gpointer iface, gpointer data); +static void sms_iface_init (gpointer iface, gpointer data); G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Channel, example_echo_2_channel, @@ -27,7 +28,8 @@ G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Channel, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_MESSAGES, tp_message_mixin_messages_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_DESTROYABLE, - destroyable_iface_init) + destroyable_iface_init); + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_SMS, sms_iface_init); ) /* type definition stuff */ @@ -35,11 +37,26 @@ G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Channel, static const char * example_echo_2_channel_interfaces[] = { TP_IFACE_CHANNEL_INTERFACE_MESSAGES, TP_IFACE_CHANNEL_INTERFACE_DESTROYABLE, + TP_IFACE_CHANNEL_INTERFACE_SMS, NULL }; +enum +{ + PROP_SMS = 1, + PROP_SMS_FLASH, + N_PROPS +}; + +struct _ExampleEcho2ChannelPrivate +{ + gboolean sms; +}; + static void example_echo_2_channel_init (ExampleEcho2Channel *self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EXAMPLE_TYPE_ECHO_2_CHANNEL, ExampleEcho2ChannelPrivate); } @@ -229,16 +246,76 @@ example_echo_2_channel_fill_immutable_properties (TpBaseChannel *chan, TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "DeliveryReportingSupport", TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "SupportedContentTypes", TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessageTypes", + TP_IFACE_CHANNEL_INTERFACE_SMS, "Flash", NULL); } static void +set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ExampleEcho2Channel *self = (ExampleEcho2Channel *) object; + + switch (property_id) + { + case PROP_SMS: + self->priv->sms = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ExampleEcho2Channel *self = (ExampleEcho2Channel *) object; + + switch (property_id) + { + case PROP_SMS: + g_value_set_boolean (value, self->priv->sms); + break; + case PROP_SMS_FLASH: + g_value_set_boolean (value, TRUE); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void example_echo_2_channel_class_init (ExampleEcho2ChannelClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; TpBaseChannelClass *base_class = (TpBaseChannelClass *) klass; + GParamSpec *param_spec; + static TpDBusPropertiesMixinPropImpl sms_props[] = { + { "SMSChannel", "sms", NULL }, + { "Flash", "sms-flash", NULL }, + { NULL } + }; + static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { + { TP_IFACE_CHANNEL_INTERFACE_SMS, + tp_dbus_properties_mixin_getter_gobject_properties, + NULL, + sms_props, + }, + { NULL } + }; + + g_type_class_add_private (klass, sizeof (ExampleEcho2ChannelPrivate)); object_class->constructor = constructor; + object_class->set_property = set_property; + object_class->get_property = get_property; object_class->finalize = finalize; base_class->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT; @@ -248,6 +325,22 @@ example_echo_2_channel_class_init (ExampleEcho2ChannelClass *klass) base_class->fill_immutable_properties = example_echo_2_channel_fill_immutable_properties; + param_spec = g_param_spec_boolean ("sms", "SMS", + "SMS.SMSChannel", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SMS, param_spec); + + param_spec = g_param_spec_boolean ("sms-flash", "SMS Flash", + "SMS.Flash", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SMS_FLASH, param_spec); + + klass->dbus_properties_class.interfaces = prop_interfaces; + tp_dbus_properties_mixin_class_init (object_class, + G_STRUCT_OFFSET (ExampleEcho2ChannelClass, dbus_properties_class)); + tp_message_mixin_init_dbus_properties (object_class); } @@ -274,3 +367,22 @@ destroyable_iface_init (gpointer iface, IMPLEMENT (destroy); #undef IMPLEMENT } + + +void +example_echo_2_channel_set_sms (ExampleEcho2Channel *self, + gboolean sms) +{ + if (self->priv->sms == sms) + return; + + self->priv->sms = sms; + + tp_svc_channel_interface_sms_emit_sms_channel_changed (self, sms); +} + +static void +sms_iface_init (gpointer iface, + gpointer data) +{ +} diff --git a/examples/cm/echo-message-parts/chan.h b/examples/cm/echo-message-parts/chan.h index dd82bed..1df724b 100644 --- a/examples/cm/echo-message-parts/chan.h +++ b/examples/cm/echo-message-parts/chan.h @@ -20,6 +20,7 @@ G_BEGIN_DECLS typedef struct _ExampleEcho2Channel ExampleEcho2Channel; typedef struct _ExampleEcho2ChannelClass ExampleEcho2ChannelClass; +typedef struct _ExampleEcho2ChannelPrivate ExampleEcho2ChannelPrivate; GType example_echo_2_channel_get_type (void); @@ -41,13 +42,18 @@ GType example_echo_2_channel_get_type (void); struct _ExampleEcho2ChannelClass { TpBaseChannelClass parent_class; + TpDBusPropertiesMixinClass dbus_properties_class; }; struct _ExampleEcho2Channel { TpBaseChannel parent; TpMessageMixin text; + ExampleEcho2ChannelPrivate *priv; }; +void example_echo_2_channel_set_sms (ExampleEcho2Channel *self, + gboolean sms); + G_END_DECLS #endif -- 1.7.4.1