38 static constexpr size_t MAX_ARG_CT =20;
39 static constexpr size_t MAX_ARG_LEN = 256;
42 const char* argv[MAX_ARG_CT];
43 char buf[MAX_ARG_CT][MAX_ARG_LEN];
49 for (
auto&
i : argv) {
54 Params(
const char* command)
64 const char* get(
int idx)
69 void apply(
const char* command)
74 for (
i = 0;
i <
strlen(command) + 1;
i++) {
75 if (at < MAX_ARG_CT) {
77 if (ch >= 32 || ch ==
'\0' || ch ==
'\n') {
78 if (ch ==
' ' || ch ==
'\n') {
81 if (
sub_at < MAX_ARG_LEN) {
94 for (
i = 0;
i < MAX_ARG_CT;
i++) {
96 buf[
i][MAX_ARG_LEN - 1] =
'\0';
105NameClient::NameClient() :
109 allowSaveScan(
false),
111 reportSaveScan(
false),
119 if (fakeServer !=
nullptr) {
121 fakeServer =
nullptr;
145 size_t i1 = name.find(
':');
146 if (
i1 != std::string::npos) {
148 if (
c.isValid() &&
c.getPort() > 0) {
153 if (altStore !=
nullptr) {
158 std::string
q(
"NAME_SERVER query ");
180 if (
suggest.isValid() || !prefix.empty() ||
typ !=
"*") {
181 if (!
suggest.getCarrier().empty()) {
186 if (!
suggest.getHost().empty()) {
189 if (!prefix.empty()) {
191 for (
size_t i = 0;
i <
ips.size();
i++) {
192 std::string ip =
ips.get(
i).asString();
193 if (ip.find(prefix) == 0) {
199 cmd.
addString((!prefix.empty()) ? prefix :
"...");
210 if (!
suggest.getCarrier().empty()) {
225 std::string
cmdOffers =
"set /port offers ";
227 for (
size_t i = 0;
i < lst.
size();
i++) {
259 std::string
q(
"NAME_SERVER unregister ");
266 std::string result =
send(cmd);
272 Params
p(txt.c_str());
275 if (std::string(
p.get(0)) ==
"registration") {
277 const char* ip =
p.get(4);
278 int port =
atoi(
p.get(6));
279 const char* carrier =
p.get(8);
288 if (bot.
size() >= 9) {
326 server.setTimeout(timeout);
366 reportSaveScan =
true;
374 server.setTimeout(timeout);
384 std::string
cmdn = cmd +
"\n";
396 if (line.length() > 1) {
397 if (line[0] ==
'*' || line[0] ==
'[') {
401 result += line +
"\n";
446 allowSaveScan =
allow;
456 return reportSaveScan;
505 if (fakeServer ==
nullptr) {
512void NameClient::setup()
514 static std::mutex mutex;
516 if ((!fake) && (!isSetup)) {
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
void append(const Bottle &alt)
Append the content of the given bottle to the current 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.
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.
A mini-server for performing network communication in the background.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
A simple abstraction for a block of bytes.
static Bottle listCarriers()
Abstract interface for a database of port names.
virtual Contact query(const std::string &name)=0
static NameStore * getQueryBypass()
static int getDefaultPortRange()
Under normal operation, YARP has a name server that manages a pool of (socket) ports starting at a po...
static bool writeToNameServer(PortWriter &cmd, PortReader &reply, const ContactStyle &style)
Variant write method specialized to name server.
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.
The output side of an active connection between two ports.
virtual OutputStream & getOutputStream()=0
Access the output stream associated with the connection.
virtual void close()=0
Negotiate an end to operations.
virtual InputStream & getInputStream()=0
Access the input stream associated with the connection.
virtual bool isOk() const =0
Check if the connection is valid and can be used.
A single value (typically within a Bottle).
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::string asString() const
Get string value.
Client for YARP name server.
Contact unregisterName(const std::string &name)
Register disassociation of name from port.
static NameClient & getNameClient()
Get an instance of the name client.
bool didScan()
Check whether the name client scanned for the address of the name server.
yarp::os::Nodes & getNodes()
static NameClient * create()
Contact probe(const std::string &cmd)
Send a message to the name server, and interpret the result as an address.
static Contact extractAddress(const std::string &txt)
Extract an address from its text representation.
bool didSave()
Check whether the name client saved the address of the name server.
void queryBypass(NameStore *store)
Contact getAddress()
The address of the name server.
bool updateAddress()
Force the name client to reread the cached location of the name server.
bool setContact(const yarp::os::Contact &contact)
std::string send(const std::string &cmd, bool multi=true, const ContactStyle &style=ContactStyle())
Send a text message to the nameserver, and return the result.
Contact queryName(const std::string &name)
Look up the address of a named port.
NameStore * getQueryBypass()
void setFakeMode(bool fake=true)
For testing, the nameclient can be set to use a "fake" name server rather than communicating with an ...
bool isFakeMode() const
Check whether a fake name server is being used.
virtual ~NameClient()
Destructor.
void setScan(bool allow=true)
Control whether the name client should scan for the name server if the cached connection information ...
Contact registerName(const std::string &name)
Register a port with a given name.
void setSave(bool allow=true)
Control whether the name client can save the address of the name server in a cache file.
Small helper class to help deal with legacy YARP configuration files.
bool fromFile(const char *ns=nullptr)
static yarp::os::Bottle getIpsAsBottle()
void setAddress(const Contact &address)
bool toFile(bool clean=false)
Implementation of a YARP2-conforming name server.
std::string apply(const std::string &txt, const Contact &remote) override
Communicating with a port via TCP.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
int getpid()
Portable wrapper for the getppid() function.