本文整理汇总了C++中NameConfig::getAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ NameConfig::getAddress方法的具体用法?C++ NameConfig::getAddress怎么用?C++ NameConfig::getAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameConfig
的用法示例。
在下文中一共展示了NameConfig::getAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: updateAddress
bool NameClient::updateAddress() {
NameConfig conf;
address = Contact();
mode = "yarp";
if (conf.fromFile()) {
address = conf.getAddress();
mode = conf.getMode();
return true;
}
return false;
}
示例3: 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;
//.........这里部分代码省略.........
示例4: 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 ") +
//.........这里部分代码省略.........