26 examples.addString(txt);
27 explains.addString((explain!=
nullptr)?explain:
"");
28 details.add(Value::makeList(txt));
29 std::string more = std::string(
" ") + ((explain !=
nullptr) ? explain :
"");
30 details.addString(more.c_str());
35 addUsage(bot.
toString().c_str(),explain);
42 if (examples.size()>=1) {
43 reply.
add(Value::makeVocab32(
"many"));
51 reply.
addString(
"no documentation available");
56 reply.
addString(
"command not recognized");
66 if (!cmd.
read(connection)) {
69 yCTrace(DEVICERESPONDER,
"Command received: %s", cmd.
toString().c_str());
70 respond(cmd, response);
71 if (response.
size() >= 1) {
73 if (writer !=
nullptr) {
75 for (
size_t i = 1; i < response.
size(); i++) {
86 response.
write(*writer);
89 yCTrace(DEVICERESPONDER,
"Response sent: %s", response.
toString().c_str());
93 if (writer !=
nullptr) {
96 response.
write(*writer);
107 addUsage(
"[help]",
"list usage");
108 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 addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in 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.
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 yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
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.
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.