anjuta r4393 - in trunk: . plugins/symbol-db



Author: mcora
Date: Sun Nov 16 14:56:26 2008
New Revision: 4393
URL: http://svn.gnome.org/viewvc/anjuta?rev=4393&view=rev

Log:
	* plugins/symbol-db/plugin.c
	(on_editor_buffer_symbol_update_scan_end),
	(on_editor_buffer_symbols_update_timeout), (on_editor_saved),
	(on_importing_project_end), (symbol_db_activate),
	(symbol_db_deactivate):
	* plugins/symbol-db/plugin.h:
	* plugins/symbol-db/symbol-db-engine.c
	(sdb_engine_get_statement_by_query_id),
	(sdb_engine_populate_db_by_tags), (sdb_engine_ctags_output_thread),
	(sdb_engine_timeout_trigger_signals), (sdb_engine_init),
	(sdb_engine_finalize), (sdb_engine_class_init),
	(sdb_engine_get_unique_scan_id), (symbol_db_engine_add_new_files),
	(sdb_engine_add_new_sym_access), (sdb_engine_add_new_heritage),
	(sdb_engine_add_new_scope_definition),
	(sdb_engine_add_new_tmp_heritage_scope),
	(on_scan_update_files_symbols_end),
	(symbol_db_engine_update_files_symbols),
	(on_scan_update_buffer_end),
	(symbol_db_engine_update_buffer_symbols):
	* plugins/symbol-db/symbol-db-engine.h:
	* plugins/symbol-db/symbol-db-system.c
	(on_engine_package_scan_end):
	* plugins/symbol-db/symbol-db-view-locals.c (on_scan_end),
	(symbol_db_view_locals_update_list):
	* plugins/symbol-db/symbol-db-view.c (on_scan_end):
	added code to destroy the pool objects in the engine.
	Now a call to add_files () or similar will return a process_id, instead of a 
	boolean.
	Fixed some docs in the engine. Fixed a bug which could cause GtkTree corruption
	when buffer scan was launched together with save scan.

Modified:
   trunk/ChangeLog
   trunk/plugins/symbol-db/plugin.c
   trunk/plugins/symbol-db/plugin.h
   trunk/plugins/symbol-db/symbol-db-engine.c
   trunk/plugins/symbol-db/symbol-db-engine.h
   trunk/plugins/symbol-db/symbol-db-system.c
   trunk/plugins/symbol-db/symbol-db-view-locals.c
   trunk/plugins/symbol-db/symbol-db-view.c

Modified: trunk/plugins/symbol-db/plugin.c
==============================================================================
--- trunk/plugins/symbol-db/plugin.c	(original)
+++ trunk/plugins/symbol-db/plugin.c	Sun Nov 16 14:56:26 2008
@@ -90,6 +90,39 @@
 	END_REGISTER_ICON;
 }
 
+static void
+on_editor_buffer_symbol_update_scan_end (SymbolDBEngine *dbe, gint process_id, 
+										  gpointer data)
+{
+	SymbolDBPlugin *sdb_plugin;
+	gint i;
+	
+	sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (data);	
+	
+	/* search for the proc id */
+	for (i = 0; i < sdb_plugin->buffer_update_ids->len; i++)
+	{
+		if (g_ptr_array_index (sdb_plugin->buffer_update_ids, i) == (gpointer)process_id)
+		{
+			gchar *str;
+			/* hey we found it */
+			/* remove both the items */
+			g_ptr_array_remove_index (sdb_plugin->buffer_update_ids, i);
+			
+			str = (gchar*)g_ptr_array_remove_index (sdb_plugin->buffer_update_files, 
+													i);
+			/* we can now free it */
+			g_free (str);
+			
+			/* last but not least, remove the signal */
+			if (sdb_plugin->buffer_update_files->len <= 0)
+				g_signal_handlers_disconnect_by_func (G_OBJECT(dbe),
+										  G_CALLBACK (on_editor_buffer_symbol_update_scan_end ),
+										  data);			
+		}
+	}
+}
+
 static gboolean
 on_editor_buffer_symbols_update_timeout (gpointer user_data)
 {
@@ -99,6 +132,10 @@
 	gint buffer_size = 0;
 	gdouble seconds_elapsed;
 	GFile* file;
+	gchar * local_path;
+	GPtrArray *real_files_list;
+	GPtrArray *text_buffers;
+	GPtrArray *buffer_sizes;
 	
 	g_return_val_if_fail (user_data != NULL, FALSE);
 	
@@ -125,6 +162,7 @@
 	 if (sdb_plugin->need_symbols_update == FALSE)
 	 	return TRUE;
 	
+	
 	DEBUG_PRINT ("%s", "on_editor_buffer_symbols_update_timeout()");
 	
 	if (sdb_plugin->current_editor) 
@@ -138,37 +176,73 @@
 	} 
 	else
 		return FALSE;
+
+	if (file == NULL)
+		return FALSE;
+	
+	/* take the path reference */
+	local_path = g_file_get_path (file);
+	
+	/* ok that's good. Let's have a last check: is the current file present
+	 * on the buffer_update_files?
+	 */
+	gint i;
+	for (i = 0; i < sdb_plugin->buffer_update_files->len; i++)
+	{
+		if (strcmp (g_ptr_array_index (sdb_plugin->buffer_update_files, i),
+					 local_path) == 0)
+		{
+			/* hey we found it */
+			/* something is already scanning this buffer file. Drop the procedure now. */
+			DEBUG_PRINT ("%s", "something is already scanning the file");
+			return FALSE;			
+		}
+	}
+
+	real_files_list = g_ptr_array_new ();
+	g_ptr_array_add (real_files_list, local_path);
+
+	text_buffers = g_ptr_array_new ();
+	g_ptr_array_add (text_buffers, current_buffer);	
+
+	buffer_sizes = g_ptr_array_new ();
+	g_ptr_array_add (buffer_sizes, (gpointer)buffer_size);	
+
+	
+	gint proc_id = symbol_db_engine_update_buffer_symbols (sdb_plugin->sdbe_project,
+											sdb_plugin->project_opened,
+											real_files_list,
+											text_buffers,
+											buffer_sizes);
 	
-	if (file) 
+	if (proc_id > 0)
 	{
-		GPtrArray *real_files_list;
-		GPtrArray *text_buffers;
-		GPtrArray *buffer_sizes;
-								
-		gchar * local_path = g_file_get_path (file);
-
-		real_files_list = g_ptr_array_new ();
-		g_ptr_array_add (real_files_list, local_path);
-
-		text_buffers = g_ptr_array_new ();
-		g_ptr_array_add (text_buffers, current_buffer);	
-
-		buffer_sizes = g_ptr_array_new ();
-		g_ptr_array_add (buffer_sizes, (gpointer)buffer_size);	
-
-		symbol_db_engine_update_buffer_symbols (sdb_plugin->sdbe_project,
-												sdb_plugin->project_opened,
-												real_files_list,
-												text_buffers,
-												buffer_sizes);												
+		/* if the size of the array is 0 then we probably want to connect it to some
+		 * signals 
+		 */
+		if (sdb_plugin->buffer_update_files->len > 0)
+			g_signal_connect (G_OBJECT (sdb_plugin->sdbe_project), "scan-end",
+		  		G_CALLBACK (on_editor_buffer_symbol_update_scan_end), sdb_plugin);
+		
+		/* good. All is ready for a buffer scan. Add the file_scan into the arrays */
+		gchar * local_path_dup = g_strdup (local_path);
+		g_ptr_array_add (sdb_plugin->buffer_update_files, local_path_dup);	
+		/* add the id too */
+		g_ptr_array_add (sdb_plugin->buffer_update_ids, (gpointer)proc_id);	
+	
+		
+		DEBUG_PRINT ("******** proc_id is %d", proc_id);			
 	}
 	
 	g_free (current_buffer);  
 	g_object_unref (file);
 
+	/* no need to free local_path, it'll be automatically freed later by the buffer_update
+	 * function */
+	
 	sdb_plugin->need_symbols_update = FALSE;
 
-	return TRUE;
+	return proc_id > 0 ? TRUE : FALSE;
 }
 
 static void
@@ -217,44 +291,52 @@
 				 SymbolDBPlugin *sdb_plugin)
 {
 	const gchar *old_uri;
-	gboolean tags_update;
+	gchar *local_filename;
+	gchar *saved_uri;
+	GPtrArray *files_array;
+	gint i;
 	
-	tags_update = TRUE;		
+	local_filename = g_file_get_path (file);
+	/* Verify that it's local file */
+	g_return_if_fail (local_filename != NULL);
 	
-	if (tags_update)
+	saved_uri = g_file_get_uri (file);
+	
+	for (i = 0; i < sdb_plugin->buffer_update_files->len; i++)
 	{
-		gchar *local_filename = g_file_get_path (file);
-		gchar *saved_uri = g_file_get_uri (file);
-		GPtrArray *files_array;
+		if (strcmp (g_ptr_array_index (sdb_plugin->buffer_update_files, i),
+					 local_filename) == 0)
+		{
+			DEBUG_PRINT ("%s", "already scanning");
+			/* something is already scanning this buffer file. Drop the procedure now. */
+			return;
+		}
+	}									
 
-		/* Verify that it's local file */
-		g_return_if_fail (local_filename != NULL);
 
-		files_array = g_ptr_array_new();		
-		DEBUG_PRINT ("local_filename saved is %s", local_filename);
-		g_ptr_array_add (files_array, local_filename);		
-		/* no need to free local_filename now */
+	files_array = g_ptr_array_new();		
+	g_ptr_array_add (files_array, local_filename);		
+	/* no need to free local_filename now */
 		
-		if (!sdb_plugin->editor_connected)
-			return;
+	if (!sdb_plugin->editor_connected)
+		return;
 	
-		old_uri = g_hash_table_lookup (sdb_plugin->editor_connected, editor);
+	old_uri = g_hash_table_lookup (sdb_plugin->editor_connected, editor);
 		
-		if (old_uri && strlen (old_uri) <= 0)
-			old_uri = NULL;
+	if (old_uri && strlen (old_uri) <= 0)
+		old_uri = NULL;
 
-		/* files_array will be freed once updating has taken place */
-		symbol_db_engine_update_files_symbols (sdb_plugin->sdbe_project, 
-				sdb_plugin->project_root_dir, files_array, TRUE);
-		g_hash_table_insert (sdb_plugin->editor_connected, editor,
-							 g_strdup (saved_uri));
+	/* files_array will be freed once updating has taken place */
+	symbol_db_engine_update_files_symbols (sdb_plugin->sdbe_project, 
+		sdb_plugin->project_root_dir, files_array, TRUE);
+	g_hash_table_insert (sdb_plugin->editor_connected, editor,
+						 g_strdup (saved_uri));
 
-		/* if we saved it we shouldn't update a second time */
-		sdb_plugin->need_symbols_update = FALSE;			
-			
-		on_editor_update_ui (editor, sdb_plugin);
-		g_free (saved_uri);
-	}
+	/* if we saved it we shouldn't update a second time */
+	sdb_plugin->need_symbols_update = FALSE;
+	
+	on_editor_update_ui (editor, sdb_plugin);
+	g_free (saved_uri);
 }
 
 static void
@@ -338,7 +420,7 @@
 
 		g_signal_connect (G_OBJECT (editor), "saved",
 						  G_CALLBACK (on_editor_saved),
-						  sdb_plugin);						  
+						  sdb_plugin);
 		g_signal_connect (G_OBJECT (editor), "char-added",
 						  G_CALLBACK (on_char_added),
 						  sdb_plugin);
@@ -861,7 +943,7 @@
 }
 
 static void
-on_importing_project_end (SymbolDBEngine *dbe, gpointer data)
+on_importing_project_end (SymbolDBEngine *dbe, gint process_id, gpointer data)
 {
 	SymbolDBPlugin *sdb_plugin;
 	GFile* file;
@@ -1156,7 +1238,7 @@
 								 sdb_plugin->sdbe_project, FALSE);
 				
 	g_signal_connect (G_OBJECT (sdb_plugin->sdbe_project), "scan-end",
-		  G_CALLBACK (on_importing_project_end), plugin);				
+		  G_CALLBACK (on_importing_project_end), plugin);
 				
 	lang_manager =	anjuta_shell_get_interface (plugin->shell, IAnjutaLanguage, 
 										NULL);
@@ -1743,6 +1825,13 @@
 	/* creates and start a new timer. */
 	symbol_db->update_timer = g_timer_new ();
 
+	/* these two arrays will maintain the same number of objects, 
+	 * so that if you search, say on the first, an occurrence of a file,
+	 * 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.
+	 */
+	symbol_db->buffer_update_files = g_ptr_array_new ();
+	symbol_db->buffer_update_ids = g_ptr_array_new ();
 	
 	DEBUG_PRINT ("SymbolDBPlugin: Initializing engines with %s", ctags_path);
 	/* create SymbolDBEngine(s) */
@@ -1996,6 +2085,19 @@
 	g_free (sdb_plugin->project_opened);
 	sdb_plugin->project_opened = NULL;
 
+	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);
+		sdb_plugin->buffer_update_files = NULL;
+	}
+
+	if (sdb_plugin->buffer_update_ids)
+	{
+		g_ptr_array_free (sdb_plugin->buffer_update_ids, TRUE);
+		sdb_plugin->buffer_update_ids = NULL;		
+	}	
+		
 	if (sdb_plugin->session_packages)
 	{
 		g_list_foreach (sdb_plugin->session_packages, (GFunc)g_free, NULL);

Modified: trunk/plugins/symbol-db/plugin.h
==============================================================================
--- trunk/plugins/symbol-db/plugin.h	(original)
+++ trunk/plugins/symbol-db/plugin.h	Sun Nov 16 14:56:26 2008
@@ -64,6 +64,8 @@
 	guint buf_update_timeout_id;
 	gboolean need_symbols_update;
 	GTimer *update_timer;
+	GPtrArray *buffer_update_files;
+	GPtrArray *buffer_update_ids;
 	guint editor_watch_id;
 	gchar *project_root_uri;
 	gchar *project_root_dir;

Modified: trunk/plugins/symbol-db/symbol-db-engine.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine.c	Sun Nov 16 14:56:26 2008
@@ -67,7 +67,8 @@
 
 183|13|Fourth_2_class|52|0||140|137|175|8|-1|-1|0|8|class|137|Fourth|172|172|namespace|Fourth
 
-//// alternativa ////
+* OR * 
+		
 = get the *derived symbol*
 select * from symbol 
 	join sym_kind on symbol.kind_id = sym_kind.sym_kind_id 
@@ -130,8 +131,8 @@
 
 #define SHARED_MEMORY_PREFIX		"/dev/shm"
 
-#define THREADS_MONITOR_TIMEOUT			10
-#define THREADS_MAX_CONCURRENT			3
+#define THREADS_MONITOR_TIMEOUT			50
+#define THREADS_MAX_CONCURRENT			7
 #define TRIGGER_SIGNALS_DELAY			100
 #define	TRIGGER_MAX_CLOSURE_RETRIES		50
 #define	THREAD_MAX_CLOSURE_RETRIES		20
@@ -365,6 +366,9 @@
 	gchar *db_directory;
 	gchar *project_directory;
 
+	gint scan_process_id;
+	GAsyncQueue *scan_process_id_queue;
+	
 	GAsyncQueue *scan_queue;	
 	GAsyncQueue *updated_symbols_id;
 	GAsyncQueue *updated_scope_symbols_id;
@@ -485,7 +489,7 @@
 
 static void
 sdb_engine_init_caches (SymbolDBEngine* dbe)
-{
+{	
 	SymbolDBEnginePriv *priv = dbe->priv;
 	priv->kind_cache = g_hash_table_new_full (g_str_hash,
 											g_str_equal,
@@ -608,14 +612,14 @@
 
 	/* no way: if connection is NULL we will break here. There must be
 	 * a connection established to db before using this function */
-	g_return_val_if_fail (priv->db_connection != NULL, NULL);
+	/*g_return_val_if_fail (priv->db_connection != NULL, NULL);*/
 	
 	if ((node = priv->static_query_list[query_id]) == NULL)
 		return NULL;
 
 	if (node->stmt == NULL)
 	{
-		DEBUG_PRINT ("generating new statement.. %d", query_id);
+		/*DEBUG_PRINT ("generating new statement.. %d", query_id);*/
 		/* create a new GdaStatement */
 		node->stmt =
 			gda_sql_parser_parse_string (priv->sql_parser, node->query_str, NULL, 
@@ -1316,9 +1320,7 @@
 
 	g_return_if_fail (priv->db_connection != NULL);
 	g_return_if_fail (fd != NULL);
-
 	
-	DEBUG_PRINT ("%s", "sdb_engine_populate_db_by_tags ()");
 	if ((tag_file = tagsOpen_1 (fd, &tag_file_info)) == NULL)
 	{
 		g_warning ("error in opening ctags file");
@@ -1380,7 +1382,7 @@
 	}
 
 	gdouble elapsed_DEBUG = g_timer_elapsed (sym_timer_DEBUG, NULL);
-	g_message ("elapsed: %f for (%d) [%f per symbol]", elapsed_DEBUG,
+	DEBUG_PRINT ("elapsed: %f for (%d) [%f per symbol]", elapsed_DEBUG,
 				 tags_total_DEBUG, elapsed_DEBUG / tags_total_DEBUG);
 
 	/* notify listeners that another file has been scanned */
@@ -1425,7 +1427,8 @@
 		/* is it an end file marker? */
 		marker_ptr = strstr (chars_ptr, CTAGS_MARKER);
 
-		do  {
+		do  
+		{
 			if (marker_ptr != NULL) 
 			{
 				gint scan_flag;
@@ -1573,38 +1576,45 @@
 }
 
 
+/**
+ * This function runs on the main glib thread, so that it can safely spread signals 
+ */
 static gboolean
 sdb_engine_timeout_trigger_signals (gpointer user_data)
 {
 	SymbolDBEngine *dbe = (SymbolDBEngine *) user_data;
 	SymbolDBEnginePriv *priv;
 
-	g_return_val_if_fail (user_data != NULL, FALSE);
-	
-	priv = dbe->priv;
-		
-/*	DEBUG_PRINT ("%s", "signals trigger");*/
+	g_return_val_if_fail (user_data != NULL, FALSE);	
+	priv = dbe->priv;		
+
 	if (g_async_queue_length (priv->signals_queue) > 0)
 	{
 		gpointer tmp;
 		gpointer sign = NULL;
 		gint real_signal;
 	
-		while ((sign = g_async_queue_try_pop (priv->signals_queue)) != NULL)  {
-
-			if (sign== NULL) {
+		while ((sign = g_async_queue_try_pop (priv->signals_queue)) != NULL)  
+		{
+			if (sign == NULL) 
+			{
 				return g_async_queue_length (priv->signals_queue) > 0 ? TRUE : FALSE;
 			}
 	
-			real_signal = (gint)sign- 1;
+			real_signal = (gint)sign -1;
 	
-			switch (real_signal) {
+			switch (real_signal) 
+			{
 				case SINGLE_FILE_SCAN_END:
 					g_signal_emit (dbe, signals[SINGLE_FILE_SCAN_END], 0);
 					break;
 		
 				case SCAN_END:
-					g_signal_emit (dbe, signals[SCAN_END], 0);
+				{
+					/* get the process id from the queue */
+					gint tmp = g_async_queue_pop (priv->scan_process_id_queue);
+					g_signal_emit (dbe, signals[SCAN_END], 0, tmp);
+				}
 					break;
 	
 				case SYMBOL_INSERTED:
@@ -2033,10 +2043,17 @@
 	/* set the ctags executable path to NULL */
 	sdbe->priv->ctags_path = NULL;
 
+	/* identify the scan process with an id. There can be multiple files associated
+	 * within a process. A call to scan_files () will put inside the queue an id
+	 * returned and emitted by scan-end.
+	 */
+	sdbe->priv->scan_process_id_queue = g_async_queue_new ();
+	sdbe->priv->scan_process_id = 1;
+	
 	/* the scan_queue? It will contain mainly 
 	 * ints that refer to the force_update status.
 	 */
-	sdbe->priv->scan_queue = g_async_queue_new ();		
+	sdbe->priv->scan_queue = g_async_queue_new ();
 
 	/* the thread list data */
 	sdbe->priv->thread_list_data = g_queue_new ();
@@ -2422,8 +2439,8 @@
 	
 	/* init memory pool object for GValue strings */
 #ifdef USE_ASYNC_QUEUE	
-	sdbe->priv->mem_pool_string = g_async_queue_new ();
-	sdbe->priv->mem_pool_int = g_async_queue_new ();
+	sdbe->priv->mem_pool_string = g_async_queue_new_full (g_free);
+	sdbe->priv->mem_pool_int = g_async_queue_new_full (g_free);
 #else
 	sdbe->priv->mem_pool_string = g_queue_new ();
 	sdbe->priv->mem_pool_int = g_queue_new ();	
@@ -2535,6 +2552,12 @@
 	sdb_engine_free_cached_queries (dbe);
 	sdb_engine_free_cached_dynamic_queries (dbe);
 	
+	if (priv->scan_process_id_queue)
+	{
+		g_async_queue_unref (priv->scan_process_id_queue);
+		priv->scan_process_id_queue = NULL;
+	}
+	
 	if (priv->scan_queue)
 	{
 		g_async_queue_unref (priv->scan_queue);
@@ -2592,6 +2615,22 @@
 
 	g_tree_destroy (priv->file_symbols_cache);
 
+#ifdef USE_ASYNC_QUEUE	
+	g_async_queue_unref (priv->mem_pool_string);
+	g_async_queue_unref (priv->mem_pool_int);
+	priv->mem_pool_string = NULL;
+	priv->mem_pool_int = NULL;	
+#else
+	g_queue_foreach (priv->mem_pool_string, (GFunc)g_free, NULL);
+	g_queue_free (priv->mem_pool_string);
+	
+	g_queue_foreach (priv->mem_pool_int, (GFunc)g_free, NULL);
+	g_queue_free (priv->mem_pool_int);	
+	
+	priv->mem_pool_string = NULL;
+	priv->mem_pool_int = NULL;	
+#endif
+		
 	g_mutex_free (priv->shutting_mutex);
 	priv->shutting_mutex = NULL;	
 	
@@ -2622,7 +2661,9 @@
 						G_SIGNAL_RUN_FIRST,
 						G_STRUCT_OFFSET (SymbolDBEngineClass, scan_end),
 						NULL, NULL,
-						g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+						g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 
+						1,
+						G_TYPE_INT);
 
 	signals[SYMBOL_INSERTED]
 		= g_signal_new ("symbol-inserted",
@@ -2662,8 +2703,7 @@
 						NULL, NULL,
 						g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 
 						1,
-						G_TYPE_INT);
-	
+						G_TYPE_INT);	
 }
 
 GType
@@ -2856,9 +2896,6 @@
 	return TRUE;
 }
 
-/**
- * Check if the database already exists into the prj_directory
- */
 gboolean
 symbol_db_engine_db_exists (SymbolDBEngine * dbe, const gchar * prj_directory)
 {
@@ -2883,9 +2920,6 @@
 	return TRUE;
 }
 
-/**
- * Check if a file is already present [and scanned] in db.
- */
 gboolean
 symbol_db_engine_file_exists (SymbolDBEngine * dbe, const gchar * abs_file_path)
 {
@@ -2948,9 +2982,6 @@
 	return sdb_engine_disconnect_from_db (dbe);
 }
 
-/**
- * Open or create a new database at given directory.
- */
 gboolean
 symbol_db_engine_open_db (SymbolDBEngine * dbe, const gchar * base_db_path,
 						  const gchar * prj_directory)
@@ -3049,9 +3080,6 @@
 	return TRUE;
 }
 
-/**
- * Test it project_name is created in the opened database
- */
 gboolean
 symbol_db_engine_project_exists (SymbolDBEngine * dbe,	/*gchar* workspace, */
 							   	const gchar * project_name)
@@ -3082,12 +3110,6 @@
 	return TRUE;
 }
 
-
-/**
- * @param workspace Can be NULL. In that case a default workspace will be created, 
- * 					and project will depend on that.
- * @param project Project name. Must NOT be NULL.
- */
 gboolean
 symbol_db_engine_add_new_project (SymbolDBEngine * dbe, const gchar * workspace,
 								  const gchar * project)
@@ -3195,7 +3217,6 @@
 	return TRUE;
 }
 
-
 static gint
 sdb_engine_add_new_language (SymbolDBEngine * dbe, const gchar *language)
 {
@@ -3205,10 +3226,10 @@
 */
 	gint table_id;
 	GValue *value;
-	SymbolDBEnginePriv *priv;
-		
+	SymbolDBEnginePriv *priv;		
+	
 	g_return_val_if_fail (language != NULL, -1);
-
+	
 	priv = dbe->priv;
 
 	MP_LEND_OBJ_STR(priv, value);
@@ -3400,7 +3421,30 @@
 	return TRUE;
 } 
 
-gboolean
+static gint 
+sdb_engine_get_unique_scan_id (SymbolDBEngine * dbe)
+{
+	SymbolDBEnginePriv *priv;
+	gint ret_id;
+	
+	priv = dbe->priv;
+	
+	if (priv->mutex)
+		g_mutex_lock (priv->mutex);
+	
+	priv->scan_process_id++;	
+	ret_id = priv->scan_process_id;
+	
+	/* add the current scan_process id into a queue */
+	g_async_queue_push (priv->scan_process_id_queue, 
+						(gpointer)priv->scan_process_id);
+
+	if (priv->mutex)
+		g_mutex_unlock (priv->mutex);
+	return ret_id;
+}
+							   
+gint
 symbol_db_engine_add_new_files (SymbolDBEngine * dbe, 
 								const gchar * project_name,
 								const GPtrArray * files_path, 
@@ -3412,6 +3456,7 @@
 	GPtrArray * filtered_files_path;
 	GPtrArray * filtered_languages;
 	gboolean ret_code;
+	gint ret_id;
 	
 	g_return_val_if_fail (dbe != NULL, FALSE);
 	g_return_val_if_fail (files_path != NULL, FALSE);
@@ -3468,10 +3513,15 @@
 	 */
 	ret_code = sdb_engine_scan_files_1 (dbe, filtered_files_path, NULL, FALSE);
 	g_ptr_array_free (filtered_files_path, TRUE);
-	return ret_code;
+	
+	if (ret_code == TRUE)
+		ret_id = sdb_engine_get_unique_scan_id (dbe);
+	else
+		ret_id = -1;
+	
+	return ret_id;
 }
 
-
 static inline gint
 sdb_engine_add_new_sym_type (SymbolDBEngine * dbe, const tagEntry * tag_entry)
 {
@@ -3494,7 +3544,7 @@
 	gboolean ret_bool;
 	
 	priv = dbe->priv;
-	
+		
 	/* we assume that tag_entry is != NULL */
 	type = tag_entry->kind;
 	type_name = tag_entry->name;
@@ -3576,7 +3626,7 @@
 	SymbolDBEnginePriv *priv;
 	
 	priv = dbe->priv;
-
+		
 	/* we assume that tag_entry is != NULL */
 	kind_name = tag_entry->kind;
 
@@ -3654,13 +3704,14 @@
 	CREATE TABLE sym_access (access_kind_id integer PRIMARY KEY AUTOINCREMENT,
                          access_name varchar (50) not null unique
                          );
-*/
+*/	
 	const gchar *access;
 	gint table_id;
 	GValue *value;
 	SymbolDBEnginePriv *priv;
 
 	priv = dbe->priv;
+		
 	
 	/* we assume that tag_entry is != NULL */	
 	if ((access = tagsField (tag_entry, "access")) == NULL)
@@ -3733,7 +3784,6 @@
 	return table_id;
 }
 
-
 static gint
 sdb_engine_add_new_sym_implementation (SymbolDBEngine * dbe,
 									   const tagEntry * tag_entry)
@@ -3749,7 +3799,7 @@
 	SymbolDBEnginePriv *priv;
 
 	priv = dbe->priv;
-	
+			
 	/* we assume that tag_entry is != NULL */	
 	if ((implementation = tagsField (tag_entry, "implementation")) == NULL)
 	{
@@ -3821,7 +3871,6 @@
 	return table_id;
 }
 
-
 static void
 sdb_engine_add_new_heritage (SymbolDBEngine * dbe, gint base_symbol_id,
 							 gint derived_symbol_id)
@@ -3838,7 +3887,8 @@
 	GValue *ret_value;
 	gboolean ret_bool;
 	SymbolDBEnginePriv *priv;
-
+	
+	
 	g_return_if_fail (base_symbol_id > 0);
 	g_return_if_fail (derived_symbol_id > 0);
 
@@ -3881,7 +3931,6 @@
 	}	
 }
 
-
 static inline gint
 sdb_engine_add_new_scope_definition (SymbolDBEngine * dbe, const tagEntry * tag_entry,
 									 gint type_table_id)
@@ -3908,6 +3957,7 @@
 
 	priv = dbe->priv;
 	
+	
 	/* This symbol will define a scope which name is tag_entry->name
 	 * For example if we get a tag MyFoo with kind "namespace", it will define 
 	 * the "MyFoo" scope, which type is "namespace MyFoo"
@@ -4027,6 +4077,7 @@
 
 	priv = dbe->priv;
 	
+		
 	if ((field_inherits = tagsField (tag_entry, "inherits")) == NULL)
 	{
 		field_inherits = "";
@@ -4204,7 +4255,7 @@
 	gboolean ret_bool;
 
 	g_return_val_if_fail (G_VALUE_HOLDS_STRING (token_value), FALSE);
-	
+		
 	priv = dbe->priv;
 	tmp_str = g_value_get_string (token_value);
 
@@ -4354,7 +4405,7 @@
 	gint i;
 	
 	priv = dbe->priv;
-
+	
 	DEBUG_PRINT ("%s", "sdb_engine_second_pass_update_scope()");
 	
 	/* temporary unlock. This function may take a while to be completed
@@ -4650,8 +4701,8 @@
 
 	priv = dbe->priv;
 	
-	DEBUG_PRINT ("%s", "sdb_engine_second_pass_do()");
-	
+	DEBUG_PRINT ("%s", "sdb_engine_second_pass_do()");	
+
 	/* prepare for scope second scan */
 	if ((stmt1 =
 		 sdb_engine_get_statement_by_query_id (dbe,
@@ -5103,7 +5154,6 @@
 	return table_id;
 }
 
-
 /**
  * Select * from __tmp_removed and emits removed signals.
  */
@@ -5282,6 +5332,7 @@
  */
 static void
 on_scan_update_files_symbols_end (SymbolDBEngine * dbe, 
+								  gint process_id,
 								  UpdateFileSymbolsData* update_data)
 {
 	SymbolDBEnginePriv *priv;
@@ -5498,18 +5549,15 @@
 	return filter_array;
 }
 
-/**
- * Update symbols of saved files. 
- * @note WARNING: files_path and it's contents will be freed on 
- * on_scan_update_files_symbols_end () callback.
- */
-gboolean
+gint
 symbol_db_engine_update_files_symbols (SymbolDBEngine * dbe, const gchar * project, 
 									   GPtrArray * files_path,
 									   gboolean update_prj_analyse_time)
 {
 	SymbolDBEnginePriv *priv;
 	UpdateFileSymbolsData *update_data;
+	gboolean ret_code;
+	gint ret_id;
 	
 	priv = dbe->priv;
 
@@ -5529,9 +5577,13 @@
 	g_signal_connect (G_OBJECT (dbe), "scan-end",
 					  G_CALLBACK (on_scan_update_files_symbols_end), update_data);
 	
-	sdb_engine_scan_files_1 (dbe, files_path, NULL, TRUE);
-
-	return TRUE;
+	ret_code = sdb_engine_scan_files_1 (dbe, files_path, NULL, TRUE);
+	if (ret_code == TRUE)
+		ret_id = sdb_engine_get_unique_scan_id (dbe);
+	else
+		ret_id = -1;
+	
+	return ret_id;
 }
 
 /* Update symbols of the whole project. It scans all file symbols etc. 
@@ -5726,8 +5778,6 @@
 	return TRUE;
 }
 
-
-/** Remove a file, together with its symbols, from a project. */
 gboolean
 symbol_db_engine_remove_file (SymbolDBEngine * dbe, const gchar * project,
 							  const gchar * file)
@@ -5778,9 +5828,8 @@
 	}	
 }
 
-
 static void
-on_scan_update_buffer_end (SymbolDBEngine * dbe, gpointer data)
+on_scan_update_buffer_end (SymbolDBEngine * dbe, gint process_id, gpointer data)
 {
 	SymbolDBEnginePriv *priv;
 	GPtrArray *files_to_scan;
@@ -5818,11 +5867,6 @@
 	data = files_to_scan = NULL;
 }
 
-/* Update symbols of a file by a memory-buffer to perform a real-time updating 
- * of symbols. 
- * 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.
- */
 gboolean
 symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar *project,
 										GPtrArray * real_files_list,
@@ -5831,6 +5875,8 @@
 {
 	SymbolDBEnginePriv *priv;
 	gint i;
+	gint ret_id;
+	gboolean ret_code;
 	/* array that'll represent the /dev/shm/anjuta-XYZ files */
 	GPtrArray *temp_files;
 	GPtrArray *real_files_on_db;
@@ -5928,8 +5974,12 @@
 	g_signal_connect (G_OBJECT (dbe), "scan-end",
 					  G_CALLBACK (on_scan_update_buffer_end), real_files_list);
 	
-	sdb_engine_scan_files_1 (dbe, temp_files, real_files_on_db, TRUE);
-
+	ret_code = sdb_engine_scan_files_1 (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));
@@ -5941,7 +5991,7 @@
 		g_free (g_ptr_array_index (real_files_on_db, i));
 	
 	g_ptr_array_free (real_files_on_db, TRUE);
-	return TRUE;
+	return ret_id;
 }
 
 gboolean
@@ -5955,7 +6005,6 @@
 	return priv->scanning_status;
 }
 
-/* user must free the returned value */
 gchar*
 symbol_db_engine_get_full_local_path (SymbolDBEngine *dbe, const gchar* file)
 {
@@ -5993,7 +6042,6 @@
 	return relative_path;
 }
 
-
 static inline gint
 sdb_engine_walk_down_scope_path (SymbolDBEngine *dbe, const GPtrArray* scope_path) 
 {
@@ -6090,13 +6138,6 @@
 	return final_definition_id;
 }
 
-
-/**
- * tries 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 NULL if no files are found.
- */
 GPtrArray *
 symbol_db_engine_get_files_with_zero_symbols (SymbolDBEngine *dbe)
 {

Modified: trunk/plugins/symbol-db/symbol-db-engine.h
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine.h	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine.h	Sun Nov 16 14:56:26 2008
@@ -50,7 +50,7 @@
 	
 	/* signals */
 	void (* single_file_scan_end) 	();
-	void (* scan_end) 				();
+	void (* scan_end) 				(gint process_id);
 	void (* symbol_inserted) 		(gint symbol_id);
 	void (* symbol_updated)  		(gint symbol_id);
 	void (* symbol_scope_updated)  	(gint symbol_id);	
@@ -106,7 +106,7 @@
 symbol_db_engine_is_locked (SymbolDBEngine *dbe);
 
 /**
- * Open or create a new database. 
+ * Open or create a new database at given directory. 
  * Be sure to give a base_db_path with the ending '/' for directory.
  * @param base_db_path directory where .anjuta_sym_db.db will be stored. It can be
  *        different from project_directory
@@ -122,16 +122,15 @@
 symbol_db_engine_open_db (SymbolDBEngine *dbe, const gchar* base_db_path,
 						  const gchar * prj_directory);
 
-
 /** Disconnect db, gda client and db_connection */
 gboolean 
 symbol_db_engine_close_db (SymbolDBEngine *dbe);
 
 /**
- * Check if the database already exists into the db_directory
+ * Check if the database already exists into the prj_directory
  */
 gboolean
-symbol_db_engine_db_exists (SymbolDBEngine * dbe, const gchar * db_directory);
+symbol_db_engine_db_exists (SymbolDBEngine * dbe, const gchar * prj_directory);
 
 /**
  * Check if a file is already present [and scanned] in db.
@@ -144,7 +143,13 @@
 symbol_db_engine_add_new_workspace (SymbolDBEngine *dbe, const gchar* workspace);
 
 
-/** Add a new project to workspace to an opened database.*/
+/** 
+ * Add a new project to workspace to an opened database.
+ *
+ * @param workspace Can be NULL. In that case a default workspace will be created, 
+ * 					and project will depend on that.
+ * @param project Project name. Must NOT be NULL.
+ */
 gboolean 
 symbol_db_engine_add_new_project (SymbolDBEngine *dbe, const gchar* workspace, 
 								  const gchar* project);
@@ -152,7 +157,7 @@
 /** 
  * Test project existence. 
  * @return false if project isn't found
- */ 
+ */
 gboolean 
 symbol_db_engine_project_exists (SymbolDBEngine *dbe, /*gchar* workspace, */
 								  const gchar* project_name);
@@ -183,9 +188,9 @@
  * 		  This is done to be uniform to the language-manager plugin.
  * @param force_scan If FALSE a check on db will be done to see
  *		  whether the file is already present or not.
- * @return true is insertion is successful.
+ * @return scan process id if insertion is successful, -1 on error.
  */
-gboolean 
+gint
 symbol_db_engine_add_new_files (SymbolDBEngine *dbe, 
 								const gchar * project_name,
 							    const GPtrArray *files_path,
@@ -211,9 +216,11 @@
 
 /**
  * Update symbols of saved files. 
- * WARNING: files_path and it's contents will be freed on callback.
+ * @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 error.
  */
-gboolean 
+gint
 symbol_db_engine_update_files_symbols (SymbolDBEngine *dbe, const gchar *project, 
 									   GPtrArray *files_path,
 									   gboolean update_prj_analyse_time);
@@ -222,9 +229,11 @@
  * Update symbols of a file by a memory-buffer to perform a real-time updating 
  * of symbols. 
  * 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. 
+ * /home/foouser/fooproject/src/main.c. 
+ * They'll be freed inside this function when the scan has ended. 
+ * @return scan process id if insertion is successful, -1 on error.
  */
-gboolean
+gint
 symbol_db_engine_update_buffer_symbols (SymbolDBEngine * dbe, const gchar * project,
 										GPtrArray * real_files_list,
 										const GPtrArray * text_buffers,

Modified: trunk/plugins/symbol-db/symbol-db-system.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-system.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-system.c	Sun Nov 16 14:56:26 2008
@@ -84,7 +84,7 @@
 				   gpointer user_data);
 
 static void
-on_engine_package_scan_end (SymbolDBEngine *dbe, gpointer user_data);
+on_engine_package_scan_end (SymbolDBEngine *dbe, gint process_id, gpointer user_data);
 
 static void
 destroy_single_scan_data (SingleScanData *ss_data)
@@ -499,7 +499,7 @@
 }
 
 static void
-on_engine_package_scan_end (SymbolDBEngine *dbe, gpointer user_data)
+on_engine_package_scan_end (SymbolDBEngine *dbe, gint process_id, gpointer user_data)
 {
 	SymbolDBSystem *sdbs;
 	SymbolDBSystemPriv *priv;

Modified: trunk/plugins/symbol-db/symbol-db-view-locals.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-view-locals.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-view-locals.c	Sun Nov 16 14:56:26 2008
@@ -999,7 +999,7 @@
 }
 
 static void
-on_scan_end (SymbolDBEngine *dbe, gpointer data)
+on_scan_end (SymbolDBEngine *dbe, gint process_id, gpointer data)
 {
 	SymbolDBViewLocals *dbvl;
 	SymbolDBViewLocalsPriv *priv;
@@ -1469,9 +1469,10 @@
 		}
 
 		/* ok, there may be some symbols left on the waiting_for_list...
- 	 	* launch the callback function by hand, flushing the list it in case 
-	 	*/
-		on_scan_end (dbe, dbvl);		
+ 	 	 * launch the callback function by hand, flushing the list it in case 
+		 * The 0 stays for an unused process_id
+		 */		
+		on_scan_end (dbe, 0, dbvl);		
 	}
 	
 	/* only gtk 2.12 ...

Modified: trunk/plugins/symbol-db/symbol-db-view.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-view.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-view.c	Sun Nov 16 14:56:26 2008
@@ -169,7 +169,7 @@
 }
 
 static void
-on_scan_end (SymbolDBEngine *dbe, gpointer data)
+on_scan_end (SymbolDBEngine *dbe, gint process_id, gpointer data)
 {
 	SymbolDBView *dbv;
 	SymbolDBViewPriv *priv;



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