Ejemplo n.º 1
0
Contact MultiNameSpace::unregisterContact(const Contact& contact) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    for (int i=0; i<(int)lst.size(); i++) {
        Contact iresult = lst[i]->unregisterContact(contact);
        if (i==0) result = iresult;
    }
    return result;
}
Ejemplo n.º 2
0
Contact MultiNameSpace::unregisterName(const ConstString& name) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    for (int i=0; i<(int)lst.size(); i++) {
        // we unregister in *all* namespaces
        Contact iresult = lst[i]->unregisterName(name);
        if (i==0) result = iresult;
    }
    return result;
}
Ejemplo n.º 3
0
Contact MultiNameSpace::registerContact(const Contact& contact) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    for (int i=0; i<(int)lst.size(); i++) {
        // we register in *all* namespaces (and query in *any*)
        Contact iresult = lst[i]->registerContact(contact);
        if (i==0) result = iresult;
    }
    return result;
}
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 void clear() {
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (ns) {
             delete ns;
             ns = NULL;
         }
     }
     spaces.clear();
     _localOnly = true;
     _usesCentralServer = false;
     _serverAllocatesPortNumbers = false;
     _connectionHasNameOfEndpoints = true;
 }
Ejemplo n.º 6
0
 NameSpace *getOne() {
     activate();
     if (spaces.size()==0) {
         return NULL;
     }
     return spaces[0];
 }
Ejemplo n.º 7
0
Contact MultiNameSpace::registerName(const ConstString& name) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    for (int i=0; i<(int)lst.size(); i++) {
        Contact iresult;
        if (result.getPort()<=0) {
            iresult = lst[i]->registerName(name);
        } else {
            iresult = lst[i]->registerContact(result);
        }
        if (i==0 || result.getPort()<=0) {
            result = iresult;
        }
    }
    return result;
}
Ejemplo n.º 8
0
 void scan() {
     // reset flags
     _localOnly = true;
     _usesCentralServer = false;
     _serverAllocatesPortNumbers = true;
     // now scan each namespace
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (!ns) continue;
         // if any namespace is nonlocal, combination is nonlocal
         if (!ns->localOnly()) _localOnly = false;
         // if any namespace uses a central server, combination also does
         if (ns->usesCentralServer()) _usesCentralServer = true;
         // if any namespace doesn't allocate port numbers, combination
         // cannot be relied on to do so either
         if (!ns->serverAllocatesPortNumbers()) {
             _serverAllocatesPortNumbers = false;
         }
         // if any namespace lacks informed connections, combination
         // cannot be relied on to be informed either
         if (!ns->connectionHasNameOfEndpoints()) {
             _connectionHasNameOfEndpoints = false;
         }
     }
 }
Ejemplo n.º 9
0
 Contact getNameServerContact() {
     activate();
     if (spaces.size()>0) {
         return spaces[0]->getNameServerContact();
     }
     return Contact();
 }
Ejemplo n.º 10
0
 Contact getNameServerContact() {
     activate(); // make sure we've loaded namespace(s)
     if (spaces.size()>0) {
         // return first name server
         return spaces[0]->getNameServerContact();
     }
     return Contact();
 }
Ejemplo n.º 11
0
 bool setLocalMode(bool flag) {
     clear();
     if (flag) {
         NameSpace *ns = new YarpDummyNameSpace;
         spaces.push_back(ns);
     }
     scan();
     return true;
 }
Ejemplo n.º 12
0
Contact MultiNameSpace::registerName(const ConstString& name) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    // loop through namespaces
    for (int i=0; i<(int)lst.size(); i++) {
        Contact iresult;
        // Register name with namespace. If contact information is
        // fleshed out while registering, we carry that along for
        // registration with the next namespace.
        if (result.getPort()<=0) {
            iresult = lst[i]->registerName(name);
        } else {
            iresult = lst[i]->registerContact(result);
        }
        if (i==0 || result.getPort()<=0) {
            result = iresult;
        }
    }
    return result;
}
Ejemplo n.º 13
0
 bool setLocalMode(bool flag) {
     // remove any existing namespaces
     clear();
     if (flag) {
         // add a dummy local namespace
         NameSpace *ns = new YarpDummyNameSpace;
         spaces.push_back(ns);
     }
     // cache flags
     scan();
     return true;
 }
Ejemplo n.º 14
0
 Contact queryName(const ConstString& name) {
     activate();
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (!ns) continue;
         if (ns->getNameServerName()==name) {
             return ns->getNameServerContact();
         }
         Contact result = ns->queryName(name);
         if (result.isValid()) return result;
     }
     return Contact();
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 Contact queryName(const char *name) {
     activate();
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (!ns) continue;
         if (ns->getNameServerName()==name) {
             return ns->getNameServerContact();
         }
         //printf("Query from %s\n", spaces[i]->getNameServerName().c_str());
         Contact result = ns->queryName(name);
         //printf("Got %s\n", result.toString().c_str());
         if (result.isValid()) return result;
     }
     return Contact();
 }
Ejemplo n.º 17
0
 void scan() {
     _localOnly = true;
     _usesCentralServer = false;
     _serverAllocatesPortNumbers = true;
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (!ns) continue;
         if (!ns->localOnly()) _localOnly = false;
         if (ns->usesCentralServer()) _usesCentralServer = true;
         if (!ns->serverAllocatesPortNumbers()) {
             _serverAllocatesPortNumbers = false;
         }
         if (!ns->connectionHasNameOfEndpoints()) {
             _connectionHasNameOfEndpoints = false;
         }
     }
 }
Ejemplo n.º 18
0
 Contact queryName(const ConstString& name) {
     activate();
     // try query against each namespace in order
     for (int i=0; i<(int)spaces.size(); i++) {
         NameSpace *ns = spaces[i];
         if (!ns) continue;
         if (ns->getNameServerName()==name) {
             // optimization: return cached server address for 
             // port names that match name of namespace
             return ns->getNameServerContact();
         }
         Contact result = ns->queryName(name);
         // return a result once we get one, skipping any remaining
         // namespaces
         if (result.isValid()) return result;
     }
     return Contact();
 }