16#include <yarp/os/idl/WireTypes.h>
19 public yarp::os::Portable
23 bool write(yarp::os::ConnectionWriter& connection)
const override;
24 bool read(yarp::os::ConnectionReader& connection)
override;
38 yarp::os::idl::WireWriter writer(connection);
39 if (!writer.writeListHeader(2)) {
42 if (!writer.writeTag(
"get_answer", 1, 2)) {
50 yarp::os::idl::WireReader reader(connection);
51 if (!reader.readListReturn()) {
62 public yarp::os::Portable
66 bool write(yarp::os::ConnectionWriter& connection)
const override;
67 bool read(yarp::os::ConnectionReader& connection)
override;
77 m_rightAnswer{rightAnswer}
84 yarp::os::idl::WireWriter writer(connection);
85 if (!writer.writeListHeader(3)) {
88 if (!writer.writeTag(
"set_answer", 1, 2)) {
99 yarp::os::idl::WireReader reader(connection);
100 if (!reader.readListReturn()) {
111 public yarp::os::Portable
115 bool write(yarp::os::ConnectionWriter& connection)
const override;
116 bool read(yarp::os::ConnectionReader& connection)
override;
133 yarp::os::idl::WireWriter writer(connection);
134 if (!writer.writeListHeader(3)) {
137 if (!writer.writeTag(
"add_int", 1, 2)) {
140 if (!writer.writeI32(
m_x)) {
148 yarp::os::idl::WireReader reader(connection);
149 if (!reader.readListReturn()) {
160 public yarp::os::Portable
164 bool write(yarp::os::ConnectionWriter& connection)
const override;
165 bool read(yarp::os::ConnectionReader& connection)
override;
179 yarp::os::idl::WireWriter writer(connection);
180 if (!writer.writeListHeader(1)) {
183 if (!writer.writeTag(
"start", 1, 1)) {
191 yarp::os::idl::WireReader reader(connection);
192 if (!reader.readListReturn()) {
203 public yarp::os::Portable
207 bool write(yarp::os::ConnectionWriter& connection)
const override;
208 bool read(yarp::os::ConnectionReader& connection)
override;
222 yarp::os::idl::WireWriter writer(connection);
223 if (!writer.writeListHeader(1)) {
226 if (!writer.writeTag(
"stop", 1, 1)) {
234 yarp::os::idl::WireReader reader(connection);
235 if (!reader.readListReturn()) {
246 public yarp::os::Portable
250 bool write(yarp::os::ConnectionWriter& connection)
const override;
251 bool read(yarp::os::ConnectionReader& connection)
override;
265 yarp::os::idl::WireWriter writer(connection);
266 if (!writer.writeListHeader(2)) {
269 if (!writer.writeTag(
"is_running", 1, 2)) {
277 yarp::os::idl::WireReader reader(connection);
278 if (!reader.readListReturn()) {
291 yarp().setOwner(*
this);
297 if (!
yarp().canWrite()) {
298 yError(
"Missing server method '%s'?",
"std::int32_t IRpcServer::get_answer()");
300 bool ok =
yarp().write(helper, helper);
307 if (!
yarp().canWrite()) {
308 yError(
"Missing server method '%s'?",
"bool IRpcServer::set_answer(const std::int32_t rightAnswer)");
310 bool ok =
yarp().write(helper, helper);
317 if (!
yarp().canWrite()) {
318 yError(
"Missing server method '%s'?",
"std::int32_t IRpcServer::add_int(const std::int32_t x)");
320 bool ok =
yarp().write(helper, helper);
327 if (!
yarp().canWrite()) {
328 yError(
"Missing server method '%s'?",
"bool IRpcServer::start()");
330 bool ok =
yarp().write(helper, helper);
337 if (!
yarp().canWrite()) {
338 yError(
"Missing server method '%s'?",
"bool IRpcServer::stop()");
340 bool ok =
yarp().write(helper, helper);
347 if (!
yarp().canWrite()) {
348 yError(
"Missing server method '%s'?",
"bool IRpcServer::is_running()");
350 bool ok =
yarp().write(helper, helper);
357 bool showAll = (functionName ==
"--all");
358 std::vector<std::string> helpString;
360 helpString.emplace_back(
"*** Available commands:");
361 helpString.emplace_back(
"get_answer");
362 helpString.emplace_back(
"set_answer");
363 helpString.emplace_back(
"add_int");
364 helpString.emplace_back(
"start");
365 helpString.emplace_back(
"stop");
366 helpString.emplace_back(
"is_running");
367 helpString.emplace_back(
"help");
369 if (functionName ==
"get_answer") {
370 helpString.emplace_back(
"std::int32_t get_answer() ");
371 helpString.emplace_back(
"Get answer from server ");
372 helpString.emplace_back(
"@return the answer ");
374 if (functionName ==
"set_answer") {
375 helpString.emplace_back(
"bool set_answer(const std::int32_t rightAnswer) ");
376 helpString.emplace_back(
"Set value for future answers. ");
377 helpString.emplace_back(
"@param rightAnswer new answer ");
378 helpString.emplace_back(
"@return true if connection was successful ");
380 if (functionName ==
"add_int") {
381 helpString.emplace_back(
"std::int32_t add_int(const std::int32_t x) ");
382 helpString.emplace_back(
"Add one integer to future answers. ");
383 helpString.emplace_back(
"@param x value to add ");
384 helpString.emplace_back(
"@return new value ");
386 if (functionName ==
"start") {
387 helpString.emplace_back(
"bool start() ");
388 helpString.emplace_back(
"Start service ");
389 helpString.emplace_back(
"@return true if service started correctly ");
391 if (functionName ==
"stop") {
392 helpString.emplace_back(
"bool stop() ");
393 helpString.emplace_back(
"Stop service ");
394 helpString.emplace_back(
"@return true if service stopped correctly ");
396 if (functionName ==
"is_running") {
397 helpString.emplace_back(
"bool is_running() ");
398 helpString.emplace_back(
"Check is service is running ");
399 helpString.emplace_back(
"@return true/false if service is/is not running ");
401 if (functionName ==
"help") {
402 helpString.emplace_back(
"std::vector<std::string> help(const std::string& functionName = \"--all\")");
403 helpString.emplace_back(
"Return list of available commands, or help message for a specific function");
404 helpString.emplace_back(
"@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
405 helpString.emplace_back(
"@return list of strings (one string per line)");
408 if (helpString.empty()) {
409 helpString.emplace_back(
"Command not found");
417 yarp::os::idl::WireReader reader(connection);
418 reader.expectAccept();
419 if (!reader.readListHeader()) {
424 std::string tag = reader.readTag();
425 bool direct = (tag ==
"__direct__");
427 tag = reader.readTag();
429 while (!reader.isError()) {
430 if (tag ==
"get_answer") {
432 yarp::os::idl::WireWriter writer(reader);
433 if (!writer.isNull()) {
434 if (!writer.writeListHeader(1)) {
444 if (tag ==
"set_answer") {
445 std::int32_t rightAnswer;
446 if (!reader.readI32(rightAnswer)) {
451 yarp::os::idl::WireWriter writer(reader);
452 if (!writer.isNull()) {
453 if (!writer.writeListHeader(1)) {
463 if (tag ==
"add_int") {
465 if (!reader.readI32(
x)) {
470 yarp::os::idl::WireWriter writer(reader);
471 if (!writer.isNull()) {
472 if (!writer.writeListHeader(1)) {
482 if (tag ==
"start") {
484 yarp::os::idl::WireWriter writer(reader);
485 if (!writer.isNull()) {
486 if (!writer.writeListHeader(1)) {
498 yarp::os::idl::WireWriter writer(reader);
499 if (!writer.isNull()) {
500 if (!writer.writeListHeader(1)) {
510 if (tag ==
"is_running") {
512 yarp::os::idl::WireWriter writer(reader);
513 if (!writer.isNull()) {
514 if (!writer.writeListHeader(1)) {
525 std::string functionName;
526 if (!reader.readString(functionName)) {
527 functionName =
"--all";
529 auto help_strings =
help(functionName);
530 yarp::os::idl::WireWriter writer(reader);
531 if (!writer.isNull()) {
532 if (!writer.writeListHeader(2)) {
535 if (!writer.writeTag(
"many", 1, 0)) {
538 if (!writer.writeListBegin(BOTTLE_TAG_INT32,
static_cast<uint32_t
>(help_strings.size()))) {
541 for (
const auto& help_string : help_strings) {
542 if (!writer.writeString(help_string)) {
546 if (!writer.writeListEnd()) {
553 if (reader.noMore()) {
557 std::string next_tag = reader.readTag();
558 if (next_tag ==
"") {
561 tag.append(
"_").append(next_tag);
IRpcServer_add_int_helper(const std::int32_t x)
bool write(yarp::os::ConnectionWriter &connection) const override
bool read(yarp::os::ConnectionReader &connection) override
static thread_local std::int32_t s_return_helper
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
static thread_local std::int32_t s_return_helper
IRpcServer_get_answer_helper()
IRpcServer_is_running_helper()
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
static thread_local bool s_return_helper
std::int32_t m_rightAnswer
IRpcServer_set_answer_helper(const std::int32_t rightAnswer)
bool write(yarp::os::ConnectionWriter &connection) const override
bool read(yarp::os::ConnectionReader &connection) override
static thread_local bool s_return_helper
bool write(yarp::os::ConnectionWriter &connection) const override
IRpcServer_start_helper()
bool read(yarp::os::ConnectionReader &connection) override
static thread_local bool s_return_helper
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
static thread_local bool s_return_helper
virtual bool stop()
Stop service.
virtual bool set_answer(const std::int32_t rightAnswer)
Set value for future answers.
virtual std::int32_t get_answer()
Get answer from server.
virtual std::int32_t add_int(const std::int32_t x)
Add one integer to future answers.
virtual bool is_running()
Check is service is running.
virtual std::vector< std::string > help(const std::string &functionName="--all")
bool read(yarp::os::ConnectionReader &connection) override
virtual bool start()
Start service.
Copyright (C) 2008 RobotCub Consortium.