30 Contact NameServiceOnTriples::query(
const std::string& portName,
32 const std::string& prefix,
39 t.setNameValue(
"port",portName.c_str());
40 int result = act.
mem.
find(
t,
nullptr);
45 if (!std::string(prefix).empty()) {
46 printf(
"LOOKING AT IPS FOR %s\n", prefix.c_str());
47 t.setNameValue(
"ips",
"*");
48 list<Triple> lst = act.
mem.
query(
t,&context);
49 for (
auto& it : lst) {
50 printf(
"LOOKING AT IPS %s\n", it.value.c_str());
51 if (it.value.find(prefix)==0) {
58 t.setNameValue(
"host",
"*");
59 list<Triple> lst = act.
mem.
query(
t,&context);
61 host = lst.begin()->value;
67 t.setNameValue(
"socket",
"*");
68 list<Triple> lst = act.
mem.
query(
t,&context);
71 sock = atoi(lst.begin()->value.c_str());
73 t.setNameValue(
"carrier",
"*");
74 std::string carrier =
"tcp";
77 carrier = lst.begin()->value;
79 t.setNameValue(
"type",
"*");
80 std::string typ =
"*";
83 typ = lst.begin()->value;
89 if (!typ.empty() && typ!=
"*") {
100 if (delegate && !nested) {
101 return delegate->queryName(portName);
110 if (!check.
getHost().empty()) {
119 return query(port,act,
"");
153 std::string host = c.
getHost();
205 t.setNameValue(
"port",port.c_str());
206 int result = act.
mem.
find(
t,
nullptr);
217 Contact c = query(port.c_str());
220 printf(
" ? checking prior registration, to avoid accidental collision\n");
221 Bottle cmd(
"[ver]"), reply;
222 double timeout = 3.0;
226 if (post-pre>timeout-1) {
230 printf(
" ? prior registration seems to be live! Denying new registration.\n");
239 return cmdQuery(act);
241 printf(
" ! prior registration seems to be no longer valid, good!\n");
254 std::string carrier =
"...";
255 std::string machine =
"...";
256 std::string typ =
"*";
261 if (carrier==
"...") {
268 if (machine ==
"...") {
269 if (carrier==
"topic") {
270 machine = serverContact.getHost();
271 }
else if (carrier!=
"mcast") {
273 if (remote.empty() || remote ==
"...") {
275 machine =
"localhost";
285 if (carrier==
"topic") {
286 sock = serverContact.getPort();
294 if (port==
"..." || (port.length()>0 && port[0]==
'=')) {
295 Contact c(port, carrier, machine, sock);
296 c = alloc->completePortName(c);
303 t.setNameValue(
"port",port.c_str());
309 t.setNameValue(
"carrier",carrier.c_str());
312 Contact c(port, carrier, machine, sock);
313 c = alloc->completeSocket(c);
316 t.setNameValue(
"host",machine.c_str());
318 sprintf(buf,
"%d",sock);
319 t.setNameValue(
"socket",buf);
322 t.setNameValue(
"type",typ.c_str());
331 if (carrier!=
"mcast") {
334 event.addString(port);
338 return cmdQuery(act);
342 bool NameServiceOnTriples::announce(
const std::string& name,
int activity)
344 if (subscriber !=
nullptr && gonePublic) {
345 subscriber->welcome(name,activity);
356 Contact contact = query(port,act,
"",
true);
357 alloc->freePortResources(contact);
360 t.setNameValue(
"port",port.c_str());
361 int result = act.
mem.
find(
t,
nullptr);
365 t.setNameValue(
"owns",
"*");
366 list<Triple> lst = act.
mem.
query(
t,&context);
368 for (
auto& it : lst) {
375 t.setNsNameValue(
"*",
"*",
"*");
378 t.setNameValue(
"port",port.c_str());
385 event.addString(port);
392 return cmdQuery(act);
406 t.setNameValue(
"port",
"*");
409 list<Triple> lst = act.
mem.
query(
t,
nullptr);
414 std::string port = it.value;
418 t.setNameValue(
"port",port.c_str());
428 t.setNameValue(
"yarprun",
"true");
429 list<Triple> lst = act.
mem.
query(
t,&context);
453 t.setNameValue(
"port",
"*");
458 list<Triple> lst = act.
mem.
query(
t,
nullptr);
460 for (
auto& it : lst) {
461 if (prefix.empty()) {
468 std::string iname = it.value;
469 if (iname.find(prefix)==0) {
470 if (iname==prefix || iname[prefix.length()]==
'/' ||
471 prefix[prefix.length()-1]==
'/') {
497 t.setNameValue(
"port", port.c_str());
498 int result = act.
mem.
find(
t,
nullptr);
505 t.setNameValue(key.c_str(),
"*");
507 for (
int i=0; i<n; i++) {
533 t.setNameValue(
"port",port.c_str());
534 int result = act.
mem.
find(
t,
nullptr);
541 t.setNameValue(key.c_str(),
"*");
542 list<Triple> lst = act.
mem.
query(
t,&context);
550 for (
auto& it : lst) {
554 for (
auto& it : lst) {
575 t.setNameValue(
"port",port.c_str());
576 int result = act.
mem.
find(
t,
nullptr);
583 t.setNameValue(key.c_str(),
"*");
584 list<Triple> lst = act.
mem.
query(
t,&context);
593 std::string present =
"false";
594 for (
auto& it : lst) {
595 if (val == it.value) {
618 q.
addString(std::string(
"tcp:/") + port2);
637 bot.
addString(
"Here are some ways to use the name server:");
642 bot.
addString(
"+ register $portname $carrier $ipAddress $portNumber");
643 bot.
addString(
" (if you want a field set automatically, write '...')");
646 bot.
addString(
"+ set $portname $property $value");
647 bot.
addString(
"+ get $portname $property");
648 bot.
addString(
"+ check $portname $property");
651 bot.
addString(
" (to get a list of the yarprun ports)");
661 std::string prefix =
" * ";
664 if (key==
"register") {
666 }
else if (key==
"set") {
674 yCInfo(NAMESERVICEONTRIPLES,
"%s%s", prefix.c_str(), cmd.
toString().c_str());
684 if (cmd.
check(
"format")) {
690 if (key ==
"NAME_SERVER") {
700 if (key==
"register") {
701 return cmdRegister(act);
703 if (key==
"unregister") {
704 return cmdUnregister(act);
707 return cmdQuery(act);
712 if (key==
"runners") {
713 return cmdListRunners(act);
722 return cmdCheck(act);
725 return cmdRoute(act);
744 void NameServiceOnTriples::lock()
750 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 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.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
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)
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
An interface to the operating system, including Port based communication.