[tracker/rss-enclosures] tracker-store: Optimize sending of class signals, avoid dbus-glib
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/rss-enclosures] tracker-store: Optimize sending of class signals, avoid dbus-glib
- Date: Sat, 26 Jun 2010 23:17:36 +0000 (UTC)
commit 5249350e333a851dce9f1587bb1f69447be6052b
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jun 10 15:49:57 2010 +0200
tracker-store: Optimize sending of class signals, avoid dbus-glib
src/tracker-store/tracker-dbus.c | 2 +-
src/tracker-store/tracker-resource-class.c | 94 +++++++++++++++++++++-------
src/tracker-store/tracker-resource-class.h | 4 +-
3 files changed, 74 insertions(+), 26 deletions(-)
---
diff --git a/src/tracker-store/tracker-dbus.c b/src/tracker-store/tracker-dbus.c
index 440c48e..360dd9b 100644
--- a/src/tracker-store/tracker-dbus.c
+++ b/src/tracker-store/tracker-dbus.c
@@ -367,7 +367,7 @@ tracker_dbus_register_objects (void)
g_free (replaced);
/* Add a org.freedesktop.Tracker1.Resources.Class */
- object = tracker_resource_class_new (rdf_class);
+ object = tracker_resource_class_new (rdf_class, path, connection);
if (!object) {
g_critical ("Could not create TrackerResourcesClass object to register:'%s' class",
rdf_class);
diff --git a/src/tracker-store/tracker-resource-class.c b/src/tracker-store/tracker-resource-class.c
index 71872dc..41f1953 100644
--- a/src/tracker-store/tracker-resource-class.c
+++ b/src/tracker-store/tracker-resource-class.c
@@ -40,8 +40,10 @@
typedef struct {
gchar *rdf_class;
+ gchar *dbus_path;
GPtrArray *adds, *ups, *dels;
GStringChunk *changed_strings;
+ DBusConnection *connection;
} TrackerResourceClassPrivate;
typedef struct {
@@ -71,6 +73,9 @@ tracker_resource_class_class_init (TrackerResourceClassClass *klass)
object_class->finalize = tracker_resource_class_finalize;
+ /* Not used by the code, but left here for the D-Bus introspection to work
+ * right (for our beloved d-feet users) */
+
signals[SUBJECTS_ADDED] =
g_signal_new ("subjects-added",
G_TYPE_FROM_CLASS (klass),
@@ -117,51 +122,86 @@ tracker_resource_class_init (TrackerResourceClass *object)
}
static void
-emit_strings (TrackerResourceClass *object, gint signal_, GPtrArray *array)
+emit_strings (TrackerResourceClass *object,
+ const gchar *signal_name,
+ GPtrArray *array)
{
- GStrv strings_to_emit;
- guint i;
+ TrackerResourceClassPrivate *priv;
+
+ priv = TRACKER_RESOURCE_CLASS_GET_PRIVATE (object);
if (array->len > 0) {
- strings_to_emit = (GStrv) g_malloc0 (sizeof (gchar *) * (array->len + 1));
+ DBusMessageIter iter;
+ DBusMessageIter strv_iter;
+ DBusMessage *message;
+ guint i;
+
+ message = dbus_message_new_signal (priv->dbus_path,
+ TRACKER_RESOURCES_CLASS_INTERFACE,
+ signal_name);
+
+ dbus_message_iter_init_append (message, &iter);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &strv_iter);
for (i = 0; i < array->len; i++) {
- strings_to_emit[i] = array->pdata [i];
+ dbus_message_iter_append_basic (&strv_iter, DBUS_TYPE_STRING, &array->pdata [i]);
}
+ dbus_message_iter_close_container (&iter, &strv_iter);
- g_signal_emit (object, signal_, 0, strings_to_emit);
+ dbus_connection_send (priv->connection, message, NULL);
- /* Normal free, not a GStrv free, we free the strings later */
- g_free (strings_to_emit);
+ dbus_message_unref (message);
}
}
static void
-emit_changed_strings (TrackerResourceClass *object, GPtrArray *array)
+emit_changed_strings (TrackerResourceClass *object,
+ GPtrArray *array)
{
- GStrv stringsa_to_emit;
- const gchar **stringsb_to_emit;
+ TrackerResourceClassPrivate *priv;
- guint i;
+ priv = TRACKER_RESOURCE_CLASS_GET_PRIVATE (object);
if (array->len > 0) {
- stringsa_to_emit = (GStrv) g_malloc0 (sizeof (gchar *) * (array->len + 1));
- stringsb_to_emit = g_malloc0 (sizeof (const gchar *) * (array->len + 1));
+ DBusMessageIter iter;
+ DBusMessageIter strv1_iter;
+ DBusMessageIter strv2_iter;
+ DBusMessage *message;
+ guint i;
+
+ message = dbus_message_new_signal (priv->dbus_path,
+ TRACKER_RESOURCES_CLASS_INTERFACE,
+ "SubjectsChanged");
+
+ dbus_message_iter_init_append (message, &iter);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &strv1_iter);
for (i = 0; i < array->len; i++) {
ChangedItem *item = array->pdata [i];
+ dbus_message_iter_append_basic (&strv1_iter, DBUS_TYPE_STRING, &item->uri);
+ }
- stringsa_to_emit[i] = item->uri;
- stringsb_to_emit[i] = tracker_property_get_uri (item->predicate);
+ dbus_message_iter_close_container (&iter, &strv1_iter);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &strv2_iter);
+
+ for (i = 0; i < array->len; i++) {
+ ChangedItem *item = array->pdata [i];
+ const gchar *predicate = tracker_property_get_uri (item->predicate);
+ dbus_message_iter_append_basic (&strv2_iter, DBUS_TYPE_STRING, &predicate);
}
- g_signal_emit (object, signals[SUBJECTS_CHANGED], 0,
- stringsa_to_emit, stringsb_to_emit);
+ dbus_message_iter_close_container (&iter, &strv2_iter);
+
+ dbus_connection_send (priv->connection, message, NULL);
- /* Normal free, not a GStrv free, we free the items later */
- g_free (stringsa_to_emit);
- g_free (stringsb_to_emit);
+ dbus_message_unref (message);
}
}
@@ -185,7 +225,7 @@ tracker_resource_class_emit_events (TrackerResourceClass *object)
priv = TRACKER_RESOURCE_CLASS_GET_PRIVATE (object);
if (priv->adds) {
- emit_strings (object, signals[SUBJECTS_ADDED], priv->adds);
+ emit_strings (object, "SubjectsAdded", priv->adds);
g_ptr_array_free (priv->adds, TRUE);
priv->adds = NULL;
}
@@ -197,7 +237,7 @@ tracker_resource_class_emit_events (TrackerResourceClass *object)
}
if (priv->dels) {
- emit_strings (object, signals[SUBJECTS_REMOVED], priv->dels);
+ emit_strings (object, "SubjectsRemoved", priv->dels);
g_ptr_array_free (priv->dels, TRUE);
priv->dels = NULL;
}
@@ -221,12 +261,16 @@ tracker_resource_class_finalize (GObject *object)
tracker_resource_class_emit_events ((TrackerResourceClass *) object);
g_free (priv->rdf_class);
+ g_free (priv->dbus_path);
+ dbus_connection_unref (priv->connection);
G_OBJECT_CLASS (tracker_resource_class_parent_class)->finalize (object);
}
TrackerResourceClass *
-tracker_resource_class_new (const gchar *rdf_class)
+tracker_resource_class_new (const gchar *rdf_class,
+ const gchar *dbus_path,
+ DBusGConnection *connection)
{
TrackerResourceClass *object;
TrackerResourceClassPrivate *priv;
@@ -236,6 +280,8 @@ tracker_resource_class_new (const gchar *rdf_class)
priv = TRACKER_RESOURCE_CLASS_GET_PRIVATE (object);
priv->rdf_class = g_strdup (rdf_class);
+ priv->dbus_path = g_strdup (dbus_path);
+ priv->connection = dbus_connection_ref (dbus_g_connection_get_connection (connection));
return object;
}
diff --git a/src/tracker-store/tracker-resource-class.h b/src/tracker-store/tracker-resource-class.h
index 1092ab0..fa6a20a 100644
--- a/src/tracker-store/tracker-resource-class.h
+++ b/src/tracker-store/tracker-resource-class.h
@@ -52,7 +52,9 @@ struct TrackerResourceClassClass {
};
GType tracker_resource_class_get_type (void);
-TrackerResourceClass *tracker_resource_class_new (const gchar *rdf_class);
+TrackerResourceClass *tracker_resource_class_new (const gchar *rdf_class,
+ const gchar *dbus_path,
+ DBusGConnection *connection);
const gchar * tracker_resource_class_get_rdf_class (TrackerResourceClass *object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]