26Contact NameServiceOnTriples::query(
const std::string& portName,
28 const std::string& prefix,
35 t.setNameValue(
"port",portName.c_str());
36 int result = act.
mem.
find(
t,
nullptr);
41 if (!std::string(prefix).empty()) {
42 printf(
"LOOKING AT IPS FOR %s\n", prefix.c_str());
43 t.setNameValue(
"ips",
"*");
44 std::list<Triple> lst = act.
mem.
query(
t,&context);
45 for (
auto& it : lst) {
46 printf(
"LOOKING AT IPS %s\n", it.value.c_str());
47 if (it.value.find(prefix)==0) {
54 t.setNameValue(
"host",
"*");
55 std::list<Triple> lst = act.
mem.
query(
t,&context);
57 host = lst.begin()->value;
63 t.setNameValue(
"socket",
"*");
64 std::list<Triple> lst = act.
mem.
query(
t,&context);
67 sock = atoi(lst.begin()->value.c_str());
69 t.setNameValue(
"carrier",
"*");
70 std::string carrier =
"tcp";
73 carrier = lst.begin()->value;
75 t.setNameValue(
"type",
"*");
76 std::string typ =
"*";
79 typ = lst.begin()->value;
85 if (!typ.empty() && typ!=
"*") {
96 if (delegate && !nested) {
105 Contact check = Contact::fromString(port);
106 if (!check.
getHost().empty()) {
115 return query(port,act,
"");
149 std::string host = c.
getHost();
201 t.setNameValue(
"port",port.c_str());
202 int result = act.
mem.
find(
t,
nullptr);
216 printf(
" ? checking prior registration, to avoid accidental collision\n");
217 Bottle cmd(
"[ver]"), reply;
218 double timeout = 3.0;
219 double pre = SystemClock::nowSystem();
221 double post = SystemClock::nowSystem();
222 if (post-pre>timeout-1) {
226 printf(
" ? prior registration seems to be live! Denying new registration.\n");
237 printf(
" ! prior registration seems to be no longer valid, good!\n");
250 std::string carrier =
"...";
251 std::string machine =
"...";
252 std::string typ =
"*";
257 if (carrier==
"...") {
264 if (machine ==
"...") {
265 if (carrier==
"topic") {
266 machine = serverContact.
getHost();
267 }
else if (carrier!=
"mcast") {
269 if (remote.empty() || remote ==
"...") {
271 machine =
"localhost";
281 if (carrier==
"topic") {
282 sock = serverContact.
getPort();
290 if (port==
"..." || (port.length()>0 && port[0]==
'=')) {
291 Contact c(port, carrier, machine, sock);
299 t.setNameValue(
"port",port.c_str());
305 t.setNameValue(
"carrier",carrier.c_str());
308 Contact c(port, carrier, machine, sock);
312 t.setNameValue(
"host",machine.c_str());
314 sprintf(buf,
"%d",sock);
315 t.setNameValue(
"socket",buf);
318 t.setNameValue(
"type",typ.c_str());
327 if (carrier!=
"mcast") {
330 event.addString(port);
340 if (subscriber !=
nullptr && gonePublic) {
341 subscriber->
welcome(name,activity);
356 t.setNameValue(
"port",port.c_str());
357 int result = act.
mem.
find(
t,
nullptr);
361 t.setNameValue(
"owns",
"*");
362 std::list<Triple> lst = act.
mem.
query(
t,&context);
364 for (
auto& it : lst) {
371 t.setNsNameValue(
"*",
"*",
"*");
374 t.setNameValue(
"port",port.c_str());
381 event.addString(port);
402 t.setNameValue(
"port",
"*");
405 std::list<Triple> lst = act.
mem.
query(
t,
nullptr);
410 std::string port = it.value;
414 t.setNameValue(
"port",port.c_str());
424 t.setNameValue(
"yarprun",
"true");
425 std::list<Triple> lst = act.
mem.
query(
t,&context);
449 t.setNameValue(
"port",
"*");
454 std::list<Triple> lst = act.
mem.
query(
t,
nullptr);
456 for (
auto& it : lst) {
457 if (prefix.empty()) {
464 std::string iname = it.value;
465 if (iname.find(prefix)==0) {
466 if (iname==prefix || iname[prefix.length()]==
'/' ||
467 prefix[prefix.length()-1]==
'/') {
493 t.setNameValue(
"port", port.c_str());
494 int result = act.
mem.
find(
t,
nullptr);
501 t.setNameValue(key.c_str(),
"*");
503 for (
int i=0; i<n; i++) {
529 t.setNameValue(
"port",port.c_str());
530 int result = act.
mem.
find(
t,
nullptr);
537 t.setNameValue(key.c_str(),
"*");
538 std::list<Triple> lst = act.
mem.
query(
t,&context);
546 for (
auto& it : lst) {
550 for (
auto& it : lst) {
571 t.setNameValue(
"port",port.c_str());
572 int result = act.
mem.
find(
t,
nullptr);
579 t.setNameValue(key.c_str(),
"*");
580 std::list<Triple> lst = act.
mem.
query(
t,&context);
589 std::string present =
"false";
590 for (
auto& it : lst) {
591 if (val == it.value) {
614 q.
addString(std::string(
"tcp:/") + port2);
633 bot.
addString(
"Here are some ways to use the name server:");
638 bot.
addString(
"+ register $portname $carrier $ipAddress $portNumber");
639 bot.
addString(
" (if you want a field set automatically, write '...')");
642 bot.
addString(
"+ set $portname $property $value");
643 bot.
addString(
"+ get $portname $property");
644 bot.
addString(
"+ check $portname $property");
647 bot.
addString(
" (to get a list of the yarprun ports)");
657 std::string prefix =
" * ";
660 if (key==
"register") {
662 }
else if (key==
"set") {
670 yCInfo(NAMESERVICEONTRIPLES,
"%s%s", prefix.c_str(), cmd.
toString().c_str());
680 if (cmd.
check(
"format")) {
686 if (key ==
"NAME_SERVER") {
696 if (key==
"register") {
699 if (key==
"unregister") {
708 if (key==
"runners") {
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
void fromString(const std::string &text)
Initializes bottle from a string.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Bottle tail() const
Get all but the first element of a bottle.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
virtual Contact queryName(const std::string &name)=0
Map from port name to contact information.
void wait()
Decrement the counter, even if we must wait to do that.
void post()
Increment the counter.
A single value (typically within a Bottle).
virtual std::int32_t asInt32() const
Get 32-bit integer value.
std::string toString() const override
Return a standard text representation of the content of the object.
void fromString(const char *str)
Set value to correspond to a textual representation.
virtual std::string asString() const
Get string value.
virtual yarp::os::Contact completePortName(const yarp::os::Contact &c)=0
virtual yarp::os::Contact completeSocket(const yarp::os::Contact &c)=0
virtual bool freePortResources(const yarp::os::Contact &c)=0
bool cmdQuery(NameTripleState &act, bool nested=false)
bool cmdCheck(NameTripleState &act)
bool cmdRoute(NameTripleState &act)
bool cmdGet(NameTripleState &act)
bool cmdSet(NameTripleState &act)
bool cmdList(NameTripleState &act)
bool cmdListRunners(NameTripleState &act)
bool cmdUnregister(NameTripleState &act)
bool cmdGc(NameTripleState &act)
bool apply(yarp::os::Bottle &cmd, yarp::os::Bottle &reply, yarp::os::Bottle &event, const yarp::os::Contact &remote) override
bool cmdHelp(NameTripleState &act)
bool announce(const std::string &name, int activity) override
bool cmdRegister(NameTripleState &act)
yarp::os::Contact query(const std::string &portName, NameTripleState &act, const std::string &prefix, bool nested=false)
State information for a single name server operation on a database.
const yarp::os::Contact & remote
std::string getNetworkChoice()
void apply(const std::string &str)
std::string getPortName()
virtual bool welcome(const std::string &port, int activity)=0
Side information for controlling access to triples.
Abstract view of a database as a collection of triples.
virtual std::list< Triple > query(Triple &ti, TripleContext *context)=0
virtual void end(TripleContext *context)=0
virtual int find(Triple &t, TripleContext *context)=0
virtual void begin(TripleContext *context)=0
virtual void update(Triple &t, TripleContext *context)=0
virtual void remove_query(Triple &ti, TripleContext *context)=0
virtual void insert(Triple &t, TripleContext *context)=0
The basic unit of data the name server works with.
#define yCInfo(component,...)
#define YARP_SERVERSQL_LOG_COMPONENT(name, name_string)
An interface to the operating system, including Port based communication.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)