[telepathy-doc/master] Implement the properties mixin

Davyd Madeley davyd at madeley.id.au
Thu Jul 30 22:26:25 PDT 2009


---
 docs/examples/glib_mc5_observer/example-observer.c |   70 ++++++++++++++++++--
 docs/examples/glib_mc5_observer/example-observer.h |    2 +
 2 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/docs/examples/glib_mc5_observer/example-observer.c b/docs/examples/glib_mc5_observer/example-observer.c
index fb2425f..1966a31 100644
--- a/docs/examples/glib_mc5_observer/example-observer.c
+++ b/docs/examples/glib_mc5_observer/example-observer.c
@@ -1,3 +1,5 @@
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-generic.h>
 #include <telepathy-glib/svc-client.h>
 
 #include "example-observer.h"
@@ -8,10 +10,23 @@ static void observer_iface_init (gpointer, gpointer);
 // #define EXAMPLE_OBSERVER_GET_PRIVATE(obj)	(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EXAMPLE_TYPE_OBSERVER, ExampleObserverPrivate))
 
 G_DEFINE_TYPE_WITH_CODE (ExampleObserver, example_observer, G_TYPE_OBJECT,
-    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CLIENT, client_iface_init);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+      tp_dbus_properties_mixin_iface_init);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CLIENT, NULL);
     G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CLIENT_OBSERVER, observer_iface_init);
     );
 
+static const char *client_interfaces[] = {
+    TP_IFACE_CLIENT_OBSERVER,
+    NULL
+};
+
+enum
+{
+  PROP_0,
+  PROP_INTERFACES
+};
+
 // typedef struct _ExampleObserverPrivate ExampleObserverPrivate;
 // struct _ExampleObserverPrivate
 // {
@@ -36,19 +51,64 @@ example_observer_observe_channels (TpSvcClientObserver   *self,
 }
 
 static void
-example_observer_class_init (ExampleObserverClass *class)
+example_observer_get_property (GObject    *self,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
 {
+  switch (property_id)
+    {
+      case PROP_INTERFACES:
+        g_value_set_boxed (value, client_interfaces);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
+        break;
+    }
 }
 
 static void
-example_observer_init (ExampleObserver *self)
+example_observer_class_init (ExampleObserverClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->get_property = example_observer_get_property;
+
+  /* D-Bus properties are exposed as GObject properties through the
+   * TpDBusPropertiesMixin */
+  /* properties on the Client interface */
+  static TpDBusPropertiesMixinPropImpl client_props[] = {
+        { "Interfaces", "interfaces", NULL },
+        { NULL }
+  };
+
+  /* complete list of interfaces with properties */
+  static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
+        { TP_IFACE_CLIENT,
+          tp_dbus_properties_mixin_getter_gobject_properties,
+          NULL,
+          client_props
+        },
+        { NULL }
+  };
+
+  g_object_class_install_property (object_class, PROP_INTERFACES,
+      g_param_spec_boxed ("interfaces",
+                          "Interfaces",
+                          "Available D-Bus Interfaces",
+                          G_TYPE_STRV,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  /* call our mixin class init */
+  klass->dbus_props_class.interfaces = prop_interfaces;
+  tp_dbus_properties_mixin_class_init (object_class,
+      G_STRUCT_OFFSET (ExampleObserverClass, dbus_props_class));
 }
 
 static void
-client_iface_init (gpointer g_iface, gpointer iface_data)
+example_observer_init (ExampleObserver *self)
 {
-  /* no methods */
 }
 
 static void
diff --git a/docs/examples/glib_mc5_observer/example-observer.h b/docs/examples/glib_mc5_observer/example-observer.h
index 3a5b4da..53ce227 100644
--- a/docs/examples/glib_mc5_observer/example-observer.h
+++ b/docs/examples/glib_mc5_observer/example-observer.h
@@ -2,6 +2,7 @@
 #define __EXAMPLE_OBSERVER_H__
 
 #include <glib-object.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
 
 G_BEGIN_DECLS
 
@@ -23,6 +24,7 @@ struct _ExampleObserver
 struct _ExampleObserverClass
 {
 	GObjectClass parent_class;
+	TpDBusPropertiesMixinClass dbus_props_class;
 };
 
 GType example_observer_get_type (void);
-- 
1.5.6.5




More information about the telepathy-commits mailing list