[telepathy-doc/master] A non-working MC5 Client.Handler

Danielle Madeley danielle.madeley at collabora.co.uk
Tue Sep 22 18:35:01 PDT 2009


---
 configure.ac                                       |    1 +
 docs/examples/Makefile.am                          |    1 +
 docs/examples/glib_mc5_ft_handler/Makefile.am      |   10 +
 .../examples/glib_mc5_ft_handler/example-handler.c |  211 ++++++++++++++++++++
 .../examples/glib_mc5_ft_handler/example-handler.h |   37 ++++
 docs/examples/glib_mc5_ft_handler/example.c        |   41 ++++
 6 files changed, 301 insertions(+), 0 deletions(-)
 create mode 100644 docs/examples/glib_mc5_ft_handler/Makefile.am
 create mode 100644 docs/examples/glib_mc5_ft_handler/example-handler.c
 create mode 100644 docs/examples/glib_mc5_ft_handler/example-handler.h
 create mode 100644 docs/examples/glib_mc5_ft_handler/example.c

diff --git a/configure.ac b/configure.ac
index 0751158..e05996b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,7 @@ AC_OUTPUT([
       docs/examples/glib_stream_tube/Makefile
       docs/examples/glib_mc5_connections/Makefile
       docs/examples/glib_mc5_observer/Makefile
+      docs/examples/glib_mc5_ft_handler/Makefile
       docs/examples/gtk_presence_app/Makefile
       docs/examples/pygtk_chat_client/Makefile
       docs/examples/python_get_parameters/Makefile
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index d14e5ac..f7a9037 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -9,6 +9,7 @@ example_dirs = \
 	glib_stream_tube \
 	glib_mc5_connections \
 	glib_mc5_observer \
+	glib_mc5_ft_handler \
 	gtk_presence_app \
 	pygtk_chat_client \
 	python_get_parameters \
diff --git a/docs/examples/glib_mc5_ft_handler/Makefile.am b/docs/examples/glib_mc5_ft_handler/Makefile.am
new file mode 100644
index 0000000..e3b381c
--- /dev/null
+++ b/docs/examples/glib_mc5_ft_handler/Makefile.am
@@ -0,0 +1,10 @@
+INCLUDES = $(TELEPATHY_GLIB_CFLAGS)
+LDADD = $(TELEPATHY_GLIB_LIBS)
+
+noinst_PROGRAMS = example
+
+example_SOURCES = \
+	example-handler.c example-handler.h \
+	example.c
+
+include $(top_srcdir)/docs/rsync-dist.make
diff --git a/docs/examples/glib_mc5_ft_handler/example-handler.c b/docs/examples/glib_mc5_ft_handler/example-handler.c
new file mode 100644
index 0000000..8bc2868
--- /dev/null
+++ b/docs/examples/glib_mc5_ft_handler/example-handler.c
@@ -0,0 +1,211 @@
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/dbus.h>
+
+#include <telepathy-glib/svc-generic.h>
+#include <telepathy-glib/svc-client.h>
+
+#include "example-handler.h"
+
+static void client_iface_init (gpointer, gpointer);
+static void handler_iface_init (gpointer, gpointer);
+
+// #define EXAMPLE_HANDLER_GET_PRIVATE(obj)	(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EXAMPLE_TYPE_HANDLER, ExampleHandlerPrivate))
+
+G_DEFINE_TYPE_WITH_CODE (ExampleHandler, example_handler, G_TYPE_OBJECT,
+    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_HANDLER, handler_iface_init);
+    );
+
+static const char *client_interfaces[] = {
+    TP_IFACE_CLIENT_HANDLER,
+    NULL
+};
+
+enum
+{
+  PROP_0,
+  PROP_INTERFACES,
+  PROP_CHANNEL_FILTER,
+  PROP_BYPASS_APPROVAL,
+  PROP_HANDLED_CHANNELS
+};
+
+// typedef struct _ExampleHandlerPrivate ExampleHandlerPrivate;
+// struct _ExampleHandlerPrivate
+// {
+// };
+
+static void
+example_handler_handle_channels (TpSvcClientHandler   *self,
+                                 const char            *account,
+                                 const char            *connection,
+                                 const GPtrArray       *channels,
+                                 const GPtrArray       *requests_satisfied,
+                                 guint64                user_action_time,
+                                 GHashTable            *handler_info,
+                                 DBusGMethodInvocation *context)
+{
+  g_print (" > example_handler_handle_channels\n");
+  g_print ("     account    = %s\n", account);
+  g_print ("     connection = %s\n", connection);
+
+  /* channels is of type a(oa{sv}) */
+  int i;
+  for (i = 0; i < channels->len; i++)
+    {
+      GValueArray *channel = g_ptr_array_index (channels, i);
+
+      char *path = g_value_get_boxed (g_value_array_get_nth (channel, 0));
+      GHashTable *map = g_value_get_boxed (g_value_array_get_nth (channel, 1));
+
+      g_print ("     channel    = %s\n", path);
+    }
+
+  tp_svc_client_handler_return_from_handle_channels (context);
+}
+
+static void
+example_handler_get_property (GObject    *self,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  switch (property_id)
+    {
+      case PROP_INTERFACES:
+        g_print (" :: interfaces\n");
+        g_value_set_boxed (value, client_interfaces);
+        break;
+
+      case PROP_CHANNEL_FILTER:
+        g_print (" :: channel-filter\n");
+
+        /* we're only interested in FT channels */
+          {
+            GPtrArray *array = g_ptr_array_new ();
+            GHashTable *map = tp_asv_new (
+                TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
+                    TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
+                NULL);
+
+            g_ptr_array_add (array, map);
+            g_value_take_boxed (value, array);
+          }
+        break;
+
+      case PROP_BYPASS_APPROVAL:
+        g_print (" :: bypass-approval\n");
+        g_value_set_boolean (value, FALSE);
+        break;
+
+      case PROP_HANDLED_CHANNELS:
+        g_print (" :: handled-channels\n");
+
+          {
+            GPtrArray *array = g_ptr_array_new ();
+            g_value_take_boxed (value, array);
+          }
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
+        break;
+    }
+}
+
+static void
+example_handler_class_init (ExampleHandlerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->get_property = example_handler_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 }
+  };
+
+  /* properties on the Client.Handler interface */
+  static TpDBusPropertiesMixinPropImpl client_handler_props[] = {
+        { "HandlerChannelFilter", "channel-filter", NULL },
+        { "BypassApproval", "bypass-approval", NULL },
+        { "HandledChannels", "handled-channels", 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
+        },
+        { TP_IFACE_CLIENT_HANDLER,
+          tp_dbus_properties_mixin_getter_gobject_properties,
+          NULL,
+          client_handler_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));
+
+  g_object_class_install_property (object_class, PROP_CHANNEL_FILTER,
+      g_param_spec_boxed ("channel-filter",
+                          "Channel Filter",
+                          "Filter for channels we handle",
+                          TP_ARRAY_TYPE_CHANNEL_CLASS_LIST,
+                          G_PARAM_READABLE));
+
+  g_object_class_install_property (object_class, PROP_BYPASS_APPROVAL,
+      g_param_spec_boolean ("bypass-approval",
+                            "Bypass Approval",
+                            "Whether or not to bypass the Approver",
+                            FALSE,
+                            G_PARAM_READABLE));
+
+  g_object_class_install_property (object_class, PROP_HANDLED_CHANNELS,
+      g_param_spec_boxed ("handled-channels",
+                          "Handled Channels",
+                          "List of channels we're handling",
+                          TP_ARRAY_TYPE_OBJECT_PATH_LIST,
+                          G_PARAM_READABLE));
+
+  /* call our mixin class init */
+  klass->dbus_props_class.interfaces = prop_interfaces;
+  tp_dbus_properties_mixin_class_init (object_class,
+      G_STRUCT_OFFSET (ExampleHandlerClass, dbus_props_class));
+}
+
+static void
+example_handler_init (ExampleHandler *self)
+{
+}
+
+static void
+handler_iface_init (gpointer g_iface, gpointer iface_data)
+{
+  TpSvcClientHandlerClass *klass = (TpSvcClientHandlerClass *) g_iface;
+
+#define IMPLEMENT(x) tp_svc_client_handler_implement_##x (klass, \
+    example_handler_##x)
+  IMPLEMENT (handle_channels);
+#undef IMPLEMENT
+}
+
+ExampleHandler *
+example_handler_new (void)
+{
+  return g_object_new (TYPE_EXAMPLE_HANDLER, NULL);
+}
diff --git a/docs/examples/glib_mc5_ft_handler/example-handler.h b/docs/examples/glib_mc5_ft_handler/example-handler.h
new file mode 100644
index 0000000..3fd61e3
--- /dev/null
+++ b/docs/examples/glib_mc5_ft_handler/example-handler.h
@@ -0,0 +1,37 @@
+#ifndef __EXAMPLE_HANDLER_H__
+#define __EXAMPLE_HANDLER_H__
+
+#include <glib-object.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_EXAMPLE_HANDLER	(example_handler_get_type ())
+#define EXAMPLE_HANDLER(obj)	(G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_EXAMPLE_HANDLER, ExampleHandler))
+#define EXAMPLE_HANDLER_CLASS(obj)	(G_TYPE_CHECK_CLASS_CAST ((obj), TYPE_EXAMPLE_HANDLER, ExampleHandlerClass))
+#define IS_EXAMPLE_HANDLER(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_EXAMPLE_HANDLER))
+#define IS_EXAMPLE_HANDLER_CLASS(obj)	(G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_EXAMPLE_HANDLER))
+#define EXAMPLE_HANDLER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_EXAMPLE_HANDLER, ExampleHandlerClass))
+
+typedef struct _ExampleHandler ExampleHandler;
+
+struct _ExampleHandler
+{
+	GObject parent;
+};
+
+/* begin ex.services.glib.properties.class */
+typedef struct _ExampleHandlerClass ExampleHandlerClass;
+struct _ExampleHandlerClass
+{
+	GObjectClass parent_class;
+	TpDBusPropertiesMixinClass dbus_props_class;
+};
+/* end ex.services.glib.properties.class */
+
+GType example_handler_get_type (void);
+ExampleHandler *example_handler_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/docs/examples/glib_mc5_ft_handler/example.c b/docs/examples/glib_mc5_ft_handler/example.c
new file mode 100644
index 0000000..c10c252
--- /dev/null
+++ b/docs/examples/glib_mc5_ft_handler/example.c
@@ -0,0 +1,41 @@
+/*
+ * An example of talking to MC5 to get available connections
+ */
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/defs.h>
+
+#include "example-handler.h"
+
+#define CLIENT_NAME "ExampleFTHandler"
+
+static GMainLoop *loop = NULL;
+
+int
+main (int argc, char **argv)
+{
+  GError *error = NULL;
+
+  g_type_init ();
+
+  loop = g_main_loop_new (NULL, FALSE);
+
+  TpDBusDaemon *tpdbus = tp_dbus_daemon_dup (NULL);
+  DBusGConnection *dbus = tp_get_bus ();
+
+  ExampleHandler *example_handler = example_handler_new ();
+
+  /* register well-known name */
+  g_assert (tp_dbus_daemon_request_name (tpdbus,
+      TP_CLIENT_BUS_NAME_BASE CLIENT_NAME,
+      TRUE, NULL));
+  /* register ExampleHandler on the bus */
+  dbus_g_connection_register_g_object (dbus,
+      TP_CLIENT_OBJECT_PATH_BASE CLIENT_NAME,
+      G_OBJECT (example_handler));
+
+  g_main_loop_run (loop);
+}
-- 
1.5.6.5




More information about the telepathy-commits mailing list