00001 #include <xercesc/util/PlatformUtils.hpp>
00002 #include <xercesc/dom/DOM.hpp>
00003 #include <xercesc/parsers/XercesDOMParser.hpp>
00004 #include <xercesc/util/XMLChar.hpp>
00005 #include <string>
00006 #include <iostream>
00007 #include <Logger.H>
00008 #include <WURDEConfiguration.H>
00009
00010
00011 XERCES_CPP_NAMESPACE_USE
00012
00013 using namespace WURDE;
00014 using namespace std;
00015
00016 string parseLaserConfig(std::string config,std::string laserName){
00017 string port=" ";
00018
00019 try {
00020 XMLPlatformUtils::Initialize();
00021 }
00022 catch (const XMLException& toCatch) {
00023 cout << "Something went wrong.\n";
00024
00025
00026 return port;
00027 }
00028
00029
00030 static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
00031 DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
00032 DOMBuilder *parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
00033 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = 0;
00034 DOMElement *root;
00035 DOMNode *curr,*name,*child, *item;
00036 DOMNodeList *theNodes,*children;
00037 DOMNamedNodeMap *attr;
00038 bool found=false;
00039
00040 doc = parser->parseURI(config.c_str());
00041 if(!doc){
00042 g_logfatal << "Config file " << config.c_str() << " not found!"<< endl;
00043 exit(1);
00044 }
00045
00046 root=doc->getDocumentElement();
00047 if(!root){
00048 g_logfatal << "Unable to read the laser-config file. Exiting." << endl;
00049 exit(1);
00050 }
00051
00052 string currentname, temp;
00053
00054
00055 temp=XMLString::transcode(root->getTagName());
00056 if(temp!="laser-config"){
00057 g_logfatal << temp << " has no laser-config.\n";
00058 exit(1);
00059 }
00060
00061
00062 theNodes=doc->getElementsByTagName(XMLString::transcode("device"));
00063
00064 for(unsigned int i=0;i<theNodes->getLength();i++){
00065 string id;
00066
00067 curr=theNodes->item(i);
00068 attr=curr->getAttributes();
00069
00070 name=attr->getNamedItem(XMLString::transcode("name"));
00071 currentname=XMLString::transcode(name->getNodeValue());
00072
00073 if(currentname==laserName){
00074 found=true;
00075
00076 name=attr->getNamedItem(XMLString::transcode("port"));
00077 port=XMLString::transcode(name->getNodeValue());
00078
00079 name=attr->getNamedItem(XMLString::transcode("log"));
00080 if(name){
00081 string log=XMLString::transcode(name->getNodeValue());
00082 if(log=="true"){
00083 g_globalConfiguration.setOption("logLaser","true");
00084 }
00085 }else{
00086 g_globalConfiguration.setOption("logLaser","false");
00087 }
00088
00089 name=attr->getNamedItem(XMLString::transcode("invert"));
00090 if(name){
00091 string invert=XMLString::transcode(name->getNodeValue());
00092 if(invert=="true"){
00093 g_globalConfiguration.setOption("invertLaser","true");
00094 }
00095 }else{
00096 g_globalConfiguration.setOption("invertLaser","false");
00097 }
00098
00099
00100 name=attr->getNamedItem(XMLString::transcode("type"));
00101 string type=XMLString::transcode(name->getNodeValue());
00102 g_globalConfiguration.setOption("laserType",type);
00103 }
00104 }
00105
00106 if(!found){
00107 g_logfatal << "Couldn't find laser " << laserName << endl;
00108 exit(1);
00109 }
00110
00111 XMLPlatformUtils::Terminate();
00112
00113 return port;
00114 }
00115