[tracker/writeback] Removed the register pattern for the DBus signal
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/writeback] Removed the register pattern for the DBus signal
- Date: Fri, 6 Nov 2009 12:58:53 +0000 (UTC)
commit edb083dae4f157310d9dec5c342fbe88cb09ab67
Author: Philip Van Hoof <philip codeminded be>
Date: Fri Nov 6 13:56:54 2009 +0100
Removed the register pattern for the DBus signal
This doesn't make a difference if it's just a signal. We can just do a
broadcast signal instead and keep things simple.
data/dbus/tracker-resources.xml | 8 --
src/tracker-store/tracker-dbus.c | 2 +-
src/tracker-store/tracker-resources.c | 186 ++++-----------------------------
src/tracker-store/tracker-resources.h | 9 +-
4 files changed, 28 insertions(+), 177 deletions(-)
---
diff --git a/data/dbus/tracker-resources.xml b/data/dbus/tracker-resources.xml
index fdefb49..39aa927 100644
--- a/data/dbus/tracker-resources.xml
+++ b/data/dbus/tracker-resources.xml
@@ -37,17 +37,9 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
</method>
- <!-- Register yourself for Writeback signals -->
- <method name="RegisterWriteback">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
- <arg type="s" name="object_path" direction="in" />
- </method>
-
-<!-- This is a private signal
<signal name="Writeback">
<arg type="as" name="subjects" />
</signal>
--->
</interface>
</node>
diff --git a/src/tracker-store/tracker-dbus.c b/src/tracker-store/tracker-dbus.c
index a5e1eaf..9c7b975 100644
--- a/src/tracker-store/tracker-dbus.c
+++ b/src/tracker-store/tracker-dbus.c
@@ -214,7 +214,7 @@ tracker_dbus_register_objects (void)
objects = g_slist_prepend (objects, object);
/* Add org.freedesktop.Tracker1.Resources */
- object = resources = tracker_resources_new (connection);
+ object = resources = tracker_resources_new ();
if (!object) {
g_critical ("Could not create TrackerResources object to register");
return FALSE;
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 0806a46..e5f2cf7 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -53,14 +53,12 @@ G_DEFINE_TYPE(TrackerResources, tracker_resources, G_TYPE_OBJECT)
#define TRACKER_RESOURCES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_RESOURCES, TrackerResourcesPrivate))
enum {
- PROP_0,
- PROP_CONNECTION
+ WRITEBACK,
+ LAST_SIGNAL
};
typedef struct {
GSList *event_sources;
- GPtrArray *writeback_destinations;
- DBusGConnection *connection;
} TrackerResourcesPrivate;
typedef struct {
@@ -68,6 +66,9 @@ typedef struct {
guint request_id;
} TrackerDBusMethodInfo;
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
static void
free_event_sources (TrackerResourcesPrivate *priv)
{
@@ -87,55 +88,11 @@ tracker_resources_finalize (GObject *object)
priv = TRACKER_RESOURCES_GET_PRIVATE (object);
- dbus_g_connection_unref (priv->connection);
-
free_event_sources (priv);
G_OBJECT_CLASS (tracker_resources_parent_class)->finalize (object);
}
-
-static void
-tracker_resources_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- TrackerResourcesPrivate *priv;
-
- priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_CONNECTION:
- priv->connection = dbus_g_connection_ref (g_value_get_pointer (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-tracker_resources_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- TrackerResourcesPrivate *priv;
-
- priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_CONNECTION:
- g_value_set_pointer (value, priv->connection);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
static void
tracker_resources_class_init (TrackerResourcesClass *klass)
{
@@ -144,15 +101,16 @@ tracker_resources_class_init (TrackerResourcesClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = tracker_resources_finalize;
- object_class->get_property = tracker_resources_get_property;
- object_class->set_property = tracker_resources_set_property;
- g_object_class_install_property (object_class,
- PROP_CONNECTION,
- g_param_spec_pointer ("connection",
- "connection",
- "connection",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ signals[WRITEBACK] =
+ g_signal_new ("writeback",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TrackerResourcesClass, writeback),
+ NULL, NULL,
+ tracker_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRV);
g_type_class_add_private (object_class, sizeof (TrackerResourcesPrivate));
}
@@ -161,19 +119,12 @@ tracker_resources_class_init (TrackerResourcesClass *klass)
static void
tracker_resources_init (TrackerResources *object)
{
- TrackerResourcesPrivate *priv;
-
- priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
- priv->writeback_destinations = g_ptr_array_new ();
}
TrackerResources *
-tracker_resources_new (DBusGConnection *connection)
+tracker_resources_new (void)
{
- return g_object_new (TRACKER_TYPE_RESOURCES,
- "connection", connection,
- NULL);
+ return g_object_new (TRACKER_TYPE_RESOURCES, NULL);
}
/*
@@ -411,62 +362,13 @@ tracker_resources_batch_commit (TrackerResources *self,
static void
-tracker_resources_register_writeback_proxy_destroyed (DBusGProxy *proxy,
- TrackerResources *object)
-{
- TrackerResourcesPrivate *priv;
-
- priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
- while (g_ptr_array_remove (priv->writeback_destinations, proxy)) {
- /* Should we unref proxy here too? I think not. I think dbus-
- * glib garbage collects it in a mainloop iteration. Right? */
- }
-}
-
-void
-tracker_resources_register_writeback (TrackerResources *object,
- const gchar *object_path,
- DBusGMethodInvocation *context,
- GError **error)
-{
- TrackerResourcesPrivate *priv;
- guint request_id;
- gchar *sender;
- DBusGProxy *proxy;
-
- priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
- request_id = tracker_dbus_get_next_request_id ();
-
- sender = dbus_g_method_get_sender (context);
-
- tracker_dbus_request_new (request_id,
- "D-Bus request for writeback registration: '%s'",
- sender);
-
- proxy = dbus_g_proxy_new_for_name (priv->connection,
- sender,
- object_path,
- "org.freedesktop.Tracker1.WritebackRecipient");
-
- g_ptr_array_add (priv->writeback_destinations, proxy);
-
- g_signal_connect (proxy, "destroy",
- G_CALLBACK (tracker_resources_register_writeback_proxy_destroyed),
- object);
-
- dbus_g_method_return (context);
- tracker_dbus_request_success (request_id);
-}
-
-static void
on_statements_committed (gpointer user_data)
{
+ TrackerResources *resources = user_data;
GPtrArray *events;
TrackerResourcesPrivate *priv;
- priv = TRACKER_RESOURCES_GET_PRIVATE (user_data);
+ priv = TRACKER_RESOURCES_GET_PRIVATE (resources);
/* For more information about this call, look at the function end_batch
* of tracker-store.c */
@@ -523,58 +425,16 @@ on_statements_committed (gpointer user_data)
if (events) {
guint t;
- DBusConnection *connection;
-
- connection = dbus_g_connection_get_connection (priv->connection);
-
- for (t = 0; t < priv->writeback_destinations->len; t++) {
- const gchar *destination;
- DBusMessageIter iter;
- DBusMessageIter strv_iter;
- DBusMessage *message;
- guint n;
- DBusGProxy *sender;
-
- /* Get the destination, we do this to reduce broadcasted
- * signal's DBus traffic. By setting destination we
- * ensure that only the explicitly registered ones awake.
- * This might be unnecessary, perhaps we can just do a
- * broadcast signal instead too? */
-
- sender = g_ptr_array_index (priv->writeback_destinations, t);
- destination = dbus_g_proxy_get_bus_name (sender);
- message = dbus_message_new_signal (TRACKER_RESOURCES_PATH,
- TRACKER_RESOURCES_INTERFACE,
- "Writeback");
+ GStrv events_strv = g_new0 (gchar *, events->len + 1);
- /* The dbus-glib library can't do this yet, this is why
- * you are seeing raw DBus API usage. No panic. */
+ for (t = 0; t < events->len; t++)
+ events_strv[t] = events->pdata[t];
- dbus_message_set_destination (message, destination);
+ g_signal_emit (resources, signals[WRITEBACK], 0, events_strv);
- dbus_message_iter_init_append (message, &iter);
+ g_free (events_strv);
- dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
- DBUS_TYPE_STRING_AS_STRING,
- &strv_iter);
-
- for (n = 0; n < events->len; n++) {
- const gchar *writeback_subject;
-
- writeback_subject = g_ptr_array_index (events, n);
-
- dbus_message_iter_append_basic (&strv_iter,
- DBUS_TYPE_STRING,
- &writeback_subject);
- }
-
- dbus_message_iter_close_container (&iter, &strv_iter);
-
- dbus_connection_send (connection, message, NULL);
-
- dbus_message_unref (message);
- }
}
tracker_writeback_reset ();
diff --git a/src/tracker-store/tracker-resources.h b/src/tracker-store/tracker-resources.h
index a640c3d..9eff7fa 100644
--- a/src/tracker-store/tracker-resources.h
+++ b/src/tracker-store/tracker-resources.h
@@ -46,10 +46,13 @@ struct TrackerResources {
struct TrackerResourcesClass {
GObjectClass parent;
+
+ void (*writeback) (TrackerResources *resources,
+ GStrv subjects);
};
GType tracker_resources_get_type (void);
-TrackerResources *tracker_resources_new (DBusGConnection *connection);
+TrackerResources *tracker_resources_new (void);
void tracker_resources_prepare (TrackerResources *object,
GSList *event_sources);
void tracker_resources_unreg_batches (TrackerResources *object,
@@ -75,10 +78,6 @@ void tracker_resources_batch_sparql_update (TrackerResources
void tracker_resources_batch_commit (TrackerResources *object,
DBusGMethodInvocation *context,
GError **error);
-void tracker_resources_register_writeback (TrackerResources *object,
- const gchar *object_path,
- DBusGMethodInvocation *context,
- GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]