[tracker/wip/resource: 2/11] fixup tracker-resource stuff
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/resource: 2/11] fixup tracker-resource stuff
- Date: Sun, 27 Mar 2016 00:56:43 +0000 (UTC)
commit 06ad360de68f190b2228da604be2944fbba7657c
Author: Sam Thursfield <ssssam gmail com>
Date: Sat Mar 26 19:50:40 2016 +0000
fixup tracker-resource stuff
src/libtracker-sparql/tracker-resource.c | 73 +++++++++++++++++++-----------
1 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index ba7e14d..1790b4f 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -17,9 +17,21 @@
* Boston, MA 02110-1301, USA.
*/
+#include <glib.h>
+
+#include <string.h>
+
#include "config.h"
+#include <tracker-resource.h>
-G_DEFINE_TYPE (TrackerResource, tracker_resource, G_TYPE_OBJECT);
+typedef struct {
+ char *identifier;
+ GHashTable *properties;
+ GHashTable *properties_overwrite;
+} TrackerResourcePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (TrackerResource, tracker_resource, G_TYPE_OBJECT);
+#define GET_PRIVATE(object) (tracker_resource_get_instance_private (object))
/**
* SECTION: tracker-resource
@@ -41,50 +53,52 @@ G_DEFINE_TYPE (TrackerResource, tracker_resource, G_TYPE_OBJECT);
* about a given resource.
*/
-struct _TrackerResourcePrivate {
- char *identifier;
- GHashTable *properties;
- GHashTable *properties_overwrite;
-}
+static void finalize (GObject *object);
static void
tracker_resource_class_init (TrackerResourceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = resource_finalize;
+ object_class->finalize = finalize;
g_type_class_add_private (object_class, sizeof (TrackerResourcePrivate));
}
+/* Destroy-notify function for the values stored in the hash table. */
+static void
+free_value (GValue *value)
+{
+ g_value_unset (value);
+ g_free (value);
+}
+
static void
tracker_resource_init (TrackerResource *resource)
{
- resource->priv = G_TYPE_INSTANCE_GET_PRIVATE (resource,
- TRACKER_TYPE_RESOURCE,
- TrackerResourcePrivate);
+ TrackerResourcePrivate *priv = GET_PRIVATE(resource);
/* Values of properties */
- resource->priv->properties = g_hash_table_new_full (
- g_direct_hash,
- g_direct_equal,
- NULL,
- g_value_unset);
+ priv->properties = g_hash_table_new_full (
+ g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) free_value);
/* TRUE for any property where we should delete any existing values. */
- resource->priv->properties_overwrite = g_hash_table_new_full (
- g_direct_hash,
- g_direct_equal,
- NULL,
+ priv->properties_overwrite = g_hash_table_new_full (
+ g_str_hash,
+ g_str_equal,
+ g_free,
NULL);
}
static void
-resource_finalize (GObject *object)
+finalize (GObject *object)
{
TrackerResourcePrivate *priv;
- priv = ((TrackerResource *)object)->priv;
+ priv = GET_PRIVATE (TRACKER_RESOURCE (object));
g_hash_table_unref (priv->properties_overwrite);
g_hash_table_unref (priv->properties);
@@ -112,8 +126,9 @@ GValue *
tracker_resource_get_property (TrackerResource *self,
const char *property)
{
+ TrackerResourcePrivate *priv = GET_PRIVATE (self);
- return g)hash_table_lookup (self->priv->properties, property);
+ return g_hash_table_lookup (priv->properties, property);
}
void
@@ -121,17 +136,23 @@ tracker_resource_set_property (TrackerResource *self,
const char *property,
GValue *value)
{
+ TrackerResourcePrivate *priv = GET_PRIVATE (self);
+ GValue *our_value;
+
+ our_value = g_slice_new (GValue);
+ g_value_copy (value, our_value);
+
/* Note that this should generate a DELETE; INSERT in the SPARQL
* query: we're assming the property has only one value.
*/
- g_hash_table_replace (self->priv->properties,
- property,
- value);
+ g_hash_table_replace (priv->properties, g_strdup (property), our_value);
};
gint
tracker_resource_identifier_compare_func (TrackerResource *resource,
const char *identifier)
{
- return g_strcmp (resource->priv->identifier, identifier);
+ TrackerResourcePrivate *priv = GET_PRIVATE (resource);
+
+ return strcmp (priv->identifier, identifier);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]