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