[tracker/miner-web: 26/26] libtracker-miner: Rewrite TrackerMinerWeb in C
- From: Adrien Bustany <abustany src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/miner-web: 26/26] libtracker-miner: Rewrite TrackerMinerWeb in C
- Date: Wed, 11 Nov 2009 20:37:27 +0000 (UTC)
commit 9fd0488b229cdcb460dcb931c3f8dff243108de0
Author: Adrien Bustany <madcat mymadcat com>
Date: Wed Nov 11 15:00:40 2009 -0300
libtracker-miner: Rewrite TrackerMinerWeb in C
This is a complete rewrite of TrackerMinerWeb. It is now an abstract class, and
the API changed a bit to be clearer. I also added a Dissociate function, in case
the user wants to stop using the service.
data/dbus/tracker-miner-web.xml | 12 ++
src/libtracker-miner/Makefile.am | 9 +-
src/libtracker-miner/tracker-miner-web-0.7.vapi | 29 ++++
src/libtracker-miner/tracker-miner-web-dbus.h | 16 ++-
src/libtracker-miner/tracker-miner-web.c | 170 +++++++++++++++++++++--
src/libtracker-miner/tracker-miner-web.h | 80 ++++++++++-
src/libtracker-miner/tracker-miner-web.vala | 46 ------
7 files changed, 297 insertions(+), 65 deletions(-)
---
diff --git a/data/dbus/tracker-miner-web.xml b/data/dbus/tracker-miner-web.xml
index d2b8c52..bff941e 100644
--- a/data/dbus/tracker-miner-web.xml
+++ b/data/dbus/tracker-miner-web.xml
@@ -48,5 +48,17 @@
<method name="Authenticate">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
</method>
+ <method name="GetAssociationData">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ <arg name="result" type="a{ss}" direction="out"/>
+ </method>
+ <method name="Associate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ <arg name="data" type="a{ss}" direction="in"/>
+ </method>
+ <method name="Dissociate">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+ </method>
+ <property name="AssociationStatus" type="u" access="read"/>
</interface>
</node>
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 3562782..9e5e1c4 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -27,7 +27,6 @@ libtracker_minerincludedir=$(includedir)/tracker-$(TRACKER_API_VERSION)/libtrack
libtracker_miner_LTLIBRARIES = libtracker-miner.la
libtracker_miner_la_VALASOURCES= \
- tracker-miner-web.vala \
password-provider.vala \
keyfile-password-provider.vala
@@ -43,6 +42,8 @@ libtracker_miner_la_SOURCES = \
tracker-miner-dbus.h \
tracker-miner-fs.c \
tracker-miner-fs.h \
+ tracker-miner-web.c \
+ tracker-miner-web.h \
tracker-miner-manager.c \
tracker-miner-manager.h \
tracker-monitor.c \
@@ -79,7 +80,8 @@ vapidir=$(datadir)/vala/vapi
vapi_DATA = \
tracker-miner-$(TRACKER_API_VERSION).vapi \
tracker-miner-web-$(TRACKER_API_VERSION).vapi \
- tracker-miner-web-$(TRACKER_API_VERSION).deps
+ tracker-miner-web-$(TRACKER_API_VERSION).deps \
+ tracker-password-provider-$(TRACKER_API_VERSION).vapi
tracker-miner-web-$(TRACKER_API_VERSION).deps: tracker-miner-web.deps.in
@sed -e "s|@VERSION[ ]|${TRACKER_API_VERSION}|" $< > $@
@@ -98,6 +100,7 @@ marshal_sources = \
dbus_sources = \
tracker-miner-glue.h \
+ tracker-miner-web-glue.h \
tracker-miner-client.h
VALAPKGS = \
@@ -127,7 +130,7 @@ endif
libtracker-miner-web.vala.stamp: $(libtracker_miner_la_VALASOURCES)
- $(VALAC) -C $(VALAPKGS) $(VALAFLAGS) -H tracker-miner-web.h --library tracker-miner-web-$(TRACKER_API_VERSION) $^
+ $(VALAC) -C $(VALAPKGS) $(VALAFLAGS) -H tracker-password-provider.h --library tracker-password-provider-$(TRACKER_API_VERSION) $^
touch $@
%-glue.h: $(top_srcdir)/data/dbus/%.xml
diff --git a/src/libtracker-miner/tracker-miner-web-0.7.vapi b/src/libtracker-miner/tracker-miner-web-0.7.vapi
new file mode 100644
index 0000000..3d5d39f
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-web-0.7.vapi
@@ -0,0 +1,29 @@
+[CCode (cprefix = "Tracker", lower_case_cprefix = "tracker_")]
+namespace Tracker {
+
+ public errordomain MinerWebError {
+ WRONG_CREDENTIALS,
+ TOKEN_EXPIRED,
+ NO_CREDENTIALS,
+ KEYRING,
+ SERVICE,
+ TRACKER
+ }
+
+ [Compact]
+ [CCode (cheader_filename = "libtracker-miner/tracker-miner-web.h")]
+ public abstract class MinerWeb : Miner {
+ public abstract void authenticate () throws GLib.Error;
+ public abstract HashTable<string, string> get_association_data () throws GLib.Error;
+ public abstract void associate (unowned HashTable<string, string> association_data) throws GLib.Error;
+ public abstract void dissociate () throws GLib.Error;
+
+ public enum AssociationStatus {
+ UNASSOCIATED,
+ ASSOCIATED
+ }
+ }
+
+ public const string MINER_WEB_DBUS_INTERFACE;
+ public const string MINER_WEB_ERROR_DOMAIN;
+}
diff --git a/src/libtracker-miner/tracker-miner-web-dbus.h b/src/libtracker-miner/tracker-miner-web-dbus.h
index 829a997..0141c13 100644
--- a/src/libtracker-miner/tracker-miner-web-dbus.h
+++ b/src/libtracker-miner/tracker-miner-web-dbus.h
@@ -28,9 +28,19 @@
G_BEGIN_DECLS
-void tracker_miner_web_authenticate (TrackerMinerWeb *web,
- DBusGMethodInvocation *context,
- GError **error);
+void tracker_miner_web_authenticate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_web_dissociate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-miner/tracker-miner-web.c b/src/libtracker-miner/tracker-miner-web.c
index d321f98..53667d1 100644
--- a/src/libtracker-miner/tracker-miner-web.c
+++ b/src/libtracker-miner/tracker-miner-web.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2009, Nokia (urho konttori nokia com)
+ * Copyright (C) 2009, Adrien Bustany (abustany gnome org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,37 +23,187 @@
#include "tracker-miner-web-dbus.h"
#include "tracker-miner-web-glue.h"
-static void tracker_miner_web_constructed (GObject *object);
+/**
+ * SECTION:tracker-miner-web
+ * @short_description: Abstract base class for miners using web services
+ * @include: libtracker-miner/tracker-miner-web.h
+ *
+ * #TrackerMinerWeb is an abstract base class for miners retrieving data
+ * from web services. It's a very thin layer above #TrackerMiner, only
+ * adding virtual methods needed to handle association with the remote
+ * service.
+ **/
+
+#define TRACKER_MINER_WEB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_WEB, TrackerMinerWebPrivate))
+
+struct TrackerMinerWebPrivate {
+ TrackerMinerWebAssociationStatus association_status;
+};
+enum {
+ PROP_0,
+ PROP_ASSOCIATION_STATUS
+};
-G_DEFINE_ABSTRACT_TYPE (TrackerMinerWeb, tracker_miner_web, TRACKER_TYPE_MINER)
+static void miner_web_set_property (GObject * object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void miner_web_get_property (GObject * object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void miner_web_constructed (GObject *object);
+static void miner_web_finalize (GObject *object);
+
+G_DEFINE_ABSTRACT_TYPE (TrackerMinerWeb, tracker_miner_web, TRACKER_TYPE_MINER_WEB)
static void
tracker_miner_web_class_init (TrackerMinerWebClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->constructed = tracker_miner_web_constructed;
+ object_class->set_property = miner_web_set_property;
+ object_class->get_property = miner_web_get_property;
+ object_class->constructed = miner_web_constructed;
+ object_class->finalize = miner_web_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_ASSOCIATION_STATUS,
+ g_param_spec_uint ("association-status",
+ "Association status",
+ "Tells if the miner is associated with the remote service",
+ TRACKER_MINER_WEB_UNASSOCIATED, /* min value */
+ TRACKER_MINER_WEB_ASSOCIATED, /* max value */
+ TRACKER_MINER_WEB_UNASSOCIATED, /* default value */
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerMinerWebPrivate));
}
static void
-tracker_miner_web_init (TrackerMinerWeb *klass)
+tracker_miner_web_init (TrackerMinerWeb *miner)
{
+ TrackerMinerWebPrivate *priv;
+ miner->private = priv = TRACKER_MINER_WEB_GET_PRIVATE (miner);
+ priv->association_status = TRACKER_MINER_WEB_UNASSOCIATED;
+}
+static void
+miner_web_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
+ switch (param_id) {
+ case PROP_ASSOCIATION_STATUS:
+ miner->private->association_status = g_value_get_uint (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
}
static void
-tracker_miner_web_constructed (GObject *object)
+miner_web_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- tracker_miner_dbus_init (TRACKER_MINER (object),
- &dbus_glib_tracker_miner_web_object_info);
+ TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
+ switch (param_id) {
+ case PROP_ASSOCIATION_STATUS:
+ g_value_set_uint (value, miner->private->association_status);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+static void
+miner_web_constructed (GObject *object)
+{
+ tracker_miner_dbus_init (TRACKER_MINER (object),
+ &dbus_glib_tracker_miner_web_object_info);
+
+ G_OBJECT_CLASS (tracker_miner_web_parent_class)->constructed (object);
+}
+
+static void
+miner_web_finalize (GObject *object)
+{
+ TrackerMinerWeb *miner = TRACKER_MINER_WEB (object);
+
+ G_OBJECT_CLASS (tracker_miner_web_parent_class)->finalize (object);
+}
- G_OBJECT_CLASS (tracker_miner_web_parent_class)->constructed (object);
+GQuark
+tracker_miner_web_error_quark (void)
+{
+ return g_quark_from_static_string (TRACKER_MINER_WEB_ERROR_DOMAIN);
}
void
-tracker_miner_web_authenticate (TrackerMinerWeb *web,
+tracker_miner_web_authenticate (TrackerMinerWeb *miner,
DBusGMethodInvocation *context,
GError **error)
{
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->authenticate (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
+void
+tracker_miner_web_get_association_data (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ GError *local_error = NULL;
+ GHashTable *association_data = TRACKER_MINER_WEB_GET_CLASS (miner)->get_association_data (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context, association_data);
+ }
}
+
+void
+tracker_miner_web_associate (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->associate (miner, association_data, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
+void
+tracker_miner_web_dissociate (TrackerMinerWeb *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
+{
+ GError *local_error = NULL;
+ TRACKER_MINER_WEB_GET_CLASS (miner)->dissociate (miner, &local_error);
+
+ if (local_error != NULL) {
+ dbus_g_method_return_error (context, local_error);
+ } else {
+ dbus_g_method_return (context);
+ }
+}
+
diff --git a/src/libtracker-miner/tracker-miner-web.h b/src/libtracker-miner/tracker-miner-web.h
index 0dac054..2672d43 100644
--- a/src/libtracker-miner/tracker-miner-web.h
+++ b/src/libtracker-miner/tracker-miner-web.h
@@ -35,19 +35,93 @@ G_BEGIN_DECLS
typedef struct TrackerMinerWeb TrackerMinerWeb;
typedef struct TrackerMinerWebPrivate TrackerMinerWebPrivate;
+/**
+ * The name of the DBus interface exposed by the web miners
+ **/
+#define TRACKER_MINER_WEB_DBUS_INTERFACE "org.freedesktop.Tracker1.MinerWeb"
+
+/**
+ * TrackerMinerWebError:
+ * @TRACKER_MINER_WEB_ERROR_WRONG_CREDENTIALS: The stored credentials are refused by the remote service
+ * @TRACKER_MINER_WEB_ERROR_TOKEN_EXPIRED : The service says the stored token has expired
+ * @TRACKER_MINER_WEB_ERROR_NO_CREDENTIALS : There are currenty no credentials stored for this service
+ * @TRACKER_MINER_WEB_ERROR_KEYRING : Error while contacting the credentials storage
+ * @TRACKER_MINER_WEB_ERROR_SERVICE : Error while contacting the remote service
+ * @TRACKER_MINER_WEB_ERROR_TRACKER : Error while contacting Tracker
+ *
+ * Describes the different errors that can occur while operating with the remote service.
+ **/
+typedef enum {
+ TRACKER_MINER_WEB_ERROR_WRONG_CREDENTIALS,
+ TRACKER_MINER_WEB_ERROR_TOKEN_EXPIRED,
+ TRACKER_MINER_WEB_ERROR_NO_CREDENTIALS,
+ TRACKER_MINER_WEB_ERROR_KEYRING,
+ TRACKER_MINER_WEB_ERROR_SERVICE,
+ TRACKER_MINER_WEB_ERROR_TRACKER
+} TrackerMinerWebError;
+#define TRACKER_MINER_WEB_ERROR tracker_miner_web_error_quark ()
+#define TRACKER_MINER_WEB_ERROR_DOMAIN "TrackerMinerWeb"
+
+/**
+ * TrackerMinerWebAssociationStatus:
+ * @TRACKER_MINER_WEB_UNASSOCIATED : The miner is currently unassociated with the remote service
+ * @TRACKER_MINER_WEB_ASSOCIATED : The miner is currently associated with the remote service
+ *
+ * Describes if the miner can currently communicate (import data) with the web service.
+ **/
+typedef enum {
+ TRACKER_MINER_WEB_UNASSOCIATED,
+ TRACKER_MINER_WEB_ASSOCIATED
+} TrackerMinerWebAssociationStatus;
+
struct TrackerMinerWeb {
- TrackerMiner parent_instance;
+ TrackerMiner parent_instance;
+ /*< private >*/
+ TrackerMinerWebPrivate *private;
};
+/**
+ * TrackerMinerWebClass
+ * @parent_class : parent object class
+ * @authenticate : called when the miner is told to authenticate against the remote service
+ * @get_association_data: called when one requests the miner's association data.
+ * In the case of a user/pass based authentication, this should return
+ * an empty hash table.
+ * In the case of a token based authentication, the following keys must
+ * be defined in the returned hash table:
+ * - url: the url to point the user too
+ * Additionally, the miner can define the following keys :
+ * - post_message: a message to display after the user completes the
+ * association process
+ * - post_url: a url to point the user after he completes the association
+ *
+ * If both post_message and post_url are defined, the message will be
+ * displayed before the url is opened.
+ * @associate : called when the miner is told to associate with the web service.
+ * In the case of a user/pass based authentication, the following keys must be defined
+ * - username: the provided username
+ * - password: the provided password
+ * In the case of a token based authentication, the hash table can be ignored
+ * since it will be empty.
+ * @dissociate : called when the miner is told to forget any user credentials it has stored
+ **/
typedef struct {
TrackerMinerClass parent_class;
/* vmethods */
- void (*authenticate) (TrackerMinerWeb *miner);
+ void (* authenticate) (TrackerMinerWeb *miner,
+ GError **error);
+ GHashTable* (* get_association_data) (TrackerMinerWeb *miner,
+ GError **error);
+ void (* associate) (TrackerMinerWeb *miner,
+ const GHashTable *association_data,
+ GError **error);
+ void (* dissociate) (TrackerMinerWeb *miner,
+ GError **error);
} TrackerMinerWebClass;
GType tracker_miner_web_get_type (void) G_GNUC_CONST;
-
+GQuark tracker_miner_web_error_quark (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]