[anjuta/sdb-core-trans: 58/59] symbol-db: many fixes on GPtrArray usage thanks to newer glib. Scan async.



commit fe8106060cbc3b9d66d369644396052af2971e3a
Author: Massimo Corà <mcora src gnome org>
Date:   Fri Jul 30 01:59:07 2010 +0200

    symbol-db: many fixes on GPtrArray usage thanks to newer glib. Scan async.
    
    Scan async queuing multiple requests is also performed now.

 plugins/symbol-db/benchmark/symbol-db/benchmark.c |    4 +-
 plugins/symbol-db/plugin.c                        |  104 ++++++-----
 plugins/symbol-db/symbol-db-engine-core.c         |  202 ++++++++++++++-------
 plugins/symbol-db/symbol-db-engine-core.h         |   40 +++--
 plugins/symbol-db/symbol-db-engine-priv.h         |    4 +-
 plugins/symbol-db/symbol-db-engine-utils.c        |    2 +-
 plugins/symbol-db/symbol-db-engine-utils.h        |    4 +-
 plugins/symbol-db/symbol-db-system.c              |   15 +--
 8 files changed, 227 insertions(+), 148 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/symbol-db/benchmark.c b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
index f021d3f..901b333 100644
--- a/plugins/symbol-db/benchmark/symbol-db/benchmark.c
+++ b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
@@ -115,7 +115,7 @@ int main (int argc, char** argv)
 		return -1;
 	}
 
-	symbol_db_engine_add_new_project (engine, NULL, root_dir);
+	symbol_db_engine_add_new_project (engine, NULL, root_dir, 1.0);
 			
 	mimes = g_hash_table_new (g_str_hash, g_str_equal);
 	g_hash_table_insert (mimes, "text/x-csrc", "text/x-csrc");
@@ -133,7 +133,7 @@ int main (int argc, char** argv)
 	g_signal_connect (G_OBJECT (engine), "single-file-scan-end",
 		  G_CALLBACK (on_single_file_scan_end), files);
 	
-	symbol_db_engine_add_new_files_full (engine, root_dir, files, languages, TRUE);	
+	symbol_db_engine_add_new_files_full_async (engine, root_dir, files, languages, TRUE);	
 
 	g_free (root_dir);
 	g_object_unref (g_dir);
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index 0ab5a2c..c287bc1 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -409,7 +409,7 @@ on_editor_buffer_symbols_update_timeout (gpointer user_data)
 		}
 	}
 
-	real_files_list = g_ptr_array_new ();
+	real_files_list = g_ptr_array_new_with_free_func (g_free);
 	g_ptr_array_add (real_files_list, local_path);
 
 	text_buffers = g_ptr_array_new ();
@@ -441,7 +441,8 @@ on_editor_buffer_symbols_update_timeout (gpointer user_data)
 		g_tree_insert (sdb_plugin->proc_id_tree, GINT_TO_POINTER (proc_id),
 					   GINT_TO_POINTER (TASK_BUFFER_UPDATE));		
 	}
-	
+
+	g_ptr_array_unref (real_files_list);
 	g_free (current_buffer);  
 	g_object_unref (file);
 
@@ -779,8 +780,8 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 	plugin = ANJUTA_PLUGIN (sdb_plugin);
 
 	/* create array of languages and the wannabe scanned files */
-	languages_array = g_ptr_array_new ();
-	to_scan_array = g_ptr_array_new ();
+	languages_array = g_ptr_array_new_with_free_func (g_free);
+	to_scan_array = g_ptr_array_new_with_free_func (g_free);
 	
 	/* to speed the things up we must avoid the dups */
 	check_unique_file_hash = g_hash_table_new_full (g_str_hash, 
@@ -874,7 +875,7 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 	 */
 	if (to_scan_array->len > 0)
 	{		
-		gint proc_id = 	symbol_db_engine_add_new_files_full (sdb_plugin->sdbe_project, 
+		gint proc_id = 	symbol_db_engine_add_new_files_full_async (sdb_plugin->sdbe_project, 
 					sdb_plugin->project_opened, to_scan_array, languages_array, 
 														   TRUE);
 		
@@ -883,14 +884,11 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 					   GINT_TO_POINTER (task));
 	}
 
-	g_ptr_array_foreach (languages_array, (GFunc)g_free, NULL);
-	g_ptr_array_free (languages_array, TRUE);
-	
 	/* get the real added number of files */
 	added_num = to_scan_array->len;
-	
-	g_ptr_array_foreach (to_scan_array, (GFunc)g_free, NULL);
-	g_ptr_array_free (to_scan_array, TRUE);	
+
+	g_ptr_array_unref (languages_array);
+	g_ptr_array_unref (to_scan_array);	
 	
 	g_hash_table_destroy (check_unique_file_hash);
 	
@@ -910,7 +908,7 @@ on_project_element_added (IAnjutaProjectManager *pm, GFile *gfile,
 
 	filename = g_file_get_path (gfile);
 
-	files_array = g_ptr_array_new ();
+	files_array = g_ptr_array_new_with_free_func (g_free);
 	g_ptr_array_add (files_array, filename);
 
 	sdb_plugin->is_adding_element = TRUE;	
@@ -922,8 +920,7 @@ on_project_element_added (IAnjutaProjectManager *pm, GFile *gfile,
 		sdb_plugin->is_adding_element = FALSE;
 	}
 	
-	g_ptr_array_foreach (files_array, (GFunc)g_free, NULL);
-	g_ptr_array_free (files_array, TRUE);
+	g_ptr_array_unref (files_array);
 }
 
 static void
@@ -950,15 +947,6 @@ on_project_element_removed (IAnjutaProjectManager *pm, GFile *gfile,
 }
 
 static void
-sources_array_free (gpointer data)
-{
-	GPtrArray* sources = (GPtrArray*) data;
-	g_ptr_array_foreach (sources, (GFunc)g_free, NULL);
-	g_ptr_array_free (sources, TRUE);
-}
-
-
-static void
 on_system_scan_package_start (SymbolDBEngine *dbe, guint num_files, 
 							  const gchar *package, gpointer user_data)
 {
@@ -1236,9 +1224,9 @@ do_import_project_sources (AnjutaPlugin *plugin, IAnjutaProjectManager *pm,
 					 g_list_length (prj_elements_list));
 
 	/* create the storage array. The file names will be strdup'd and put here. 
-	 + This is just a sort of GList -> GPtrArray conversion.
+	 * This is just a sort of GList -> GPtrArray conversion.
 	 */
-	sources_array = g_ptr_array_new ();
+	sources_array = g_ptr_array_new_with_free_func (g_free);
 	for (i=0; i < g_list_length (prj_elements_list); i++)
 	{	
 		gchar *local_filename;
@@ -1269,8 +1257,7 @@ do_import_project_sources (AnjutaPlugin *plugin, IAnjutaProjectManager *pm,
 
 	
 	/* free the ptr array */
-	g_ptr_array_foreach (sources_array, (GFunc)g_free, NULL);
-	g_ptr_array_free (sources_array, TRUE);
+	g_ptr_array_unref (sources_array);
 
 	/* and the list of project files */
 	g_list_foreach (prj_elements_list, (GFunc) g_object_unref, NULL);
@@ -1303,8 +1290,7 @@ do_import_system_sources (SymbolDBPlugin *sdb_plugin)
 	{
 		do_import_system_sources_after_abort (sdb_plugin, sys_src_array);
 			
-		g_ptr_array_foreach (sys_src_array, (GFunc)g_free, NULL);
-		g_ptr_array_free (sys_src_array, TRUE);
+		g_ptr_array_unref (sys_src_array);
 	}	
 }
 
@@ -1401,7 +1387,7 @@ do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
 	if (it && gda_data_model_iter_move_to_row (it, 0))
 	{
 		GPtrArray *remove_array;
-		remove_array = g_ptr_array_new ();
+		remove_array = g_ptr_array_new_with_free_func (g_free);
 		do {
 			const GValue *val = gda_data_model_iter_get_value_at (it, 0);
 			const gchar * file = g_value_get_string (val);
@@ -1414,8 +1400,7 @@ do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
 		symbol_db_engine_remove_files (sdb_plugin->sdbe_project,
 									   sdb_plugin->project_opened,
 									   remove_array);
-		g_ptr_array_foreach (remove_array, (GFunc) g_free, NULL);
-		g_ptr_array_free (remove_array, TRUE);		
+		g_ptr_array_unref (remove_array);
 	}
 
 	/* great, at this point we should have this situation:
@@ -1468,7 +1453,7 @@ do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
 	
 	g_object_unref (it);
 	g_object_unref (model);
-	g_ptr_array_free (to_add_files, TRUE);
+	g_ptr_array_unref (to_add_files);
 	g_hash_table_destroy (prj_elements_hash);
 	
 	return real_added > 0 ? TRUE : FALSE;	
@@ -1640,12 +1625,8 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 	{
 		gboolean needs_sources_scan = FALSE;
 		gboolean project_exist = FALSE;
-		GHashTable* lang_hash;
 		guint id;
 			
-		lang_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
-										  sources_array_free);
-
 		/* we'll use the same values for db_directory and project_directory */
 		DEBUG_PRINT ("Opening db %s and project_dir %s", root_dir, root_dir);
 		gint open_status = symbol_db_engine_open_db (sdb_plugin->sdbe_project, root_dir, 
@@ -1680,7 +1661,8 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 			DEBUG_PRINT ("Creating new project.");
 			symbol_db_engine_add_new_project (sdb_plugin->sdbe_project,
 											  NULL,	/* still no workspace logic */
-											  sdb_plugin->project_opened);
+											  sdb_plugin->project_opened,
+			    							  1.0);
 		}
 
 		/*
@@ -1707,10 +1689,8 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 
 			if (sources_array != NULL && sources_array->len > 0) 
 			{				
-				do_import_project_sources_after_abort (plugin, sources_array);
-				
-				g_ptr_array_foreach (sources_array, (GFunc)g_free, NULL);
-				g_ptr_array_free (sources_array, TRUE);
+				do_import_project_sources_after_abort (plugin, sources_array);				
+				g_ptr_array_unref (sources_array);
 			}
 
 			/* check for offline changes */				
@@ -1729,8 +1709,6 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 
 		/* root dir */
 		sdb_plugin->project_root_dir = root_dir;
-			
-		g_hash_table_unref (lang_hash);			
 	}
 	/* this is uri */
 	sdb_plugin->project_root_uri = g_strdup (root_uri);	
@@ -1959,7 +1937,7 @@ symbol_db_activate (AnjutaPlugin *plugin)
 	 * you'll be able to get in O(1) the _index in the second array, where the 
 	 * scan process ids are stored. This is true in the other way too.
 	 */
-	sdb_plugin->buffer_update_files = g_ptr_array_new ();
+	sdb_plugin->buffer_update_files = g_ptr_array_new_with_free_func (g_free);
 	sdb_plugin->buffer_update_ids = g_ptr_array_new ();
 	sdb_plugin->buffer_update_semaphore = FALSE;
 	
@@ -2262,14 +2240,13 @@ symbol_db_deactivate (AnjutaPlugin *plugin)
 
 	if (sdb_plugin->buffer_update_files)
 	{
-		g_ptr_array_foreach (sdb_plugin->buffer_update_files, (GFunc)g_free, NULL);
-		g_ptr_array_free (sdb_plugin->buffer_update_files, TRUE);
+		g_ptr_array_unref (sdb_plugin->buffer_update_files);
 		sdb_plugin->buffer_update_files = NULL;
 	}
 
 	if (sdb_plugin->buffer_update_ids)
 	{
-		g_ptr_array_free (sdb_plugin->buffer_update_ids, TRUE);
+		g_ptr_array_unref (sdb_plugin->buffer_update_ids);
 		sdb_plugin->buffer_update_ids = NULL;		
 	}	
 		
@@ -2505,10 +2482,41 @@ isymbol_manager_create_query (IAnjutaSymbolManager *isymbol_manager,
 	return IANJUTA_SYMBOL_QUERY (query);
 }
 
+static gboolean
+isymbol_manager_add_package (IAnjutaSymbolManager *isymbol_manager,
+    						 const gchar* pkg_name, 
+    						 const gchar* pkg_version, 
+    						 const GList* files,
+    						 GError *err)
+{
+	
+}
+
+static gboolean
+isymbol_manager_activate_package (IAnjutaSymbolManager *isymbol_manager,
+    							  const gchar *pkg_name, 
+    							  const gchar *pkg_version,
+    							  GError *err)
+{
+	
+}
+
+static gboolean
+isymbol_manager_deactivate_package (IAnjutaSymbolManager *isymbol_manager,
+        							const gchar *pkg_name, 
+    							  	const gchar *pkg_version,
+    							  	GError *err)
+{
+	
+}
+
 static void
 isymbol_manager_iface_init (IAnjutaSymbolManagerIface *iface)
 {
 	iface->create_query = isymbol_manager_create_query;
+	iface->add_package = isymbol_manager_add_package;
+	iface->activate_package = isymbol_manager_activate_package;
+	iface->deactivate_package = isymbol_manager_deactivate_package;
 }
 
 ANJUTA_PLUGIN_BEGIN (SymbolDBPlugin, symbol_db);
diff --git a/plugins/symbol-db/symbol-db-engine-core.c b/plugins/symbol-db/symbol-db-engine-core.c
index 06adb8a..2d55188 100644
--- a/plugins/symbol-db/symbol-db-engine-core.c
+++ b/plugins/symbol-db/symbol-db-engine-core.c
@@ -94,6 +94,14 @@ typedef struct _TableMapSymbol {
 
 } TableMapSymbol;
 
+typedef struct _EngineScanDataAsync {
+	GPtrArray *files_list;
+	GPtrArray *real_files_list;
+	gboolean symbols_update;
+	
+} EngineScanDataAsync;
+
+
 typedef void (SymbolDBEngineCallback) (SymbolDBEngine * dbe,
 									   gpointer user_data);
 
@@ -224,6 +232,17 @@ sdb_engine_tablemap_tmp_heritage_destroy (TableMapTmpHeritage *node)
 }
 
 static void
+sdb_engine_scan_data_destroy (gpointer data)
+{
+	EngineScanDataAsync *esda =  (EngineScanDataAsync *)data;
+
+	g_ptr_array_unref (esda->files_list);
+	g_ptr_array_unref (esda->real_files_list);
+
+	g_free (esda);
+}
+
+static void
 sdb_engine_clear_tablemaps (SymbolDBEngine *dbe)
 {
 	SymbolDBEnginePriv *priv = dbe->priv;
@@ -1079,7 +1098,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_aqueue));
-					priv->scanning--;
+					priv->is_scanning = FALSE;
 					g_signal_emit (dbe, signals[SCAN_END], 0, int_tmp);
 				}
 					break;
@@ -1321,7 +1340,6 @@ sdb_engine_scan_files_2 (GFile *gfile,
  * on db. In this mode files_list and real_files_list must have the same size.
  *
  */
-/* server mode version */
 static gboolean
 sdb_engine_scan_files_1 (SymbolDBEngine * dbe, const GPtrArray * files_list,
 						 const GPtrArray *real_files_list, gboolean symbols_update)
@@ -1329,19 +1347,7 @@ sdb_engine_scan_files_1 (SymbolDBEngine * dbe, const GPtrArray * files_list,
 	SymbolDBEnginePriv *priv;
 	gint i;
 
-	g_return_val_if_fail (files_list != NULL, FALSE);
-	
-	if (files_list->len == 0)
-		return FALSE;	
-	
-	/* start process in server mode */
 	priv = dbe->priv;
-
-	if (real_files_list != NULL && (files_list->len != real_files_list->len)) 
-	{
-		g_warning ("no matched size between real_files_list and files_list");		
-		return FALSE;
-	}
 	
 	/* if ctags_launcher isn't initialized, then do it now. */
 	/* lazy initialization */
@@ -1350,7 +1356,9 @@ sdb_engine_scan_files_1 (SymbolDBEngine * dbe, const GPtrArray * files_list,
 		sdb_engine_ctags_launcher_create (dbe);
 	}
 
-	priv->scanning++; /* Enter scanning state */
+	
+	/* Enter scanning state */
+	priv->is_scanning = TRUE; 
 	DEBUG_PRINT ("%s", "EMITTING scan begin.");
 	g_signal_emit_by_name (dbe, "scan-begin",
 	                       anjuta_launcher_get_child_pid (priv->ctags_launcher));
@@ -1436,6 +1444,68 @@ sdb_engine_scan_files_1 (SymbolDBEngine * dbe, const GPtrArray * files_list,
 }
 
 static void
+on_scan_files_async_end (SymbolDBEngine *dbe, gint process_id, gpointer user_data)
+{
+	SymbolDBEnginePriv *priv;
+	EngineScanDataAsync *esda;
+
+	priv = dbe->priv;
+	
+	/* fine, check on the queue if there's something left to scan */
+	if ((esda = g_async_queue_try_pop (priv->waiting_scan_aqueue)) == NULL)
+		return;
+
+	sdb_engine_scan_files_1 (dbe, esda->files_list, esda->real_files_list, 
+	    esda->symbols_update);
+
+	sdb_engine_scan_data_destroy (esda);	
+}
+
+static gboolean
+sdb_engine_scan_files_async (SymbolDBEngine * dbe, const GPtrArray * files_list,
+						 const GPtrArray *real_files_list, gboolean symbols_update)
+{
+	SymbolDBEnginePriv *priv;
+	g_return_val_if_fail (files_list != NULL, FALSE);
+	
+	if (files_list->len == 0)
+		return FALSE;	
+	
+	priv = dbe->priv;
+
+	if (real_files_list != NULL && (files_list->len != real_files_list->len)) 
+	{
+		g_warning ("no matched size between real_files_list and files_list");		
+		return FALSE;
+	}
+
+	/* is the engine scanning or is there already something waiting on the queue? */
+	if (symbol_db_engine_is_scanning (dbe) == TRUE ||
+	    g_async_queue_length (priv->waiting_scan_aqueue) > 0)
+	{
+		/* push the data into the queue for later retrieval */
+		EngineScanDataAsync * esda = g_new0 (EngineScanDataAsync, 1);
+
+		esda->files_list = anjuta_util_clone_string_gptrarray (files_list);
+		if (real_files_list)
+			esda->real_files_list = anjuta_util_clone_string_gptrarray (real_files_list);
+		else
+			esda->real_files_list = NULL;
+		esda->symbols_update = symbols_update;
+
+		g_async_queue_push (priv->waiting_scan_aqueue, esda);
+		return TRUE;
+	}
+
+	/* there's no scan active right now nor data waiting on the queue. 
+	 * Proceed with normal scan.
+	 */
+	sdb_engine_scan_files_1 (dbe, files_list, real_files_list, symbols_update);
+
+	return TRUE;
+}
+
+static void
 sdb_engine_init (SymbolDBEngine * object)
 {
 	SymbolDBEngine *sdbe;
@@ -1558,7 +1628,12 @@ sdb_engine_init (SymbolDBEngine * object)
 	sdbe->priv->updated_syms_id_aqueue = g_async_queue_new ();
 	sdbe->priv->updated_scope_syms_id_aqueue = g_async_queue_new ();
 	sdbe->priv->inserted_syms_id_aqueue = g_async_queue_new ();
-	sdbe->priv->scanning = 0;
+	sdbe->priv->is_scanning = FALSE;
+
+	sdbe->priv->waiting_scan_aqueue = g_async_queue_new_full (sdb_engine_scan_data_destroy);
+	sdbe->priv->waiting_scan_handler = g_signal_connect (G_OBJECT (sdbe), "scan-end",
+ 				G_CALLBACK (on_scan_files_async_end), NULL);
+
 	
 	/*
 	 * STATIC QUERY STRUCTURE INITIALIZE
@@ -1833,6 +1908,9 @@ sdb_engine_finalize (GObject * object)
 	
 	dbe = SYMBOL_DB_ENGINE (object);
 	priv = dbe->priv;
+
+	g_signal_handler_disconnect (dbe, priv->waiting_scan_handler);
+	priv->waiting_scan_handler = 0;
 	
 	if (priv->thread_pool)
 	{
@@ -1897,6 +1975,12 @@ sdb_engine_finalize (GObject * object)
 		g_async_queue_unref (priv->inserted_syms_id_aqueue);
 		priv->inserted_syms_id_aqueue = NULL;
 	}	
+
+	if (priv->waiting_scan_aqueue)
+	{
+		g_async_queue_unref (priv->waiting_scan_aqueue);
+		priv->waiting_scan_aqueue = NULL;
+	}
 	
 	if (priv->shared_mem_file) 
 	{
@@ -2228,7 +2312,7 @@ gboolean
 symbol_db_engine_is_scanning (SymbolDBEngine *dbe)
 {
 	g_return_val_if_fail (SYMBOL_IS_DB_ENGINE (dbe), FALSE);
-	return (dbe->priv->scanning > 0);
+	return dbe->priv->is_scanning;
 }
 
 /**
@@ -2929,17 +3013,8 @@ sdb_engine_get_unique_scan_id (SymbolDBEngine * dbe)
 	return ret_id;
 }
 
-void
-symbol_db_engine_add_new_files_async (SymbolDBEngine *dbe, 
-    							IAnjutaLanguage* lang_manager,
-								const gchar * project_name,
-							    const GPtrArray *sources_array)
-{
-	
-}
-
 gint
-symbol_db_engine_add_new_files (SymbolDBEngine *dbe, 
+symbol_db_engine_add_new_files_async (SymbolDBEngine *dbe, 
     							IAnjutaLanguage* lang_manager,
 								const gchar * project_name,
 							    const GPtrArray *sources_array)
@@ -2954,7 +3029,7 @@ symbol_db_engine_add_new_files (SymbolDBEngine *dbe,
 
 	priv = dbe->priv;
 
-	lang_array = g_ptr_array_new ();
+	lang_array = g_ptr_array_new_with_free_func (g_free);
 
 	for (i = 0; i < sources_array->len; i++)
 	{		
@@ -2999,18 +3074,17 @@ symbol_db_engine_add_new_files (SymbolDBEngine *dbe,
 		g_object_unref (gfile_info);
 	}
 
-	gint res = symbol_db_engine_add_new_files_full (dbe, project_name, sources_array,
+	gint res = symbol_db_engine_add_new_files_full_async (dbe, project_name, sources_array,
 	    lang_array, TRUE);
 
 	/* free resources */
-	g_ptr_array_foreach (lang_array, (GFunc)g_free, NULL);
-	g_ptr_array_free (lang_array, TRUE);
+	g_ptr_array_unref (lang_array);
 
 	return res;
 }
 
 gint
-symbol_db_engine_add_new_files_full (SymbolDBEngine * dbe, 
+symbol_db_engine_add_new_files_full_async (SymbolDBEngine * dbe, 
 								const gchar * project_name,
 								const GPtrArray * files_path, 
 								const GPtrArray * languages,
@@ -3019,7 +3093,6 @@ symbol_db_engine_add_new_files_full (SymbolDBEngine * dbe,
 	gint i;
 	SymbolDBEnginePriv *priv;
 	GPtrArray * filtered_files_path;
-	GPtrArray * filtered_languages;
 	gboolean ret_code;
 	gint ret_id;
 	
@@ -3033,7 +3106,6 @@ symbol_db_engine_add_new_files_full (SymbolDBEngine * dbe,
 	g_return_val_if_fail (languages->len > 0, FALSE);
 
 	filtered_files_path = g_ptr_array_new ();
-	filtered_languages = g_ptr_array_new ();
 	
 	for (i = 0; i < files_path->len; i++)
 	{
@@ -3072,14 +3144,15 @@ symbol_db_engine_add_new_files_full (SymbolDBEngine * dbe,
 	 * AnjutaLauncher and ctags in server mode. After the ctags cmd has been 
 	 * executed, the populating process'll take place.
 	 */
-	ret_code = sdb_engine_scan_files_1 (dbe, filtered_files_path, NULL, FALSE);
+	ret_code = sdb_engine_scan_files_async (dbe, filtered_files_path, NULL, FALSE);
 	
 	if (ret_code == TRUE)
 		ret_id = sdb_engine_get_unique_scan_id (dbe);
 	else
 		ret_id = -1;
-	
-	g_ptr_array_free (filtered_files_path, TRUE);
+
+	/* no need to free the items contained in the array */
+	g_ptr_array_unref (filtered_files_path);
 	return ret_id;
 }
 
@@ -4722,7 +4795,6 @@ on_scan_update_files_symbols_end (SymbolDBEngine * dbe,
 					   strlen (priv->project_directory));
 			return;
 		}
-		g_free (node);
 	}
 		
 	g_signal_handlers_disconnect_by_func (dbe, on_scan_update_files_symbols_end,
@@ -4769,7 +4841,7 @@ on_scan_update_files_symbols_end (SymbolDBEngine * dbe,
 	}	
 	
 	/* free the GPtrArray. */
-	g_ptr_array_free (files_to_scan, TRUE);
+	g_ptr_array_unref (files_to_scan);
 
 	g_free (update_data->project);
 	g_free (update_data);
@@ -4777,7 +4849,7 @@ on_scan_update_files_symbols_end (SymbolDBEngine * dbe,
 
 gint
 symbol_db_engine_update_files_symbols (SymbolDBEngine * dbe, const gchar * project, 
-									   GPtrArray * files_path,
+									   const GPtrArray * files_path,
 									   gboolean update_prj_analyse_time)
 {
 	SymbolDBEnginePriv *priv;
@@ -4792,14 +4864,14 @@ symbol_db_engine_update_files_symbols (SymbolDBEngine * dbe, const gchar * proje
 	g_return_val_if_fail (priv->db_connection != NULL, FALSE);
 	g_return_val_if_fail (project != NULL, FALSE);
 
-	ready_files = g_ptr_array_new ();
+	ready_files = g_ptr_array_new_with_free_func (g_free);
 	
 	/* check if the files exist in db before passing them to the scan procedure */
 	for (i = 0; i < files_path->len; i++) 
 	{
 		gchar *curr_abs_file;
 		
-		curr_abs_file = g_ptr_array_index (files_path, i);
+		curr_abs_file = g_strdup (g_ptr_array_index (files_path, i));
 		/* check if the file exists in db. We will not scan buffers for files
 		 * which aren't already in db
 		 */
@@ -4815,14 +4887,11 @@ symbol_db_engine_update_files_symbols (SymbolDBEngine * dbe, const gchar * proje
 		/* ok the file exists in db. Add it to ready_files */
 		g_ptr_array_add (ready_files, curr_abs_file);
 	}
-	
-	/* free just the array but not its values */
-	g_ptr_array_free (files_path, FALSE);
-	
+		
 	/* if no file has been added to the array then bail out here */
 	if (ready_files->len <= 0)
 	{
-		g_ptr_array_free (ready_files, TRUE);
+		g_ptr_array_unref (ready_files);
 		DEBUG_PRINT ("not enough files to update");
 		return -1;
 	}
@@ -4839,8 +4908,8 @@ symbol_db_engine_update_files_symbols (SymbolDBEngine * dbe, const gchar * proje
 	 */
 	g_signal_connect (G_OBJECT (dbe), "scan-end",
 					  G_CALLBACK (on_scan_update_files_symbols_end), update_data);
-	
-	ret_code = sdb_engine_scan_files_1 (dbe, ready_files, NULL, TRUE);
+
+	ret_code = sdb_engine_scan_files_async (dbe, ready_files, NULL, TRUE);
 	if (ret_code == TRUE)
 		ret_id = sdb_engine_get_unique_scan_id (dbe);
 	else
@@ -4929,7 +4998,7 @@ symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe,
 	}
 
 	/* initialize the array */
-	files_to_scan = g_ptr_array_new ();
+	files_to_scan = g_ptr_array_new_with_free_func (g_free);
 
 	/* we can now scan each filename entry to check the last modification time. */
 	for (i = 0; i < num_rows; i++)
@@ -5029,10 +5098,13 @@ symbol_db_engine_update_project_symbols (SymbolDBEngine *dbe,
 	if (files_to_scan->len > 0)
 	{
 		SDB_UNLOCK(priv);
-		
+
 		/* at the end let the scanning function do its job */
-		return symbol_db_engine_update_files_symbols (dbe, project_name,
+		gint id = symbol_db_engine_update_files_symbols (dbe, project_name,
 											   files_to_scan, TRUE);
+
+		g_ptr_array_unref (files_to_scan);
+		return id;
 	}
 	
 	SDB_UNLOCK(priv);
@@ -5154,20 +5226,19 @@ on_scan_update_buffer_end (SymbolDBEngine * dbe, gint process_id, gpointer data)
 				return;
 			}
 		}
-		g_free (node);
 	}
 		
 	g_signal_handlers_disconnect_by_func (dbe, on_scan_update_buffer_end,
 										  files_to_scan);
 
 	/* free the GPtrArray. */
-	g_ptr_array_free (files_to_scan, TRUE);
+	g_ptr_array_unref (files_to_scan);
 	data = files_to_scan = NULL;
 }
 
 gint
 symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *project,
-										GPtrArray * real_files_list,
+										const GPtrArray * real_files,
 										const GPtrArray * text_buffers,
 										const GPtrArray * buffer_sizes)
 {
@@ -5177,6 +5248,7 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
 	gboolean ret_code;
 	/* array that'll represent the /dev/shm/anjuta-XYZ files */
 	GPtrArray *temp_files;
+	GPtrArray *real_files_list;
 	GPtrArray *real_files_on_db;
 	
 	g_return_val_if_fail (dbe != NULL, FALSE);
@@ -5184,12 +5256,13 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
 	
 	g_return_val_if_fail (priv->db_connection != NULL, FALSE);
 	g_return_val_if_fail (project != NULL, FALSE);
-	g_return_val_if_fail (real_files_list != NULL, FALSE);
+	g_return_val_if_fail (real_files != NULL, FALSE);
 	g_return_val_if_fail (text_buffers != NULL, FALSE);
 	g_return_val_if_fail (buffer_sizes != NULL, FALSE);
 	
-	temp_files = g_ptr_array_new();	
-	real_files_on_db = g_ptr_array_new();
+	temp_files = g_ptr_array_new_with_free_func (g_free);	
+	real_files_on_db = g_ptr_array_new_with_free_func (g_free);
+	real_files_list = anjuta_util_clone_string_gptrarray (real_files);
 	
 	/* obtain a GPtrArray with real_files on database */
 	for (i=0; i < real_files_list->len; i++) 
@@ -5217,8 +5290,7 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
 		relative_path = symbol_db_util_get_file_db_path (dbe, curr_abs_file);
 		if (relative_path == NULL)
 		{
-			g_warning ("symbol_db_engine_update_buffer_symbols  (): "
-					   "relative_path is NULL");
+			g_warning ("relative_path is NULL");
 			continue;
 		}
 		g_ptr_array_add (real_files_on_db, (gpointer) relative_path);
@@ -5281,20 +5353,16 @@ symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *proje
 		g_signal_connect (G_OBJECT (dbe), "scan-end",
 						  G_CALLBACK (on_scan_update_buffer_end), real_files_list);
 	
-		ret_code = sdb_engine_scan_files_1 (dbe, temp_files, real_files_on_db, TRUE);
+		ret_code = sdb_engine_scan_files_async (dbe, temp_files, real_files_on_db, TRUE);
 		if (ret_code == TRUE)
 			ret_id = sdb_engine_get_unique_scan_id (dbe);
 		else
 			ret_id = -1;
 	}
 	
-	/* let's free the temp_files array */
-	for (i=0; i < temp_files->len; i++)
-		g_free (g_ptr_array_index (temp_files, i));
-	
-	g_ptr_array_free (temp_files, TRUE);
 	
-	g_ptr_array_free (real_files_on_db, TRUE);
+	g_ptr_array_unref (temp_files);	
+	g_ptr_array_unref (real_files_on_db);
 	return ret_id;
 }
 
diff --git a/plugins/symbol-db/symbol-db-engine-core.h b/plugins/symbol-db/symbol-db-engine-core.h
index 5f0acbd..ca4ccfc 100644
--- a/plugins/symbol-db/symbol-db-engine-core.h
+++ b/plugins/symbol-db/symbol-db-engine-core.h
@@ -204,14 +204,20 @@ symbol_db_engine_project_exists (SymbolDBEngine *dbe, /*gchar* workspace, */
  * @param force_scan If FALSE a check on db will be done to see
  *		  whether the file is already present or not. In the latter care the scan will begin.
  *
+ * The function is suffixed with 'async'. This means that the scanning of the files is delayed
+ * until the scanner is available. So you should use the gint id returned to identify
+ * if a 'scan-end' signal is the one that you were expecting. 
+ * Please note also that, if db is disconnected before the waiting queue is processed,
+ * the scan of those files won't be performed.
+ *
  * @return scan process id if insertion is successful, -1 on error.
  */
 gint
-symbol_db_engine_add_new_files_full (SymbolDBEngine *dbe, 
-									const gchar * project_name,
-							    	const GPtrArray *files_path,
-									const GPtrArray *languages,
-									gboolean force_scan);
+symbol_db_engine_add_new_files_full_async (SymbolDBEngine *dbe, 
+										   const gchar * project_name,
+							    		   const GPtrArray *files_path,
+										   const GPtrArray *languages,
+										   gboolean force_scan);
 
 /**
  * See symbol_db_engine_add_new_files_full () for doc.
@@ -220,13 +226,20 @@ symbol_db_engine_add_new_files_full (SymbolDBEngine *dbe,
  * GPtrArray of languages, but it'll try to autodetect them.
  * When added, the files are forced to be scanned.
  *
+ *
+ * The function is suffixed with 'async'. This means that the scanning of the files is delayed
+ * until the scanner is available. So you should use the gint id returned to identify
+ * if a 'scan-end' signal is the one that you were expecting. 
+ * Please note also that, if db is disconnected before the waiting queue is processed,
+ * the scan of those files won't be performed.
+ *
  * @return scan process id if insertion is successful, -1 on error.
  */
 gint
-symbol_db_engine_add_new_files (SymbolDBEngine *dbe, 
-    							IAnjutaLanguage* lang_manager,
-								const gchar * project_name,
-							    const GPtrArray *files_path);
+symbol_db_engine_add_new_files_async (SymbolDBEngine *dbe, 
+    								  IAnjutaLanguage* lang_manager,
+									  const gchar * project_name,
+							    	  const GPtrArray *files_path);
 
 /**
  * Update symbols of the whole project. It scans all file symbols etc. 
@@ -248,26 +261,23 @@ symbol_db_engine_remove_files (SymbolDBEngine * dbe, const gchar *project,
 
 /**
  * Update symbols of saved files. 
- * @note WARNING: files_path and it's contents will be freed on 
- * on_scan_update_files_symbols_end () callback.
  * @return scan process id if insertion is successful, -1 on 'no files scanned'.
  */
 gint
 symbol_db_engine_update_files_symbols (SymbolDBEngine *dbe, const gchar *project, 
-									   GPtrArray *files_path,
+									   const GPtrArray *files_path,
 									   gboolean update_prj_analyse_time);
 
 /**
  * Update symbols of a file by a memory-buffer to perform a real-time updating 
  * of symbols. 
  * @param real_files_list: full path on disk to 'real file' to update. e.g.
- * /home/foouser/fooproject/src/main.c. They'll be freed inside this function 
- * when the scan has ended. 
+ * /home/foouser/fooproject/src/main.c. 
  * @return scan process id if insertion is successful, -1 on error.
  */
 gint
 symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar * project,
-										GPtrArray * real_files_list,
+										const GPtrArray * real_files_list,
 										const GPtrArray * text_buffers,
 										const GPtrArray * buffer_sizes);
 
diff --git a/plugins/symbol-db/symbol-db-engine-priv.h b/plugins/symbol-db/symbol-db-engine-priv.h
index 701bb4f..6eb6af4 100644
--- a/plugins/symbol-db/symbol-db-engine-priv.h
+++ b/plugins/symbol-db/symbol-db-engine-priv.h
@@ -141,6 +141,7 @@ typedef struct _static_query_node
 
 } static_query_node;
 
+/* normalize with iface naming */
 typedef IAnjutaSymbolType SymType;
 
 /* the SymbolDBEngine Private structure */
@@ -164,7 +165,7 @@ struct _SymbolDBEnginePriv
 	GAsyncQueue *updated_syms_id_aqueue;
 	GAsyncQueue *updated_scope_syms_id_aqueue;
 	GAsyncQueue *inserted_syms_id_aqueue;
-	gint scanning;
+	gboolean is_scanning;
 	
 	gchar *shared_mem_str;
 	FILE *shared_mem_file;
@@ -176,6 +177,7 @@ struct _SymbolDBEnginePriv
 	gsize symbols_scanned_count;
 
 	GAsyncQueue *waiting_scan_aqueue;
+	gulong waiting_scan_handler;
 
 	/* Threads management */
 	GMutex* mutex;
diff --git a/plugins/symbol-db/symbol-db-engine-utils.c b/plugins/symbol-db/symbol-db-engine-utils.c
index ff4e6c2..02609e2 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.c
+++ b/plugins/symbol-db/symbol-db-engine-utils.c
@@ -120,7 +120,7 @@ symbol_db_util_get_files_with_zero_symbols (SymbolDBEngine *dbe)
 	}	
 		
 	/* initialize the array */
-	files_to_scan = g_ptr_array_new ();
+	files_to_scan = g_ptr_array_new_with_free_func (g_free);
 
 	/* we can now scan each filename entry to check the last modification time. */
 	for (i = 0; i < num_rows; i++)
diff --git a/plugins/symbol-db/symbol-db-engine-utils.h b/plugins/symbol-db/symbol-db-engine-utils.h
index a02705c..12c9025 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.h
+++ b/plugins/symbol-db/symbol-db-engine-utils.h
@@ -63,7 +63,9 @@ symbol_db_util_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_fi
 /**
  * Try to get all the files with zero symbols: these should be the ones
  * excluded by an abort on population process.
- * @return A GPtrArray with paths on disk of the files. Must be freed by caller.
+ * @return A GPtrArray with paths on disk of the files. Must be unreffed by caller using
+ * g_ptr_array_unref (). Being created with g_ptr_array_new_with_free_func (g_free) there's
+ * no need to free its items.
  * @return NULL if no files are found.
  */
 GPtrArray *
diff --git a/plugins/symbol-db/symbol-db-system.c b/plugins/symbol-db/symbol-db-system.c
index bc2089c..ce416e6 100644
--- a/plugins/symbol-db/symbol-db-system.c
+++ b/plugins/symbol-db/symbol-db-system.c
@@ -499,7 +499,7 @@ sdb_system_do_engine_scan (SymbolDBSystem *sdbs, EngineScanData *es_data)
 								 languages_array);
 		
 		symbol_db_engine_add_new_project (priv->sdbe_globals, NULL,
-								  		es_data->package_name);
+								  		es_data->package_name, 1.0);
 	}
 	else 
 	{
@@ -513,7 +513,7 @@ sdb_system_do_engine_scan (SymbolDBSystem *sdbs, EngineScanData *es_data)
 	 * infact to have more references of the same files in different
 	 * packages
 	 */
-	proc_id = symbol_db_engine_add_new_files_full (priv->sdbe_globals,
+	proc_id = symbol_db_engine_add_new_files_full_async (priv->sdbe_globals,
 							es_data->special_abort_scan == FALSE ? 
 									es_data->package_name : NULL, 
 							files_to_scan_array,
@@ -682,17 +682,6 @@ on_pkg_config_exit (AnjutaLauncher * launcher, int child_pid,
 						 g_queue_get_length (priv->engine_queue),
 						 es_data->package_name);
 			g_queue_push_tail (priv->engine_queue, es_data);
-
-/*			
-			gint i;			
-			for (i = 0; i < g_queue_get_length (priv->engine_queue); i++)
-			{
-				EngineScanData *node;
-				node = g_queue_peek_nth (priv->engine_queue, i);
-				DEBUG_PRINT ("DEBUG queue engine [%d]: %s", i, 
-							 node->package_name);
-			}
-*/		
 		}
 		else
 		{



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