本文整理汇总了C++中NameConfig::fromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ NameConfig::fromFile方法的具体用法?C++ NameConfig::fromFile怎么用?C++ NameConfig::fromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameConfig
的用法示例。
在下文中一共展示了NameConfig::fromFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: detectNameServer
Contact RosNameSpace::detectNameServer(bool useDetectedServer,
bool& scanNeeded,
bool& serverUsed) {
YARP_UNUSED(useDetectedServer);
NameConfig nc;
nc.fromFile();
Contact c = nc.getAddress();
scanNeeded = false;
serverUsed = false;
if (!c.isValid()) {
scanNeeded = true;
fprintf(stderr, "Checking for ROS_MASTER_URI...\n");
ConstString addr = NetworkBase::getEnvironment("ROS_MASTER_URI");
c = Contact::fromString(addr.c_str());
if (c.isValid()) {
c.setCarrier("xmlrpc");
c.setName(nc.getNamespace().c_str());
NameConfig nc;
nc.setAddress(c);
nc.setMode("ros");
nc.toFile();
serverUsed = true;
}
}
return c;
}
示例2: activate
bool activate(bool force = false) {
if (force) {
// wipe if forced
clear();
}
// return if namespaces already present
if (spaces.size()!=0) return true;
// read namespace list from config file
NameConfig conf;
if (!conf.fromFile()) {
double now = Time::now();
static double last_shown = now-10;
if (now-last_shown>3) {
last_shown = now;
fprintf(stderr,"warning: YARP name server(s) not configured, ports will be anonymous\n");
fprintf(stderr,"warning: check your namespace and settings with 'yarp detect'\n");
}
return false;
}
Bottle ns = conf.getNamespaces();
// loop through namespaces
for (int i=0; i<ns.size(); i++) {
ConstString n = ns.get(i).asString();
NameConfig conf2;
// read configuration of individual namespace
if (!conf2.fromFile(n.c_str())) {
fprintf(stderr, "Could not find namespace %s\n",
n.c_str());
continue;
}
String mode = conf2.getMode();
Contact address = conf2.getAddress().addName(n);
if (mode=="yarp"||mode=="//") {
// add a yarp namespace
NameSpace *ns = new YarpNameSpace(address);
spaces.push_back(ns);
} else if (mode=="ros") {
// add a ros namespace
NameSpace *ns = new RosNameSpace(address);
spaces.push_back(ns);
} else if (mode=="local") {
NameSpace *ns = new YarpDummyNameSpace;
spaces.push_back(ns);
} else {
// shrug
YARP_SPRINTF1(Logger::get(),error,
"cannot deal with namespace of type %s",
mode.c_str());
return false;
}
}
// cache flags
scan();
return true;
}
示例3: setNameServerContact
bool NetworkBase::setNameServerContact(Contact &nameServerContact)
{
NameConfig nameConfig;
if (nameServerContact.getName() != "")
setNameServerName(nameServerContact.getName());
nameConfig.fromFile();
nameConfig.setAddress(nameServerContact);
bool result = nameConfig.toFile();
getNameSpace().activate(true);
return result;
}
示例4: updateAddress
bool NameClient::updateAddress() {
NameConfig conf;
address = Contact();
mode = "yarp";
if (conf.fromFile()) {
address = conf.getAddress();
mode = conf.getMode();
return true;
}
return false;
}
示例5: activate
bool activate(bool force = false) {
if (force) {
clear();
}
if (spaces.size()!=0) return true;
NameConfig conf;
if (!conf.fromFile()) {
return false;
}
Bottle ns = conf.getNamespaces();
for (int i=0; i<ns.size(); i++) {
ConstString n = ns.get(i).asString();
//printf("NAMESPACE %s\n", n.c_str());
NameConfig conf2;
if (!conf2.fromFile(n.c_str())) {
fprintf(stderr, "Could not find namespace %s\n",
n.c_str());
continue;
}
String mode = conf2.getMode();
Contact address = conf2.getAddress().toContact().addName(n);
//printf("ADDRESS %s\n", address.toString().c_str());
if (mode=="yarp"||mode=="//") {
NameSpace *ns = new YarpNameSpace(address);
spaces.push_back(ns);
} else if (mode=="ros") {
NameSpace *ns = new RosNameSpace(address);
spaces.push_back(ns);
} else {
YARP_SPRINTF1(Logger::get(),error,
"cannot deal with namespace of type %s",
mode.c_str());
return false;
}
}
scan();
return true;
}
示例6: configFileBootstrap
bool BootstrapServer::configFileBootstrap(yarp::os::Contact& contact,
bool configFileRequired,
bool mayEditConfigFile) {
Contact suggest = contact;
// see what address is lying around
Contact prev;
NameConfig conf;
if (conf.fromFile()) {
prev = conf.getAddress();
} else if (configFileRequired) {
fprintf(stderr,"Could not read configuration file %s\n",
conf.getConfigFileName().c_str());
return false;
}
// merge
if (prev.isValid()) {
if (suggest.getHost() == "...") {
suggest.setHost(prev.getHost());
}
if (suggest.getCarrier() == "...") {
suggest.setCarrier(prev.getCarrier());
}
if (suggest.getPort() == 0) {
suggest.setPort(prev.getPort());
}
}
if (suggest.getRegName() == "...") {
suggest.setName(conf.getNamespace());
}
// still something not set?
if (suggest.getPort() == 0) {
suggest.setPort(10000);
}
if (suggest.getHost() == "...") {
// should get my IP
suggest.setHost(conf.getHostName());
}
if (!configFileRequired) {
// finally, should make sure IP is local, and if not, correct it
if (!conf.isLocalName(suggest.getHost())) {
fprintf(stderr,"Overriding non-local address for name server\n");
suggest.setHost(conf.getHostName());
} else {
// Let's just check we're not a loopback
ConstString betterHost = conf.getHostName(false,suggest.getHost());
if (betterHost!=suggest.getHost()) {
fprintf(stderr,"Overriding loopback address for name server\n");
suggest.setHost(betterHost);
}
}
}
else
{
if (!conf.isLocalName(conf.getHostName())) {
fprintf(stderr,"The address written in config file doesn't belong any interface \n");
return false;
}
suggest.setHost(conf.getHostName());
}
bool changed = false;
if (prev.isValid()) {
changed = (prev.getHost() != suggest.getHost()) ||
(prev.getPort() != suggest.getPort()) ||
(conf.getMode() != "yarp" && conf.getMode() != "");
}
if (changed && !mayEditConfigFile) {
fprintf(stderr,"PROBLEM: need to change settings in %s\n",
conf.getConfigFileName().c_str());
fprintf(stderr," Current settings: host %s port %d family %s\n",
prev.getHost().c_str(), prev.getPort(),
(conf.getMode()=="")?"yarp":conf.getMode().c_str());
fprintf(stderr," Desired settings: host %s port %d family %s\n",
suggest.getHost().c_str(), suggest.getPort(), "yarp");
fprintf(stderr,"Please specify '--write' if it is ok to overwrite current settings, or\n");
if(!configFileRequired)
fprintf(stderr,"Please specify '--read' to use the current settings, or\n");
else
fprintf(stderr,"Please set an existing address in config file, or\n");
fprintf(stderr,"delete %s\n", conf.getConfigFileName().c_str());
return false;
}
bool shouldSave = changed || !prev.isValid();
if (shouldSave) {
// and save
conf.setAddress(suggest);
if (!conf.toFile()) {
fprintf(stderr,"Could not save configuration file %s\n",
conf.getConfigFileName().c_str());
}
}
contact = suggest;
return true;
//.........这里部分代码省略.........
示例7: main
int NameServer::main(int argc, char *argv[]) {
//Network yarp;
// pick an address
Contact suggest("...",0); // suggestion is initially empty
ConstString nameSpace = "";
if (argc>=1) {
if (argv[0][0]=='/') {
nameSpace = argv[0];
// BUT: not used yet
argv++;
argc--;
}
if (argc>=2) {
suggest = Contact(argv[0],NetType::toInt(argv[1]));
} else if (argc>=1) {
suggest = Contact("...",NetType::toInt(argv[0]));
}
}
Property config;
config.fromCommand(argc,argv,false);
bool bNoAuto=config.check("noauto");
// see what address is lying around
Contact prev;
NameConfig conf;
if (nameSpace!="") {
conf.setNamespace(nameSpace.c_str());
}
if (conf.fromFile()) {
prev = conf.getAddress();
}
else if (bNoAuto)
{
YARP_ERROR(Logger::get(), ConstString("Could not find configuration file ") +
conf.getConfigFileName());
return 1;
}
// merge
if (prev.isValid()) {
if (suggest.getHost()=="...") {
suggest = Contact(prev.getHost(),suggest.getPort());
}
if (suggest.getPort()==0) {
suggest = Contact(suggest.getHost(),prev.getPort());
}
}
// still something not set?
if (suggest.getPort()==0) {
suggest = Contact(suggest.getHost(),NetworkBase::getDefaultPortRange());
}
if (suggest.getHost()=="...") {
// should get my IP
suggest = Contact(conf.getHostName(),suggest.getPort());
}
// finally, should make sure IP is local, and if not, correct it
if (!conf.isLocalName(suggest.getHost())) {
YARP_INFO(Logger::get(),"Overriding non-local address for name server");
suggest = Contact(conf.getHostName(),suggest.getPort());
}
// and save
conf.setAddress(suggest);
if (!conf.toFile()) {
YARP_ERROR(Logger::get(), ConstString("Could not save configuration file ") +
conf.getConfigFileName());
}
MainNameServer name(suggest.getPort() + 2);
// register root for documentation purposes
name.registerName(conf.getNamespace(),suggest);
Port server;
name.setPort(server);
server.setReaderCreator(name);
suggest.setName(conf.getNamespace());
bool ok = server.open(suggest, false);
if (ok) {
YARP_DEBUG(Logger::get(), ConstString("Name server listening at ") +
suggest.toURI());
YARP_SPRINTF2(Logger::get(),info,
"Name server can be browsed at http://%s:%d/",
suggest.getHost().c_str(), suggest.getPort());
#ifdef YARP_HAS_ACE
FallbackNameServer fallback(name);
fallback.start();
// register fallback root for documentation purposes
name.registerName("fallback",FallbackNameServer::getAddress());
YARP_INFO(Logger::get(), ConstString("Bootstrap server listening at ") +
//.........这里部分代码省略.........