void clear() { if (!mutex.try_lock()) { return; } while (name_cache.begin() != name_cache.end()) { Contactable *c = name_cache.begin()->first; if (c) { mutex.unlock(); c->interrupt(); c->close(); mutex.lock(); // Close will remove the Contactable from the map only the first // time that a node is found (for example if "/foo+@/node" and // "/foo-@node" are registered, only the first time that "/node" // is found it is removed automatically. The second time it must // be removed manually. if (!name_cache.empty() && name_cache.begin()->first == c) { name_cache.erase(name_cache.begin()); } } } mutex.unlock(); port.interrupt(); }
bool XmlRpcCarrier::shouldInterpretRosMessages(ConnectionState& proto) { // We need to set the interpretRos flag, which controls // whether ROS-style admin messages are treated as // admin messages or data messages in YARP. // In the future, they should always be data messages. // For now, they should be admin messages for all ports // except ports tagged as corresponding to ros nodes. bool nodelike = false; Contactable *port = proto.getContactable(); Property opt; if (port) { Property *pport = port->acquireProperties(true); if (pport) { opt = *pport; } port->releaseProperties(pport); } if (opt.check("node_like")) { nodelike = true; } Name n(proto.getRoute().getCarrierName() + "://test"); ConstString rospass = n.getCarrierModifier("ros"); interpretRos = !nodelike; if (rospass=="1"||rospass=="on") { interpretRos = true; } if (rospass=="0"||rospass=="off") { interpretRos = false; } return interpretRos; }
void yarp::os::Nodes::Private::update(Contactable& contactable) { NestedContact nc(contactable.getName()); if (!nc.isNested()) { return; } if (!active) { return; } Node* node = getNode(contactable.getName(), true); if (node) { node->update(contactable); } }
void Nodes::update(Contactable& contactable) { NestedContact nc(contactable.getName()); if (!nc.isNested()) return; HELPER(this).mutex.unlock(); HELPER(this).update(contactable); HELPER(this).mutex.lock(); }
void update() { if (nc.getTypeName()=="") { if (!contactable) return; Type typ = contactable->getType(); if (typ.isValid()) { nc.setTypeName(typ.getName()); } } }
void yarp::os::Nodes::Private::remove(Contactable& contactable) { if (!active) { return; } Node* node = getNode(contactable.getName(), false); if (node) { node->remove(contactable); } }
static bool waitForOutput(Contactable& c,double timeout) { double start = Time::now(); while (Time::now()-start<timeout) { if (c.getOutputCount()>0) { return true; } Time::delay(0.1); } return false; }
void yarp::os::Node::Helper::remove(Contactable& contactable) { mutex.lock(); NodeItem item = name_cache[&contactable]; name_cache.erase(&contactable); std::string nestedName = item.nc.getNestedName(); for (std::multimap<std::string, NodeItem>::iterator it = by_part_name.begin(); it != by_part_name.end(); ++it) { if (it->first == nestedName && it->second.contactable->where().toString() == contactable.where().toString()) { by_part_name.erase(it); break; } } std::string category = item.nc.getCategory(); for (std::multimap<std::string, NodeItem>::iterator it = by_category.begin(); it != by_category.end(); ++it) { if (it->first == category && it->second.contactable->where().toString() == contactable.where().toString()) { by_category.erase(it); break; } } mutex.unlock(); }
void NodeHelper::add(Contactable& contactable) { NodeItem item; item.nc.fromString(contactable.getName()); if (name=="") name = item.nc.getNodeName(); if (name!=item.nc.getNodeName()) { fprintf(stderr,"Node name mismatch, expected [%s] but got [%s]\n", name.c_str(), item.nc.getNodeName().c_str()); return; } prepare(name); item.contactable = &contactable; name_cache[&contactable] = item; by_part_name[item.nc.getNestedName()] = item; by_category.insert(std::pair<ConstString,NodeItem>(item.nc.getCategory(),item)); }
void NodesHelper::remove(Contactable& contactable) { if (!active) return; Node *node = getNode(contactable.getName(),false); if (node) node->remove(contactable); }
void NodesHelper::update(Contactable& contactable) { if (!active) return; Node *node = getNode(contactable.getName(),true); if (node) node->update(contactable); }