[anjuta] symbol-db: Added new apis to sdb core and util.



commit 799cbbe58af95b445ee396f501e125d0e6350672
Author: Massimo Corà <mcora src gnome org>
Date:   Fri Jul 24 11:14:11 2009 +0200

    symbol-db: Added new apis to sdb core and util.
    
    Modified also the benchmark program to reflect the changes.

 plugins/symbol-db/benchmark/Makefile.am    |    3 +-
 plugins/symbol-db/benchmark/benchmark.c    |   63 ++++-----------------------
 plugins/symbol-db/symbol-db-engine-core.c  |   34 ++++++++++++++-
 plugins/symbol-db/symbol-db-engine-core.h  |    7 +++
 plugins/symbol-db/symbol-db-engine-priv.h  |    1 +
 plugins/symbol-db/symbol-db-engine-utils.c |   43 +++++++++++++++++++
 plugins/symbol-db/symbol-db-engine-utils.h |   18 ++++++--
 7 files changed, 108 insertions(+), 61 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/Makefile.am b/plugins/symbol-db/benchmark/Makefile.am
index 29b1444..1eb94e9 100644
--- a/plugins/symbol-db/benchmark/Makefile.am
+++ b/plugins/symbol-db/benchmark/Makefile.am
@@ -30,7 +30,8 @@ benchmark_SOURCES = \
 	../symbol-db-engine-iterator.h \
 	../symbol-db-engine-queries.h \
 	../libgda-extra/gda-data-model-concat.c \
-	../libgda-extra/gda-data-model-concat.h
+	../libgda-extra/gda-data-model-concat.h \
+	../symbol-db-engine.h
  
 
 benchmark_LDFLAGS = \
diff --git a/plugins/symbol-db/benchmark/benchmark.c b/plugins/symbol-db/benchmark/benchmark.c
index af2a771..2d1dcc5 100644
--- a/plugins/symbol-db/benchmark/benchmark.c
+++ b/plugins/symbol-db/benchmark/benchmark.c
@@ -1,7 +1,7 @@
 /* Symbol db performance stress test */
 
 
-#include <../symbol-db-engine.h>
+#include "../symbol-db-engine.h"
 #include <gtk/gtk.h>
 
 static void on_single_file_scan_end (SymbolDBEngine* engine, GPtrArray* files)
@@ -10,67 +10,26 @@ static void on_single_file_scan_end (SymbolDBEngine* engine, GPtrArray* files)
 	g_message ("Finished [%d]: %s", i, (gchar*)g_ptr_array_index (files, i));
 	i++;
 }
-
-static GPtrArray* get_files (const gchar* dir)
-{
-	GPtrArray* files = g_ptr_array_new();
-	GFile *file;
-	GFileEnumerator *enumerator;
-	GFileInfo* info;
-	GError *error = NULL;
-	
-	file = g_file_new_for_commandline_arg (dir);
-	enumerator = g_file_enumerate_children (file, 
-			G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
-			G_FILE_ATTRIBUTE_STANDARD_NAME,
-			G_FILE_QUERY_INFO_NONE,
-			NULL, &error);
-
-	if (!enumerator)
-	{
-		g_warning ("Could not enumerate: %s %s\n", 
-				g_file_get_path (file),
-				error->message);
-		g_error_free (error);
-		g_object_unref (file);
-		return files;
-	}
-
-	for (info = g_file_enumerator_next_file (enumerator, NULL, NULL); info != NULL; 
-			info = g_file_enumerator_next_file (enumerator, NULL, NULL))
-	{
-		const gchar *mime_type = g_file_info_get_content_type (info);
-		if (!mime_type)
-			continue;
-		if (g_str_equal (mime_type, "text/x-csrc") ||
-				g_str_equal (mime_type, "text/x-chdr"))
-		{
-			g_message ("File: %s", g_file_info_get_name (info));
-			g_ptr_array_add (files, g_build_filename (dir, g_file_info_get_name (info), NULL));
-		}
-	}
-	
-	return files;
-}	
 	
 static void 
 on_scan_end (SymbolDBEngine* engine, gpointer user_data)
 {
 	g_message ("on_scan_end  ()");
-//	g_object_unref (engine);
-//  	exit(0);
+	symbol_db_engine_close_db (engine);
+	g_object_unref (engine);
+  	exit(0);
 }
 
 int main (int argc, char** argv)
 {
-  SymbolDBEngine* engine;
-  GPtrArray* files;
+  	SymbolDBEngine* engine;
+  	GPtrArray* files;
 	GPtrArray* languages = g_ptr_array_new();
 	const gchar* root_dir;
 	int i;
 	
-  gtk_init(&argc, &argv);
-  g_thread_init (NULL);
+  	gtk_init(&argc, &argv);
+  	g_thread_init (NULL);
 	gda_init ();
 	
 	if (argc != 2)
@@ -81,8 +40,6 @@ int main (int argc, char** argv)
 	root_dir = argv[1];
 	
     engine = symbol_db_engine_new ("/usr/bin/ctags");
-    
-	
   
 	if (!symbol_db_engine_open_db (engine, root_dir, root_dir))
 	{
@@ -92,7 +49,7 @@ int main (int argc, char** argv)
 
 	symbol_db_engine_add_new_project (engine, NULL, root_dir);
 			
-	files = get_files (root_dir);
+	files = symbol_db_util_get_c_source_files (root_dir);
 	for (i = 0; i < files->len; i++)
 		g_ptr_array_add (languages, "C");
 	
@@ -100,7 +57,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 (engine, root_dir, files, languages, TRUE);
+	symbol_db_engine_add_new_files (engine, root_dir, files, languages, TRUE);	
 	
 	gtk_main();
 	
diff --git a/plugins/symbol-db/symbol-db-engine-core.c b/plugins/symbol-db/symbol-db-engine-core.c
index 4110b9a..281903e 100644
--- a/plugins/symbol-db/symbol-db-engine-core.c
+++ b/plugins/symbol-db/symbol-db-engine-core.c
@@ -1995,6 +1995,9 @@ sdb_engine_init (SymbolDBEngine * object)
 	/* set the ctags executable path to NULL */
 	sdbe->priv->ctags_path = NULL;
 
+	/* NULL the name of the default db */
+	sdbe->priv->anjuta_db_file = 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.
@@ -2550,6 +2553,12 @@ sdb_engine_finalize (GObject * object)
 	
 	sdb_engine_clear_caches (dbe);
 
+	g_free (priv->anjuta_db_file);
+	priv->anjuta_db_file = NULL;
+	
+	g_free (priv->ctags_path);
+	priv->ctags_path = NULL;
+	
 	g_tree_destroy (priv->file_symbols_cache);
 
 #ifdef USE_ASYNC_QUEUE	
@@ -2722,6 +2731,7 @@ symbol_db_engine_new (const gchar * ctags_path)
 	
 	priv = sdbe->priv;
 	priv->mutex = g_mutex_new ();
+	priv->anjuta_db_file = g_strdup (ANJUTA_DB_FILE);
 
 	/* set the mandatory ctags_path */
 	if (!symbol_db_engine_set_ctags_path (sdbe, ctags_path))
@@ -2732,6 +2742,24 @@ symbol_db_engine_new (const gchar * ctags_path)
 	return sdbe;
 }
 
+SymbolDBEngine* 
+symbol_db_engine_new_full (const gchar * ctags_path, const gchar * database_name)
+{
+	SymbolDBEngine* dbe;
+	SymbolDBEnginePriv* priv;
+
+	g_return_val_if_fail (database_name != NULL, NULL);
+	dbe = symbol_db_engine_new (ctags_path);
+
+	g_return_val_if_fail (dbe != NULL, NULL);
+
+	priv = dbe->priv;
+	g_free (priv->anjuta_db_file);
+	priv->anjuta_db_file = g_strdup (database_name);
+
+	return dbe;
+}
+
 /**
  * Set some default parameters to use with the current database.
  */
@@ -2870,7 +2898,7 @@ symbol_db_engine_db_exists (SymbolDBEngine * dbe, const gchar * prj_directory)
 
 	/* check whether the db filename already exists.*/
 	gchar *tmp_file = g_strdup_printf ("%s/%s.db", prj_directory,
-									   ANJUTA_DB_FILE);
+									   priv->anjuta_db_file);
 	
 	if (g_file_test (tmp_file, G_FILE_TEST_EXISTS) == FALSE)
 	{
@@ -3044,7 +3072,7 @@ symbol_db_engine_open_db (SymbolDBEngine * dbe, const gchar * base_db_path,
 	/* check whether the db filename already exists. If it's not the case
 	 * create the tables for the database. */
 	gchar *tmp_file = g_strdup_printf ("%s/%s.db", base_db_path,
-									   ANJUTA_DB_FILE);
+									   priv->anjuta_db_file);
 
 	if (g_file_test (tmp_file, G_FILE_TEST_EXISTS) == FALSE)
 	{
@@ -3059,7 +3087,7 @@ symbol_db_engine_open_db (SymbolDBEngine * dbe, const gchar * base_db_path,
 	priv->project_directory = g_strdup (prj_directory);
 
 	cnc_string = g_strdup_printf ("DB_DIR=%s;DB_NAME=%s", base_db_path,
-								ANJUTA_DB_FILE);
+								priv->anjuta_db_file);
 
 	DEBUG_PRINT ("Connecting to "
 				 "database with %s...", cnc_string);
diff --git a/plugins/symbol-db/symbol-db-engine-core.h b/plugins/symbol-db/symbol-db-engine-core.h
index 68ebd5d..1043a62 100644
--- a/plugins/symbol-db/symbol-db-engine-core.h
+++ b/plugins/symbol-db/symbol-db-engine-core.h
@@ -71,12 +71,19 @@ GType sdb_engine_get_type (void) G_GNUC_CONST;
 
 /**
  * Create a new instance of an engine. 
+ * Default name of database is ANJUTA_DB_FILE (see symbol-db-engine-priv.h)
  * @param ctags_path is mandatory. No NULL value is accepted.
  */
 SymbolDBEngine* 
 symbol_db_engine_new (const gchar * ctags_path);
 
 /**
+ * similar to symbol_db_engine_new but you can specify the name of resulting db.
+ */
+SymbolDBEngine* 
+symbol_db_engine_new_full (const gchar * ctags_path, const gchar * database_name);
+
+/**
  * Set a new path for ctags executable.
  */ 
 gboolean
diff --git a/plugins/symbol-db/symbol-db-engine-priv.h b/plugins/symbol-db/symbol-db-engine-priv.h
index a14fa08..25c45bb 100644
--- a/plugins/symbol-db/symbol-db-engine-priv.h
+++ b/plugins/symbol-db/symbol-db-engine-priv.h
@@ -261,6 +261,7 @@ typedef enum {
 /* the SymbolDBEngine Private structure */
 struct _SymbolDBEnginePriv
 {
+	gchar *anjuta_db_file;
 	gchar *ctags_path;
 	
 	GdaConnection *db_connection;
diff --git a/plugins/symbol-db/symbol-db-engine-utils.c b/plugins/symbol-db/symbol-db-engine-utils.c
index 6b00d27..9e5a469 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.c
+++ b/plugins/symbol-db/symbol-db-engine-utils.c
@@ -447,3 +447,46 @@ symbol_db_util_get_sym_type_conversion_hash (SymbolDBEngine *dbe)
 		
 	return priv->sym_type_conversion_hash;
 }
+
+GPtrArray* 
+symbol_db_util_get_c_source_files (const gchar* dir)
+{
+	GPtrArray* files = g_ptr_array_new();
+	GFile *file;
+	GFileEnumerator *enumerator;
+	GFileInfo* info;
+	GError *error = NULL;
+	
+	file = g_file_new_for_commandline_arg (dir);
+	enumerator = g_file_enumerate_children (file, 
+			G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+			G_FILE_ATTRIBUTE_STANDARD_NAME,
+			G_FILE_QUERY_INFO_NONE,
+			NULL, &error);
+
+	if (!enumerator)
+	{
+		g_warning ("Could not enumerate: %s %s\n", 
+				g_file_get_path (file),
+				error->message);
+		g_error_free (error);
+		g_object_unref (file);
+		return files;
+	}
+
+	for (info = g_file_enumerator_next_file (enumerator, NULL, NULL); info != NULL; 
+			info = g_file_enumerator_next_file (enumerator, NULL, NULL))
+	{
+		const gchar *mime_type = g_file_info_get_content_type (info);
+		if (!mime_type)
+			continue;
+		if (g_str_equal (mime_type, "text/x-csrc") ||
+				g_str_equal (mime_type, "text/x-chdr"))
+		{
+			DEBUG_PRINT ("File: %s", g_file_info_get_name (info));
+			g_ptr_array_add (files, g_build_filename (dir, g_file_info_get_name (info), NULL));
+		}
+	}
+	
+	return files;
+}
diff --git a/plugins/symbol-db/symbol-db-engine-utils.h b/plugins/symbol-db/symbol-db-engine-utils.h
index 1e455d5..080f7ad 100644
--- a/plugins/symbol-db/symbol-db-engine-utils.h
+++ b/plugins/symbol-db/symbol-db-engine-utils.h
@@ -49,7 +49,7 @@ symbol_db_glist_compare_func (gconstpointer a, gconstpointer b);
  * User must care to free the returned string.
  * @param db_file Relative path inside project.
  */
-gchar*
+gchar *
 symbol_db_util_get_full_local_path (SymbolDBEngine *dbe, const gchar* db_file);
 
 /**
@@ -57,14 +57,14 @@ symbol_db_util_get_full_local_path (SymbolDBEngine *dbe, const gchar* db_file);
  * /home/user/foo_project/src/foo.c returned file should be /src/foo.c.
  * Return NULL on error.
  */
-gchar*
+gchar *
 symbol_db_util_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_file_path);
 
 /** 
  * Hash table that converts from a char like 'class' 'struct' etc to an 
  * IANJUTA_SYMBOL_TYPE
  */
-const GHashTable*
+const GHashTable *
 symbol_db_util_get_sym_type_conversion_hash (SymbolDBEngine *dbe);
 
 /**
@@ -86,7 +86,7 @@ symbol_db_util_get_files_with_zero_symbols (SymbolDBEngine *dbe);
  * @return The pixbufs. It will initialize pixbufs first if they weren't before
  * @param node_access can be NULL.
  */
-const GdkPixbuf* 
+const GdkPixbuf *
 symbol_db_util_get_pixbuf  (const gchar *node_type, const gchar *node_access);
 
 /**
@@ -98,4 +98,14 @@ symbol_db_util_get_pixbuf  (const gchar *node_type, const gchar *node_access);
 gboolean
 symbol_db_util_is_pattern_exact_match (const gchar *pattern);
 
+/**
+ * This function gets all the .c/.h source files in the specified dir and returns
+ * the GPtrArray associated.
+ * 
+ * @param dir Directory of the files
+ * @return A GPtrArray composed by gchar * strings like "dir + g_file_info_get_name ()"
+ */
+GPtrArray * 
+symbol_db_util_get_c_source_files (const gchar* dir);
+
 #endif



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