29 examples.addString(txt);
30 explains.addString((explain!=
nullptr)?explain:
"");
31 details.add(Value::makeList(txt));
32 std::string more = std::string(
" ") + ((explain !=
nullptr) ? explain :
"");
33 details.addString(more.c_str());
38 addUsage(bot.
toString().c_str(),explain);
45 if (examples.size()>=1) {
46 reply.
add(Value::makeVocab(
"many"));
54 reply.
addString(
"no documentation available");
59 reply.
addString(
"command not recognized");
69 if (!cmd.
read(connection)) {
72 yCTrace(DEVICERESPONDER,
"Command received: %s", cmd.
toString().c_str());
73 respond(cmd, response);
74 if (response.
size() >= 1) {
76 if (writer !=
nullptr) {
78 for (
size_t i = 1; i < response.
size(); i++) {
89 response.
write(*writer);
92 yCTrace(DEVICERESPONDER,
"Response sent: %s", response.
toString().c_str());
96 if (writer !=
nullptr) {
99 response.
write(*writer);
110 addUsage(
"[help]",
"list usage");
111 addUsage(
"[help] [more]",
"list usage with some comments");
DeviceResponder()
Constructor.
virtual bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
Respond to a message.
void addUsage(const char *txt, const char *explain=nullptr)
Add information about a message that the respond() method understands.
void makeUsage()
Regenerate usage information.
bool read(yarp::os::ConnectionReader &connection) override
Handler for reading messages from the network, and passing them on to the respond() method.
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 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.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
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.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
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.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
virtual bool isTextMode() const =0
Check if the connection is text mode.
A single value (typically within a Bottle).
virtual bool isList() const
Checks if value is a list.
virtual Bottle * asList() const
Get list value.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)