19 #include <boost/regex.hpp> 21 #if (BOOST_VERSION <= 103301) 22 #include <boost/filesystem/path.hpp> 23 #include <boost/filesystem/operations.hpp> 24 #include <boost/filesystem/convenience.hpp> 26 #include <boost/filesystem.hpp> 31 using namespace boost;
53 options(
"Allowed options"),
54 commandLineOptions(
"Allowed options")
76 program_options::value<string>()->default_value(
"127.0.0.1:2809"),
77 "Nameserver used by OpenHRP (hostname:port)")
80 program_options::value<string>()->default_value(
"ControllerBridge"),
81 "Name of the OpenHRP controller factory server")
84 program_options::value<string>()->default_value(
""),
85 "Name of the virtual robot RTC type")
93 "Set an out-port that transfers data from the simulator to the controller")
97 "Set an in-port transfers data from the controller to the simulator")
101 "Port connection setting")
105 "Periodic rate of execution context (INSTANCE_NAME:TIME_RATE[<=1.0])");
110 program_options::value<string>(),
111 "configuration file of the controller bridge")
113 (
"help,h",
"Show this help");
147 program_options::parsed_options parsed =
148 program_options::command_line_parser(argc, argv).options(
commandLineOptions).allow_unregistered().run();
149 program_options::store(parsed,
vmap);
151 if(
vmap.count(
"help")){
155 if(
vmap.count(
"config-file")){
156 string fileName(
vmap[
"config-file"].as<string>());
157 ifstream
ifs(fileName.c_str());
160 throw invalid_argument(
string(
"cannot open the config file"));
162 program_options::store(program_options::parse_config_file(
ifs,
options),
vmap);
166 program_options::notify(
vmap);
177 if(
vmap.count(
"module")){
178 vector<string> values =
vmap[
"module"].as<vector<string> >();
179 for(
size_t i=0;
i < values.size(); ++
i){
180 string modulePath( values[
i] );
181 if( filesystem::extension(filesystem::path( modulePath )).empty() )
189 if(
vmap.count(
"out-port")){
193 if(
vmap.count(
"in-port")){
197 if(
vmap.count(
"connection")){
198 vector<string> values =
vmap[
"connection"].as<vector<string> >();
199 for(
size_t i=0;
i < values.size(); ++
i){
215 if(
vmap.count(
"periodic-rate")){
216 vector<string> values =
vmap[
"periodic-rate"].as<vector<string> >();
217 for(
size_t i=0;
i < values.size(); ++
i){
226 vector<string> ports =
vmap[optionLabel].as<vector<string> >();
227 for(
size_t i=0;
i < ports.size(); ++
i){
229 int n = parameters.size();
231 throw invalid_argument(
string(
"invalid in port setting"));
241 throw invalid_argument(
string(
"invalid data type"));
242 string st=parameters[j];
244 for(
size_t i=0; i<owners.size(); i++){
246 for(string::iterator itr=owners[i].begin(); itr!=owners[
i].end(); itr++){
255 if(owners.size() > 1){
256 throw invalid_argument(
string(
"invalid VisionSensor setting"));
270 info.
stepTime = atof(parameters[j].c_str());
277 throw invalid_argument(
string(
"invalid in port setting"));
278 portInfos.insert(make_pair(info.
portName, info));
286 int n = parameters.size();
288 throw std::invalid_argument(
string(
"Invalied port connection"));
293 if(parameters.size() == 2){
295 throw std::invalid_argument(
string(
"RTC instance name must be specified in a connection option"));
308 std::vector<RTC::RtcBase*> components = rtcManager.
getComponents();
309 for(std::vector<RTC::RtcBase*>::iterator it=components.begin(); it != components.end(); ++it){
311 info.
componentName = (*it)->get_component_profile()->type_name;
324 if(parameters.size() == 0 || parameters.size() > 2){
325 throw std::invalid_argument(std::string(
"invalid module set"));
330 if(parameters.size() == 1){
344 if (parameters.size() == 0 || parameters.size() > 2) {
345 throw std::invalid_argument(std::string(
"invalid time rate set"));
347 timeRateMap.insert( std::map<std::string, double>::value_type(parameters[0], atof(parameters[1].c_str())) );
356 if(!moduleInfo->isLoaded){
357 rtcManager.
load(moduleInfo->fileName.c_str(), moduleInfo->initFuncName.c_str());
358 moduleInfo->isLoaded =
true;
359 moduleInfo->rtcServant = rtcManager.
createComponent(moduleInfo->componentName.c_str());
385 vector<string> result;
386 string::size_type sepPos = 0;
387 string::size_type nowPos = 0;
389 while (sepPos != string::npos) {
390 sepPos = str.find(delimiter, nowPos);
395 result.push_back(str.substr(nowPos, sepPos-nowPos));
407 regex variablePattern(
"\\$([A-z][A-z_0-9]*)");
409 match_results<string::const_iterator> result;
410 match_flag_type
flags = match_default;
412 string::const_iterator
start, end;
417 vector< pair< int, int > > results;
419 while ( regex_search(start, end, result, variablePattern, flags) ) {
420 results.push_back(std::make_pair(pos+result.position(1), result.length(1)));
423 start = result[0].second;
424 pos += result.length(0);
426 flags |= boost::match_prev_avail;
427 flags |= boost::match_not_bob;
431 while (!results.empty()) {
432 int begin = results.back().first;
433 int length = results.back().second;
435 string envName = str.substr(begin, length);
436 char* envValue =
getenv(envName.c_str());
439 str.replace(begin-1, length+1,
string(envValue));
RTObject_impl * createComponent(const char *comp_args)
std::string nameServerIdentifier
void initLabelToDataTypeMap()
Modifications controlling boost library behavior.
boost::program_options::variables_map vmap
std::vector< std::string > extractParameters(const std::string &str, const char delimiter=':')
std::string controllerName
void addModuleInfo(const std::string &value)
void load(const char *fname, const char *initfunc)
png_bytep png_bytep png_size_t length
std::string controllerInstanceName
static Manager & instance()
std::string expandEnvironmentVariables(std::string str)
PortConnectionList portConnections
std::string basename(const std::string name)
static BridgeConf * initialize(int argc, char *argv[])
static BridgeConf * instance()
bool isProcessingConfigFile
LabelToDataTypeIdMap labelToDataTypeIdMap
std::string componentName
const char * getOpenHRPNameServerIdentifier()
void addTimeRateInfo(const std::string &value)
std::map< std::string, DataTypeId > LabelToDataTypeIdMap
std::string robotPortName
void setPortInfos(const char *optionLabel, PortInfoMap &portInfos)
RTC::RtcBase * rtcServant
void parseCommandLineOptions(int argc, char *argv[])
void setPreLoadModuleInfo()
std::map< std::string, PortInfo > PortInfoMap
char * getenv(const char *name)
boost::program_options::options_description commandLineOptions
#define SUFFIX_SHARED_EXT
void addPortConnection(const std::string &value)
const char * getControllerName()
BridgeConf(int argc, char *argv[])
std::vector< std::string > dataOwnerName
std::string virtualRobotRtcTypeName
std::string controllerPortName
void initOptionsDescription()
const char * getVirtualRobotRtcTypeName()
std::vector< RTObject_impl *> getComponents()
boost::program_options::options_description options
ModuleInfoList moduleInfoList