[tracker] Simplify resource resource registration and fix a memory leak
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Simplify resource resource registration and fix a memory leak
- Date: Fri, 10 Jul 2009 11:54:57 +0000 (UTC)
commit 9aeca21ac75d3bab7b30e44e6d80ab985ce74bde
Author: Martyn Russell <martyn imendio com>
Date: Thu Jul 9 12:08:37 2009 +0100
Simplify resource resource registration and fix a memory leak
src/tracker-store/tracker-dbus.c | 143 +++++++++++++++++++++-----------------
1 files changed, 79 insertions(+), 64 deletions(-)
---
diff --git a/src/tracker-store/tracker-dbus.c b/src/tracker-store/tracker-dbus.c
index d1b0350..534e8d0 100644
--- a/src/tracker-store/tracker-dbus.c
+++ b/src/tracker-store/tracker-dbus.c
@@ -177,9 +177,10 @@ gboolean
tracker_dbus_register_objects (TrackerConfig *config,
TrackerLanguage *language)
{
- gpointer object, resources;
- GSList *event_sources = NULL;
TrackerDBResultSet *result_set;
+ GSList *event_sources = NULL;
+ GStrv classes, p;
+ gpointer object, resources;
g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), FALSE);
@@ -192,7 +193,7 @@ tracker_dbus_register_objects (TrackerConfig *config,
/* Add org.freedesktop.Tracker */
object = tracker_statistics_new ();
if (!object) {
- g_critical ("Could not create TrackerDaemon object to register");
+ g_critical ("Could not create TrackerStatistics object to register");
return FALSE;
}
@@ -204,12 +205,11 @@ tracker_dbus_register_objects (TrackerConfig *config,
objects = g_slist_prepend (objects, object);
/* Add org.freedesktop.Tracker.Resources */
- object = tracker_resources_new ();
+ object = resources = tracker_resources_new ();
if (!object) {
g_critical ("Could not create TrackerResources object to register");
return FALSE;
}
- resources = object;
dbus_register_object (connection,
gproxy,
@@ -237,69 +237,84 @@ tracker_dbus_register_objects (TrackerConfig *config,
result_set = tracker_data_query_sparql ("SELECT ?class WHERE { ?class tracker:notify true }", NULL);
- if (result_set) {
- GStrv classes_to_signal;
- guint ui, count = 0;
-
- classes_to_signal = tracker_dbus_query_result_to_strv (result_set, 0, &count);
-
- for (ui = 0; ui < count; ui++) {
- const gchar *rdf_class = classes_to_signal[ui];
- gchar *replaced;
- gchar *path, *uri, *hash;
-
- uri = g_strdup (rdf_class);
-
- hash = strrchr (uri, '#');
- if (hash == NULL) {
- /* support ontologies whose namespace uri does not end in a hash, e.g. dc */
- hash = strrchr (uri, '/');
- }
- if (hash == NULL) {
- g_critical ("Unknown namespace of property %s", uri);
- } else {
- gchar *namespace_uri = g_strndup (uri, hash - uri + 1);
- TrackerNamespace *namespace;
-
- namespace = tracker_ontology_get_namespace_by_uri (namespace_uri);
- if (namespace == NULL) {
- g_critical ("Unknown namespace %s of property %s", namespace_uri, uri);
- } else {
- replaced = g_strdup_printf ("%s/%s", tracker_namespace_get_prefix (namespace), hash + 1);
- }
- g_free (namespace_uri);
- }
-
- g_free (uri);
-
- path = g_strdup_printf (TRACKER_RESOURCES_CLASS_PATH,
- replaced);
-
- g_free (replaced);
-
- /* Add a org.freedesktop.Tracker.Resources.Class */
- object = tracker_resource_class_new (rdf_class);
- if (!object) {
- g_critical ("Could not create TrackerResourcesClass object to register");
- return FALSE;
- }
-
- dbus_register_object (connection,
- gproxy,
- G_OBJECT (object),
- &dbus_glib_tracker_resources_class_object_info,
- path);
- g_free (path);
+ if (!result_set) {
+ g_message ("No Nepomuk classes to register on DBus");
+ return TRUE;
+ }
- /* TrackerResources takes over ownership and unrefs the gobjects too */
- event_sources = g_slist_prepend (event_sources, g_object_ref (object));
- objects = g_slist_prepend (objects, object);
+ classes = tracker_dbus_query_result_to_strv (result_set, 0, NULL);
+ g_object_unref (result_set);
+
+ if (!classes) {
+ g_message ("No Nepomuk classes to register on DBus");
+ return TRUE;
+ }
+
+ for (p = classes; *p; p++) {
+ TrackerNamespace *namespace;
+ const gchar *rdf_class;
+ gchar *namespace_uri;
+ gchar *replaced, *path, *hash;
+
+ rdf_class = *p;
+ hash = strrchr (rdf_class, '#');
+
+ if (!hash) {
+ /* Support ontologies whose namespace
+ * uri does not end in a hash, e.g.
+ * dc.
+ */
+ hash = strrchr (rdf_class, '/');
+ }
+
+ if (!hash) {
+ g_critical ("Unknown namespace for class:'%s'",
+ rdf_class);
+ continue;
}
- g_strfreev (classes_to_signal);
- g_object_unref (result_set);
- }
+ namespace_uri = g_strndup (rdf_class, hash - rdf_class + 1);
+ namespace = tracker_ontology_get_namespace_by_uri (namespace_uri);
+ g_free (namespace_uri);
+
+ if (!namespace) {
+ g_critical ("Unknown namespace:'%s' for class:'%s'",
+ namespace_uri,
+ rdf_class);
+ continue;
+ }
+ replaced = g_strdup_printf ("%s/%s",
+ tracker_namespace_get_prefix (namespace),
+ hash + 1);
+ path = g_strdup_printf (TRACKER_RESOURCES_CLASS_PATH,
+ replaced);
+ g_free (replaced);
+
+ /* Add a org.freedesktop.Tracker.Resources.Class */
+ object = tracker_resource_class_new (rdf_class);
+ if (!object) {
+ g_critical ("Could not create TrackerResourcesClass object to register:'%s' class",
+ rdf_class);
+ g_free (path);
+ return FALSE;
+ }
+
+ dbus_register_object (connection,
+ gproxy,
+ G_OBJECT (object),
+ &dbus_glib_tracker_resources_class_object_info,
+ path);
+ g_free (path);
+
+ /* TrackerResources takes over ownership and unrefs
+ * the gobjects too.
+ */
+ event_sources = g_slist_prepend (event_sources, g_object_ref (object));
+ objects = g_slist_prepend (objects, object);
+ }
+
+ g_strfreev (classes);
tracker_resources_prepare (resources, event_sources);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]