Esempio n. 1
0
EngineDescription readEngine(Element &engineElem)
{
    //Check for illegal elements here
    Iterator< Node > c;
    for ( c = c.begin(&engineElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            if(s != "component")
            {
                LOG(LFATAL) << "Illegal element in xml file: " << s;
                throw XmlParsingException("Illegal element in xml file: " + s);
            }
        }
    }

    EngineDescription theEngine;
    theEngine.name = engineElem.GetAttribute("name");
    theEngine.type = engineElem.GetAttribute("class");
    boost::to_lower(theEngine.name);
    boost::to_lower(theEngine.type);
    LOG(LINFO) << "Parsed engine: " << theEngine.name;

    //Parse all the components and add to the engine description
    Iterator< Element > child("component");
    for ( child = child.begin(&engineElem); child != child.end(); child++ )
    {
        ComponentDescription comp = readComponent(*child);
        comp.engineName = theEngine.name;
        theEngine.components.push_back(comp);
    }

    return theEngine;
}
Esempio n. 2
0
ComponentDescription readComponent(Element &componentElem)
{
    //Check for illegal nodes here
    Iterator< Node > c;
    for ( c = c.begin(&componentElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            if(s != "port" && s != "parameter")
            {
                LOG(LFATAL) << "Illegal element in xml file: " << s;
                throw XmlParsingException("Illegal element in xml file: " + s);
            }
        }
    }

    ComponentDescription theComponent;

    //Parse the component type and name
    theComponent.name = componentElem.GetAttribute("name");
    theComponent.type = componentElem.GetAttribute("class");
    boost::to_lower(theComponent.name);
    boost::to_lower(theComponent.type);
    LOG(LINFO) << "Parsed component: " << theComponent.name;

    //Parse all the parameters and add to the component description
    Iterator< Element > child("parameter");
    for ( child = child.begin(&componentElem); child != child.end(); child++ )
    {
        ParameterDescription param;
        param.name = child->GetAttribute("name");
        param.value = child->GetAttribute("value");
        boost::to_lower(param.name);
        boost::to_lower(param.value);
        theComponent.parameters.push_back(param);
    }

    //Parse all the ports and add to the component description
    Iterator< Element > child2("port");
    for ( child2 = child2.begin(&componentElem); child2 != child2.end(); child2++ )
    {
        PortDescription port;
        port.name = child2->GetAttribute("name");
        port.type = child2->GetAttribute("class");
        boost::to_lower(port.name);
        boost::to_lower(port.type);
        theComponent.ports.push_back(port);
    }

    return theComponent;
}
Esempio n. 3
0
LinkDescription readLink(Element &linkElem)
{
    //Check for illegal nodes here
    Iterator< Node > c;
    for ( c = c.begin(&linkElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            LOG(LFATAL) << "Illegal element in xml file: " << s;
            throw XmlParsingException("Illegal element in xml file: " + s);
        }
    }

    LinkDescription theLink;
    string source, sink;
    if(linkElem.HasAttribute("sink"))
        sink = linkElem.GetAttribute("sink");
    else
        sink = linkElem.GetAttribute("below");
    if(linkElem.HasAttribute("source"))
        source = linkElem.GetAttribute("source");
    else
        source = linkElem.GetAttribute("above");

    //Create tokenizers
    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
    boost::char_separator<char> sep(".");
    tokenizer sourceTokens(source, sep);
    tokenizer sinkTokens(sink, sep);

    //Pull out source component and port
    tokenizer::iterator tok_iter = sourceTokens.begin();
    theLink.sourceComponent = (*tok_iter++);
    theLink.sourcePort = (*tok_iter);

    //Pull out sink component and port
    tok_iter = sinkTokens.begin();
    theLink.sinkComponent = (*tok_iter++);
    theLink.sinkPort = (*tok_iter);

    boost::to_lower(theLink.sourceComponent);
    boost::to_lower(theLink.sourcePort);
    boost::to_lower(theLink.sinkComponent);
    boost::to_lower(theLink.sinkPort);

    LOG(LINFO) << "Parsed link: " << theLink.sourceComponent << " . " << theLink.sourcePort \
        << " -> " << theLink.sinkComponent << " . " << theLink.sinkPort;

    return theLink;
}
Esempio n. 4
0
void XmlParser::parseXmlString( std::string &xml, RadioRepresentation &radio)
{
    try{
        Document doc;
        doc.Parse(xml);

        //Pull out the root element
        Element* head = doc.FirstChildElement();
        string headValue = head->Value();
        if( headValue == "softwareradio")
        {
            readSoftwareRadio(*head, radio);
        }else{
            throw XmlParsingException("The top element of the xml configuration must be softwareradio.");
        }

        //Instruct the radio description to build a graph of the radio
        radio.buildGraphs();
    }
    catch( Exception& ex )
    {
        throw XmlParsingException(ex.what());
    }
}
Esempio n. 5
0
ControllerDescription readController(Element &controllerElem)
{
    //Check for illegal nodes here
    Iterator< Node > c;
    for ( c = c.begin(&controllerElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            if(s != "parameter")
            {
              LOG(LFATAL) << "Illegal element in xml file: " << s;
              throw XmlParsingException("Illegal element in xml file: " + s);
            }
        }
    }

    ControllerDescription theController;

    //Parse the controller type and name
    theController.name = controllerElem.GetAttribute("name");
    theController.type = controllerElem.GetAttribute("class");
    if(theController.name.empty())
      theController.name = theController.type;
    boost::to_lower(theController.name);
    boost::to_lower(theController.type);

    //Parse all the parameters and add to the controller description
    Iterator< Element > child("parameter");
    for ( child = child.begin(&controllerElem); child != child.end(); child++ )
    {
      ParameterDescription param;
      param.name = child->GetAttribute("name");
      param.value = child->GetAttribute("value");
      boost::to_lower(param.name);
      boost::to_lower(param.value);
      theController.parameters.push_back(param);
    }

    LOG(LINFO) << "Parsed controller: " << theController.name;

    return theController;
}
Esempio n. 6
0
void readSoftwareRadio(Element &headElem, RadioRepresentation& theRadio)
{
    //Check for illegal nodes here
    Iterator< Node > c;
    for ( c = c.begin(&headElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            if(s != "controller" && s != "engine" && s!= "link")
            {
                LOG(LFATAL) << "Illegal element in xml file: " << s;
                throw XmlParsingException("Illegal element in xml file: " + s);
            }
        }
    }

    //Parse all the controllers
    Iterator< Element > child("controller");
    for ( child = child.begin(&headElem); child != child.end(); child++ )
    {
        ControllerDescription con = readController(*child);
        theRadio.addControllerDescription(con);
    }

    //Parse all the engines
    Iterator< Element > child1("engine");
    for ( child1 = child1.begin(&headElem); child1 != child1.end(); child1++ )
    {
        EngineDescription eng = readEngine(*child1);
        theRadio.addEngineDescription(eng);
    }

    //Parse all the links
    Iterator< Element > child2("link");
    for ( child2 = child2.begin(&headElem); child2 != child2.end(); child2++ )
    {
        LinkDescription link = readLink(*child2);
        theRadio.addLinkDescription(link);
    }
}
Esempio n. 7
0
ControllerDescription readController(Element &controllerElem)
{
    //Check for illegal nodes here
    Iterator< Node > c;
    for ( c = c.begin(&controllerElem); c != c.end(); c++ )
    {
        if(c->Type() == TiXmlNode::ELEMENT)
        {
            string s = c->Value();
            LOG(LFATAL) << "Illegal element in xml file: " << s;
            throw XmlParsingException("Illegal element in xml file: " + s);
        }
    }

    ControllerDescription theController;

    //Parse the component type
    theController.type = controllerElem.GetAttribute("class");
    boost::to_lower(theController.type);
    LOG(LINFO) << "Parsed controller: " << theController.type;

    return theController;
}