[anjuta] am: Avoid using g_type_query which is not working with dynamic type



commit 0655f7eacb04bbc7467600196ad56f6bc63df8da
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sat Nov 20 21:11:59 2010 +0100

    am: Avoid using g_type_query which is not working with dynamic type

 plugins/am-project/am-node.c    |   77 ++++++++++++++++++++++++++++++++++--
 plugins/am-project/am-node.h    |    9 +++-
 plugins/am-project/am-project.c |   81 ++++++++++++++++++++-------------------
 3 files changed, 121 insertions(+), 46 deletions(-)
---
diff --git a/plugins/am-project/am-node.c b/plugins/am-project/am-node.c
index 501fcae..f759d3b 100644
--- a/plugins/am-project/am-node.c
+++ b/plugins/am-project/am-node.c
@@ -263,6 +263,7 @@ amp_root_set_configure (AnjutaAmRootNode *root, GFile *configure, GObject* proje
 {
 	if (root->configure != NULL) g_object_unref (root->configure);
 	if (root->configure_file != NULL) anjuta_token_file_free (root->configure_file);
+	if (root->monitor) g_object_unref (root->monitor);
 	if (configure != NULL)
 	{
 		root->configure_file = anjuta_token_file_new (configure);
@@ -285,7 +286,6 @@ amp_root_set_configure (AnjutaAmRootNode *root, GFile *configure, GObject* proje
 	{
 		root->configure_file = NULL;
 		root->configure = NULL;
-		if (root->monitor) g_object_unref (root->monitor);
 		root->monitor = NULL;
 	}
 	
@@ -305,10 +305,13 @@ amp_root_get_configure_token (AnjutaAmRootNode *root)
 }
 
 void
-amp_root_update_monitor (AnjutaAmRootNode *root)
+amp_root_update_node (AnjutaAmRootNode *root, AnjutaAmRootNode *new_root)
 {
-	if (root->monitor != NULL) g_object_unref (root->monitor);
+	if (root->configure != NULL) g_object_unref (root->configure);
+	if (root->configure_file != NULL) anjuta_token_file_free (root->configure_file);
+	if (root->monitor) g_object_unref (root->monitor);
 
+	root->configure = new_root->configure;
 	if (root->configure != NULL)
 	{
 		root->monitor = g_file_monitor_file (root->configure,
@@ -323,6 +326,15 @@ amp_root_update_monitor (AnjutaAmRootNode *root)
 					  root);
 		}
 	}
+	else
+	{
+		root->monitor = NULL;
+	}
+	new_root->configure = NULL;
+	root->configure_file = new_root->configure_file;
+	new_root->configure_file = NULL;
+	root->configure_token = new_root->configure_token;
+	root->project = new_root->project;
 }
 
 /* GObjet implementation
@@ -399,6 +411,12 @@ amp_module_get_token (AnjutaAmModuleNode *node)
 	return node->module;
 }
 
+void
+amp_module_update_node (AnjutaAmModuleNode *node, AnjutaAmModuleNode *new_node)
+{
+	node->module = new_node->module;
+}
+
 AnjutaAmModuleNode*
 amp_module_new (const gchar *name, GError **error)
 {
@@ -509,6 +527,15 @@ amp_package_add_token (AnjutaAmPackageNode *node, AnjutaToken *token)
 	node->token = token;
 }
 
+void
+amp_package_update_node (AnjutaAmPackageNode *node, AnjutaAmPackageNode *new_node)
+{
+	node->token = new_node->token;
+	g_free (node->version);
+	node->version = new_node->version;
+	new_node->version = NULL;
+}
+
 
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
@@ -673,10 +700,30 @@ amp_group_get_makefile_name (AnjutaAmGroupNode *group)
 }
 
 void
-amp_group_update_monitor (AnjutaAmGroupNode *group)
+amp_group_update_node (AnjutaAmGroupNode *group, AnjutaAmGroupNode *new_group)
 {
+	gint i;
+	
 	if (group->monitor != NULL) g_object_unref (group->monitor);
-
+	if (group->makefile != NULL) g_object_unref (group->makefile);
+	if (group->tfile) anjuta_token_file_free (group->tfile);
+	for (i = 0; i < AM_GROUP_TOKEN_LAST; i++)
+	{
+		if (group->tokens[i] != NULL) g_list_free (group->tokens[i]);
+	}
+	if (group->variables) g_hash_table_destroy (group->variables);
+
+	group->dist_only = new_group->dist_only;
+	group->makefile = new_group->makefile;
+	new_group->makefile = NULL;
+	group->tfile = new_group->tfile;
+	new_group->tfile = NULL;
+	memcpy (group->tokens, new_group->tokens, sizeof (group->tokens));
+	memset (new_group->tokens, 0, sizeof (new_group->tokens));
+	group->variables = new_group->variables;
+	new_group->variables = NULL;
+	group->project = new_group->project;
+	
 	if (group->makefile != NULL)
 	{
 		group->monitor = g_file_monitor_file (group->makefile, 
@@ -691,6 +738,7 @@ amp_group_update_monitor (AnjutaAmGroupNode *group)
 					  group);
 		}
 	}
+
 }
 
 AnjutaAmGroupNode*
@@ -844,6 +892,19 @@ amp_target_get_next_token_type (AnjutaAmTargetNode *target, AnjutaTokenType type
 	return tagged_token_list_next (target->tokens, type);
 }
 
+void
+amp_target_update_node (AnjutaAmTargetNode *node, AnjutaAmTargetNode *new_node)
+{
+	g_free (node->install);
+	g_list_free (node->tokens);
+
+	node->install = new_node->install;
+	new_node->install = NULL;
+	node->flags = new_node->flags;
+	node->tokens = new_node->tokens;
+	new_node->tokens = NULL;
+}
+
 AnjutaAmTargetNode*
 amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags, GError **error)
 {
@@ -973,6 +1034,12 @@ amp_source_add_token (AnjutaAmSourceNode *node, AnjutaToken *token)
 	node->token = token;
 }
 
+void
+amp_source_update_node (AnjutaAmSourceNode *node, AnjutaAmSourceNode *new_node)
+{
+	node->token = new_node->token;
+}
+
 AnjutaProjectNode*
 amp_source_new (GFile *file, GError **error)
 {
diff --git a/plugins/am-project/am-node.h b/plugins/am-project/am-node.h
index fc04169..8279807 100644
--- a/plugins/am-project/am-node.h
+++ b/plugins/am-project/am-node.h
@@ -50,18 +50,21 @@ void amp_root_clear (AnjutaAmRootNode *node);
 AnjutaTokenFile* amp_root_set_configure (AnjutaAmRootNode *node, GFile *configure, GObject* project);
 gboolean amp_root_update_configure (AnjutaAmRootNode *group, AnjutaToken *token);
 AnjutaToken* amp_root_get_configure_token (AnjutaAmRootNode *root);
-void amp_root_update_monitor (AnjutaAmRootNode *node);
+void amp_root_update_node (AnjutaAmRootNode *node, AnjutaAmRootNode *new_node);
+
 
 AnjutaAmModuleNode* amp_module_new (const gchar *name, GError **error);
 void amp_module_free (AnjutaAmModuleNode *node);
 AnjutaToken *amp_module_get_token (AnjutaAmModuleNode *node);
 void amp_module_add_token (AnjutaAmModuleNode *group, AnjutaToken *token);
+void amp_module_update_node (AnjutaAmModuleNode *node, AnjutaAmModuleNode *new_node);
 
 AnjutaAmPackageNode* amp_package_new (const gchar *name, GError **error);
 void amp_package_free (AnjutaAmPackageNode *node);
 void amp_package_set_version (AnjutaAmPackageNode *node, const gchar *compare, const gchar *version);
 AnjutaToken *amp_package_get_token (AnjutaAmPackageNode *node);
 void amp_package_add_token (AnjutaAmPackageNode *node, AnjutaToken *token);
+void amp_package_update_node (AnjutaAmPackageNode *node, AnjutaAmPackageNode *new_node);
 
 
 void amp_group_add_token (AnjutaAmGroupNode *group, AnjutaToken *token, AmpGroupTokenCategory category);
@@ -72,9 +75,9 @@ AnjutaTokenFile* amp_group_set_makefile (AnjutaAmGroupNode *group, GFile *makefi
 AnjutaToken* amp_group_get_makefile_token (AnjutaAmGroupNode *group);
 gchar *amp_group_get_makefile_name (AnjutaAmGroupNode *group);
 gboolean amp_group_update_makefile (AnjutaAmGroupNode *group, AnjutaToken *token);
-void amp_group_update_monitor (AnjutaAmGroupNode *node);
 AnjutaAmGroupNode* amp_group_new (GFile *file, gboolean dist_only, GError **error);
 void amp_group_free (AnjutaAmGroupNode *node);
+void amp_group_update_node (AnjutaAmGroupNode *node, AnjutaAmGroupNode *new_node);
 
 typedef enum _AmpTargetFlag
 {
@@ -95,11 +98,13 @@ AnjutaTokenType amp_target_get_first_token_type (AnjutaAmTargetNode *target);
 AnjutaTokenType amp_target_get_next_token_type (AnjutaAmTargetNode *target, AnjutaTokenType type);
 AnjutaAmTargetNode* amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags, GError **error);
 void amp_target_free (AnjutaAmTargetNode *node);
+void amp_target_update_node (AnjutaAmTargetNode *node, AnjutaAmTargetNode *new_node);
 
 AnjutaProjectNode* amp_source_new (GFile *file, GError **error);
 void amp_source_free (AnjutaAmSourceNode *node);
 AnjutaToken *amp_source_get_token (AnjutaAmSourceNode *node);
 void amp_source_add_token (AnjutaAmSourceNode *node, AnjutaToken *token);
+void amp_source_update_node (AnjutaAmSourceNode *node, AnjutaAmSourceNode *new_node);
 
 G_END_DECLS
 
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 11a0632..4642481 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -1418,7 +1418,7 @@ amp_project_compare_node (AnjutaProjectNode *old_node, AnjutaProjectNode *new_no
 	file1 = anjuta_project_node_get_file (old_node);
 	file2 = anjuta_project_node_get_file (new_node);
 
-	return (anjuta_project_node_get_node_type (old_node) == anjuta_project_node_get_node_type (new_node))
+	return (anjuta_project_node_get_full_type (old_node) == anjuta_project_node_get_full_type (new_node))
 		&& ((name1 == NULL) || (name2 == NULL) || (strcmp (name1, name2) == 0))
 		&& ((file1 == NULL) || (file2 == NULL) || g_file_equal (file1, file2)) ? 0 : 1;
 }
@@ -1480,7 +1480,7 @@ amp_project_map_node (AnjutaProjectNode *old_node, AnjutaProjectNode *new_node)
 
 
 static void
-amp_project_replace_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_node, GHashTable *map)
+amp_project_update_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_node, GHashTable *map)
 {
 	if (old_node == NULL)
 	{
@@ -1491,33 +1491,42 @@ amp_project_replace_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_no
 	{
 		if (old_node != new_node)
 		{
-			GTypeQuery type_info;
-			gchar *data;
-
-			g_type_query (G_TYPE_FROM_INSTANCE (old_node), &type_info);
-
-			/* Swap new and old node */
-			data = g_new0 (gchar, type_info.instance_size - sizeof (GInitiallyUnowned));
-			memcpy (data, (gchar *)old_node + sizeof (GInitiallyUnowned), type_info.instance_size - sizeof (GInitiallyUnowned));
-			memcpy ((gchar *)old_node + sizeof (GInitiallyUnowned), (gchar *)new_node + sizeof (GInitiallyUnowned),  type_info.instance_size - sizeof (GInitiallyUnowned));
-			memcpy ((gchar *)new_node + sizeof (GInitiallyUnowned), data,  type_info.instance_size - sizeof (GInitiallyUnowned));
-			g_free (data);
-
-			/* Get old file */
-			if (old_node->file != NULL) g_object_unref (old_node->file);
-			old_node->file = new_node->file;
-			new_node->file = NULL;
-
-			/* Update file monitor if it is a group */
-			if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_GROUP)
-			{
-				amp_group_update_monitor (ANJUTA_AM_GROUP_NODE (old_node));
-			}
-			else if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_ROOT)
+			GList *properties;
+		
+			switch (anjuta_project_node_get_node_type (old_node))
 			{
-				amp_root_update_monitor (ANJUTA_AM_ROOT_NODE (old_node));
+				case ANJUTA_PROJECT_GROUP:
+					amp_group_update_node (ANJUTA_AM_GROUP_NODE (old_node), ANJUTA_AM_GROUP_NODE (new_node));
+					break;
+				case ANJUTA_PROJECT_TARGET:
+					amp_target_update_node (ANJUTA_AM_TARGET_NODE (old_node), ANJUTA_AM_TARGET_NODE (new_node));
+					break;
+				case ANJUTA_PROJECT_SOURCE:
+					amp_source_update_node (ANJUTA_AM_SOURCE_NODE (old_node), ANJUTA_AM_SOURCE_NODE (new_node));
+					break;
+				case ANJUTA_PROJECT_MODULE:
+					amp_module_update_node (ANJUTA_AM_MODULE_NODE (old_node), ANJUTA_AM_MODULE_NODE (new_node));
+					break;
+				case ANJUTA_PROJECT_PACKAGE:
+					amp_package_update_node (ANJUTA_AM_PACKAGE_NODE (old_node), ANJUTA_AM_PACKAGE_NODE (new_node));
+					break;
+				case ANJUTA_PROJECT_ROOT:
+					amp_root_update_node (ANJUTA_AM_ROOT_NODE (old_node), ANJUTA_AM_ROOT_NODE (new_node));
+					break;
+				default:
+					break;
 			}
-			
+
+			/* Swap custom properties */
+			properties = old_node->custom_properties;
+			old_node->custom_properties = new_node->custom_properties;
+			new_node->custom_properties = properties;
+
+			old_node->parent = new_node->parent;
+			old_node->children = new_node->children;
+			old_node->next = new_node->next;
+			old_node->prev = new_node->prev;
+		
 			/* Unlink old node and free it */
 			new_node->parent = NULL;
 			new_node->children = NULL;
@@ -1527,7 +1536,7 @@ amp_project_replace_node (AnjutaProjectNode *new_node, AnjutaProjectNode *old_no
 
 			new_node = old_node;
 		}
-		
+
 		/* Update links */
 		old_node = g_hash_table_lookup (map, new_node->parent);
 		if (old_node != NULL) new_node->parent = old_node;
@@ -1544,19 +1553,13 @@ static AnjutaProjectNode *
 amp_project_duplicate_node (AnjutaProjectNode *old_node)
 {
 	AnjutaProjectNode *new_node;
-	GTypeQuery type_info;
 
 	/* Create new node */
 	new_node = g_object_new (G_TYPE_FROM_INSTANCE (old_node), NULL);
-	g_type_query (G_TYPE_FROM_INSTANCE (old_node), &type_info);
-	memcpy ((gchar *)new_node + sizeof (GInitiallyUnowned), (gchar *)old_node + sizeof (GInitiallyUnowned),  type_info.instance_size - sizeof (GInitiallyUnowned));
-	new_node->custom_properties = NULL;
-	if (new_node->file != NULL) new_node->file = g_file_dup (new_node->file);
-	if (new_node->name != NULL) new_node->name = g_strdup (new_node->name);
-	new_node->children = NULL;
-
-	/* Remove loaded node specific data */
-	memset ((gchar *)old_node + sizeof (AnjutaProjectNode), 0, type_info.instance_size - sizeof (AnjutaProjectNode));
+	if (old_node->file != NULL) new_node->file = g_file_dup (old_node->file);
+	if (old_node->name != NULL) new_node->name = g_strdup (old_node->name);
+	new_node->type = old_node->type;
+	new_node->parent = old_node->parent;
 
 	return new_node;
 }
@@ -2253,7 +2256,7 @@ amp_load_complete (PmJob *job)
 	GHashTable *map;
 
 	map = amp_project_map_node (job->node, job->proxy);
-	g_hash_table_foreach (map, (GHFunc)amp_project_replace_node, map);
+	g_hash_table_foreach (map, (GHFunc)amp_project_update_node, map);
 	job->node->parent = job->parent;
 	job->proxy->parent = NULL;
 	g_hash_table_destroy (map);



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