[tracker/gdbus: 5/74] libtracker-miner: GDBus porting of tracker-miner-object.c (unfinished)
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/gdbus: 5/74] libtracker-miner: GDBus porting of tracker-miner-object.c (unfinished)
- Date: Fri, 14 Jan 2011 13:05:07 +0000 (UTC)
commit 2ffaddf3ff61feed02bdb58d9cf1b489ced2f2a6
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Dec 29 16:51:11 2010 +0100
libtracker-miner: GDBus porting of tracker-miner-object.c (unfinished)
src/libtracker-miner/Makefile.am | 31 +--
src/libtracker-miner/tracker-miner-object.c | 513 +++++++++++++++++----------
2 files changed, 329 insertions(+), 215 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index f429f2c..da8d032 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -92,19 +92,6 @@ $(top_builddir)/src/libtracker-miner/tracker-marshal.c: tracker-marshal.list
$(AM_V_GEN)(echo "#include \"tracker-marshal.h\""; \
$(GLIB_GENMARSHAL) $< --prefix=tracker_marshal --body) > $@
-# Generate DBus files from XML data.
-dbus_sources = \
- tracker-miner-glue.h \
- tracker-miner-web-glue.h \
- tracker-miner-files-index-client.h \
- tracker-miner-client.h
-
-%-glue.h: $(top_srcdir)/data/dbus/%.xml
- $(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=_$(subst -,_,$*) $^
-
-%-client.h: $(top_srcdir)/data/dbus/%.xml
- $(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-client --output=$@ --prefix=_$(subst -,_,$*) $^
-
# Vala bindings
vapidir = $(datadir)/vala/vapi
vapi_DATA = \
@@ -117,19 +104,6 @@ tracker-miner-$(TRACKER_API_VERSION).vapi: tracker-miner.vapi
tracker-miner-$(TRACKER_API_VERSION).deps: tracker-miner.deps
cp $< $@
-# Custom rule to avoid API duplication. There is also a workaround for bug
-# in dbus-binding-tool where it generates bad code when two files are passed
-# on the command line (though the man page says it supports it)
-# This bug is reported at https://bugs.freedesktop.org/show_bug.cgi?id=25056
-tracker-miner-web-glue.h: $(top_srcdir)/data/dbus/tracker-miner-web.xml $(top_srcdir)/data/dbus/tracker-miner.xml
- echo '<?xml version="1.0" encoding="UTF-8"?>' > tracker-miner-web-full.xml
- echo '<node name="/">' >> tracker-miner-web-full.xml
- cat $^ | grep -v -e '<node' -e '<?xml' -e '</node>' >> tracker-miner-web-full.xml
- echo '</node>' >> tracker-miner-web-full.xml
- $(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=_tracker_miner_web_dbus tracker-miner-web-full.xml
-
-tracker-miner-web-full.xml: tracker-miner-web-glue.h
-
BUILT_SOURCES = \
$(dbus_sources) \
$(libtracker_miner_marshal_sources) \
@@ -138,10 +112,7 @@ BUILT_SOURCES = \
CLEANFILES = $(BUILT_SOURCES)
-DISTCLEANFILES = tracker-miner-web-full.xml
-
EXTRA_DIST = \
tracker-marshal.list \
tracker-miner.vapi \
- tracker-miner.deps \
- tracker-miner-web-full.xml
+ tracker-miner.deps
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index ed3eaf2..f7c095f 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -29,7 +29,6 @@
#include "tracker-marshal.h"
#include "tracker-miner-object.h"
#include "tracker-miner-dbus.h"
-#include "tracker-miner-glue.h"
#include "tracker-dbus.h"
/* Here we use ceil() to eliminate decimal points beyond what we're
@@ -41,6 +40,8 @@
*/
#define PROGRESS_ROUNDED(x) (ceil (((x) * 100) - 0.49) / 100)
+#define TRACKER_SERVICE "org.freedesktop.Tracker1"
+
/**
* SECTION:tracker-miner
* @short_description: Abstract base class for data miners
@@ -57,18 +58,58 @@
static GQuark miner_error_quark = 0;
+
+/* Introspection data for the service we are exporting */
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.freedesktop.Tracker1.Miner'>"
+ " <method name='GetStatus'>"
+ " <arg type='s' name='status' direction='out' />"
+ " </method>"
+ " <method name='GetProgress'>"
+ " <arg type='d' name='progress' direction='out' />"
+ " </method>"
+ " <method name='GetPauseDetails'>"
+ " <arg type='as' name='pause_applications' direction='out' />"
+ " <arg type='as' name='pause_reasons' direction='out' />"
+ " </method>"
+ " <method name='Pause'>"
+ " <arg type='s' name='application' direction='in' />"
+ " <arg type='s' name='reason' direction='in' />"
+ " <arg type='i' name='cookie' direction='out' />"
+ " </method>"
+ " <method name='Resume'>"
+ " <arg type='i' name='cookie' direction='in' />"
+ " </method>"
+ " <method name='IgnoreNextUpdate'>"
+ " <arg type='as' name='urls' direction='in' />"
+ " </method>"
+ " <signal name='Started' />"
+ " <signal name='Stopped'>"
+ " <arg type='b' name='interrupted' />"
+ " </signal>"
+ " <signal name='Paused' />"
+ " <signal name='Resumed' />"
+ " <signal name='Progress'>"
+ " <arg type='s' name='status' />"
+ " <arg type='d' name='progress' />"
+ " </signal>"
+ " </interface>"
+ "</node>";
+
struct _TrackerMinerPrivate {
TrackerSparqlConnection *connection;
-
GHashTable *pauses;
-
gboolean started;
-
gchar *name;
gchar *status;
gdouble progress;
-
gint availability_cookie;
+ GDBusConnection *d_connection;
+ GDBusNodeInfo *introspection_data;
+ guint watch_name_id;
+ guint registration_id;
+ guint own_id;
};
typedef struct {
@@ -109,9 +150,6 @@ static void miner_constructed (GObject *object);
static void pause_data_destroy (gpointer data);
static PauseData *pause_data_new (const gchar *application,
const gchar *reason);
-static void store_name_monitor_cb (TrackerMiner *miner,
- const gchar *name,
- gboolean available);
G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
@@ -368,77 +406,6 @@ miner_get_property (GObject *object,
}
}
-static void
-miner_finalize (GObject *object)
-{
- TrackerMiner *miner = TRACKER_MINER (object);
-
- g_free (miner->private->status);
- g_free (miner->private->name);
-
- if (miner->private->connection) {
- g_object_unref (miner->private->connection);
- }
-
- g_hash_table_unref (miner->private->pauses);
-
- _tracker_miner_dbus_remove_name_watch (miner,
- "org.freedesktop.Tracker1",
- store_name_monitor_cb);
- _tracker_miner_dbus_shutdown (miner);
-
- G_OBJECT_CLASS (tracker_miner_parent_class)->finalize (object);
-}
-
-static void
-miner_constructed (GObject *object)
-{
- TrackerMiner *miner = TRACKER_MINER (object);
-
- _tracker_miner_dbus_init (miner, &dbus_glib__tracker_miner_object_info);
- _tracker_miner_dbus_add_name_watch (miner,
- "org.freedesktop.Tracker1",
- store_name_monitor_cb);
-}
-
-static void
-store_name_monitor_cb (TrackerMiner *miner,
- const gchar *name,
- gboolean available)
-{
- GError *error = NULL;
-
- g_debug ("Miner:'%s' noticed store availability has changed to %s",
- miner->private->name,
- available ? "AVAILABLE" : "UNAVAILABLE");
-
- if (available && miner->private->availability_cookie != 0) {
- tracker_miner_resume (miner,
- miner->private->availability_cookie,
- &error);
-
- if (error) {
- g_warning ("Error happened resuming miner, %s", error->message);
- g_error_free (error);
- }
-
- miner->private->availability_cookie = 0;
- } else if (!available && miner->private->availability_cookie == 0) {
- gint cookie_id;
-
- cookie_id = tracker_miner_pause (miner,
- _("Data store is not available"),
- &error);
-
- if (error) {
- g_warning ("Could not pause, %s", error->message);
- g_error_free (error);
- } else {
- miner->private->availability_cookie = cookie_id;
- }
- }
-}
-
static PauseData *
pause_data_new (const gchar *application,
const gchar *reason)
@@ -657,157 +624,333 @@ tracker_miner_get_connection (TrackerMiner *miner)
return miner->private->connection;
}
-/* DBus methods */
-void
-_tracker_miner_dbus_get_status (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error)
+static void
+miner_finalize (GObject *object)
{
- TrackerDBusRequest *request;
+ TrackerMiner *miner = TRACKER_MINER (object);
- tracker_dbus_async_return_if_fail (miner != NULL, context);
+ if (miner->private->watch_name_id != 0) {
+ g_bus_unwatch_name (miner->private->watch_name_id);
+ }
- request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
+ if (miner->private->own_id != 0) {
+ g_bus_unown_name (miner->private->own_id);
+ }
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context, miner->private->status);
-}
+ if (miner->private->registration_id != 0) {
+ g_dbus_connection_unregister_object (miner->private->d_connection,
+ miner->private->registration_id);
+ }
-void
-_tracker_miner_dbus_get_progress (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error)
-{
- TrackerDBusRequest *request;
+ if (miner->private->introspection_data) {
+ g_dbus_node_info_unref (miner->private->introspection_data);
+ }
+
+ if (miner->private->d_connection) {
+ g_object_unref (miner->private->d_connection);
+ }
+
+ g_free (miner->private->status);
+ g_free (miner->private->name);
- tracker_dbus_async_return_if_fail (miner != NULL, context);
+ if (miner->private->connection) {
+ g_object_unref (miner->private->connection);
+ }
- request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
+ g_hash_table_unref (miner->private->pauses);
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context, miner->private->progress);
+ G_OBJECT_CLASS (tracker_miner_parent_class)->finalize (object);
}
-void
-_tracker_miner_dbus_get_pause_details (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error)
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- GSList *applications, *reasons;
- GStrv applications_strv, reasons_strv;
- GHashTableIter iter;
- gpointer key, value;
+ TrackerMiner *miner = user_data;
TrackerDBusRequest *request;
- tracker_dbus_async_return_if_fail (miner != NULL, context);
+ tracker_gdbus_async_return_if_fail (miner != NULL, invocation);
- request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
+ if (g_strcmp0 (method_name, "IgnoreNextUpdate") == 0) {
+ GStrv urls;
- applications = NULL;
- reasons = NULL;
+ g_variant_get (parameters, "as", &urls);
- g_hash_table_iter_init (&iter, miner->private->pauses);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- PauseData *pd = value;
+ request = tracker_g_dbus_request_begin (invocation,
+ "%s", __PRETTY_FUNCTION__);
- applications = g_slist_prepend (applications, pd->application);
- reasons = g_slist_prepend (reasons, pd->reason);
- }
+ tracker_miner_ignore_next_update (miner, urls);
- applications = g_slist_reverse (applications);
- reasons = g_slist_reverse (reasons);
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else
+ if (g_strcmp0 (method_name, "Resume") == 0) {
+ GError *local_error = NULL;
+ gint cookie;
- applications_strv = tracker_gslist_to_string_list (applications);
- reasons_strv = tracker_gslist_to_string_list (reasons);
+ g_variant_get (parameters, "i", &cookie);
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context, applications_strv, reasons_strv);
+ request = tracker_g_dbus_request_begin (invocation,
+ "%s(cookie:%d)",
+ __PRETTY_FUNCTION__,
+ cookie);
- g_strfreev (applications_strv);
- g_strfreev (reasons_strv);
+ if (!tracker_miner_resume (miner, cookie, &local_error)) {
+ tracker_dbus_request_end (request, local_error);
- g_slist_free (applications);
- g_slist_free (reasons);
-}
+ g_dbus_method_invocation_return_gerror (invocation, local_error);
-void
-_tracker_miner_dbus_pause (TrackerMiner *miner,
- const gchar *application,
- const gchar *reason,
- DBusGMethodInvocation *context,
- GError **error)
-{
- GError *local_error = NULL;
- TrackerDBusRequest *request;
- gint cookie;
+ g_error_free (local_error);
+ return;
+ }
- tracker_dbus_async_return_if_fail (miner != NULL, context);
- tracker_dbus_async_return_if_fail (application != NULL, context);
- tracker_dbus_async_return_if_fail (reason != NULL, context);
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else
+ if (g_strcmp0 (method_name, "Pause") == 0) {
+ GError *local_error = NULL;
+ gint cookie;
+ gchar *application = NULL, *reason = NULL;
- request = tracker_dbus_g_request_begin (context,
- "%s(application:'%s', reason:'%s')",
- __PRETTY_FUNCTION__,
- application,
- reason);
+ g_variant_get (parameters, "ss", &application, &reason);
- cookie = tracker_miner_pause_internal (miner, application, reason, &local_error);
- if (cookie == -1) {
- tracker_dbus_request_end (request, local_error);
- dbus_g_method_return_error (context, local_error);
+ tracker_gdbus_async_return_if_fail (application != NULL, invocation);
+ tracker_gdbus_async_return_if_fail (reason != NULL, invocation);
- g_error_free (local_error);
+ request = tracker_g_dbus_request_begin (invocation,
+ "%s(application:'%s', reason:'%s')",
+ __PRETTY_FUNCTION__,
+ application,
+ reason);
- return;
+ cookie = tracker_miner_pause_internal (miner, application, reason, &local_error);
+ if (cookie == -1) {
+ tracker_dbus_request_end (request, local_error);
+
+ g_dbus_method_invocation_return_gerror (invocation, local_error);
+
+ g_error_free (local_error);
+
+ return;
+ }
+
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("i", cookie));
+ } else
+ if (g_strcmp0 (method_name, "GetPauseDetails") == 0) {
+ GSList *applications, *reasons;
+ GStrv applications_strv, reasons_strv;
+ GHashTableIter iter;
+ gpointer key, value;
+ TrackerDBusRequest *request;
+
+ request = tracker_g_dbus_request_begin (invocation, "%s()", __PRETTY_FUNCTION__);
+
+ applications = NULL;
+ reasons = NULL;
+ g_hash_table_iter_init (&iter, miner->private->pauses);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ PauseData *pd = value;
+
+ applications = g_slist_prepend (applications, pd->application);
+ reasons = g_slist_prepend (reasons, pd->reason);
+ }
+ applications = g_slist_reverse (applications);
+ reasons = g_slist_reverse (reasons);
+ applications_strv = tracker_gslist_to_string_list (applications);
+ reasons_strv = tracker_gslist_to_string_list (reasons);
+
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("asas",
+ applications_strv,
+ reasons_strv));
+
+ g_strfreev (applications_strv);
+ g_strfreev (reasons_strv);
+ g_slist_free (applications);
+ g_slist_free (reasons);
+ } else
+ if (g_strcmp0 (method_name, "GetProgress") == 0) {
+
+ request = tracker_g_dbus_request_begin (invocation, "%s()", __PRETTY_FUNCTION__);
+
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("i", miner->private->progress));
+ } else
+ if (g_strcmp0 (method_name, "GetStatus") == 0) {
+
+
+ request = tracker_g_dbus_request_begin (invocation, "%s()", __PRETTY_FUNCTION__);
+
+ tracker_dbus_request_end (request, NULL);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("s", miner->private->status));
}
+}
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context, cookie);
+static GVariant *
+handle_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
+{
+ return NULL;
}
-void
-_tracker_miner_dbus_resume (TrackerMiner *miner,
- gint cookie,
- DBusGMethodInvocation *context,
- GError **error)
+static gboolean
+handle_set_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GVariant *value,
+ GError **error,
+ gpointer user_data)
{
- GError *local_error = NULL;
- TrackerDBusRequest *request;
+ return TRUE;
+}
- tracker_dbus_async_return_if_fail (miner != NULL, context);
+static const GDBusInterfaceVTable interface_vtable = {
+ handle_method_call,
+ handle_get_property,
+ handle_set_property
+};
- request = tracker_dbus_g_request_begin (context,
- "%s(cookie:%d)",
- __PRETTY_FUNCTION__,
- cookie);
+static void
+on_tracker_store_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
- if (!tracker_miner_resume (miner, cookie, &local_error)) {
- tracker_dbus_request_end (request, local_error);
- dbus_g_method_return_error (context, local_error);
+{
+ TrackerMiner *miner = user_data;
- g_error_free (local_error);
+ g_debug ("Miner:'%s' noticed store availability has changed to AVAILABLE",
+ miner->private->name);
- return;
+ if (miner->private->availability_cookie != 0) {
+ GError *error = NULL;
+
+ tracker_miner_resume (miner,
+ miner->private->availability_cookie,
+ &error);
+
+ if (error) {
+ g_warning ("Error happened resuming miner, %s", error->message);
+ g_error_free (error);
+ }
+
+ miner->private->availability_cookie = 0;
}
+}
+
+static void
+on_tracker_store_disappeared (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ TrackerMiner *miner = user_data;
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context);
+ g_debug ("Miner:'%s' noticed store availability has changed to UNAVAILABLE",
+ miner->private->name);
+
+ if (miner->private->availability_cookie == 0) {
+ GError *error = NULL;
+ gint cookie_id;
+
+ cookie_id = tracker_miner_pause (miner,
+ _("Data store is not available"),
+ &error);
+
+ if (error) {
+ g_warning ("Could not pause, %s", error->message);
+ g_error_free (error);
+ } else {
+ miner->private->availability_cookie = cookie_id;
+ }
+ }
}
-void
-_tracker_miner_dbus_ignore_next_update (TrackerMiner *miner,
- const GStrv urls,
- DBusGMethodInvocation *context,
- GError **error)
+static void
+miner_constructed (GObject *object)
{
- TrackerDBusRequest *request;
+ TrackerMiner *miner = TRACKER_MINER (object);
+ gchar *name, *full_path, *full_name;
+ GError *error = NULL;
+
+ miner->private->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+ if (!miner->private->d_connection) {
+ g_critical ("Could not connect to the D-Bus session bus, %s",
+ error ? error->message : "no error given.");
+ g_clear_error (&error);
+ return;
+ }
+
+ miner->private->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
- tracker_dbus_async_return_if_fail (miner != NULL, context);
+ g_object_get (miner, "name", &name, NULL);
- request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
+ if (!name) {
+ g_critical ("Miner '%s' should have been given a name, bailing out",
+ G_OBJECT_TYPE_NAME (miner));
+ g_assert_not_reached ();
+ }
+
+ full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX, name, NULL);
+
+ miner->private->own_id = g_bus_own_name_on_connection (miner->private->d_connection,
+ full_name,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
+
+ g_free (full_name);
+
+ /* Register the service name for the miner */
+ full_path = g_strconcat (TRACKER_MINER_DBUS_PATH_PREFIX, name, NULL);
+
+ g_message ("Registering D-Bus object...");
+ g_message (" Path:'%s'", full_path);
+ g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (miner));
+
+ miner->private->registration_id =
+ g_dbus_connection_register_object (miner->private->d_connection,
+ full_path,
+ miner->private->introspection_data->interfaces[0],
+ &interface_vtable,
+ miner,
+ NULL,
+ &error);
+
+ if (error) {
+ g_critical ("Could not register the D-Bus object %s, %s",
+ full_path,
+ error ? error->message : "no error given.");
+ g_clear_error (&error);
+ return;
+ }
- tracker_miner_ignore_next_update (miner, urls);
+ g_free (name);
+ g_free (full_path);
- tracker_dbus_request_end (request, NULL);
- dbus_g_method_return (context);
+ miner->private->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+ TRACKER_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_tracker_store_appeared,
+ on_tracker_store_disappeared,
+ miner,
+ NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]