28 const std::string& prefix,
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());
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) {
55 std::list<Triple> lst =
act.mem.query(t,&context);
57 host = lst.begin()->value;
64 std::list<Triple> lst =
act.mem.query(t,&context);
67 sock =
atoi(lst.begin()->value.c_str());
70 std::string carrier =
"tcp";
71 lst =
act.mem.query(t,&context);
73 carrier = lst.begin()->value;
76 std::string
typ =
"*";
77 lst =
act.mem.query(t,&context);
79 typ = lst.begin()->value;
85 if (!
typ.empty() &&
typ!=
"*") {
96 if (delegate && !nested) {
106 if (!check.
getHost().empty()) {
121 std::string port =
act.cmd.get(1).asString();
142 if (
act.reply.size()==0 && !
act.bottleMode) {
143 act.reply.addString(
"old");
149 std::string host =
c.getHost();
150 std::string carrier =
c.getCarrier();
151 int sock =
c.getPort();
153 if (!
act.bottleMode) {
165 bname.addString(
"name");
166 bname.addString(port);
171 bnum.addString(
"port_number");
183 if (
act.bottleMode) {
185 bstate.addString(
"error");
187 bstate.addString(
"port not known");
197 std::string port =
act.cmd.get(1).asString();
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;
220 bool ok = Network::write(
c,cmd,reply,
true,
true,timeout);
222 if (post-
pre>timeout-1) {
226 printf(
" ? prior registration seems to be live! Denying new registration.\n");
234 act.cmd.fromString(
"query");
237 printf(
" ! prior registration seems to be no longer valid, good!\n");
246 act.reply.addString(
"old");
250 std::string carrier =
"...";
252 std::string
typ =
"*";
253 if (
act.cmd.size()>at) {
254 carrier =
act.cmd.get(at).asString();
257 if (carrier==
"...") {
260 if (
act.cmd.size()>at) {
265 if (carrier==
"topic") {
267 }
else if (carrier!=
"mcast") {
268 std::string remote =
act.remote.getHost();
269 if (remote.empty() || remote ==
"...") {
277 if (
act.cmd.size()>at) {
278 sock =
act.cmd.get(at).asInt32();
281 if (carrier==
"topic") {
285 if (
act.cmd.size()>at) {
286 typ =
act.cmd.get(at).asString();
290 if (port==
"..." || (port.length()>0 && port[0]==
'=')) {
300 act.mem.remove_query(t,
nullptr);
301 act.mem.insert(t,
nullptr);
302 result =
act.mem.find(t,
nullptr);
306 act.mem.update(t,&context);
313 act.mem.update(t,&context);
316 act.mem.update(t,&context);
319 act.mem.update(t,&context);
324 act.cmd.addString(
"query");
325 act.cmd.addString(port);
327 if (carrier!=
"mcast") {
329 event.addVocab32(
"add");
330 event.addString(port);
340 if (subscriber !=
nullptr && gonePublic) {
348 std::string port =
act.cmd.get(1).asString();
354 act.reply.addString(
"old");
357 int result =
act.mem.find(t,
nullptr);
362 std::list<Triple> lst =
act.mem.query(t,&context);
364 for (
auto&
it : lst) {
366 act.cmd.addString(
"unregister");
367 act.cmd.addString(
it.value.c_str());
372 act.mem.remove_query(t,&context);
375 act.mem.remove_query(t,
nullptr);
380 event.addVocab32(
"del");
381 event.addString(port);
395 act.reply.addString(
"old");
398 act.reply.addString(
"ports");
405 std::list<Triple> lst =
act.mem.query(t,
nullptr);
406 act.nestedMode =
true;
410 std::string port =
it.value;
415 int rid =
act.mem.find(t,
nullptr);
425 std::list<Triple> lst =
act.mem.query(t,&context);
430 act.cmd.addString(
"query");
431 act.cmd.addString(port);
442 if (!
act.bottleMode) {
443 act.reply.addString(
"old");
445 act.reply.addString(
"ports");
451 if (
act.cmd.size()>1) {
452 prefix =
act.cmd.get(1).asString();
454 std::list<Triple> lst =
act.mem.query(t,
nullptr);
455 act.nestedMode =
true;
456 for (
auto&
it : lst) {
457 if (prefix.empty()) {
459 act.cmd.addString(
"query");
460 act.cmd.addString(
it.value.c_str());
465 if (
iname.find(prefix)==0) {
466 if (
iname==prefix ||
iname[prefix.length()]==
'/' ||
467 prefix[prefix.length()-1]==
'/') {
469 act.cmd.addString(
"query");
485 if (!
act.bottleMode) {
486 act.reply.addString(
"old");
488 std::string port =
act.cmd.get(1).asString();
489 std::string key =
act.cmd.get(2).toString();
491 int n =
act.cmd.size() - at;
494 int result =
act.mem.find(t,
nullptr);
502 act.mem.remove_query(t,&context);
503 for (
int i=0; i<
n; i++) {
506 act.mem.insert(t,&context);
510 act.cmd.addString(
"get");
511 act.cmd.addString(port);
512 act.cmd.addString(key);
521 if (!
act.bottleMode) {
522 if (
act.reply.size()==0) {
523 act.reply.addString(
"old");
526 std::string port =
act.cmd.get(1).asString();
527 std::string key =
act.cmd.get(2).toString();
530 int result =
act.mem.find(t,
nullptr);
538 std::list<Triple> lst =
act.mem.query(t,&context);
540 if (!
act.bottleMode) {
546 for (
auto&
it : lst) {
550 for (
auto&
it : lst) {
564 if (
act.reply.size()==0) {
565 act.reply.addString(
"old");
567 std::string port =
act.cmd.get(1).asString();
568 std::string key =
act.cmd.get(2).toString();
569 std::string val =
act.cmd.get(3).toString();
572 int result =
act.mem.find(t,
nullptr);
580 std::list<Triple> lst =
act.mem.query(t,&context);
590 for (
auto&
it : lst) {
591 if (val ==
it.value) {
603 if (
act.reply.size()==0) {
604 act.reply.addString(
"old");
606 std::string
port1 =
act.cmd.get(1).asString();
607 std::string
port2 =
act.cmd.get(2).asString();
620 act.reply.addString(
"old");
631 if (!
act.bottleMode) {
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") {
680 if (cmd.
check(
"format")) {
682 act.bottleMode =
true;
686 if (key ==
"NAME_SERVER") {
691 act.bottleMode =
true;
696 if (key==
"register") {
699 if (key==
"unregister") {
708 if (key==
"runners") {
731 act.reply.addString(
"old");
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.
Bottle & addList()
Places an empty nested list 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.
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
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.
static double nowSystem()
A single value (typically within a Bottle).
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.
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 void end(TripleContext *context)=0
virtual void begin(TripleContext *context)=0
The basic unit of data the name server works with.
void setNsNameValue(const char *ns, const char *name, const char *value)
void setNameValue(const char *name, const char *value)
#define yCInfo(component,...)
#define YARP_SERVERSQL_LOG_COMPONENT(name, name_string)
An interface to the operating system, including Port based communication.