tracker r1289 - in branches/xesam-support: . src/trackerd



Author: pvanhoof
Date: Wed Apr 23 11:20:31 2008
New Revision: 1289
URL: http://svn.gnome.org/viewvc/tracker?rev=1289&view=rev

Log:
2008-04-23  Philip Van Hoof  <pvanhoof gnome org>

        * Added error reporting
        * Added some more ad-hoc implementations in TrackerXesamSearch



Modified:
   branches/xesam-support/ChangeLog
   branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
   branches/xesam-support/src/trackerd/tracker-xesam-live-search.h
   branches/xesam-support/src/trackerd/tracker-xesam-search.c
   branches/xesam-support/src/trackerd/tracker-xesam-session.c
   branches/xesam-support/src/trackerd/tracker-xesam-session.h
   branches/xesam-support/src/trackerd/tracker-xesam.c
   branches/xesam-support/src/trackerd/tracker-xesam.h

Modified: branches/xesam-support/src/trackerd/tracker-xesam-live-search.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-live-search.c	Wed Apr 23 11:20:31 2008
@@ -52,6 +52,10 @@
 	priv->search_id = NULL;
 }
 
+void 
+tracker_xesam_live_search_activate (TrackerXesamLiveSearch *self)
+{
+}
 
 
 const gchar* 

Modified: branches/xesam-support/src/trackerd/tracker-xesam-live-search.h
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-live-search.h	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-live-search.h	Wed Apr 23 11:20:31 2008
@@ -53,7 +53,7 @@
 void tracker_xesam_live_search_set_id (TrackerXesamLiveSearch *self, const gchar *search_id);
 const gchar* tracker_xesam_live_search_get_id (TrackerXesamLiveSearch *self);
 const gchar* tracker_xesam_live_search_get_query (TrackerXesamLiveSearch *self);
-
+void tracker_xesam_live_search_activate (TrackerXesamLiveSearch *self);
 
 G_END_DECLS
 

Modified: branches/xesam-support/src/trackerd/tracker-xesam-search.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-search.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-search.c	Wed Apr 23 11:20:31 2008
@@ -280,7 +280,7 @@
 {
 	gchar *sid = NULL;
 
-	tracker_xesam_create_session (object, &sid);
+	tracker_xesam_create_session (object, &sid, error);
 
 	if (sid) {
 		guint request_id = tracker_dbus_get_next_request_id ();
@@ -301,7 +301,8 @@
 {
 	guint request_id = tracker_dbus_get_next_request_id ();
 
-	tracker_xesam_close_session (session_id);
+	tracker_xesam_close_session (session_id, error);
+
 	tracker_dbus_request_success (request_id);
 
 	return TRUE;
@@ -316,7 +317,15 @@
 				  gpointer            *new_val,  /* not sure */
 				  GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamSession *session = tracker_xesam_get_session (session_id, error);
+
+	if (session)
+		tracker_xesam_session_set_property (session, prop, val);
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 
@@ -326,7 +335,19 @@
 				   gpointer            *value,  /* not sure */
 				   GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamSession *session = tracker_xesam_get_session (session_id, error);
+
+	if (session) {
+		gchar *ret = NULL;
+		ret = tracker_xesam_session_get_property (session, prop);
+		*value = g_strdup (ret);
+		g_free (ret);
+	}
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 
@@ -337,7 +358,21 @@
 				 gchar              **search_id,
 				 GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamSession *session = tracker_xesam_get_session (session_id, error);
+
+	if (session) {
+		TrackerXesamLiveSearch *search;
+		gchar *ret = NULL;
+		search = tracker_xesam_session_create_search (session, query_xml, &ret);
+		*search_id = g_strdup (ret);
+		g_free (ret);
+		g_object_unref (search);
+	}
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 
@@ -345,7 +380,16 @@
 				   const gchar         *search_id,
 				   GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamLiveSearch *search = tracker_xesam_get_live_search (search_id, error);
+
+	tracker_xesam_live_search_activate (search);
+
+	g_object_unref (search);
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 
@@ -354,64 +398,12 @@
 				    guint               *count,
 				    GError             **error)
 {
-	TrackerXesamSearchPriv *priv;
-	TrackerQueryTree *tree;
-	GArray *hit_counts;
-	GArray *mail_hit_counts;
-	guint request_id;
-	DBConnection *db_con;
-	guint i, counter = 0;
-	const gchar *search_text;
-	TrackerXesamLiveSearch *search_i;
-
-	tracker_dbus_return_val_if_fail (search_id != NULL, FALSE, error);
-	tracker_dbus_return_val_if_fail (count != NULL, FALSE, error);
-
-	request_id = tracker_dbus_get_next_request_id ();
-
-	search_i = tracker_xesam_get_live_search (search_id);
-	search_text = tracker_xesam_live_search_get_query (search_i);
-
-	priv = GET_PRIV (object);
-
-	db_con = priv->db_con;
-
-	tracker_dbus_request_new (request_id,
-				  "DBus request to get search hit count for all, "
-				  "search text:'%s'",
-				  tracker_xesam_live_search_get_query (search_i));
-
-	if (tracker_is_empty_string (search_text)) {
-		tracker_dbus_request_failed (request_id,
-					     error, 
-					     "No search term was specified");
-		g_object_unref (search_i);
-		return FALSE;
-	}
-
-	tree = tracker_query_tree_new (search_text, db_con->word_index, NULL);
-
-	hit_counts = tracker_query_tree_get_hit_counts (tree);
-	tracker_query_tree_set_indexer (tree, priv->email_index);
-	mail_hit_counts = tracker_query_tree_get_hit_counts (tree);
-	g_array_append_vals (hit_counts, mail_hit_counts->data, mail_hit_counts->len);
-	g_array_free (mail_hit_counts, TRUE);
-
-	counter = 0;
-
-	for (i = 0; i < hit_counts->len; i++) {
-		TrackerHitCount mcount;
-		mcount = g_array_index (hit_counts, TrackerHitCount, i);
-		counter += mcount.count;
-	}
-
-	*count = counter;
-
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamLiveSearch *search = tracker_xesam_get_live_search (search_id, error);
 
-	g_array_free (hit_counts, TRUE);
-	g_object_unref (tree);
+	*count = 0;
 
-	g_object_unref (search_i);
+	g_object_unref (search);
 
 	tracker_dbus_request_success (request_id);
 
@@ -425,7 +417,16 @@
 			       gpointer           **hits, /* not sure */
 			       GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamLiveSearch *search = tracker_xesam_get_live_search (search_id, error);
+
+	*hits = NULL;
+
+	g_object_unref (search);
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 
@@ -436,7 +437,16 @@
 				   gpointer           **hit_data, /* not sure */
 				   GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamLiveSearch *search = tracker_xesam_get_live_search (search_id, error);
+
+	*hit_data = NULL;
+
+	g_object_unref (search);
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 
@@ -444,7 +454,21 @@
 				   const gchar         *search_id,
 				   GError             **error)
 {
-	return FALSE;
+	guint request_id = tracker_dbus_get_next_request_id ();
+	TrackerXesamLiveSearch *search = NULL;
+	TrackerXesamSession *session = tracker_xesam_get_session_for_search (search_id, &search, error);
+
+	if (search && session)
+		tracker_xesam_session_close_search (session, search);
+
+	if (session)
+		g_object_unref (session);
+	if (search)
+		g_object_unref (search);
+
+	tracker_dbus_request_success (request_id);
+
+	return TRUE;
 }
 
 gboolean 

Modified: branches/xesam-support/src/trackerd/tracker-xesam-session.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-session.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-session.c	Wed Apr 23 11:20:31 2008
@@ -175,7 +175,7 @@
 
 
 TrackerXesamLiveSearch* 
-tracker_xesam_session_create_search (TrackerXesamSession *self, const gchar *query_xml) 
+tracker_xesam_session_create_search (TrackerXesamSession *self, const gchar *query_xml, gchar **search_id) 
 {
 	TrackerXesamLiveSearch *search;
 	TrackerXesamSessionPriv *priv = self->priv;
@@ -189,9 +189,20 @@
 		g_strdup (tracker_xesam_live_search_get_id (search)),
 		g_object_ref (search));
 
+	if (search_id) 
+		*search_id = g_strdup (tracker_xesam_live_search_get_id (search));
+
 	return search;
 }
 
+void 
+tracker_xesam_session_close_search (TrackerXesamSession *self, TrackerXesamLiveSearch *search)
+{
+	TrackerXesamSessionPriv *priv = self->priv;
+	g_hash_table_remove (priv->searches, 
+		tracker_xesam_live_search_get_id (search));
+}
+
 TrackerXesamLiveSearch* 
 tracker_xesam_session_get_search (TrackerXesamSession *self, const gchar *search_id)
 {

Modified: branches/xesam-support/src/trackerd/tracker-xesam-session.h
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam-session.h	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam-session.h	Wed Apr 23 11:20:31 2008
@@ -60,11 +60,12 @@
 void tracker_xesam_session_state_changed (TrackerXesamSession *self, gchar **state_info, gint state_info_length);
 void tracker_xesam_session_set_property (TrackerXesamSession *self, const gchar *prop, const gchar* val);
 char* tracker_xesam_session_get_property (TrackerXesamSession *self, const gchar *prop);
-TrackerXesamLiveSearch* tracker_xesam_session_create_search (TrackerXesamSession *self, const gchar *query_xml);
+TrackerXesamLiveSearch* tracker_xesam_session_create_search (TrackerXesamSession *self, const gchar *query_xml , gchar **search_id);
 TrackerXesamLiveSearch* tracker_xesam_session_get_search (TrackerXesamSession *self, const gchar *search_id);
 GList *tracker_xesam_session_get_searches (TrackerXesamSession *self);
 void tracker_xesam_session_set_id (TrackerXesamSession *self, const gchar *session_id);
 const gchar* tracker_xesam_session_get_id (TrackerXesamSession *self);
+void tracker_xesam_session_close_search (TrackerXesamSession *self, TrackerXesamLiveSearch *search);
 
 TrackerXesamSession* tracker_xesam_session_new (TrackerXesamSearch *dbus_proxy);
 GType tracker_xesam_session_get_type (void);

Modified: branches/xesam-support/src/trackerd/tracker-xesam.c
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam.c	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam.c	Wed Apr 23 11:20:31 2008
@@ -32,7 +32,7 @@
 }
 
 TrackerXesamSession *
-tracker_xesam_create_session (TrackerXesamSearch *dbus_proxy, gchar **session_id)
+tracker_xesam_create_session (TrackerXesamSearch *dbus_proxy, gchar **session_id, GError **error)
 {
 	TrackerXesamSession *session;
 
@@ -50,23 +50,34 @@
 }
 
 void 
-tracker_xesam_close_session (const gchar *session_id)
+tracker_xesam_close_session (const gchar *session_id, GError **error)
 {
-	g_hash_table_remove (tracker->xesam_sessions, session_id);
+	gpointer inst = g_hash_table_lookup (tracker->xesam_sessions, session_id);
+	if (!inst)
+		g_set_error (error, TRACKER_XESAM_ERROR, 
+				TRACKER_XESAM_ERROR_SESSION_ID_NOT_REGISTERED,
+				"Session ID is not registered");
+	else
+		g_hash_table_remove (tracker->xesam_sessions, session_id);
 }
 
 
 TrackerXesamSession *
-tracker_xesam_get_session (const gchar *session_id)
+tracker_xesam_get_session (const gchar *session_id, GError **error)
 {
 	TrackerXesamSession *retval = g_hash_table_lookup (tracker->xesam_sessions, session_id);
 	if (retval)
 		g_object_ref (retval);
+	else
+		g_set_error (error, TRACKER_XESAM_ERROR, 
+				TRACKER_XESAM_ERROR_SESSION_ID_NOT_REGISTERED,
+				"Session ID is not registered");
+
 	return retval;
 }
 
 TrackerXesamSession *
-tracker_xesam_get_session_for_search (const gchar *search_id)
+tracker_xesam_get_session_for_search (const gchar *search_id, TrackerXesamLiveSearch **search_in, GError **error)
 {
 	TrackerXesamSession *retval = NULL;
 	GList * sessions = g_hash_table_get_values (tracker->xesam_sessions);
@@ -74,18 +85,25 @@
 	while (sessions) {
 		TrackerXesamLiveSearch *search = tracker_xesam_session_get_search (sessions->data, search_id);
 		if (search) {
+			if (search_in)
+				*search_in = g_object_ref (search);
 			retval = g_object_ref (sessions->data);
 			break;
 		}
 		sessions = g_list_next (sessions);
 	}
 
+	if (!retval) 
+		g_set_error (error, TRACKER_XESAM_ERROR, 
+				TRACKER_XESAM_ERROR_SEARCH_ID_NOT_REGISTERED,
+				"Search ID is not registered");
+
 	return retval;
 }
 
 
 TrackerXesamLiveSearch *
-tracker_xesam_get_live_search  (const gchar *search_id)
+tracker_xesam_get_live_search  (const gchar *search_id, GError **error)
 {
 	TrackerXesamLiveSearch *retval = NULL;
 	GList * sessions = g_hash_table_get_values (tracker->xesam_sessions);
@@ -99,6 +117,11 @@
 		sessions = g_list_next (sessions);
 	}
 
+	if (!retval) 
+		g_set_error (error, TRACKER_XESAM_ERROR, 
+				TRACKER_XESAM_ERROR_SEARCH_ID_NOT_REGISTERED,
+				"Search ID is not registered");
+
 	return retval;
 }
 

Modified: branches/xesam-support/src/trackerd/tracker-xesam.h
==============================================================================
--- branches/xesam-support/src/trackerd/tracker-xesam.h	(original)
+++ branches/xesam-support/src/trackerd/tracker-xesam.h	Wed Apr 23 11:20:31 2008
@@ -25,11 +25,20 @@
  * Boston, MA  02110-1301, USA. 
  */  
 
-TrackerXesamSession* tracker_xesam_get_session (const gchar *session_id);
-TrackerXesamSession* tracker_xesam_get_session_for_search (const gchar *search_id);
-TrackerXesamLiveSearch* tracker_xesam_get_live_search  (const gchar *search_id);
-TrackerXesamSession* tracker_xesam_create_session (TrackerXesamSearch *dbus_proxy, gchar **session_id);
-void tracker_xesam_close_session (const gchar *session_id);
+TrackerXesamSession* tracker_xesam_get_session (const gchar *session_id, GError **error);
+TrackerXesamSession* tracker_xesam_get_session_for_search (const gchar *search_id, TrackerXesamLiveSearch **search_in, GError **error);
+TrackerXesamLiveSearch* tracker_xesam_get_live_search  (const gchar *search_id, GError **error);
+TrackerXesamSession* tracker_xesam_create_session (TrackerXesamSearch *dbus_proxy, gchar **session_id, GError **error);
+void tracker_xesam_close_session (const gchar *session_id, GError **error);
+
+typedef enum {
+	TRACKER_XESAM_ERROR = 1
+} TrackerXesamErrorDomain;
+
+typedef enum {
+	TRACKER_XESAM_ERROR_SEARCH_ID_NOT_REGISTERED = 1,
+	TRACKER_XESAM_ERROR_SESSION_ID_NOT_REGISTERED = 2,
+} TrackerXesamError;
 
 
 void tracker_xesam_init (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]