[Telepathy-commits] [telepathy-glib/master] Add skeletal MessageMixin

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Dec 18 10:41:25 PST 2008


20080408172732-53eee-7a0e97bb1e4186e490d583d46775a023d7521d80.gz
---
 telepathy-glib/message-mixin.c |  331 ++++++++++++++++++++++++++++++++++++++++
 telepathy-glib/message-mixin.h |   76 +++++++++
 2 files changed, 407 insertions(+), 0 deletions(-)
 create mode 100644 telepathy-glib/message-mixin.c
 create mode 100644 telepathy-glib/message-mixin.h

diff --git a/telepathy-glib/message-mixin.c b/telepathy-glib/message-mixin.c
new file mode 100644
index 0000000..f9e1087
--- /dev/null
+++ b/telepathy-glib/message-mixin.c
@@ -0,0 +1,331 @@
+/*
+ * message-mixin.c - Source for TpMessageMixin
+ * Copyright (C) 2006-2008 Collabora Ltd.
+ * Copyright (C) 2006-2008 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
+ */
+
+/**
+ * SECTION:message-mixin
+ * @title: TpMessageMixin
+ * @short_description: a mixin implementation of the text channel type
+ * @see_also: #TpSvcChannelTypeText
+ *
+ * This mixin can be added to a channel GObject class to implement the
+ * text channel type in a general way. It implements the pending message
+ * queue and GetMessageTypes, so the implementation should only need to
+ * implement Send.
+ *
+ * To use the text mixin, include a #TpMessageMixinClass somewhere in your
+ * class structure and a #TpMessageMixin somewhere in your instance structure,
+ * and call tp_message_mixin_class_init() from your class_init function,
+ * tp_message_mixin_init() from your init function or constructor, and
+ * tp_message_mixin_finalize() from your dispose or finalize function.
+ *
+ * To use the text mixin as the implementation of
+ * #TpSvcTextInterface, in the function you pass to G_IMPLEMENT_INTERFACE,
+ * you should first call tp_message_mixin_iface_init(), then call
+ * tp_svc_channel_type_text_implement_send() to register your implementation
+ * of the Send method.
+ */
+
+#include <telepathy-glib/message-mixin.h>
+
+#include <dbus/dbus-glib.h>
+#include <string.h>
+
+#include <telepathy-glib/enums.h>
+#include <telepathy-glib/errors.h>
+#include <telepathy-glib/gtypes.h>
+
+#define DEBUG_FLAG TP_DEBUG_IM
+
+#include "debug-internal.h"
+
+/**
+ * TpMessageMixinClass:
+ *
+ * Structure to be included in the class structure of objects that
+ * use this mixin. Initialize it with tp_message_mixin_class_init().
+ *
+ * There are no public fields.
+ */
+
+/**
+ * TpMessageMixin:
+ *
+ * Structure to be included in the instance structure of objects that
+ * use this mixin. Initialize it with tp_message_mixin_init().
+ *
+ * There are no public fields.
+ */
+
+struct _TpMessageMixinPrivate
+{
+  TpHandleRepoIface *contacts_repo;
+  guint recv_id;
+  gboolean message_lost;
+
+  GQueue *pending;
+
+  GArray *msg_types;
+};
+
+/**
+ * tp_message_mixin_class_get_offset_quark:
+ *
+ * <!--no documentation beyond Returns: needed-->
+ *
+ * Returns: the quark used for storing mixin offset on a GObjectClass
+ */
+GQuark
+tp_message_mixin_class_get_offset_quark (void)
+{
+  static GQuark offset_quark = 0;
+
+  if (G_UNLIKELY (offset_quark == 0))
+    offset_quark = g_quark_from_static_string (
+        "tp_message_mixin_class_get_offset_quark at 0.7.7");
+
+  return offset_quark;
+}
+
+/**
+ * tp_message_mixin_get_offset_quark:
+ *
+ * <!--no documentation beyond Returns: needed-->
+ *
+ * Returns: the quark used for storing mixin offset on a GObject
+ */
+GQuark
+tp_message_mixin_get_offset_quark (void)
+{
+  static GQuark offset_quark = 0;
+
+  if (G_UNLIKELY (offset_quark == 0))
+    offset_quark = g_quark_from_static_string (
+        "tp_message_mixin_get_offset_quark at 0.7.7");
+
+  return offset_quark;
+}
+
+
+/**
+ * tp_message_mixin_class_init:
+ * @obj_cls: The class of the implementation that uses this mixin
+ * @offset: The byte offset of the TpMessageMixinClass within the class
+ *  structure
+ *
+ * Initialize the mixin. Should be called from the implementation's
+ * class_init function like so:
+ *
+ * <informalexample><programlisting>
+ * tp_message_mixin_class_init ((GObjectClass *) klass,
+ *     G_STRUCT_OFFSET (SomeObjectClass, message_mixin));
+ * </programlisting></informalexample>
+ */
+
+void
+tp_message_mixin_class_init (GObjectClass *obj_cls,
+                             gsize offset)
+{
+  TpMessageMixinClass *mixin_cls;
+
+  g_assert (G_IS_OBJECT_CLASS (obj_cls));
+
+  g_type_set_qdata (G_OBJECT_CLASS_TYPE (obj_cls),
+      TP_MESSAGE_MIXIN_CLASS_OFFSET_QUARK,
+      GINT_TO_POINTER (offset));
+
+  mixin_cls = TP_MESSAGE_MIXIN_CLASS (obj_cls);
+}
+
+
+/**
+ * tp_message_mixin_init:
+ * @obj: An instance of the implementation that uses this mixin
+ * @offset: The byte offset of the TpMessageMixin within the object structure
+ * @contacts_repo: The connection's %TP_HANDLE_TYPE_CONTACT repository
+ *
+ * Initialize the mixin. Should be called from the implementation's
+ * instance init function like so:
+ *
+ * <informalexample><programlisting>
+ * tp_message_mixin_init ((GObject *) self,
+ *     G_STRUCT_OFFSET (SomeObject, message_mixin),
+ *     self->contact_repo);
+ * </programlisting></informalexample>
+ */
+void
+tp_message_mixin_init (GObject *obj,
+                       gsize offset,
+                       TpHandleRepoIface *contacts_repo)
+{
+  TpMessageMixin *mixin;
+
+  g_assert (G_IS_OBJECT (obj));
+
+  g_type_set_qdata (G_OBJECT_TYPE (obj),
+                    TP_MESSAGE_MIXIN_OFFSET_QUARK,
+                    GINT_TO_POINTER (offset));
+
+  mixin = TP_MESSAGE_MIXIN (obj);
+
+  mixin->priv = g_slice_new0 (TpMessageMixinPrivate);
+
+  mixin->priv->pending = g_queue_new ();
+  mixin->priv->contacts_repo = contacts_repo;
+  mixin->priv->recv_id = 0;
+  mixin->priv->msg_types = g_array_sized_new (FALSE, FALSE, sizeof (guint),
+      NUM_TP_CHANNEL_TEXT_MESSAGE_TYPES);
+
+  mixin->priv->message_lost = FALSE;
+}
+
+static void
+tp_message_mixin_clear (GObject *obj)
+{
+  TpMessageMixin *mixin = TP_MESSAGE_MIXIN (obj);
+  gpointer msg;
+
+  while ((msg = g_queue_pop_head (mixin->priv->pending)) != NULL)
+    {
+      /* FIXME */
+    }
+}
+
+/**
+ * tp_message_mixin_finalize:
+ * @obj: An object with this mixin.
+ *
+ * Free resources held by the text mixin.
+ */
+void
+tp_message_mixin_finalize (GObject *obj)
+{
+  TpMessageMixin *mixin = TP_MESSAGE_MIXIN (obj);
+
+  DEBUG ("%p", obj);
+
+  tp_message_mixin_clear (obj);
+  g_queue_free (mixin->priv->pending);
+  g_array_free (mixin->priv->msg_types, TRUE);
+
+  g_slice_free (TpMessageMixinPrivate, mixin->priv);
+}
+
+static void
+tp_message_mixin_acknowledge_pending_messages_async (
+    TpSvcChannelTypeText *iface,
+    const GArray *ids,
+    DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+static void
+tp_message_mixin_list_pending_messages_async (TpSvcChannelTypeText *iface,
+                                              gboolean clear,
+                                              DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+static void
+tp_message_mixin_get_pending_message_content_async (
+    TpSvcChannelInterfaceMessageParts *iface,
+    guint message_id,
+    const GArray *part_numbers,
+    DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+static void
+tp_message_mixin_get_message_types_async (TpSvcChannelTypeText *iface,
+                                          DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+static void
+tp_message_mixin_send_async (TpSvcChannelTypeText *iface,
+                             guint message_type,
+                             const gchar *text,
+                             DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+static void
+tp_message_mixin_send_message_async (TpSvcChannelInterfaceMessageParts *iface,
+                                     guint message_type,
+                                     const GPtrArray *parts,
+                                     guint flags,
+                                     DBusGMethodInvocation *context)
+{
+  GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" };
+
+  dbus_g_method_return_error (context, &e);
+}
+
+/**
+ * tp_message_mixin_iface_init:
+ * @g_iface: A pointer to the #TpSvcChannelTypeTextClass in an object class
+ * @iface_data: Ignored
+ *
+ * Fill in this mixin's AcknowledgePendingMessages, GetMessageTypes and
+ * ListPendingMessages implementations in the given interface vtable.
+ * In addition to calling this function during interface initialization, the
+ * implementor is expected to call tp_svc_channel_type_text_implement_send(),
+ * providing a Send implementation.
+ */
+void
+tp_message_mixin_text_iface_init (gpointer g_iface, gpointer iface_data)
+{
+  TpSvcChannelTypeTextClass *klass = g_iface;
+
+#define IMPLEMENT(x) tp_svc_channel_type_text_implement_##x (klass,\
+    tp_message_mixin_##x##_async)
+  IMPLEMENT (acknowledge_pending_messages);
+  IMPLEMENT (get_message_types);
+  IMPLEMENT (list_pending_messages);
+  IMPLEMENT (send);
+#undef IMPLEMENT
+}
+
+void
+tp_message_mixin_message_parts_iface_init (gpointer g_iface,
+                                           gpointer iface_data)
+{
+  TpSvcChannelInterfaceMessagePartsClass *klass = g_iface;
+
+#define IMPLEMENT(x) tp_svc_channel_interface_message_parts_implement_##x (\
+    klass, tp_message_mixin_##x##_async)
+  IMPLEMENT (send_message);
+  IMPLEMENT (get_pending_message_content);
+#undef IMPLEMENT
+}
diff --git a/telepathy-glib/message-mixin.h b/telepathy-glib/message-mixin.h
new file mode 100644
index 0000000..81bd7e9
--- /dev/null
+++ b/telepathy-glib/message-mixin.h
@@ -0,0 +1,76 @@
+/*
+ * message-mixin.h - Header for TpMessageMixin
+ * Copyright (C) 2006-2008 Collabora Ltd.
+ * Copyright (C) 2006-2008 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 TP_MESSAGE_MIXIN_H
+#define TP_MESSAGE_MIXIN_H
+
+#include <telepathy-glib/handle-repo.h>
+#include <telepathy-glib/svc-channel.h>
+#include "util.h"
+
+G_BEGIN_DECLS
+
+typedef struct _TpMessageMixinClass TpMessageMixinClass;
+typedef struct _TpMessageMixinClassPrivate TpMessageMixinClassPrivate;
+typedef struct _TpMessageMixin TpMessageMixin;
+typedef struct _TpMessageMixinPrivate TpMessageMixinPrivate;
+
+struct _TpMessageMixinClass {
+    /*<private>*/
+    TpMessageMixinClassPrivate *priv;
+};
+
+struct _TpMessageMixin {
+  /*<private>*/
+  TpMessageMixinPrivate *priv;
+};
+
+#define TP_MESSAGE_MIXIN_CLASS_OFFSET_QUARK \
+  (tp_message_mixin_class_get_offset_quark ())
+#define TP_MESSAGE_MIXIN_CLASS_OFFSET(o) \
+  (GPOINTER_TO_UINT (g_type_get_qdata (G_OBJECT_CLASS_TYPE (o), \
+                                       TP_MESSAGE_MIXIN_CLASS_OFFSET_QUARK)))
+#define TP_MESSAGE_MIXIN_CLASS(o) \
+  ((TpMessageMixinClass *) tp_mixin_offset_cast (o, \
+    TP_MESSAGE_MIXIN_CLASS_OFFSET (o)))
+
+#define TP_MESSAGE_MIXIN_OFFSET_QUARK (tp_message_mixin_get_offset_quark ())
+#define TP_MESSAGE_MIXIN_OFFSET(o) \
+  (GPOINTER_TO_UINT (g_type_get_qdata (G_OBJECT_TYPE (o), \
+                                       TP_MESSAGE_MIXIN_OFFSET_QUARK)))
+#define TP_MESSAGE_MIXIN(o) \
+  ((TpMessageMixin *) tp_mixin_offset_cast (o, TP_MESSAGE_MIXIN_OFFSET (o)))
+
+GQuark tp_message_mixin_class_get_offset_quark (void);
+GQuark tp_message_mixin_get_offset_quark (void);
+
+void tp_message_mixin_class_init (GObjectClass *obj_cls, gsize offset);
+
+void tp_message_mixin_init (GObject *obj, gsize offset,
+    TpHandleRepoIface *contact_repo);
+void tp_message_mixin_finalize (GObject *obj);
+
+void tp_message_mixin_text_iface_init (gpointer g_iface, gpointer iface_data);
+void tp_message_mixin_message_parts_iface_init (gpointer g_iface,
+    gpointer iface_data);
+
+G_END_DECLS
+
+#endif
-- 
1.5.6.5




More information about the Telepathy-commits mailing list