[Galago-commits] r2617 - in trunk/libgalago: . libgalago tests
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Sun Mar 19 17:24:54 PST 2006
Author: chipx86
Date: 2006-03-19 17:24:51 -0800 (Sun, 19 Mar 2006)
New Revision: 2617
Added:
trunk/libgalago/libgalago/galago-key-value.c
trunk/libgalago/libgalago/galago-key-value.h
Modified:
trunk/libgalago/ChangeLog
trunk/libgalago/libgalago/Makefile.am
trunk/libgalago/libgalago/galago-object.h
trunk/libgalago/libgalago/galago-status.c
trunk/libgalago/libgalago/galago-status.h
trunk/libgalago/libgalago/galago.h
trunk/libgalago/tests/presence-feed.c
Log:
- Added GalagoKeyValue, a small data structure containing a string key and a GValue.
- Removed GalagoStatusAttr. GalagoKeyValue now holds this data, and implementations of galago_object_get_attributes() will return lists of these.
- Cleaned up cruft. Yay cruft!
Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/ChangeLog 2006-03-20 01:24:51 UTC (rev 2617)
@@ -1,3 +1,20 @@
+Sun Mar 19 17:23:49 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ A libgalago/galago-key-value.c:
+ A libgalago/galago-key-value.h:
+ * libgalago/galago.h:
+ * libgalago/galago-object.h:
+ * libgalago/galago-status.c:
+ * libgalago/galago-status.h:
+ * libgalago/Makefile.am:
+ * tests/presence-feed.c:
+ - Added GalagoKeyValue, a small data structure containing a string key
+ and a GValue.
+ - Removed GalagoStatusAttr. GalagoKeyValue now holds this data, and
+ implementations of galago_object_get_attributes() will return lists
+ of these.
+ - Cleaned up cruft. Yay cruft!
+
Sun Mar 19 16:22:20 PST 2006 Christian Hammond <chipx86 at chipx86.com>
* libgalago/galago-status.c:
Modified: trunk/libgalago/libgalago/Makefile.am
===================================================================
--- trunk/libgalago/libgalago/Makefile.am 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/Makefile.am 2006-03-20 01:24:51 UTC (rev 2617)
@@ -15,6 +15,7 @@
galago-context-base.h \
galago-dbus.h \
galago-image.h \
+ galago-key-value.h \
galago-object.h \
galago-person.h \
galago-presence.h \
@@ -44,6 +45,7 @@
galago-dbus.c \
galago-enum-types.c \
galago-image.c \
+ galago-key-value.c \
galago-object.c \
galago-person.c \
galago-presence.c \
Added: trunk/libgalago/libgalago/galago-key-value.c
===================================================================
--- trunk/libgalago/libgalago/galago-key-value.c 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago-key-value.c 2006-03-20 01:24:51 UTC (rev 2617)
@@ -0,0 +1,47 @@
+/**
+ * @file libgalago/galago-key-value.c Galago Key/Value Data Structure
+ *
+ * @Copyright (C) 2006 Christian Hammond
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <libgalago/galago-key-value.h>
+
+GalagoKeyValue *
+galago_key_value_new(const char *key, GValue *value)
+{
+ GalagoKeyValue *key_value;
+
+ g_return_val_if_fail(key != NULL && *key != '\0', NULL);
+ g_return_val_if_fail(value != NULL, NULL);
+
+ key_value = g_new0(GalagoKeyValue, 1);
+ key_value->key = g_strdup(key);
+ key_value->value = value;
+
+ return key_value;
+}
+
+void
+galago_key_value_destroy(GalagoKeyValue *key_value)
+{
+ g_return_if_fail(key_value != NULL);
+
+ g_free(key_value->key);
+ g_value_unset(key_value->value);
+ g_free(key_value->value);
+ g_free(key_value);
+}
Added: trunk/libgalago/libgalago/galago-key-value.h
===================================================================
--- trunk/libgalago/libgalago/galago-key-value.h 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago-key-value.h 2006-03-20 01:24:51 UTC (rev 2617)
@@ -0,0 +1,36 @@
+/**
+ * @file libgalago/galago-key-value.h Galago Key/Value Data Structure
+ *
+ * @Copyright (C) 2006 Christian Hammond
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef _GALAGO_KEY_VALUE_H_
+#define _GALAGO_KEY_VALUE_H_
+
+#include <glib-object.h>
+
+typedef struct
+{
+ char *key;
+ GValue *value;
+
+} GalagoKeyValue;
+
+GalagoKeyValue *galago_key_value_new(const char *key, GValue *value);
+void galago_key_value_destroy(GalagoKeyValue *key_value);
+
+#endif /* _GALAGO_KEY_VALUE_H_ */
Modified: trunk/libgalago/libgalago/galago-object.h
===================================================================
--- trunk/libgalago/libgalago/galago-object.h 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago-object.h 2006-03-20 01:24:51 UTC (rev 2617)
@@ -356,11 +356,12 @@
const char *name);
/**
- * Returns the list of attributes in an object.
+ * Returns the list of attributes in an object, represented by GalagoKeyValue
+ * structs.
*
* @param object The object.
*
- * @return The attributes in the object.
+ * @return The attributes in the object. Each one is a GalagoKeyValue.
*/
GList *galago_object_get_attributes(const GalagoObject *object);
Modified: trunk/libgalago/libgalago/galago-status.c
===================================================================
--- trunk/libgalago/libgalago/galago-status.c 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago-status.c 2006-03-20 01:24:51 UTC (rev 2617)
@@ -21,6 +21,7 @@
#include <libgalago/galago-private.h>
#include <libgalago/galago-core.h>
#include <libgalago/galago-enum-types.h>
+#include <libgalago/galago-key-value.h>
#include <libgalago/galago-status.h>
#include <stdio.h>
#include <string.h>
@@ -40,12 +41,6 @@
GList *attrs;
};
-struct _GalagoStatusAttr
-{
- char *id;
- GValue *value;
-};
-
enum
{
PROP_0,
@@ -58,9 +53,6 @@
static GHashTable *status_id_map_table = NULL;
-static GalagoStatusAttr *status_attr_new(const char *id, GValue *value);
-static void status_attr_destroy(GalagoStatusAttr *attr);
-
/**************************************************************************
* Object/Class support
**************************************************************************/
@@ -147,7 +139,7 @@
status->priv->attrs_table =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- (GFreeFunc)status_attr_destroy);
+ (GFreeFunc)galago_key_value_destroy);
}
static void
@@ -203,18 +195,16 @@
l != NULL;
l = l->next)
{
- GalagoStatusAttr *attr = (GalagoStatusAttr *)l->data;
- const char *attr_id = galago_status_attr_get_id(attr);
- const GValue *value = galago_status_attr_get_gvalue(attr);
+ GalagoKeyValue *key_value = (GalagoKeyValue *)l->data;
dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL,
&struct_iter);
dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING,
- &attr_id);
+ &key_value->key);
- if (G_VALUE_HOLDS(value, G_TYPE_BOOLEAN))
+ if (G_VALUE_HOLDS(key_value->value, G_TYPE_BOOLEAN))
{
- gboolean value = galago_status_attr_get_bool(attr);
+ gboolean value = g_value_get_boolean(key_value->value);
dbus_message_iter_open_container(&struct_iter,
DBUS_TYPE_VARIANT,
DBUS_TYPE_BOOLEAN_AS_STRING,
@@ -222,11 +212,10 @@
dbus_message_iter_append_basic(&value_iter,
DBUS_TYPE_BOOLEAN, &value);
dbus_message_iter_close_container(&struct_iter, &value_iter);
- break;
}
- else if (G_VALUE_HOLDS(value, G_TYPE_STRING))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_STRING))
{
- const char *value = galago_status_attr_get_string(attr);
+ const char *value = g_value_get_string(key_value->value);
dbus_message_iter_open_container(&struct_iter,
DBUS_TYPE_VARIANT,
DBUS_TYPE_STRING_AS_STRING,
@@ -234,11 +223,10 @@
dbus_message_iter_append_basic(&value_iter,
DBUS_TYPE_STRING, &value);
dbus_message_iter_close_container(&struct_iter, &value_iter);
- break;
}
- else if (G_VALUE_HOLDS(value, G_TYPE_INT))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_INT))
{
- int value = galago_status_attr_get_int(attr);
+ int value = g_value_get_int(key_value->value);
dbus_message_iter_open_container(&struct_iter,
DBUS_TYPE_VARIANT,
DBUS_TYPE_UINT32_AS_STRING,
@@ -246,11 +234,10 @@
dbus_message_iter_append_basic(&value_iter,
DBUS_TYPE_UINT32, &value);
dbus_message_iter_close_container(&struct_iter, &value_iter);
- break;
}
- else if (G_VALUE_HOLDS(value, G_TYPE_DOUBLE))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_DOUBLE))
{
- double value = galago_status_attr_get_double(attr);
+ double value = g_value_get_double(key_value->value);
dbus_message_iter_open_container(&struct_iter,
DBUS_TYPE_VARIANT,
DBUS_TYPE_DOUBLE_AS_STRING,
@@ -258,7 +245,6 @@
dbus_message_iter_append_basic(&value_iter,
DBUS_TYPE_DOUBLE, &value);
dbus_message_iter_close_container(&struct_iter, &value_iter);
- break;
}
else
g_assert_not_reached();
@@ -530,29 +516,27 @@
l != NULL;
l = l->next)
{
- GalagoStatusAttr *status_attr = (GalagoStatusAttr *)l->data;
- const char *attr_id = galago_status_attr_get_id(status_attr);
- const GValue *value = galago_status_attr_get_gvalue(status_attr);
+ GalagoKeyValue *key_value = (GalagoKeyValue *)l->data;
- if (G_VALUE_HOLDS(value, G_TYPE_BOOLEAN))
+ if (G_VALUE_HOLDS(key_value->value, G_TYPE_BOOLEAN))
{
galago_object_set_attr_bool(GALAGO_OBJECT(new_status),
- attr_id, galago_status_attr_get_bool(status_attr));
+ key_value->key, g_value_get_boolean(key_value->value));
}
- else if (G_VALUE_HOLDS(value, G_TYPE_STRING))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_STRING))
{
galago_object_set_attr_string(GALAGO_OBJECT(new_status),
- attr_id, galago_status_attr_get_string(status_attr));
+ key_value->key, g_value_get_string(key_value->value));
}
- else if (G_VALUE_HOLDS(value, G_TYPE_INT))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_INT))
{
galago_object_set_attr_int(GALAGO_OBJECT(new_status),
- attr_id, galago_status_attr_get_int(status_attr));
+ key_value->key, g_value_get_int(key_value->value));
}
- else if (G_VALUE_HOLDS(value, G_TYPE_DOUBLE))
+ else if (G_VALUE_HOLDS(key_value->value, G_TYPE_DOUBLE))
{
galago_object_set_attr_double(GALAGO_OBJECT(new_status),
- attr_id, galago_status_attr_get_double(status_attr));
+ key_value->key, g_value_get_double(key_value->value));
}
}
@@ -637,30 +621,31 @@
GValue *value)
{
GalagoStatus *status = GALAGO_STATUS(object);
- GalagoStatusAttr *attr;
GalagoPresence *presence;
+ GalagoKeyValue *key_value;
- attr = g_hash_table_lookup(status->priv->attrs_table, name);
+ key_value = g_hash_table_lookup(status->priv->attrs_table, name);
- if (attr == NULL)
+ if (key_value == NULL)
{
- attr = status_attr_new(name, value);
+ key_value = galago_key_value_new(name, value);
- g_hash_table_insert(status->priv->attrs_table, g_strdup(name), attr);
- status->priv->attrs = g_list_append(status->priv->attrs, attr);
+ g_hash_table_insert(status->priv->attrs_table,
+ g_strdup(name), key_value);
+ status->priv->attrs = g_list_append(status->priv->attrs, key_value);
}
- else if (G_VALUE_HOLDS(attr->value, G_VALUE_TYPE(value)))
+ else if (G_VALUE_HOLDS(key_value->value, G_VALUE_TYPE(value)))
{
- g_value_unset(attr->value);
- g_free(attr->value);
- attr->value = value;
+ g_value_unset(key_value->value);
+ g_free(key_value->value);
+ key_value->value = value;
}
else
{
g_warning("Attempted to set existing attribute ID %s of type %s with "
"attribute of type %s",
name,
- G_VALUE_TYPE_NAME(attr->value),
+ G_VALUE_TYPE_NAME(key_value->value),
G_VALUE_TYPE_NAME(value));
return;
@@ -676,15 +661,15 @@
galago_status_remove_attribute(GalagoObject *object, const char *name)
{
GalagoStatus *status = GALAGO_STATUS(object);
- GalagoStatusAttr *attr;
+ GalagoKeyValue *key_value;
- attr = g_hash_table_lookup(status->priv->attrs_table, name);
+ key_value = g_hash_table_lookup(status->priv->attrs_table, name);
- if (attr == NULL)
+ if (key_value == NULL)
return FALSE;
g_hash_table_remove(status->priv->attrs_table, name);
- status->priv->attrs = g_list_remove(status->priv->attrs, attr);
+ status->priv->attrs = g_list_remove(status->priv->attrs, key_value);
return TRUE;
}
@@ -693,11 +678,11 @@
galago_status_get_attribute(const GalagoObject *object, const char *name)
{
GalagoStatus *status = GALAGO_STATUS(object);
- GalagoStatusAttr *attr;
+ GalagoKeyValue *key_value;
- attr = g_hash_table_lookup(status->priv->attrs_table, name);
+ key_value = g_hash_table_lookup(status->priv->attrs_table, name);
- return (attr == NULL ? NULL : attr->value);
+ return (key_value == NULL ? NULL : key_value->value);
}
gboolean
@@ -715,83 +700,3 @@
{
return GALAGO_STATUS(object)->priv->attrs;
}
-
-/**************************************************************************
- * GalagoStatusAttr API
- **************************************************************************/
-static GalagoStatusAttr *
-status_attr_new(const char *id, GValue *value)
-{
- GalagoStatusAttr *attr;
-
- g_return_val_if_fail(id != NULL, NULL);
-
- attr = g_new0(GalagoStatusAttr, 1);
- attr->id = g_strdup(id);
- attr->value = value;
-
- return attr;
-}
-
-static void
-status_attr_destroy(GalagoStatusAttr *attr)
-{
- if (attr->id != NULL)
- g_free(attr->id);
-
- g_value_unset(attr->value);
- g_free(attr->value);
- g_free(attr);
-}
-
-const GValue *
-galago_status_attr_get_gvalue(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, NULL);
-
- return attr->value;
-}
-
-const char *
-galago_status_attr_get_id(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, NULL);
-
- return attr->id;
-}
-
-gboolean
-galago_status_attr_get_bool(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, FALSE);
- g_return_val_if_fail(G_VALUE_HOLDS(attr->value, G_TYPE_BOOLEAN), FALSE);
-
- return g_value_get_boolean(attr->value);
-}
-
-const char *
-galago_status_attr_get_string(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, NULL);
- g_return_val_if_fail(G_VALUE_HOLDS(attr->value, G_TYPE_STRING), NULL);
-
- return g_value_get_string(attr->value);
-}
-
-gint32
-galago_status_attr_get_int(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, -1);
- g_return_val_if_fail(G_VALUE_HOLDS(attr->value, G_TYPE_INT), 0);
-
- return g_value_get_int(attr->value);
-}
-
-double
-galago_status_attr_get_double(const GalagoStatusAttr *attr)
-{
- g_return_val_if_fail(attr != NULL, 0.0);
- g_return_val_if_fail(G_VALUE_HOLDS(attr->value, G_TYPE_DOUBLE), 0);
-
- return g_value_get_double(attr->value);
-}
Modified: trunk/libgalago/libgalago/galago-status.h
===================================================================
--- trunk/libgalago/libgalago/galago-status.h 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago-status.h 2006-03-20 01:24:51 UTC (rev 2617)
@@ -25,7 +25,6 @@
typedef struct _GalagoStatus GalagoStatus;
typedef struct _GalagoStatusClass GalagoStatusClass;
typedef struct _GalagoStatusPrivate GalagoStatusPrivate;
-typedef struct _GalagoStatusAttr GalagoStatusAttr;
typedef enum
{
@@ -38,16 +37,6 @@
} GalagoStatusType;
-typedef enum
-{
- GALAGO_STATUS_ATTR_UNSET = -1, /**< Unset type */
- GALAGO_STATUS_ATTR_BOOL = 0, /**< Boolean type */
- GALAGO_STATUS_ATTR_STRING, /**< String type */
- GALAGO_STATUS_ATTR_INT, /**< Integer type */
- GALAGO_STATUS_ATTR_DOUBLE /**< Double type */
-
-} GalagoStatusAttrType;
-
#include <libgalago/galago-presence.h>
#include <libgalago/galago-object.h>
@@ -251,67 +240,6 @@
/*@}*/
-/**************************************************************************/
-/** @name GalagoStatusAttr API */
-/**************************************************************************/
-/*@{*/
-
-/**
- * Returns the GValue of a status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The status attribute's GValue.
- */
-const GValue *galago_status_attr_get_gvalue(const GalagoStatusAttr *attr);
-
-/**
- * Returns the ID of a status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The status attribute's ID.
- */
-const char *galago_status_attr_get_id(const GalagoStatusAttr *attr);
-
-/**
- * Returns the value of a boolean status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The boolean value.
- */
-gboolean galago_status_attr_get_bool(const GalagoStatusAttr *attr);
-
-/**
- * Returns the value of a string status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The string value.
- */
-const char *galago_status_attr_get_string(const GalagoStatusAttr *attr);
-
-/**
- * Returns the value of an integer status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The integer value.
- */
-gint32 galago_status_attr_get_int(const GalagoStatusAttr *attr);
-
-/**
- * Returns the value of a double status attribute.
- *
- * @param attr The status attribute.
- *
- * @return The double value.
- */
-double galago_status_attr_get_double(const GalagoStatusAttr *attr);
-
-/*@}*/
-
G_END_DECLS
#endif /* _GALAGO_STATUS_H_ */
Modified: trunk/libgalago/libgalago/galago.h
===================================================================
--- trunk/libgalago/libgalago/galago.h 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/libgalago/galago.h 2006-03-20 01:24:51 UTC (rev 2617)
@@ -43,6 +43,7 @@
#include <libgalago/galago-context.h>
#include <libgalago/galago-dbus.h>
#include <libgalago/galago-enum-types.h>
+#include <libgalago/galago-key-value.h>
#include <libgalago/galago-object.h>
#include <libgalago/galago-person.h>
#include <libgalago/galago-presence.h>
Modified: trunk/libgalago/tests/presence-feed.c
===================================================================
--- trunk/libgalago/tests/presence-feed.c 2006-03-20 00:23:30 UTC (rev 2616)
+++ trunk/libgalago/tests/presence-feed.c 2006-03-20 01:24:51 UTC (rev 2617)
@@ -50,7 +50,6 @@
status = galago_status_new(GALAGO_STATUS_AWAY, "away", "Away", TRUE);
galago_object_set_attr_string(GALAGO_OBJECT(status), "message",
"I'm eating dinner.");
-
galago_presence_add_status(presence, status);
/* Add contacts to our AIM account */
More information about the galago-commits
mailing list