[telepathy-gabble/master] Add a stub ContactSearch channel implementation

Will Thompson will.thompson at collabora.co.uk
Wed Aug 26 09:21:45 PDT 2009


---
 src/Makefile.am      |    2 +
 src/search-channel.c |  295 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/search-channel.h |   63 +++++++++++
 3 files changed, 360 insertions(+), 0 deletions(-)
 create mode 100644 src/search-channel.c
 create mode 100644 src/search-channel.h

diff --git a/src/Makefile.am b/src/Makefile.am
index dc7efc8..6ea17ba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -126,6 +126,8 @@ libgabble_convenience_la_SOURCES = \
     roomlist-channel.c \
     roomlist-manager.h \
     roomlist-manager.c \
+    search-channel.h \
+    search-channel.c \
     search-manager.h \
     search-manager.c \
     tube-iface.h \
diff --git a/src/search-channel.c b/src/search-channel.c
new file mode 100644
index 0000000..6733bed
--- /dev/null
+++ b/src/search-channel.c
@@ -0,0 +1,295 @@
+/*
+ * search-channel.c - implementation of ContactSearch channels
+ * Copyright (C) 2009 Collabora Ltd.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * 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
+ */
+
+#include "config.h"
+#include "search-channel.h"
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-channel.h>
+
+#define DEBUG_FLAG GABBLE_DEBUG_SEARCH
+#include "base-channel.h"
+#include "debug.h"
+
+#include "extensions/extensions.h"
+
+static const gchar *gabble_search_channel_interfaces[] = {
+    NULL
+};
+
+/* properties */
+enum
+{
+  PROP_CHANNEL_PROPERTIES = 1,
+  PROP_SEARCH_STATE,
+  PROP_AVAILABLE_SEARCH_KEYS,
+  PROP_SERVER,
+  LAST_PROPERTY
+};
+
+/* private structure */
+
+struct _GabbleSearchChannelPrivate
+{
+  GabbleChannelContactSearchState state;
+  gchar **available_search_keys;
+  gchar *server;
+};
+
+static void channel_iface_init (gpointer, gpointer);
+static void contact_search_iface_init (gpointer, gpointer);
+
+G_DEFINE_TYPE_WITH_CODE (GabbleSearchChannel, gabble_search_channel,
+    GABBLE_TYPE_BASE_CHANNEL,
+    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init);
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CHANNEL_TYPE_CONTACT_SEARCH,
+        contact_search_iface_init);
+    )
+
+static void
+gabble_search_channel_init (GabbleSearchChannel *self)
+{
+  GabbleSearchChannelPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      GABBLE_TYPE_SEARCH_CHANNEL, GabbleSearchChannelPrivate);
+
+  self->priv = priv;
+
+}
+
+static GObject *
+gabble_search_channel_constructor (GType type,
+                                   guint n_props,
+                                   GObjectConstructParam *props)
+{
+  GObject *obj;
+  GabbleSearchChannel *chan;
+  GabbleBaseChannel *base;
+  TpBaseConnection *conn;
+
+  obj = G_OBJECT_CLASS (gabble_search_channel_parent_class)->constructor (
+      type, n_props, props);
+  chan = GABBLE_SEARCH_CHANNEL (obj);
+  base = GABBLE_BASE_CHANNEL (obj);
+  conn = (TpBaseConnection *) base->conn;
+
+  base->channel_type = GABBLE_IFACE_CHANNEL_TYPE_CONTACT_SEARCH;
+  base->interfaces = gabble_search_channel_interfaces;
+  base->target_type = TP_HANDLE_TYPE_NONE;
+  base->target = 0;
+  base->initiator = conn->self_handle;
+
+  base->object_path = g_strdup_printf ("%s/ContactSearchChannel%p",
+      conn->object_path, obj);
+
+  return obj;
+}
+
+static void
+gabble_search_channel_finalize (GObject *obj)
+{
+  GabbleSearchChannel *chan = GABBLE_SEARCH_CHANNEL (obj);
+
+  g_free (chan->priv->server);
+}
+
+static void
+gabble_search_channel_get_property (GObject *object,
+                                    guint property_id,
+                                    GValue *value,
+                                    GParamSpec *pspec)
+{
+  GabbleSearchChannel *chan = GABBLE_SEARCH_CHANNEL (object);
+
+  switch (property_id)
+    {
+      case PROP_SEARCH_STATE:
+        g_value_set_uint (value, chan->priv->state);
+        break;
+      case PROP_AVAILABLE_SEARCH_KEYS:
+        g_value_set_boxed (value, chan->priv->available_search_keys);
+        break;
+      case PROP_SERVER:
+        g_value_set_string (value, chan->priv->server);
+        break;
+      case PROP_CHANNEL_PROPERTIES:
+        g_value_take_boxed (value,
+            tp_dbus_properties_mixin_make_properties_hash (object,
+                TP_IFACE_CHANNEL, "TargetHandle",
+                TP_IFACE_CHANNEL, "TargetHandleType",
+                TP_IFACE_CHANNEL, "ChannelType",
+                TP_IFACE_CHANNEL, "TargetID",
+                TP_IFACE_CHANNEL, "InitiatorHandle",
+                TP_IFACE_CHANNEL, "InitiatorID",
+                TP_IFACE_CHANNEL, "Requested",
+                TP_IFACE_CHANNEL, "Interfaces",
+                GABBLE_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, "AvailableSearchKeys",
+                GABBLE_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, "Server",
+                NULL));
+      break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+gabble_search_channel_set_property (GObject *object,
+                                    guint property_id,
+                                    const GValue *value,
+                                    GParamSpec *pspec)
+{
+  GabbleSearchChannel *chan = GABBLE_SEARCH_CHANNEL (object);
+
+  switch (property_id)
+    {
+      case PROP_SEARCH_STATE:
+        {
+          GabbleChannelContactSearchState state = g_value_get_uint (value);
+
+          /* The search state can only go forward because it can't find
+           * reverse
+           */
+          g_return_if_fail (state > chan->priv->state);
+
+          chan->priv->state = state;
+          gabble_svc_channel_type_contact_search_emit_search_state_changed (
+              chan, state);
+          break;
+        }
+      case PROP_SERVER:
+        chan->priv->server = g_value_dup_string (value);
+        g_assert (chan->priv->server != NULL);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+gabble_search_channel_class_init (GabbleSearchChannelClass *klass)
+{
+  static TpDBusPropertiesMixinPropImpl search_channel_props[] = {
+      { "SearchState", "search-state", NULL },
+      { "AvailableSearchKeys", "available-search-keys", NULL },
+      { "Server", "server", NULL },
+      { NULL }
+  };
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GParamSpec *param_spec;
+
+  g_type_class_add_private (klass, sizeof (GabbleSearchChannelPrivate));
+
+  object_class->constructor = gabble_search_channel_constructor;
+  object_class->finalize = gabble_search_channel_finalize;
+
+  object_class->get_property = gabble_search_channel_get_property;
+  object_class->set_property = gabble_search_channel_set_property;
+
+  g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
+      "channel-properties");
+
+  param_spec = g_param_spec_uint ("search-state", "Search state",
+      "The current state of the search represented by this channel",
+      GABBLE_CHANNEL_CONTACT_SEARCH_STATE_NOT_STARTED,
+      GABBLE_CHANNEL_CONTACT_SEARCH_STATE_COMPLETED,
+      GABBLE_CHANNEL_CONTACT_SEARCH_STATE_NOT_STARTED,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_SEARCH_STATE,
+      param_spec);
+
+  param_spec = g_param_spec_boxed ("available-search-keys",
+      "Available search keys",
+      "The set of search keys supported by this channel",
+      G_TYPE_STRV,
+      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_AVAILABLE_SEARCH_KEYS,
+      param_spec);
+
+  param_spec = g_param_spec_string ("server", "Search server",
+      "The user directory server used by this search",
+      NULL,
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_SERVER, param_spec);
+
+  tp_dbus_properties_mixin_implement_interface (object_class,
+      GABBLE_IFACE_QUARK_CHANNEL_TYPE_CONTACT_SEARCH,
+      tp_dbus_properties_mixin_getter_gobject_properties, NULL,
+      search_channel_props);
+}
+
+/**
+ * gabble_search_channel_close
+ *
+ * Implements D-Bus method Close
+ * on interface org.freedesktop.Telepathy.Channel
+ */
+static void
+gabble_search_channel_close (TpSvcChannel *iface,
+                             DBusGMethodInvocation *context)
+{
+  GabbleSearchChannel *chan = GABBLE_SEARCH_CHANNEL (iface);
+
+  if (chan->base.closed)
+    {
+      DEBUG ("Already closed, doing nothing");
+    }
+  else
+    {
+      DEBUG ("Emitting Closed");
+      chan->base.closed = TRUE;
+      tp_svc_channel_emit_closed (chan);
+    }
+
+  tp_svc_channel_return_from_close (context);
+}
+
+static void
+channel_iface_init (gpointer g_iface,
+                    gpointer iface_data)
+{
+  TpSvcChannelClass *klass = g_iface;
+
+#define IMPLEMENT(x) tp_svc_channel_implement_##x (\
+    klass, gabble_search_channel_##x)
+  IMPLEMENT(close);
+#undef IMPLEMENT
+}
+
+static void
+gabble_search_channel_search (GabbleSvcChannelTypeContactSearch *self,
+                              GHashTable *terms,
+                              DBusGMethodInvocation *context)
+{
+  tp_dbus_g_method_return_not_implemented (context);
+}
+
+static void
+contact_search_iface_init (gpointer g_iface,
+                           gpointer iface_data)
+{
+  GabbleSvcChannelTypeContactSearchClass *klass = g_iface;
+
+#define IMPLEMENT(x) gabble_svc_channel_type_contact_search_implement_##x (\
+    klass, gabble_search_channel_##x)
+  IMPLEMENT(search);
+#undef IMPLEMENT
+}
diff --git a/src/search-channel.h b/src/search-channel.h
new file mode 100644
index 0000000..f3474b9
--- /dev/null
+++ b/src/search-channel.h
@@ -0,0 +1,63 @@
+/*
+ * search-channel.h - Header for GabbleSearchChannel
+ * Copyright (C) 2009 Collabora Ltd.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * 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
+ */
+
+#ifndef __GABBLE_SEARCH_CHANNEL_H__
+#define __GABBLE_SEARCH_CHANNEL_H__
+
+#include <glib-object.h>
+
+#include "base-channel.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GabbleSearchChannel GabbleSearchChannel;
+typedef struct _GabbleSearchChannelClass GabbleSearchChannelClass;
+typedef struct _GabbleSearchChannelPrivate GabbleSearchChannelPrivate;
+
+struct _GabbleSearchChannelClass {
+    GabbleBaseChannelClass base_class;
+};
+
+struct _GabbleSearchChannel {
+    GabbleBaseChannel base;
+    GabbleSearchChannelPrivate *priv;
+};
+
+GType gabble_search_channel_get_type (void);
+
+/* TYPE MACROS */
+#define GABBLE_TYPE_SEARCH_CHANNEL \
+  (gabble_search_channel_get_type ())
+#define GABBLE_SEARCH_CHANNEL(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GABBLE_TYPE_SEARCH_CHANNEL, GabbleSearchChannel))
+#define GABBLE_SEARCH_CHANNEL_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GABBLE_TYPE_SEARCH_CHANNEL,\
+                           GabbleSearchChannelClass))
+#define GABBLE_IS_SEARCH_CHANNEL(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GABBLE_TYPE_SEARCH_CHANNEL))
+#define GABBLE_IS_SEARCH_CHANNEL_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), GABBLE_TYPE_SEARCH_CHANNEL))
+#define GABBLE_SEARCH_CHANNEL_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_SEARCH_CHANNEL, \
+                              GabbleSearchChannelClass))
+
+G_END_DECLS
+
+#endif /* #ifndef __GABBLE_SEARCH_CHANNEL_H__*/
-- 
1.5.6.5




More information about the telepathy-commits mailing list