r7136 - dumbhippo/trunk/client/common/ddm



Author: otaylor
Date: 2008-01-07 11:35:03 -0600 (Mon, 07 Jan 2008)
New Revision: 7136

Modified:
   dumbhippo/trunk/client/common/ddm/ddm-data-resource.c
   dumbhippo/trunk/client/common/ddm/ddm-data-resource.h
Log:
* Add ddm_data_resource_set/get_data() for setting string-keyed user data
  for a resource
* Preserve order for list properties, at the expense of a some efficiency
  in list creation.


Modified: dumbhippo/trunk/client/common/ddm/ddm-data-resource.c
===================================================================
--- dumbhippo/trunk/client/common/ddm/ddm-data-resource.c	2008-01-07 16:13:08 UTC (rev 7135)
+++ dumbhippo/trunk/client/common/ddm/ddm-data-resource.c	2008-01-07 17:35:03 UTC (rev 7136)
@@ -78,6 +78,7 @@
     DDMDataFetch *requested_fetch;
     gint64 requested_serial;
 
+    GData *data;
 };
 
 static void property_remove_rule_source(DDMDataProperty *property,
@@ -240,6 +241,8 @@
     resource->received_fetch = NULL;
     resource->local = local;
 
+    g_datalist_init(&resource->data);
+
     return resource;
 }
 
@@ -410,6 +413,8 @@
             g_warning("Freeing resource '%s' that is still referenced", resource->resource_id);
             g_slist_free(resource->referencing_rule_properties);
         }
+
+        g_datalist_clear(&resource->data);
         
         g_free(resource->resource_id);
         g_free(resource->class_id);
@@ -430,6 +435,22 @@
 }
 
 void
+ddm_data_resource_set_data (DDMDataResource *resource,
+                            const char      *key,
+                            gpointer         data,
+                            GDestroyNotify   notify)
+{
+    g_datalist_set_data_full(&resource->data, key, data, notify);
+}
+
+gpointer
+ddm_data_resource_get_data (DDMDataResource *resource,
+                            const char      *key)
+{
+    return g_datalist_get_data(&resource->data, key);
+}
+
+void
 ddm_data_resource_set_class_id(DDMDataResource    *resource,
                                const char         *class_id)
 {
@@ -992,23 +1013,23 @@
 
     switch (value->type) {
     case DDM_DATA_BOOLEAN:
-        property->value.u.list = g_slist_prepend(property->value.u.list, g_memdup(&value->u.boolean, sizeof(gboolean)));
+        property->value.u.list = g_slist_append(property->value.u.list, g_memdup(&value->u.boolean, sizeof(gboolean)));
         return;
     case DDM_DATA_INTEGER:
-        property->value.u.list = g_slist_prepend(property->value.u.list, g_memdup(&value->u.integer, sizeof(int)));
+        property->value.u.list = g_slist_append(property->value.u.list, g_memdup(&value->u.integer, sizeof(int)));
         return;
     case DDM_DATA_LONG:
-        property->value.u.list = g_slist_prepend(property->value.u.list, g_memdup(&value->u.long_, sizeof(gint64)));
+        property->value.u.list = g_slist_append(property->value.u.list, g_memdup(&value->u.long_, sizeof(gint64)));
         return;
     case DDM_DATA_FLOAT:
-        property->value.u.list = g_slist_prepend(property->value.u.list, g_memdup(&value->u.float_, sizeof(double)));
+        property->value.u.list = g_slist_append(property->value.u.list, g_memdup(&value->u.float_, sizeof(double)));
         return;
     case DDM_DATA_RESOURCE:
-        property->value.u.list = g_slist_prepend(property->value.u.list, value->u.resource);
+        property->value.u.list = g_slist_append(property->value.u.list, value->u.resource);
         return;
     case DDM_DATA_STRING:
     case DDM_DATA_URL:
-        property->value.u.list = g_slist_prepend(property->value.u.list, g_strdup(value->u.string));
+        property->value.u.list = g_slist_append(property->value.u.list, g_strdup(value->u.string));
         return;
     case DDM_DATA_NONE:
     case DDM_DATA_FEED:

Modified: dumbhippo/trunk/client/common/ddm/ddm-data-resource.h
===================================================================
--- dumbhippo/trunk/client/common/ddm/ddm-data-resource.h	2008-01-07 16:13:08 UTC (rev 7135)
+++ dumbhippo/trunk/client/common/ddm/ddm-data-resource.h	2008-01-07 17:35:03 UTC (rev 7136)
@@ -92,6 +92,13 @@
 DDMDataResource *ddm_data_resource_ref   (DDMDataResource *resource);
 void             ddm_data_resource_unref (DDMDataResource *resource);
 
+void     ddm_data_resource_set_data (DDMDataResource *resource,
+                                     const char      *key,
+                                     gpointer         data,
+                                     GDestroyNotify   notify);
+gpointer ddm_data_resource_get_data (DDMDataResource *resource,
+                                     const char      *key);
+
 void ddm_data_value_get_element(DDMDataValue *value,
                                 GSList         *element_node,
                                 DDMDataValue *element);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]