26 Contact 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) {
97 return delegate->queryName(portName);
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);
213 Contact c = query(port.c_str());
216 printf(
" ? checking prior registration, to avoid accidental collision\n");
217 Bottle cmd(
"[ver]"), reply;
218 double timeout = 3.0;
222 if (post-pre>timeout-1) {
226 printf(
" ? prior registration seems to be live! Denying new registration.\n");
235 return cmdQuery(act);
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);
292 c = alloc->completePortName(c);
299 t.setNameValue(
"port",port.c_str());
305 t.setNameValue(
"carrier",carrier.c_str());
308 Contact c(port, carrier, machine, sock);
309 c = alloc->completeSocket(c);
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);
334 return cmdQuery(act);
338 bool NameServiceOnTriples::announce(
const std::string& name,
int activity)
340 if (subscriber !=
nullptr && gonePublic) {
341 subscriber->welcome(name,activity);
352 Contact contact = query(port,act,
"",
true);
353 alloc->freePortResources(contact);
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);
388 return cmdQuery(act);
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") {
697 return cmdRegister(act);
699 if (key==
"unregister") {
700 return cmdUnregister(act);
703 return cmdQuery(act);
708 if (key==
"runners") {
709 return cmdListRunners(act);
718 return cmdCheck(act);
721 return cmdRoute(act);
740 void NameServiceOnTriples::lock()
746 void NameServiceOnTriples::unlock()
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.
static bool write(const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
Send a single command to a port and await a single response.
static double nowSystem()
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.
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()
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 int find(Triple &t, 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.