Ignore:
Timestamp:
Nov 1, 2010, 6:24:56 PM (14 years ago)
Author:
Torben Dannhauer
Message:

start to move osgVisual from argument based configuratiobn to xml file based configuration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/src/util/visual_util.cpp

    r130 r144  
    2525util::~util(void)
    2626{
     27}
     28
     29xmlNode* util::getModuleXMLConfig(std::string configFilename, std::string moduleName, xmlDoc*& doc)
     30{
     31        doc = NULL;
     32        xmlNode *root_element = NULL;
     33
     34        // Check for valid parameters
     35        if(configFilename == "")
     36        {
     37                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Configuration Filename!" << std::endl;
     38                return NULL;
     39        }
     40        if(moduleName == "")
     41        {
     42                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Module Filename!" << std::endl;
     43                return NULL;
     44        }
     45
     46        // It is a valid XML document?
     47        doc = xmlReadFile(configFilename.c_str(), NULL, 0);     
     48        if (doc == NULL)
     49        {
     50                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not a valid XML file!" << std::endl;
     51                return NULL;
     52        }
     53
     54        //  Get the root element node
     55        root_element = xmlDocGetRootElement(doc);
     56
     57        // Check if it is an osgVisual configuration file
     58        std::string node_name=reinterpret_cast<const char*>(root_element->name);
     59        if(!(root_element->type == XML_ELEMENT_NODE && node_name == "osgvisualconfiguration"))
     60        {
     61                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not an osgVisual configuration file!" << std::endl;
     62                return NULL;
     63        }
     64
     65        // If file is a valid osgVisual config file, check all the root xml node and all of it's children of osgvisualconfiguration for the specified module
     66        xmlNode* tmpNode = checkXMLNodeChildrenForModule(root_element, moduleName);
     67
     68        if( !tmpNode ) // if no valid node was found: clena up. Otherwise: the caller has to clean up.
     69        {
     70                xmlFreeDoc(doc);        // free the document
     71                xmlCleanupParser();     // Free the global variables that may have been allocated by the parser.
     72                return NULL;
     73        }
     74        else
     75                return tmpNode;
     76
     77}
     78
     79xmlNode* util::checkXMLNodeChildrenForModule(xmlNode* node, std::string moduleName)
     80{
     81        for (xmlNode *cur_node = node; cur_node; cur_node = cur_node->next)     // iterate through all elements
     82        {
     83                // Is the node the one we are searching for?
     84                if (cur_node->type == XML_ELEMENT_NODE)
     85                {
     86                        std::string node_name=reinterpret_cast<const char*>(cur_node->name);
     87                        if (node_name == "module")
     88                        {
     89                                OSG_DEBUG << "XML node module found" << std::endl;
     90                                return cur_node;
     91                        }
     92                        else    // Otherwise: check its children..
     93                        {
     94                                xmlNode* tmp_XmlNode = checkXMLNodeChildrenForModule(cur_node->children, moduleName);
     95                                if(tmp_XmlNode)
     96                                        return tmp_XmlNode;
     97                        }
     98                }       // IF NODE TYPE = ELEMENT END
     99
     100                // Proceed with next node in this loop.
     101        }
    27102}
    28103
Note: See TracChangeset for help on using the changeset viewer.