[anjuta/sdb-queries] symbol-db: Implemented queued query (single)



commit 0f4ef4e2928fcfa3a636bedb5cc534c999b39a97
Author: Naba Kumar <naba gnome org>
Date:   Sat Jun 5 12:16:23 2010 +0300

    symbol-db: Implemented queued query (single)

 plugins/symbol-db/symbol-db-engine-core.c |   13 ++++-
 plugins/symbol-db/symbol-db-engine-core.h |    6 ++
 plugins/symbol-db/symbol-db-engine-priv.h |    1 +
 plugins/symbol-db/symbol-db-query.c       |   84 ++++++++++++++++++++++-------
 4 files changed, 82 insertions(+), 22 deletions(-)
---
diff --git a/plugins/symbol-db/symbol-db-engine-core.c b/plugins/symbol-db/symbol-db-engine-core.c
index 35f7ca8..6a94740 100644
--- a/plugins/symbol-db/symbol-db-engine-core.c
+++ b/plugins/symbol-db/symbol-db-engine-core.c
@@ -1707,6 +1707,7 @@ sdb_engine_timeout_trigger_signals (gpointer user_data)
 				{
 					/* get the process id from the queue */
 					gint int_tmp = GPOINTER_TO_INT(g_async_queue_pop (priv->scan_process_id_queue));
+					priv->scanning--;
 					g_signal_emit (dbe, signals[SCAN_END], 0, int_tmp);
 				}
 					break;
@@ -1976,7 +1977,8 @@ sdb_engine_scan_files_1 (SymbolDBEngine * dbe, const GPtrArray * files_list,
 	{
 		sdb_engine_ctags_launcher_create (dbe);
 	}
-	
+
+	priv->scanning++; /* Enter scanning state */
 	g_signal_emit_by_name (dbe, "scan-begin",
 	                       anjuta_launcher_get_child_pid (priv->ctags_launcher));
 	
@@ -2177,7 +2179,7 @@ sdb_engine_init (SymbolDBEngine * object)
 	sdbe->priv->updated_symbols_id = g_async_queue_new ();
 	sdbe->priv->updated_scope_symbols_id = g_async_queue_new ();
 	sdbe->priv->inserted_symbols_id = g_async_queue_new ();
-	
+	sdbe->priv->scanning = 0;
 	
 	/*
 	 * STATIC QUERY STRUCTURE INITIALIZE
@@ -3018,6 +3020,13 @@ symbol_db_engine_is_connected (SymbolDBEngine * dbe)
 		gda_connection_is_opened (priv->db_connection );
 }
 
+gboolean
+symbol_db_engine_is_scanning (SymbolDBEngine *dbe)
+{
+	g_return_val_if_fail (SYMBOL_IS_DB_ENGINE (dbe), FALSE);
+	return (dbe->priv->scanning > 0);
+}
+
 /**
  * Creates required tables for the database to work.
  * @param tables_sql_file File containing sql code.
diff --git a/plugins/symbol-db/symbol-db-engine-core.h b/plugins/symbol-db/symbol-db-engine-core.h
index a0c78b2..59fb3c3 100644
--- a/plugins/symbol-db/symbol-db-engine-core.h
+++ b/plugins/symbol-db/symbol-db-engine-core.h
@@ -126,6 +126,12 @@ gboolean
 symbol_db_engine_is_connected (SymbolDBEngine * dbe);
 
 /**
+ * Check if engine is scanning busy
+ */
+gboolean
+symbol_db_engine_is_scanning (SymbolDBEngine *dbe);
+
+/**
  * Getter for the connection string. Returned char must be freed by caller.
  */
 gchar *
diff --git a/plugins/symbol-db/symbol-db-engine-priv.h b/plugins/symbol-db/symbol-db-engine-priv.h
index 5dcd729..e5ec721 100644
--- a/plugins/symbol-db/symbol-db-engine-priv.h
+++ b/plugins/symbol-db/symbol-db-engine-priv.h
@@ -289,6 +289,7 @@ struct _SymbolDBEnginePriv
 	GAsyncQueue *updated_symbols_id;
 	GAsyncQueue *updated_scope_symbols_id;
 	GAsyncQueue *inserted_symbols_id;
+	gint scanning;
 	
 	gchar *shared_mem_str;
 	FILE *shared_mem_file;
diff --git a/plugins/symbol-db/symbol-db-query.c b/plugins/symbol-db/symbol-db-query.c
index e07345c..6a68909 100644
--- a/plugins/symbol-db/symbol-db-query.c
+++ b/plugins/symbol-db/symbol-db-query.c
@@ -64,6 +64,7 @@ struct _SymbolDBQueryPriv {
 
 	/* Aync results */
 	gboolean is_canceled;
+	gboolean query_queued;
 	IAnjutaIterable *async_result;
 };
 
@@ -315,26 +316,6 @@ sdb_query_execute_real (SymbolDBQuery *query)
 	return IANJUTA_ITERABLE (iter);
 }
 
-static IAnjutaIterable*
-sdb_query_execute (SymbolDBQuery *query)
-{
-	switch (query->priv->mode)
-	{
-		case IANJUTA_SYMBOL_QUERY_MODE_SYNC:
-			return sdb_query_execute_real (query);
-		case IANJUTA_SYMBOL_QUERY_MODE_ASYNC:
-			query->priv->is_canceled = FALSE;
-			anjuta_command_start (ANJUTA_COMMAND (query));
-			return NULL;
-		case IANJUTA_SYMBOL_QUERY_MODE_QUEUED_SINGLE:
-		case IANJUTA_SYMBOL_QUERY_MODE_QUEUED_MULTI:
-			/* FIXME */
-		default:
-			g_warn_if_reached ();
-	}
-	return NULL;
-}
-
 static void
 on_sdb_query_async_data_arrived (SymbolDBQuery *query, gpointer data)
 {
@@ -369,6 +350,49 @@ sdb_query_async_cancel (AnjutaCommand *command)
 
 	g_return_if_fail (query->priv->mode != IANJUTA_SYMBOL_QUERY_MODE_SYNC);
 	query->priv->is_canceled = TRUE;
+	query->priv->query_queued = FALSE;
+}
+
+static void
+on_sdb_query_dbe_scan_end (SymbolDBEngine *dbe, gint something,
+                           SymbolDBQuery *query)
+{
+	g_return_if_fail (SYMBOL_DB_IS_QUERY (query));
+	g_return_if_fail (query->priv->mode == IANJUTA_SYMBOL_QUERY_MODE_QUEUED_SINGLE);
+	
+	if (!query->priv->is_canceled && query->priv->query_queued &&
+	    !symbol_db_engine_is_scanning (query->priv->dbe_system) &&
+	    !symbol_db_engine_is_scanning (query->priv->dbe_project))
+	{
+		g_signal_emit_by_name (query, "async-result",
+		                       sdb_query_execute_real (query));
+		query->priv->is_canceled = FALSE;
+		query->priv->query_queued = FALSE;
+	}
+}
+
+static IAnjutaIterable*
+sdb_query_execute (SymbolDBQuery *query)
+{
+	switch (query->priv->mode)
+	{
+		case IANJUTA_SYMBOL_QUERY_MODE_SYNC:
+			return sdb_query_execute_real (query);
+		case IANJUTA_SYMBOL_QUERY_MODE_ASYNC:
+			query->priv->is_canceled = FALSE;
+			anjuta_command_start (ANJUTA_COMMAND (query));
+			return NULL;
+		case IANJUTA_SYMBOL_QUERY_MODE_QUEUED_SINGLE:
+			query->priv->is_canceled = FALSE;
+			query->priv->query_queued = TRUE;
+			on_sdb_query_dbe_scan_end (NULL, 0, query);
+			break;
+		case IANJUTA_SYMBOL_QUERY_MODE_QUEUED_MULTI:
+			/* FIXME */
+		default:
+			g_warn_if_reached ();
+	}
+	return NULL;
 }
 
 static void
@@ -403,6 +427,8 @@ sdb_query_init (SymbolDBQuery *query)
 
 	/* Prepare async signals */
 	priv->is_canceled = FALSE;
+	priv->async_result = NULL;
+	priv->query_queued = FALSE;
 	g_signal_connect (query, "notify-data-arrived",
 	                  G_CALLBACK (on_sdb_query_async_data_arrived), query);
 }
@@ -447,10 +473,28 @@ sdb_query_set_property (GObject *object, guint prop_id, const GValue *value, GPa
 		gda_holder_set_value (priv->param_offset, value, NULL);
 		break;
 	case PROP_DB_ENGINE_SYSTEM:
+		if (priv->dbe_system)
+		{
+			g_signal_handlers_disconnect_by_func (priv->dbe_system,
+			                                      on_sdb_query_dbe_scan_end,
+			                                      query);
+		}
+		g_object_unref (priv->dbe_system);
 		priv->dbe_system = g_value_get_object (value);
+		g_signal_connect (priv->dbe_system, "scan-end",
+		                  G_CALLBACK (on_sdb_query_dbe_scan_end), query);
 		break;
 	case PROP_DB_ENGINE_PROJECT:
+		if (priv->dbe_project)
+		{
+			g_signal_handlers_disconnect_by_func (priv->dbe_project,
+			                                      on_sdb_query_dbe_scan_end,
+			                                      query);
+		}
+		g_object_unref (priv->dbe_system);
 		priv->dbe_project = g_value_get_object (value);
+		g_signal_connect (priv->dbe_project, "scan-end",
+		                  G_CALLBACK (on_sdb_query_dbe_scan_end), query);
 		break;
 	case PROP_DB_ENGINE_SELECTED:
 		priv->dbe_selected = g_value_get_object (value);



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