telepathy-logger: Add TplClientFactory

Xavier Claessens xclaesse at kemper.freedesktop.org
Thu Jul 5 08:06:43 PDT 2012


Module: telepathy-logger
Branch: master
Commit: 83321bc4095d064652a0dd2b537e171b5f6fedd5
URL:    http://cgit.freedesktop.org/telepathy/telepathy-logger/commit/?id=83321bc4095d064652a0dd2b537e171b5f6fedd5

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Wed Jul  4 13:32:26 2012 +0200

Add TplClientFactory

It is a TpAutomaticClientFactory subclass that creates
TplTextChannel and TplCallChannel instances

---

 telepathy-logger/Makefile.am               |    2 +
 telepathy-logger/call-channel-internal.h   |    7 ++
 telepathy-logger/call-channel.c            |   12 +++
 telepathy-logger/client-factory-internal.h |   59 ++++++++++++++++
 telepathy-logger/client-factory.c          |  103 ++++++++++++++++++++++++++++
 telepathy-logger/text-channel-internal.h   |   10 +++-
 telepathy-logger/text-channel.c            |   12 +++
 7 files changed, 204 insertions(+), 1 deletions(-)

diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index db2fd57..6bc36e5 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -58,6 +58,8 @@ libtelepathy_logger_la_SOURCES = \
 		channel.c			\
 		channel-factory.c		\
 		channel-factory-internal.h	\
+		client-factory.c		\
+		client-factory-internal.h	\
 		conf.c				\
 		conf-internal.h			\
 		entity.c			\
diff --git a/telepathy-logger/call-channel-internal.h b/telepathy-logger/call-channel-internal.h
index 439b3af..9ec0d5f 100644
--- a/telepathy-logger/call-channel-internal.h
+++ b/telepathy-logger/call-channel-internal.h
@@ -69,5 +69,12 @@ TplCallChannel * _tpl_call_channel_new (TpConnection *conn,
     GHashTable *tp_chan_props,
     GError **error);
 
+TplCallChannel * _tpl_call_channel_new_with_factory (
+    TpSimpleClientFactory *factory,
+    TpConnection *conn,
+    const gchar *object_path,
+    const GHashTable *tp_chan_props,
+    GError **error);
+
 G_END_DECLS
 #endif /* __TPL_CALL_CHANNEL_H__ */
diff --git a/telepathy-logger/call-channel.c b/telepathy-logger/call-channel.c
index 2b09bbb..711422f 100644
--- a/telepathy-logger/call-channel.c
+++ b/telepathy-logger/call-channel.c
@@ -521,6 +521,17 @@ _tpl_call_channel_new (TpConnection *conn,
     GHashTable *tp_chan_props,
     GError **error)
 {
+  return _tpl_call_channel_new_with_factory (NULL, conn, object_path,
+      tp_chan_props, error);
+}
+
+TplCallChannel *
+_tpl_call_channel_new_with_factory (TpSimpleClientFactory *factory,
+    TpConnection *conn,
+    const gchar *object_path,
+    const GHashTable *tp_chan_props,
+    GError **error)
+{
   TpProxy *conn_proxy = TP_PROXY (conn);
   TplCallChannel *self;
 
@@ -535,6 +546,7 @@ _tpl_call_channel_new (TpConnection *conn,
     return NULL;
 
   self = g_object_new (TPL_TYPE_CALL_CHANNEL,
+      "factory", factory,
       "connection", conn,
       "dbus-daemon", conn_proxy->dbus_daemon,
       "bus-name", conn_proxy->bus_name,
diff --git a/telepathy-logger/client-factory-internal.h b/telepathy-logger/client-factory-internal.h
new file mode 100644
index 0000000..9612c30
--- /dev/null
+++ b/telepathy-logger/client-factory-internal.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors: Xavier Claessens <xavier.claessens at collabora.co.uk>
+ */
+
+#ifndef __TPL_CLIENT_FACTORY_H__
+#define __TPL_CLIENT_FACTORY_H__
+
+#include <telepathy-glib/telepathy-glib.h>
+
+typedef struct _TplClientFactory TplClientFactory;
+typedef struct _TplClientFactoryClass TplClientFactoryClass;
+
+struct _TplClientFactoryClass {
+    /*<public>*/
+    TpAutomaticClientFactoryClass parent_class;
+};
+
+struct _TplClientFactory {
+    /*<private>*/
+    TpAutomaticClientFactory parent;
+};
+
+GType _tpl_client_factory_get_type (void);
+
+#define TPL_TYPE_CLIENT_FACTORY \
+  (_tpl_client_factory_get_type ())
+#define TPL_CLIENT_FACTORY(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CLIENT_FACTORY, \
+                               TplClientFactory))
+#define TPL_CLIENT_FACTORY_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CLIENT_FACTORY, \
+                            TplClientFactoryClass))
+#define TPL_IS_CLIENT_FACTORY(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CLIENT_FACTORY))
+#define TPL_IS_CLIENT_FACTORY_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CLIENT_FACTORY))
+#define TPL_CLIENT_FACTORY_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CLIENT_FACTORY, \
+                              TplClientFactoryClass))
+
+TpSimpleClientFactory *_tpl_client_factory_new (TpDBusDaemon *dbus);
+
+#endif /* __TPL_CLIENT_FACTORY_H__ */
diff --git a/telepathy-logger/client-factory.c b/telepathy-logger/client-factory.c
new file mode 100644
index 0000000..0d4b131
--- /dev/null
+++ b/telepathy-logger/client-factory.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors: Xavier Claessens <xavier.claessens at collabora.co.uk>
+ */
+
+#include "config.h"
+#include "client-factory-internal.h"
+
+#include <telepathy-glib/telepathy-glib.h>
+
+#include <telepathy-logger/text-channel-internal.h>
+#include <telepathy-logger/call-channel-internal.h>
+
+G_DEFINE_TYPE (TplClientFactory, _tpl_client_factory,
+    TP_TYPE_AUTOMATIC_CLIENT_FACTORY)
+
+#define chainup ((TpSimpleClientFactoryClass *) \
+    _tpl_client_factory_parent_class)
+
+static TpChannel *
+create_channel_impl (TpSimpleClientFactory *self,
+    TpConnection *conn,
+    const gchar *object_path,
+    const GHashTable *properties,
+    GError **error)
+{
+  const gchar *chan_type;
+
+  chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
+
+  if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
+    {
+      return (TpChannel *) _tpl_text_channel_new_with_factory (self, conn,
+          object_path, properties, error);
+    }
+  else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_CALL))
+    {
+      return (TpChannel *) _tpl_call_channel_new_with_factory (self, conn,
+          object_path, properties, error);
+    }
+
+  return chainup->create_channel (self, conn, object_path, properties, error);
+}
+
+static GArray *
+dup_channel_features_impl (TpSimpleClientFactory *self,
+    TpChannel *channel)
+{
+  GArray *features;
+  GQuark f;
+
+  features = chainup->dup_channel_features (self, channel);
+
+  if (TPL_IS_CALL_CHANNEL (channel))
+    {
+      f = TPL_CALL_CHANNEL_FEATURE_CORE;
+      g_array_append_val (features, f);
+    }
+  else if (TPL_IS_TEXT_CHANNEL (channel))
+    {
+      f = TPL_TEXT_CHANNEL_FEATURE_CORE;
+      g_array_append_val (features, f);
+    }
+
+  return features;
+}
+
+static void
+_tpl_client_factory_init (TplClientFactory *self)
+{
+}
+
+static void
+_tpl_client_factory_class_init (TplClientFactoryClass *cls)
+{
+  TpSimpleClientFactoryClass *simple_class = (TpSimpleClientFactoryClass *) cls;
+
+  simple_class->create_channel = create_channel_impl;
+  simple_class->dup_channel_features = dup_channel_features_impl;
+}
+
+TpSimpleClientFactory *
+_tpl_client_factory_new (TpDBusDaemon *dbus)
+{
+  return g_object_new (TPL_TYPE_CLIENT_FACTORY,
+      "dbus-daemon", dbus,
+      NULL);
+}
diff --git a/telepathy-logger/text-channel-internal.h b/telepathy-logger/text-channel-internal.h
index 6107b59..c1ae5ca 100644
--- a/telepathy-logger/text-channel-internal.h
+++ b/telepathy-logger/text-channel-internal.h
@@ -71,7 +71,15 @@ typedef struct
 GType _tpl_text_channel_get_type (void);
 
 TplTextChannel * _tpl_text_channel_new (TpConnection *conn,
-    const gchar *object_path, GHashTable *tp_chan_props,
+    const gchar *object_path,
+    GHashTable *tp_chan_props,
+    GError **error);
+
+TplTextChannel * _tpl_text_channel_new_with_factory (
+    TpSimpleClientFactory *factory,
+    TpConnection *conn,
+    const gchar *object_path,
+    const GHashTable *tp_chan_props,
     GError **error);
 
 G_END_DECLS
diff --git a/telepathy-logger/text-channel.c b/telepathy-logger/text-channel.c
index d2560fb..3c3b5cd 100644
--- a/telepathy-logger/text-channel.c
+++ b/telepathy-logger/text-channel.c
@@ -759,6 +759,17 @@ _tpl_text_channel_new (TpConnection *conn,
     GHashTable *tp_chan_props,
     GError **error)
 {
+  return _tpl_text_channel_new_with_factory (NULL, conn, object_path,
+      tp_chan_props, error);
+}
+
+TplTextChannel *
+_tpl_text_channel_new_with_factory (TpSimpleClientFactory *factory,
+    TpConnection *conn,
+    const gchar *object_path,
+    const GHashTable *tp_chan_props,
+    GError **error)
+{
   TpProxy *conn_proxy = TP_PROXY (conn);
   TplTextChannel *self;
 
@@ -773,6 +784,7 @@ _tpl_text_channel_new (TpConnection *conn,
 
   self = g_object_new (TPL_TYPE_TEXT_CHANNEL,
       /* TpChannel properties */
+      "factory", factory,
       "connection", conn,
       "dbus-daemon", conn_proxy->dbus_daemon,
       "bus-name", conn_proxy->bus_name,



More information about the telepathy-commits mailing list