本文整理汇总了C++中NameConfig::getNamespace方法的典型用法代码示例。如果您正苦于以下问题:C++ NameConfig::getNamespace方法的具体用法?C++ NameConfig::getNamespace怎么用?C++ NameConfig::getNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameConfig
的用法示例。
在下文中一共展示了NameConfig::getNamespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: detectNameServer
Contact YarpNameSpace::detectNameServer(bool useDetectedServer,
bool& scanNeeded,
bool& serverUsed) {
NameConfig nc;
NameClient& nic = HELPER(this);
nic.setFakeMode(false);
nic.updateAddress();
nic.setScan();
if (useDetectedServer) {
nic.setSave();
}
nic.send("ping", false);
scanNeeded = nic.didScan();
serverUsed = nic.didSave();
Contact c = nic.getAddress();
c.setName(nc.getNamespace().c_str());
//Contact c = nic.getAddress().toContact();
// if (scanNeeded) {
// Address addr = nic.getAddress();
// c.setSocket("tcp", addr.getName().c_str(), addr.getPort());
////}
//c.setName(nc.getNamespace().c_str());
return c;
}
示例2: 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;
}
示例3: run
void FallbackNameClient::run() {
NameConfig nc;
Contact call = FallbackNameServer::getAddress();
DgramTwoWayStream send;
send.join(call, true);
listen.join(call, false);
if (!listen.isOk()) {
YARP_ERROR(Logger::get(), ConstString("Multicast not available"));
return;
}
ConstString msg = ConstString("NAME_SERVER query ") + nc.getNamespace();
send.beginPacket();
send.writeLine(msg.c_str(), (int)msg.length());
send.flush();
send.endPacket();
for (int i=0; i<5; i++) {
listen.beginPacket();
ConstString txt = listen.readLine();
listen.endPacket();
if (closed) return;
YARP_DEBUG(Logger::get(), ConstString("Fallback name client got ") + txt);
if (txt.find("registration ")==0) {
address = NameClient::extractAddress(txt);
YARP_INFO(Logger::get(), ConstString("Received address ") +
address.toURI());
return;
}
}
}
示例4: setNameServerName
bool NetworkBase::setNameServerName(const ConstString& name) {
NameConfig nc;
ConstString fname = nc.getConfigFileName(YARP_CONFIG_NAMESPACE_FILENAME);
nc.writeConfig(fname,name + "\n");
nc.getNamespace(true);
getNameSpace().activate(true);
return true;
}
示例5: getNameServerName
ConstString NetworkBase::getNameServerName() {
NameConfig nc;
ConstString name = nc.getNamespace(false);
return name.c_str();
}
示例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: yarp_readdir
int yarp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
printf(">>>>>>>>>>>READING DIR\n");
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
YPath ypath(path);
if (ypath.isPort()) {
filler(buf, "rw", NULL, 0);
//filler(buf, "write", NULL, 0); //deprecated
//filler(buf, "status", NULL, 0);
return 0;
}
NameConfig nc;
ConstString name = nc.getNamespace();
Bottle msg, reply;
msg.addString("bot");
msg.addString("list");
Network::write(name.c_str(),
msg,
reply);
printf("Got %s\n", reply.toString().c_str());
ACE_Ordered_MultiSet<ConstString> lines;
for (int i=1; i<reply.size(); i++) {
Bottle *entry = reply.get(i).asList();
string rpath = path;
if (rpath[rpath.length()-1]!='/') {
rpath = rpath + "/";
}
if (entry!=NULL) {
ConstString name = entry->check("name",Value("")).asString();
if (name!="") {
if (strstr(name.c_str(),rpath.c_str())==
name.c_str()) {
printf(">>> %s is in path %s\n", name.c_str(),
rpath.c_str());
ConstString part(name.c_str()+rpath.length());
if (part[0]=='/') {
part = part.substr(1,part.length()-1);
}
printf(" %s is the addition\n", part.c_str());
char *brk = (char*)strstr(part.c_str(),"/");
if (brk!=NULL) {
*brk = '\0';
}
ConstString item(part.c_str());
printf(" %s is the item\n", item.c_str());
if (item!="") {
lines.remove(item);
lines.insert(item);
}
}
}
}
}
// return result in alphabetical order
ACE_Ordered_MultiSet_Iterator<ConstString> iter(lines);
iter.first();
while (!iter.done()) {
printf("adding item %s\n", (*iter).c_str());
filler(buf, (*iter).c_str(), NULL, 0);
iter.advance();
}
return 0;
}
示例8: 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 ") +
//.........这里部分代码省略.........