本文整理汇总了C++中NameConfig::toFile方法的典型用法代码示例。如果您正苦于以下问题:C++ NameConfig::toFile方法的具体用法?C++ NameConfig::toFile怎么用?C++ NameConfig::toFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameConfig
的用法示例。
在下文中一共展示了NameConfig::toFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: send
String NameClient::send(const String& cmd, bool multi) {
//printf("*** OLD YARP command %s\n", cmd.c_str());
setup();
if (NetworkBase::getQueryBypass()) {
ContactStyle style;
Bottle bcmd(cmd.c_str()), reply;
NetworkBase::writeToNameServer(bcmd,reply,style);
ConstString si = reply.toString(), so;
for (int i=0; i<(int)si.length(); i++) {
if (si[i]!='\"') {
so += si[i];
}
}
return so.c_str();
}
bool retried = false;
bool retry = false;
String result;
Contact server = getAddress();
float timeout = 10;
server.setTimeout(timeout);
do {
YARP_DEBUG(Logger::get(),String("sending to nameserver: ") + cmd);
if (isFakeMode()) {
//YARP_DEBUG(Logger::get(),"fake mode nameserver");
return getServer().apply(cmd,Contact::bySocket("tcp","127.0.0.1",NetworkBase::getDefaultPortRange())) + "\n";
}
TcpFace face;
YARP_DEBUG(Logger::get(),String("connecting to ") + getAddress().toURI());
OutputProtocol *ip = NULL;
if (!retry) {
ip = face.write(server);
} else {
retried = true;
}
if (ip==NULL) {
YARP_INFO(Logger::get(),"No connection to nameserver");
if (!allowScan) {
YARP_INFO(Logger::get(),"*** try running: yarp detect ***");
}
Contact alt;
if (!isFakeMode()) {
if (allowScan) {
YARP_INFO(Logger::get(),"no connection to nameserver, scanning mcast");
reportScan = true;
#ifdef YARP_HAS_ACE
alt = FallbackNameClient::seek();
#else
return ""; // nothing to do, nowhere to turn
#endif
}
}
if (alt.isValid()) {
address = alt;
if (allowSaveScan) {
reportSaveScan = true;
NameConfig nc;
nc.setAddress(alt);
nc.toFile();
}
server = getAddress();
server.setTimeout(timeout);
ip = face.write(server);
if (ip==NULL) {
YARP_ERROR(Logger::get(),
"no connection to nameserver, scanning mcast");
return "";
}
} else {
return "";
}
}
String cmdn = cmd + "\n";
Bytes b((char*)cmdn.c_str(),cmdn.length());
ip->getOutputStream().write(b);
bool more = multi;
while (more) {
String line = "";
line = ip->getInputStream().readLine();
if (!(ip->isOk())) {
more = false;
//YARP_DEBUG(Logger::get(), e.toString() + " <<< exception from name server");
retry = true;
break;
}
if (line.length()>1) {
if (line[0] == '*'||line[0] == '[') {
more = false;
}
}
result += line + "\n";
}
ip->close();
delete ip;
YARP_SPRINTF1(Logger::get(),
//.........这里部分代码省略.........
示例4: 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;
//.........这里部分代码省略.........
示例5: 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 ") +
//.........这里部分代码省略.........