Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <math.h>
00008 #include <labust/xml/XMLReader.hpp>
00009 #include <moos/MoosConfig.hpp>
00010 #include <boost/algorithm/string.hpp>
00011 #include <boost/foreach.hpp>
00012 #include <fstream>
00013
00014
00015
00016 const labust::xml::Reader& LABUST::COMMUNICATION::operator>>(const labust::xml::Reader& reader, MoosConfig& config)
00017 {
00018 reader.value("param[@name='Hostname']/@value", &config.hostname);
00019
00020 std::string temp;
00021
00022 if (!reader.try_value("param[@name='Port']/@value", &config.port))
00023 {
00024 config.port = 9000;
00025 }
00026
00027 if (!reader.try_value("param[@name='ProcessName']/@value", &config.processName))
00028 {
00029 config.processName = "MoosCommsInterface";
00030 }
00031
00032 if (!reader.try_value("param[@name='AppTick']/@value", &config.appTick))
00033 {
00034 config.appTick = 10;
00035 }
00036
00037 if (!reader.try_value("param[@name='CommsTick']/@value", &config.commsTick))
00038 {
00039 config.commsTick = 10;
00040 }
00041
00042 labust::xml::NodeCollectionPtr nodes;
00043 try
00044 {
00045 nodes = reader.value<labust::xml::NodeCollectionPtr > ("param[@name='Subscription']");
00046 config.subscriptionVars.clear();
00047
00048 _xmlNode* curr = reader.currentNode();
00049 BOOST_FOREACH(_xmlNode* pt, *nodes)
00050 {
00051 const_cast<labust::xml::Reader&>(reader).useNode(pt);
00052 config.subscriptionVars.push_back(reader.value<std::string>("@value"));
00053 }
00054 const_cast<labust::xml::Reader&>(reader).useNode(curr);
00055 }
00056 catch (...)
00057 {
00058
00059 }
00060
00061
00062 return reader;
00063 }
00064
00065 LABUST::COMMUNICATION::MoosConfig LABUST::COMMUNICATION::moos_configure(const labust::xml::Reader& reader, std::ofstream& moosConfig)
00066 {
00067 MoosConfig config;
00068
00069 reader >> config;
00070
00071 moosConfig.open("config.moos", std::ios_base::out | std::ios_base::trunc);
00072 moosConfig << "ServerPort = " << config.port << std::endl;
00073 moosConfig << "ServerHost = " << config.hostname << std::endl;
00074 moosConfig << "ProcessConfig = " << config.processName << std::endl;
00075 moosConfig << "{" << std::endl;
00076 moosConfig << "AppTick = " << config.appTick << std::endl;
00077 moosConfig << "commsTick = " << config.commsTick << std::endl;
00078 moosConfig << "}" << std::endl;
00079 moosConfig.close();
00080
00081 return config;
00082 }