soylent r192 - trunk/libsoylent
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r192 - trunk/libsoylent
- Date: Wed, 9 Jul 2008 13:53:26 +0000 (UTC)
Author: svenp
Date: Wed Jul 9 13:53:26 2008
New Revision: 192
URL: http://svn.gnome.org/viewvc/soylent?rev=192&view=rev
Log:
added entity-handler interface (backend for SlEntity)
Modified:
trunk/libsoylent/sl-entity.c
trunk/libsoylent/sl-entity.h
Modified: trunk/libsoylent/sl-entity.c
==============================================================================
--- trunk/libsoylent/sl-entity.c (original)
+++ trunk/libsoylent/sl-entity.c Wed Jul 9 13:53:26 2008
@@ -6,11 +6,28 @@
struct _SlEntityPriv
{
- gchar *foo;
+ SlEntityHandler *entity_handler;
+ GList *attributes;
+};
+
+struct _SlAttributePriv
+{
+ SlEntity *entity;
+ gchar *name;
+ GList *values;
+};
+
+struct _SlAttributeHandler
+{
+ SlAttributeHandlerType type;
+ gpointer (*writer)(const gchar *attrname, gpointer value);
+ gpointer (*reader)(const gchar *attrname, gpointer value);
};
static GObjectClass *parent_class = NULL;
+static GObjectClass *attribute_parent_class = NULL;
+
static void sl_entity_class_init (gpointer g_class, gpointer class_data);
static void sl_entity_init (GTypeInstance *instance, gpointer g_class);
static void sl_entity_dispose (GObject *object);
@@ -19,29 +36,76 @@
static void sl_entity_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec);
+static void sl_attribute_class_init (gpointer g_class, gpointer class_data);
+static void sl_attribute_init (GTypeInstance *instance, gpointer g_class);
+static void sl_attribute_dispose (GObject *object);
+static void sl_attribute_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec);
+static void sl_attribute_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec);
+
GType
sl_entity_get_type (void)
{
- static GType type = 0;
- static const GTypeInfo info =
+ static GType type = 0;
+ static const GTypeInfo info =
{
- sizeof (SlEntityClass),
- NULL,
- NULL,
- sl_entity_class_init,
- NULL,
- NULL,
- sizeof (SlEntity),
- 0,
- sl_entity_init,
- NULL
- };
-
- if (type == 0)
+ sizeof (SlEntityClass),
+ NULL,
+ NULL,
+ sl_entity_class_init,
+ NULL,
+ NULL,
+ sizeof (SlEntity),
+ 0,
+ sl_entity_init,
+ NULL
+ };
+
+ if (type == 0)
+ {
+ type = g_type_register_static(G_TYPE_OBJECT, "SlEntity", &info, 0);
+ }
+ return type;
+}
+
+GType
+sl_attribute_get_type (void)
+{
+ static GType type = 0;
+ static const GTypeInfo info =
+ {
+ sizeof (SlAttributeClass),
+ NULL,
+ NULL,
+ sl_attribute_class_init,
+ NULL,
+ NULL,
+ sizeof (SlAttribute),
+ 0,
+ sl_attribute_init,
+ NULL
+ };
+
+ if (type == 0)
{
- type = g_type_register_static(G_TYPE_OBJECT, "SlEntity", &info, 0);
+ type = g_type_register_static(G_TYPE_OBJECT, "SlAttribute", &info, 0);
}
- return type;
+ return type;
+}
+
+void
+sl_entity_install_attribute_handler (const gchar *attrname,
+ SlAttributeHandlerType type, gpointer (*writer)(const gchar *attrname,
+ gpointer value), gpointer (*reader)(const gchar *attrname, gpointer value))
+{
+ g_warning ("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_remove_attribute_handler (const gchar *attrname)
+{
+ g_warning ("%s not implemented", __FUNCTION__);
}
static void
@@ -62,7 +126,7 @@
SlEntity *self = SL_ENTITY (instance);
SlEntityPriv *priv = g_new (SlEntityPriv, 1);
self->priv = priv;
- self->priv->foo = "FOO";
+ self->priv->attributes = NULL;
self->disposed = FALSE;
}
@@ -71,6 +135,7 @@
SlEntity *self = SL_ENTITY (object);
g_return_if_fail (!self->disposed);
+ g_list_free (self->priv->attributes);
g_free (self->priv);
self->disposed = TRUE;
@@ -98,8 +163,206 @@
return entity;
}
+SlEntityHandler *sl_entity_get_handler (SlEntity *self)
+{
+ return self->priv->entity_handler;
+}
+
+SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname)
+{
+ /* TODO: use hashtable? I think yes... */
+ GList *iter = self->priv->attributes;
+ for (; iter != NULL; iter = iter->next)
+ {
+ SlAttribute *attr = iter->data;
+ if (g_str_equal (sl_attribute_get_name (attr), attrname))
+ {
+ return attr;
+ }
+ }
+ return NULL;
+}
+
+GList *sl_entity_get_attributes (SlEntity *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void
+sl_entity_set (SlEntity *self, gchar *attrname, gpointer value)
+{
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (!attr) return;
+ sl_attribute_set (attr, value);
+}
+
gpointer
-sl_entity_get (SlEntity *self, const gchar *attrname)
+sl_entity_get (SlEntity *self, gchar *attrname)
+{
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (!attr) return NULL;
+ return sl_attribute_get (attr);
+}
+
+void
+sl_entity_remove (SlEntity *self, gchar *attrname)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_set_at (SlEntity *self, gchar *attrname, gint index, gpointer value)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+gpointer
+sl_entity_get_at (SlEntity *self, gchar *attrname, gint index)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void
+sl_entity_remove_at (SlEntity *self, gchar *attrname, gint index)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_set_values (SlEntity *self, gchar *attrname, GList *values)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+GList *
+sl_entity_get_values (SlEntity *self, gchar *attrname)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void
+sl_entity_remove_values (SlEntity *self, gchar *attrname)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+static void
+sl_attribute_class_init (gpointer g_class, gpointer class_data)
+{
+ attribute_parent_class = g_type_class_peek (g_type_parent
+ (SL_ATTRIBUTE_TYPE));
+ g_assert (attribute_parent_class != NULL);
+
+ GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
+ obj_class->dispose = sl_attribute_dispose;
+ obj_class->get_property = sl_attribute_get_property;
+ obj_class->set_property = sl_attribute_set_property;
+}
+
+static void
+sl_attribute_init (GTypeInstance *instance, gpointer g_class)
+{
+ SlAttribute *self = SL_ATTRIBUTE (instance);
+ SlAttributePriv *priv = g_new (SlAttributePriv, 1);
+ self->priv = priv;
+ self->disposed = FALSE;
+}
+
+static void
+sl_attribute_dispose (GObject *object)
+{
+ SlAttribute *self = SL_ATTRIBUTE (object);
+ g_return_if_fail (!self->disposed);
+
+ g_free (self->priv);
+ self->disposed = TRUE;
+
+ attribute_parent_class->dispose (object);
+}
+
+static void
+sl_attribute_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+static void
+sl_attribute_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+SlAttribute *
+sl_attribute_new (const gchar *name)
+{
+ /* TODO: add constr-param name and values */
+ SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+ return self;
+}
+
+void sl_attribute_set (SlAttribute *self, gpointer value)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+gpointer sl_attribute_get (SlAttribute *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void sl_attribute_remove (SlAttribute *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+void sl_attribute_set_at (SlAttribute *self, gint index, gpointer value)
+{
+ /*SlEntityHandler *entity_handler = sl_entity_get_handler (self->priv->entity);
+ *sl_entity_handler_set_at (entity_handler, self->name, index, value);
+ * TODO: behind the scenes in EDS-handler:
+ * GList *values = vcard_attribute_get_values (attrname);
+ * for (... look for value
+ * modify value in list
+ * if direct list manipulation is not possible: set_at not possible at the
+ * moment */
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+gpointer sl_attribute_get_at (SlAttribute *self, gint index)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void sl_attribute_remove_at (SlAttribute *self, gint index)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+void sl_attribute_set_values (SlAttribute *self, GList *values)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+GList *sl_attribute_get_values (SlAttribute *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
+}
+
+void sl_attribute_remove_values (SlAttribute *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+const gchar *sl_attribute_get_name (SlAttribute *self)
{
- return self->priv->foo;
+ g_warning("%s not implemented", __FUNCTION__);
+ return NULL;
}
Modified: trunk/libsoylent/sl-entity.h
==============================================================================
--- trunk/libsoylent/sl-entity.h (original)
+++ trunk/libsoylent/sl-entity.h Wed Jul 9 13:53:26 2008
@@ -3,39 +3,110 @@
#ifndef SL_ENTITY_H
#define SL_ENTITY_H
+#include "sl-entity-handler.h"
+
#include <glib.h>
#include <glib-object.h>
#define SL_ENTITY_TYPE (sl_entity_get_type ())
-#define SL_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+#define SL_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, \
SL_ENTITY_TYPE, SlEntity))
-#define SL_ENTITY_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST(cls, \
+#define SL_ENTITY_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, \
SL_ENTITY_TYPE, SlEntityClass))
-#define SL_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, \
+#define SL_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
SL_ENTITY_TYPE))
-#define SL_IS_ENTITY_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE(cls, SL_ENTITY_TYPE))
+#define SL_IS_ENTITY_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE (cls, \
+ SL_ENTITY_TYPE))
#define SL_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS(obj, \
SL_ENTITY_TYPE))
+#define SL_ATTRIBUTE_TYPE (sl_attribute_get_type ())
+#define SL_ATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, \
+ SL_ATTRIBUTE_TYPE, SlAttribute))
+#define SL_ATTRIBUTE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, \
+ SL_ATTRIBUTE_TYPE, SlAttributeClass))
+#define SL_IS_ATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
+ SL_ATTRIBUTE_TYPE))
+#define SL_IS_ATTRIBUTE_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE (cls, \
+ SL_ATTRIBUTE_TYPE))
+#define SL_ATTRIBUTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS(obj, \
+ SL_ATTRIBUTE_TYPE))
+
typedef struct _SlEntity SlEntity;
typedef struct _SlEntityClass SlEntityClass;
typedef struct _SlEntityPriv SlEntityPriv;
+typedef struct _SlAttribute SlAttribute;
+typedef struct _SlAttributeClass SlAttributeClass;
+typedef struct _SlAttributePriv SlAttributePriv;
+
+typedef struct _SlAttributeHandler SlAttributeHandler;
+
+typedef enum _SlAttributeHandlerType SlAttributeHandlerType;
+
+enum _SlAttributeHandlerType
+{
+ SL_ATTRIBUTE_HANDLER_TYPE_STRING,
+ SL_ATTRIBUTE_HANDLER_TYPE_BIN
+};
+
struct _SlEntity
{
- GObject parent;
- gboolean disposed;
- SlEntityPriv *priv;
+ GObject parent;
+ gboolean disposed;
+ SlEntityPriv *priv;
};
struct _SlEntityClass
{
- GObjectClass parent;
+ GObjectClass parent;
+};
+
+struct _SlAttribute
+{
+ GObject parent;
+ gboolean disposed;
+ SlAttributePriv *priv;
+};
+
+struct _SlAttributeClass
+{
+ GObjectClass parent;
};
GType sl_entity_get_type (void);
+GType sl_attribute_get_type (void);
+
+void sl_entity_install_attribute_handler (const gchar *attrname, SlAttributeHandlerType type, gpointer (*writer)(const gchar *attrname, gpointer value), gpointer (*reader)(const gchar *attrname, gpointer value));
+void sl_entity_remove_attribute_handler (const gchar *attrname);
SlEntity *sl_entity_new (void);
-gpointer sl_entity_get (SlEntity *self, const gchar *attrname);
+SlEntityHandler *sl_entity_get_handler (SlEntity *self);
+SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname);
+GList *sl_entity_get_attributes (SlEntity *self);
+
+void sl_entity_set (SlEntity *self, gchar *attrname, gpointer value);
+gpointer sl_entity_get (SlEntity *self, gchar *attrname);
+void sl_entity_remove (SlEntity *self, gchar *attrname);
+void sl_entity_set_at (SlEntity *self, gchar *attrname, gint index, gpointer value);
+gpointer sl_entity_get_at (SlEntity *self, gchar *attrname, gint index);
+void sl_entity_remove_at (SlEntity *self, gchar *attrname, gint index);
+void sl_entity_set_values (SlEntity *self, gchar *attrname, GList *values);
+GList *sl_entity_get_values (SlEntity *self, gchar *attrname);
+void sl_entity_remove_values (SlEntity *self, gchar *attrname);
+/* TODO: perhaps gboolean instead of void to indicate that an attrname doesn't
+ * exist */
+
+SlAttribute *sl_attribute_new (const gchar *name);
+void sl_attribute_set (SlAttribute *self, gpointer value);
+gpointer sl_attribute_get (SlAttribute *self);
+void sl_attribute_remove (SlAttribute *self);
+void sl_attribute_set_at (SlAttribute *self, gint index, gpointer value);
+gpointer sl_attribute_get_at (SlAttribute *self, gint index);
+void sl_attribute_remove_at (SlAttribute *self, gint index);
+void sl_attribute_set_values (SlAttribute *self, GList *values);
+GList *sl_attribute_get_values (SlAttribute *self);
+void sl_attribute_remove_values (SlAttribute *self);
+const gchar *sl_attribute_get_name (SlAttribute *self);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]