tracker r1457 - branches/xesam-support/src/trackerd



Author: pvanhoof
Date: Tue May 20 09:38:38 2008
New Revision: 1457
URL: http://svn.gnome.org/viewvc/tracker?rev=1457&view=rev

Log:
Code cleanup

Modified:
   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-session.c
   branches/xesam-support/src/trackerd/tracker-xesam.c

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	Tue May 20 09:38:38 2008
@@ -729,8 +729,10 @@
  * @self: a #TrackerXesamLiveSearch
  *
  * Parses the current xml query and sets the sql
+ *
+ * Return value: whether parsing succeeded, if not @error will also be set
  **/
-void
+gboolean
 tracker_xesam_live_search_parse_query (TrackerXesamLiveSearch  *self,
 				       GError                 **error)
 {
@@ -738,11 +740,12 @@
 	TrackerDBusXesam           *proxy = TRACKER_DBUS_XESAM (tracker_dbus_get_object (TRACKER_TYPE_DBUS_XESAM));
 	DBConnection               *db_con = NULL;
 	GError                     *parse_error = NULL;
+	gchar                      *orig_from, *orig_where;
 
 	g_object_get (proxy, "db-connection", &db_con, NULL);
 
-	g_free (priv->from_sql);
-	g_free (priv->where_sql);
+	orig_from = priv->from_sql;
+	orig_where = priv->where_sql;
 
 	priv->from_sql = NULL;
 	priv->where_sql = NULL;
@@ -753,16 +756,24 @@
 				    &parse_error);
 
 	if (parse_error) {
-			gchar *str = g_strdup_printf ("Parse error: %s", 
-				parse_error->message);
-			g_set_error (error, TRACKER_XESAM_ERROR_DOMAIN, 
-				     TRACKER_XESAM_ERROR_PARSING_FAILED,
-				     str);
-			g_free (str);
-			g_error_free (parse_error);
+		gchar *str = g_strdup_printf ("Parse error: %s", 
+			parse_error->message);
+		g_set_error (error, TRACKER_XESAM_ERROR_DOMAIN, 
+			     TRACKER_XESAM_ERROR_PARSING_FAILED,
+			     str);
+		g_free (str);
+		g_error_free (parse_error);
+
+		priv->from_sql = orig_from;
+		priv->where_sql = orig_where;
+
+		return FALSE;
+	} else {
+		g_free (orig_from);
+		g_free (orig_where);
 	}
 
-	return;
+	return TRUE;
 }
 
 /**

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	Tue May 20 09:38:38 2008
@@ -66,7 +66,7 @@
 void         tracker_xesam_live_search_activate           (TrackerXesamLiveSearch  *self,
 							   GError                 **error);
 gboolean     tracker_xesam_live_search_is_active          (TrackerXesamLiveSearch  *self);
-void         tracker_xesam_live_search_parse_query        (TrackerXesamLiveSearch  *self,
+gboolean     tracker_xesam_live_search_parse_query        (TrackerXesamLiveSearch  *self,
 							   GError                 **error);
 void         tracker_xesam_live_search_get_hit_data       (TrackerXesamLiveSearch  *self,
 							   GArray                  *hit_ids,

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	Tue May 20 09:38:38 2008
@@ -73,11 +73,11 @@
 	const gchar *exts[1] = {NULL};
 	const gchar *dummy_onto[4] = {"dummy-onto","0.1","/usr/share/xesam/ontologies/dummy-onto-0.1", NULL};
 	GPtrArray *ontos = g_ptr_array_new ();
-	
+
 	priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,TRACKER_TYPE_XESAM_SESSION,struct _TrackerXesamSessionPriv);
 
 	g_ptr_array_add (ontos, dummy_onto);
-	
+
 	priv->session_id = NULL;
 
 	priv->searches = g_hash_table_new_full (g_str_hash, g_str_equal, 
@@ -369,7 +369,7 @@
  * Signals will not be emitted before a call to @tracker_xesam_live_search_activate
  * has been made. 
  *
- * @returns: (caller-owns): a new non-activated #TrackerXesamLiveSearch
+ * @returns: (null-ok) (caller-owns): a new non-activated #TrackerXesamLiveSearch
  **/
 TrackerXesamLiveSearch* 
 tracker_xesam_session_create_search (TrackerXesamSession  *self, 
@@ -381,18 +381,23 @@
 	TrackerXesamSessionPriv *priv = self->priv;
 
 	search = tracker_xesam_live_search_new (query_xml);
+
 	tracker_xesam_live_search_set_session (search, self);
 	tracker_xesam_live_search_set_id (search, tracker_xesam_generate_unique_key ());
-	if (search_id) 
-		*search_id = g_strdup (tracker_xesam_live_search_get_id (search));
 
-	tracker_xesam_live_search_set_session (search, self);
+	if (tracker_xesam_live_search_parse_query (search, error)) {
 
-	g_hash_table_insert (priv->searches, 
-		g_strdup (tracker_xesam_live_search_get_id (search)),
-		g_object_ref (search));
+		g_hash_table_insert (priv->searches, 
+			g_strdup (tracker_xesam_live_search_get_id (search)),
+			g_object_ref (search));
 
-	tracker_xesam_live_search_parse_query (search, error);
+		if (search_id) 
+			*search_id = g_strdup (tracker_xesam_live_search_get_id (search));
+
+	} else {
+		g_object_unref (search);
+		search = NULL;
+	}
 
 	return search;
 }
@@ -417,6 +422,11 @@
 
 	if (search)
 		g_object_ref (search);
+	else {
+		g_set_error (error, TRACKER_XESAM_ERROR_DOMAIN, 
+				TRACKER_XESAM_ERROR_SEARCH_ID_NOT_REGISTERED,
+				"SearchID not registered");
+	}
 
 	return search;
 }

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	Tue May 20 09:38:38 2008
@@ -271,12 +271,12 @@
 
 	/* We could do this in a thread too, in case blocking the GMainLoop is
 	 * not ideal (it's not, because during these blocks of code, no DBus
-	 * request handler can run). I have added sufficient locking to let a
-	 * thread do it too (although untested).
+	 * request handler can run). 
 	 * 
 	 * In case of a thread we could use usleep() and stop the thread if
-	 * we didn't get a wakeup-call nor we had items to process this loop
-	 */
+	 * we didn't get a wakeup-call nor we had items to process this loop.
+	 * For a thread we would also have to setup a new DBConnection. */
+
 	if (!live_search_handler_running) {
 		live_search_handler_running = TRUE;
 		g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
@@ -295,9 +295,6 @@
 	guint         t, ut, p, u, r;
 	GTimeVal      tv;
 
-	/* This function is hardly cryptographically random but should
-	 * be "good enough" 
-	 */
 	g_get_current_time (&tv);
 
 	t = tv.tv_sec;
@@ -311,39 +308,9 @@
 	u = 0;
 #endif
 
-	/* Don't bother to seed; if it's based on the time or any
-	 * other changing info we can get, we may as well just use
-	 * that changing info. since we don't seed we'll at least get
-	 * a different number on every call to this function in the
-	 * same executable.
-	 */
 	r = rand ();
-
-	/* The letters may increase uniqueness by preventing "melds"
-	 * i.e. 01t01k01 and 0101t0k1 are not the same  
-	 */
 	key = g_strdup_printf ("%ut%uut%uu%up%ur%uk%u",
-			       /* Duplicate keys must be generated by
-				* two different program instances */ 
-			       serial,
-			       /* Duplicate keys must be generated in
-				* the same microsecond */
-			       t,
-			       ut,
-			       /* Duplicate keys must be generated by
-				* the same user */
-			       u,
-			       /* Duplicate keys must be generated by
-				* two programs that got the same PID */
-			       p,
-			       /* Duplicate keys must be generated with
-				* the same random seed and the same
-				* index into the series of pseudorandom
-				* values */
-			       r,
-			       /* Duplicate keys must result from
-				* running this function at the same
-				* stack location */
+			       serial, t, ut, u, p, r,
 			       GPOINTER_TO_UINT (&key));
 
 	++serial;



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