Beispiel #1
0
GPtrArray *generate_target_array(const gchar *manifest_file)
{
    /* Declarations */
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;
    GPtrArray *targets_array = NULL;
    
    /* Parse the XML document */
    
    if((doc = xmlParseFile(manifest_file)) == NULL)
    {
	g_printerr("Error with parsing the manifest XML file!\n");
	xmlCleanupParser();
	return NULL;
    }
    
    /* Retrieve root element */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
	g_printerr("The manifest XML file is empty!\n");
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return NULL;
    }
    
    /* Query the targets elements */
    result = executeXPathQuery(doc, "/manifest/targets/target");
    
    /* Iterate over all the targets elements and add them to the array */
    
    if(result)
    {
	unsigned int i;
	xmlNodeSetPtr nodeset = result->nodesetval;
	
	/* Create a targets array */
	targets_array = g_ptr_array_new();
	
	/* Iterate over all the target elements */
	for(i = 0; i < nodeset->nodeNr; i++)
	{
	    xmlNodePtr targets_children = nodeset->nodeTab[i]->children;
	    Target *target = (Target*)g_malloc(sizeof(Target));
	
	    gchar *system = NULL;
	    gchar *client_interface = NULL;
	    gchar *target_property = NULL;
	    int num_of_cores = 0;
	    int available_cores = 0;
	    GPtrArray *properties = NULL;
	    GPtrArray *containers = NULL;
	
	    while(targets_children != NULL)
	    {
	        if(xmlStrcmp(targets_children->name, (xmlChar*) "system") == 0)
	            system = duplicate_node_text(targets_children);
	        else if(xmlStrcmp(targets_children->name, (xmlChar*) "clientInterface") == 0)
	            client_interface = duplicate_node_text(targets_children);
	        else if(xmlStrcmp(targets_children->name, (xmlChar*) "targetProperty") == 0)
	            target_property = duplicate_node_text(targets_children);
	        else if(xmlStrcmp(targets_children->name, (xmlChar*) "numOfCores") == 0)
	        {
	            gchar *num_of_cores_str = duplicate_node_text(targets_children);
	            
	            if(num_of_cores_str != NULL)
	            {
	                num_of_cores = atoi((char*)num_of_cores_str);
	                available_cores = num_of_cores;
	                g_free(num_of_cores_str);
	            }
	        }
	        else if(xmlStrcmp(targets_children->name, (xmlChar*) "properties") == 0)
	        {
	            xmlNodePtr properties_children = targets_children->children;
	            properties = g_ptr_array_new();
	            
	            /* Iterate over all properties */
	            while(properties_children != NULL)
	            {
	                TargetProperty *target_property = (TargetProperty*)g_malloc(sizeof(TargetProperty));
	                target_property->name = g_strdup((gchar*)properties_children->name);
	                target_property->value = duplicate_node_text(properties_children);
	                g_ptr_array_add(properties, target_property);
	                
	                properties_children = properties_children->next;
	            }
	            
	            /* Sort the target properties */
	            g_ptr_array_sort(properties, (GCompareFunc)compare_target_property);
	        }
	        else if(xmlStrcmp(targets_children->name, (xmlChar*) "containers") == 0)
	        {
	            xmlNodePtr container_children = targets_children->children;
	            containers = g_ptr_array_new();
	            
	            /* Iterate over all containers */
	            while(container_children != NULL)
	            {
	                Container *container = (Container*)g_malloc(sizeof(Container));
	                container->name = g_strdup((gchar*)container_children->name);
	                
	                if(container_children->children == NULL)
	                    container->properties = NULL;
	                else
	                {
	                    xmlNodePtr properties_children = container_children->children;
	                    GPtrArray *properties = g_ptr_array_new();
	                    
	                    /* Iterate over all properties */
	                    while(properties_children != NULL)
	                    {
	                        TargetProperty *target_property = (TargetProperty*)g_malloc(sizeof(TargetProperty));
	                        target_property->name = g_strdup((gchar*)properties_children->name);
	                        target_property->value = duplicate_node_text(properties_children);
	                
	                        g_ptr_array_add(properties, target_property);
	                
	                        properties_children = properties_children->next;
	                    }
	                    
	                    /* Sort the target properties */
	                    g_ptr_array_sort(properties, (GCompareFunc)compare_target_property);
	                    
	                    container->properties = properties;
	                }
	                
	                g_ptr_array_add(containers, container);
	                
	                container_children = container_children->next;
	            }
	            
	            /* Sort the containers */
	            g_ptr_array_sort(containers, (GCompareFunc)compare_container);
	        }
	        
	        targets_children = targets_children->next;
	    }
	    
	    target->system = system;
	    target->client_interface = client_interface;
	    target->target_property = target_property;
	    target->num_of_cores = num_of_cores;
	    target->available_cores = available_cores;
	    target->properties = properties;
	    target->containers = containers;
	    
	    if(target->system == NULL || target->client_interface == NULL || target->target_property == NULL)
	    {
	        /* Check if all mandatory properties have been provided */
	        g_printerr("A mandatory property seems to be missing. Have you provided a correct\n");
	        g_printerr("manifest file?\n");
	        delete_target_array(targets_array);
	        targets_array = NULL;
	        break;
	    }
	    else
	        g_ptr_array_add(targets_array, target); /* Add target item to the targets array */
	}
	
	/* Sort the targets array */
	if(targets_array != NULL)
	    g_ptr_array_sort(targets_array, (GCompareFunc)compare_target);
	
	/* Cleanup */
	xmlXPathFreeObject(result);
    }
    
    /* Cleanup */
    xmlFreeDoc(doc);
    xmlCleanupParser();
    
    /* Sort the targets array */
    if(targets_array != NULL)
        g_ptr_array_sort(targets_array, (GCompareFunc)compare_target);
    
    /* Return the targets array */
    return targets_array;
}
Beispiel #2
0
GPtrArray *create_candidate_target_array(const char *candidate_mapping_file)
{
    /* Declarations */
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;
    GPtrArray *candidate_target_array = NULL;
    
    /* Parse the XML document */
    
    if((doc = xmlParseFile(candidate_mapping_file)) == NULL)
    {
	fprintf(stderr, "Error with candidate mapping XML file!\n");
	xmlCleanupParser();
	return NULL;
    }

    /* Retrieve root element */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
        fprintf(stderr, "The candidate mapping XML file is empty!\n");
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return NULL;
    }

    /* Query the mapping elements */
    result = executeXPathQuery(doc, "/distribution/distributionitem");
    
    /* Iterate over all the mapping elements and add them to the array */
    
    if(result)
    {
	unsigned int i;
	xmlNodeSetPtr nodeset = result->nodesetval;
	
	/* Create a candidate target array */
        candidate_target_array = g_ptr_array_new();
	
	/* Iterate over all the distributionitem elements */
	for(i = 0; i < nodeset->nodeNr; i++)
        {
	    xmlNodePtr distributionitem_children = nodeset->nodeTab[i]->children;
	    DistributionItem *item = (DistributionItem*)g_malloc(sizeof(DistributionItem));
	    gchar *service = NULL;
	    GPtrArray *targets = NULL;
	    
	    /* Iterate over all the distributionitem children (derivation and target elements) */
	    
	    while(distributionitem_children != NULL)
	    {
		if(xmlStrcmp(distributionitem_children->name, (xmlChar*) "service") == 0)
		    service = g_strdup((gchar*)distributionitem_children->children->content);
		else if(xmlStrcmp(distributionitem_children->name, (xmlChar*) "targets") == 0)
		{
		    xmlNodePtr targets_children = distributionitem_children->children;
		    targets = g_ptr_array_new();
		    
		    /* Iterate over the targets children */
		    
		    while(targets_children != NULL)
		    {
			if(xmlStrcmp(targets_children->name, (xmlChar*) "target") == 0) /* Only iterate over target nodes */
			{
			    gchar *target = g_strdup((gchar*)targets_children->children->content);
			    g_ptr_array_add(targets, target);
			}
			
			targets_children = targets_children->next;
		    }
		}
		    
		distributionitem_children = distributionitem_children->next;
	    }
	    
	    /* Add the distributionitem to the array */
	    
	    item->service = service;
	    item->targets = targets;
	    g_ptr_array_add(candidate_target_array, item);
	}
    }
    
    /* Cleanup */
    xmlXPathFreeObject(result);
    xmlFreeDoc(doc);
    xmlCleanupParser();
    
    /* Return the candidate host array */
    return candidate_target_array;
}
Beispiel #3
0
GArray *create_derivation_array(const gchar *distributed_derivation_file)
{
    /* Declarations */
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;
    GArray *derivation_array = NULL;
    
    /* Parse the XML document */
    
    if((doc = xmlParseFile(distributed_derivation_file)) == NULL)
    {
	g_printerr("Error with parsing the distributed derivation XML file!\n");
	xmlCleanupParser();
	return NULL;
    }
    
    /* Retrieve root element */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
        g_printerr("The distributed derivation XML file is empty!\n");
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return NULL;
    }

    /* Query the mapping elements */
    result = executeXPathQuery(doc, "/distributedderivation/mapping");
    
    /* Iterate over all the mapping elements and add them to the array */
    
    if(result)
    {
	xmlNodeSetPtr nodeset = result->nodesetval;
	unsigned int i;
	
	/* Create a derivation array */
        derivation_array = g_array_new(FALSE, FALSE, sizeof(DerivationItem*));
	
	/* Iterate over all the mapping elements */
	for(i = 0; i < nodeset->nodeNr; i++)
        {
	    xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
	    DerivationItem *item = (DerivationItem*)g_malloc(sizeof(DerivationItem));
	    gchar *derivation = NULL, *target = NULL;
	    
	    /* Iterate over all the mapping item children (derivation and target elements) */
	    
	    while(mapping_children != NULL)
	    {
		if(xmlStrcmp(mapping_children->name, (xmlChar*) "derivation") == 0)
		    derivation = g_strdup(mapping_children->children->content);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "target") == 0)
		    target = g_strdup(mapping_children->children->content);
		
		mapping_children = mapping_children->next;
	    }
	    
	    /* Added the mapping to the array */
	    item->derivation = derivation;
	    item->target = target;
	    g_array_append_val(derivation_array, item);
        }
    }
    
    /* Cleanup */    
    xmlXPathFreeObject(result);
    xmlFreeDoc(doc);
    xmlCleanupParser();

    /* Return the derivation array */
    return derivation_array;
}
Beispiel #4
0
GPtrArray *create_derivation_array(const gchar *distributed_derivation_file)
{
    /* Declarations */
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;
    GPtrArray *derivation_array = NULL;
    
    /* Parse the XML document */
    
    if((doc = xmlParseFile(distributed_derivation_file)) == NULL)
    {
	g_printerr("Error with parsing the distributed derivation XML file!\n");
	xmlCleanupParser();
	return NULL;
    }
    
    /* Retrieve root element */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
        g_printerr("The distributed derivation XML file is empty!\n");
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return NULL;
    }

    /* Query the mapping elements */
    result = executeXPathQuery(doc, "/distributedderivation/build/mapping");
    
    /* Iterate over all the mapping elements and add them to the array */
    
    if(result)
    {
	xmlNodeSetPtr nodeset = result->nodesetval;
	unsigned int i;
	
	/* Create a derivation array */
        derivation_array = g_ptr_array_new();
	
	/* Iterate over all the mapping elements */
	for(i = 0; i < nodeset->nodeNr; i++)
        {
	    xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
	    DerivationItem *item = (DerivationItem*)g_malloc(sizeof(DerivationItem));
	    gchar *derivation = NULL, *target = NULL;
	    
	    /* Iterate over all the mapping item children (derivation and target elements) */
	    
	    while(mapping_children != NULL)
	    {
		if(xmlStrcmp(mapping_children->name, (xmlChar*) "derivation") == 0)
		    derivation = duplicate_node_text(mapping_children);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "target") == 0)
		    target = duplicate_node_text(mapping_children);
		
		mapping_children = mapping_children->next;
	    }
	    
	    /* Added the mapping to the array */
	    item->derivation = derivation;
	    item->target = target;
	    item->result = NULL;
	    
	    if(item->derivation == NULL || item->target == NULL)
	    {
	        /* Check if all mandatory properties have been provided */
	        g_printerr("A mandatory property seems to be missing. Have you provided a correct\n");
	        g_printerr("distributed derivation file?\n");
	        delete_derivation_array(derivation_array);
	        derivation_array = NULL;
	        break;
	    }
	    else
	        g_ptr_array_add(derivation_array, item); /* Add item to the array */
        }
        
        xmlXPathFreeObject(result);
    }
    
    /* Cleanup */
    xmlFreeDoc(doc);
    xmlCleanupParser();
    
    /* Return the derivation array */
    return derivation_array;
}
Beispiel #5
0
GPtrArray *create_snapshots_array(const gchar *manifest_file, const gchar *container_filter, const gchar *component_filter)
{
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;
    GPtrArray *snapshots_array;
    
    /* Parse the XML document */
    
    if((doc = xmlParseFile(manifest_file)) == NULL)
    {
	g_printerr("Error with parsing the manifest XML file!\n");
	xmlCleanupParser();
	return NULL;
    }

    /* Retrieve root element */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
        g_printerr("The distribution manifest XML file is empty!\n");
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return NULL;
    }

    /* Query the distribution elements */
    result = executeXPathQuery(doc, "/manifest/snapshots/mapping");
    
    /* Initialize snapshots array */
    snapshots_array = g_ptr_array_new();
    
    /* Iterate over all the distribution elements and add them to the array */
    
    if(result)
    {
	xmlNodeSetPtr nodeset = result->nodesetval;
	unsigned int i;
	
	/* Iterate over all the mapping elements */
	for(i = 0; i < nodeset->nodeNr; i++)
        {
	    xmlNodePtr mapping_children = nodeset->nodeTab[i]->children;
	    gchar *component = NULL;
	    gchar *container = NULL;
	    gchar *target = NULL;
	    gchar *service = NULL;
	    gchar *type = NULL;
	    SnapshotMapping *mapping = (SnapshotMapping*)g_malloc(sizeof(SnapshotMapping));
	    
	    /* Iterate over all the mapping item children (service,target,targetProperty,type,dependsOn elements) */
	    
	    while(mapping_children != NULL)
	    {
		if(xmlStrcmp(mapping_children->name, (xmlChar*) "component") == 0)
		    component = duplicate_node_text(mapping_children);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "container") == 0)
		    container = duplicate_node_text(mapping_children);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "target") == 0)
		    target = duplicate_node_text(mapping_children);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "service") == 0)
		    service = duplicate_node_text(mapping_children);
		else if(xmlStrcmp(mapping_children->name, (xmlChar*) "type") == 0)
		    type = duplicate_node_text(mapping_children);
		
		mapping_children = mapping_children->next;
	    }
	    mapping->component = component;
	    mapping->container = container;
	    mapping->target = target;
	    mapping->service = service;
	    mapping->type = type;
	    mapping->transferred = FALSE;
	    
	    if(mapping_is_selected(mapping, container_filter, component_filter))
	    {
	        if(component == NULL || container == NULL || target == NULL || service == NULL || type == NULL)
	        {
	            /* Check if all mandatory properties have been provided */
	            g_printerr("A mandatory property seems to be missing. Have you provided a correct\n");
	            g_printerr("manifest file?\n");
	            delete_snapshots_array(snapshots_array);
	            snapshots_array = NULL;
	            break;
	        }
	        else
	            g_ptr_array_add(snapshots_array, mapping); /* Add the mapping to the array */
	    }
	    else
	        delete_snapshot_mapping(mapping);
	}
	
	xmlXPathFreeObject(result);
    }

    /* Cleanup */
    xmlFreeDoc(doc);
    xmlCleanupParser();

    /* Sort the snapshots array */
    if(snapshots_array != NULL)
        g_ptr_array_sort(snapshots_array, (GCompareFunc)compare_snapshot_mapping);
    
    /* Return the snapshots array */
    return snapshots_array;
}
Beispiel #6
0
int open_port_configuration(PortConfiguration *port_configuration, const gchar *port_configuration_file)
{
    /* Declarations */
    xmlDocPtr doc;
    xmlNodePtr node_root;
    xmlXPathObjectPtr result;

    /* Parse the XML document */
    
    if((doc = xmlParseFile(port_configuration_file)) == NULL)
    {
        g_printerr("Error with parsing the port configuration XML file!\n");
        xmlCleanupParser();
        return FALSE;
    }
    
    /* Check if the document has a root */
    node_root = xmlDocGetRootElement(doc);
    
    if(node_root == NULL)
    {
        g_printerr("The port configuration XML file is empty!\n");
        xmlFreeDoc(doc);
        xmlCleanupParser();
        return FALSE;
    }
    
    /* Query the global config properties */
    result = executeXPathQuery(doc, "/portConfiguration/globalConfig");
    
    if(result)
    {
        unsigned int i;
        xmlNodeSetPtr nodeset = result->nodesetval;
        
        for(i = 0; i < nodeset->nodeNr; i++)
            port_configuration->global_config = parse_target_config(nodeset->nodeTab[i]);
    }
    else
        port_configuration->global_config = NULL;
    
    /* Query the target config properties */
    result = executeXPathQuery(doc, "/portConfiguration/targetConfigs");
    
    port_configuration->target_configs = g_hash_table_new_full(g_str_hash, g_str_equal, delete_target_key, delete_config_value);
    
    if(result)
    {
        unsigned int i;
        xmlNodeSetPtr nodeset = result->nodesetval;
        
        for(i = 0; i < nodeset->nodeNr; i++)
        {
            xmlNodePtr target_node_children = nodeset->nodeTab[i]->children;
            
            while(target_node_children != NULL)
            {
                if(xmlStrcmp(target_node_children->name, (xmlChar *) "text") != 0)
                {
                    TargetConfig *target_config = parse_target_config(target_node_children);
                    gchar *target = g_strdup((gchar*)target_node_children->name);
                
                    g_hash_table_insert(port_configuration->target_configs, target, target_config);
                }
                
                target_node_children = target_node_children->next;
            }
        }
    }
    
    /* Cleanup */
    xmlFreeDoc(doc);
    xmlCleanupParser();
    
    return TRUE;
}