diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-04-11 15:42:18 -0400 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-04-11 15:44:03 -0400 |
commit | 4b10dcb0ce4de96c304a6e28dda8a342452b53b0 (patch) | |
tree | 40e46399f29cd8f73c15d736f0d467458a4cb14e | |
parent | ac985bdd4887d52eba73784656bb66ecc91b50ab (diff) |
feature-mixin: add initial boilerplate version
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | docs/reference/telepathy-glib-docs.sgml | 1 | ||||
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 23 | ||||
-rw-r--r-- | telepathy-glib/Makefile.am | 2 | ||||
-rw-r--r-- | telepathy-glib/feature-mixin.c | 157 | ||||
-rw-r--r-- | telepathy-glib/feature-mixin.h | 69 | ||||
-rw-r--r-- | telepathy-glib/proxy.c | 9 | ||||
-rw-r--r-- | telepathy-glib/proxy.h | 3 |
7 files changed, 264 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-docs.sgml b/docs/reference/telepathy-glib-docs.sgml index 622b0b392..b2237ee78 100644 --- a/docs/reference/telepathy-glib-docs.sgml +++ b/docs/reference/telepathy-glib-docs.sgml @@ -182,6 +182,7 @@ <xi:include href="xml/gnio-util.xml"/> <xi:include href="xml/debug.xml"/> <xi:include href="xml/debug-sender.xml"/> + <xi:include href="xml/feature-mixin.xml"/> <xi:include href="xml/intset.xml"/> <xi:include href="xml/heap.xml"/> </chapter> diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 4ed815412..653b7a027 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -1719,6 +1719,29 @@ TP_PRESENCE_MIXIN </SECTION> <SECTION> +<INCLUDE>telepathy-glib/feature-mixin.h</INCLUDE> +<FILE>feature-mixin</FILE> +<TITLE>TpFeatureMixin</TITLE> +TpFeatureMixin +TpFeatureMixinClass +tp_feature_mixin_class_init +tp_feature_mixin_init +tp_feature_mixin_finalize +<SUBSECTION Private> +TP_FEATURE_MIXIN_CLASS_OFFSET_QUARK +TP_FEATURE_MIXIN_CLASS_OFFSET +TP_FEATURE_MIXIN_OFFSET_QUARK +TP_FEATURE_MIXIN_OFFSET +tp_feature_mixin_class_get_offset_quark +tp_feature_mixin_get_offset_quark +TpFeatureMixinPrivate +TpFeatureMixinClassPrivate +<SUBSECTION Standard> +TP_FEATURE_MIXIN_CLASS +TP_FEATURE_MIXIN +</SECTION> + +<SECTION> <FILE>debug</FILE> <TITLE>debug</TITLE> <INCLUDE>telepathy-glib/debug.h</INCLUDE> diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 3b5b76d8c..98cceeb72 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -273,6 +273,8 @@ libtelepathy_glib_main_internal_la_SOURCES = \ dtmf.c \ debug-internal.h \ exportable-channel.c \ + feature-mixin.c \ + feature-mixin.h \ file-transfer-channel.c \ gnio-util.c \ group-mixin.c \ diff --git a/telepathy-glib/feature-mixin.c b/telepathy-glib/feature-mixin.c new file mode 100644 index 000000000..89c88c1c9 --- /dev/null +++ b/telepathy-glib/feature-mixin.c @@ -0,0 +1,157 @@ +/* + * feature-mixin.c - Proxy features + * Copyright (C) 2010-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 + */ + +/** + * SECTION:feature-mixin + * @title: TpFeatureMixin + * @short_description: a mixin implementation of features for proxies + * + * This mixin can be added to a #GObject subclass to implement features. + * + * To use the feature mixin, include a #TpFeatureMixinClass somewhere in your + * class structure and a #TpFeatureMixin somewhere in your instance structure, + * call tp_feature_mixin_class_init() from your class_init function, + * tp_feature_mixin_init() from your init function or constructor, and + * tp_feature_mixin_finalize() from your dispose or finalize function. + * + * Since: 0.UNRELEASED + */ + +/** + * TpFeatureMixinClass: + * + * Structure to be included in the class structure of objects that + * use this mixin. Initialize it with tp_feature_mixin_class_init(). + * + * There are no public fields. + */ + +/** + * TpFeatureMixin: + * + * Structure to be included in the instance structure of objects that + * use this mixin. Initialize it with tp_feature_mixin_init(). + * + * There are no public fields. + */ + +#include "config.h" + +#include <telepathy-glib/feature-mixin.h> + +#define DEBUG_FLAG TP_DEBUG_MISC +#include "telepathy-glib/debug-internal.h" + +/** + * tp_feature_mixin_class_get_offset_quark: (skip) + * + * <!-- --> + * + * Returns: the quark used for storing mixin offset on a GObjectClass + */ +GQuark +tp_feature_mixin_class_get_offset_quark () +{ + static GQuark offset_quark = 0; + if (!offset_quark) + offset_quark = g_quark_from_static_string ("TpFeatureMixinClassOffsetQuark"); + return offset_quark; +} + +/** + * tp_feature_mixin_get_offset_quark: (skip) + * + * <!-- --> + * + * Returns: the quark used for storing mixin offset on a GObject + */ +GQuark +tp_feature_mixin_get_offset_quark () +{ + static GQuark offset_quark = 0; + if (!offset_quark) + offset_quark = g_quark_from_static_string ("TpFeatureMixinOffsetQuark"); + return offset_quark; +} + +/** + * tp_feature_mixin_class_init: (skip) + * @obj_cls: The class of the implementation that uses this mixin + * @offset: The byte offset of the TpFeatureMixinClass within the class + * structure + * + * Initialize the feature mixin. Should be called from the implementation's + * class_init function like so: + * + * <informalexample><programlisting> + * tp_feature_mixin_class_init ((GObjectClass *) klass, + * G_STRUCT_OFFSET (SomeObjectClass, + * feature_mixin_class)); + * </programlisting></informalexample> + */ +void +tp_feature_mixin_class_init (GObjectClass *obj_cls, + gsize offset) +{ + DEBUG ("%p", obj_cls); + + g_assert (G_IS_OBJECT_CLASS (obj_cls)); + + g_type_set_qdata (G_OBJECT_CLASS_TYPE (obj_cls), + TP_FEATURE_MIXIN_CLASS_OFFSET_QUARK, + GINT_TO_POINTER (offset)); +} + +/** + * tp_feature_mixin_init: (skip) + * @obj: An instance of the implementation that uses this mixin + * @offset: The byte offset of the TpFeatureMixin within the object structure + * + * Initialize the feature mixin. Should be called from the implementation's + * instance init function like so: + * + * <informalexample><programlisting> + * tp_feature_mixin_init ((GObject *) self, + * G_STRUCT_OFFSET (SomeObject, feature_mixin)); + * </programlisting></informalexample> + */ +void +tp_feature_mixin_init (GObject *obj, + glong offset) +{ + DEBUG ("%p", obj); + + g_assert (G_IS_OBJECT (obj)); + + g_type_set_qdata (G_OBJECT_TYPE (obj), + TP_FEATURE_MIXIN_OFFSET_QUARK, + GINT_TO_POINTER (offset)); +} + +/** + * tp_feature_mixin_finalize: (skip) + * @obj: An object with this mixin. + * + * Free resources held by the feature mixin. + */ +void +tp_feature_mixin_finalize (GObject *obj) +{ + DEBUG ("%p", obj); +} diff --git a/telepathy-glib/feature-mixin.h b/telepathy-glib/feature-mixin.h new file mode 100644 index 000000000..4ba9aa310 --- /dev/null +++ b/telepathy-glib/feature-mixin.h @@ -0,0 +1,69 @@ +/* + * feature-mixin.h - Proxy features + * Copyright (C) 2010-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 + */ + +#ifndef __TP_FEATURE_MIXIN_H__ +#define __TP_FEATURE_MIXIN_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +typedef struct _TpFeatureMixinClass TpFeatureMixinClass; +typedef struct _TpFeatureMixinClassPrivate TpFeatureMixinClassPrivate; +typedef struct _TpFeatureMixin TpFeatureMixin; +typedef struct _TpFeatureMixinPrivate TpFeatureMixinPrivate; + +struct _TpFeatureMixinClass { + /*<private>*/ + TpFeatureMixinPrivate *priv; +}; + +struct _TpFeatureMixin { + /*<private>*/ + TpFeatureMixinPrivate *priv; +}; + +/* TYPE MACROS */ +#define TP_FEATURE_MIXIN_CLASS_OFFSET_QUARK \ + (tp_feature_mixin_class_get_offset_quark ()) +#define TP_FEATURE_MIXIN_CLASS_OFFSET(o) \ + tp_mixin_class_get_offset (o, TP_FEATURE_MIXIN_CLASS_OFFSET_QUARK) +#define TP_FEATURE_MIXIN_CLASS(o) \ + ((TpFeatureMixinClass *) tp_mixin_offset_cast (o, \ + TP_FEATURE_MIXIN_CLASS_OFFSET (o))) + +#define TP_FEATURE_MIXIN_OFFSET_QUARK (tp_feature_mixin_get_offset_quark ()) +#define TP_FEATURE_MIXIN_OFFSET(o) \ + tp_mixin_instance_get_offset (o, TP_FEATURE_MIXIN_OFFSET_QUARK) +#define TP_FEATURE_MIXIN(o) \ + ((TpFeatureMixin *) tp_mixin_offset_cast (o, TP_FEATURE_MIXIN_OFFSET (o))) + +GQuark tp_feature_mixin_class_get_offset_quark (void); +GQuark tp_feature_mixin_get_offset_quark (void); + +void tp_feature_mixin_class_init (GObjectClass *cls, + gsize offset); + +void tp_feature_mixin_init (GObject *obj, + glong offset); +void tp_feature_mixin_finalize (GObject *obj); + +G_END_DECLS + +#endif /* #ifndef __TP_FEATURE_MIXIN_H__ */ diff --git a/telepathy-glib/proxy.c b/telepathy-glib/proxy.c index 100b4ce09..4ff131b84 100644 --- a/telepathy-glib/proxy.c +++ b/telepathy-glib/proxy.c @@ -30,6 +30,7 @@ #include <telepathy-glib/interfaces.h> #include <telepathy-glib/automatic-client-factory.h> #include <telepathy-glib/util.h> +#include <telepathy-glib/feature-mixin.h> #include "dbus-internal.h" #define DEBUG_FLAG TP_DEBUG_PROXY @@ -1089,6 +1090,9 @@ tp_proxy_constructor (GType type, g_return_val_if_fail (self->bus_name[0] == ':', NULL); } + tp_feature_mixin_init ((GObject *) self, + G_STRUCT_OFFSET (TpProxy, feature)); + return (GObject *) self; } @@ -1122,6 +1126,8 @@ tp_proxy_finalize (GObject *object) DEBUG ("%p", self); + tp_feature_mixin_finalize (object); + if (self->priv->features != NULL) g_datalist_clear (&self->priv->features); @@ -1369,6 +1375,9 @@ tp_proxy_class_init (TpProxyClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_INT, G_TYPE_STRING); + + tp_feature_mixin_class_init ((GObjectClass *) klass, + G_STRUCT_OFFSET (TpProxyClass, feature_class)); } /** diff --git a/telepathy-glib/proxy.h b/telepathy-glib/proxy.h index 22bc426d5..d8acc11b9 100644 --- a/telepathy-glib/proxy.h +++ b/telepathy-glib/proxy.h @@ -27,6 +27,7 @@ #include <telepathy-glib/defs.h> #include <telepathy-glib/_gen/genums.h> +#include <telepathy-glib/feature-mixin.h> G_BEGIN_DECLS @@ -60,6 +61,7 @@ typedef enum { struct _TpProxy { /*<private>*/ GObject parent; + TpFeatureMixin feature; TpDBusDaemon *dbus_daemon; DBusGConnection *dbus_connection; @@ -109,6 +111,7 @@ typedef const TpProxyFeature *(*TpProxyClassFeatureListFunc) ( struct _TpProxyClass { /*<public>*/ GObjectClass parent_class; + TpFeatureMixinClass feature_class; GQuark interface; |