13 #include <yarp/os/idl/WireTypes.h> 21 void init(
const std::string& name);
22 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
23 virtual bool read(yarp::os::ConnectionReader& connection)
override;
30 void init(
const std::string& name);
31 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
32 virtual bool read(yarp::os::ConnectionReader& connection)
override;
39 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
40 virtual bool read(yarp::os::ConnectionReader& connection)
override;
48 void init(
const std::string& old_name,
const std::string& new_name);
49 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
50 virtual bool read(yarp::os::ConnectionReader& connection)
override;
57 void init(
const std::string& sw);
58 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
59 virtual bool read(yarp::os::ConnectionReader& connection)
override;
66 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
67 virtual bool read(yarp::os::ConnectionReader& connection)
override;
73 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
74 virtual bool read(yarp::os::ConnectionReader& connection)
override;
80 virtual bool write(yarp::os::ConnectionWriter& connection)
const override;
81 virtual bool read(yarp::os::ConnectionReader& connection)
override;
85 yarp::os::idl::WireWriter writer(connection);
86 if (!writer.writeListHeader(3))
return false;
87 if (!writer.writeTag(
"train_object",1,2))
return false;
88 if (!writer.writeString(
name))
return false;
93 yarp::os::idl::WireReader reader(connection);
94 if (!reader.readListReturn())
return false;
95 if (!reader.readBool(
_return)) {
108 yarp::os::idl::WireWriter writer(connection);
109 if (!writer.writeListHeader(3))
return false;
110 if (!writer.writeTag(
"remove_object",1,2))
return false;
111 if (!writer.writeString(
name))
return false;
116 yarp::os::idl::WireReader reader(connection);
117 if (!reader.readListReturn())
return false;
118 if (!reader.readBool(
_return)) {
131 yarp::os::idl::WireWriter writer(connection);
132 if (!writer.writeListHeader(2))
return false;
133 if (!writer.writeTag(
"remove_all",1,2))
return false;
138 yarp::os::idl::WireReader reader(connection);
139 if (!reader.readListReturn())
return false;
140 if (!reader.readBool(
_return)) {
152 yarp::os::idl::WireWriter writer(connection);
153 if (!writer.writeListHeader(4))
return false;
154 if (!writer.writeTag(
"change_name",1,2))
return false;
155 if (!writer.writeString(old_name))
return false;
156 if (!writer.writeString(new_name))
return false;
161 yarp::os::idl::WireReader reader(connection);
162 if (!reader.readListReturn())
return false;
163 if (!reader.readBool(
_return)) {
172 this->old_name = old_name;
173 this->new_name = new_name;
177 yarp::os::idl::WireWriter writer(connection);
178 if (!writer.writeListHeader(4))
return false;
179 if (!writer.writeTag(
"set_object_persistence",1,3))
return false;
180 if (!writer.writeString(sw))
return false;
185 yarp::os::idl::WireReader reader(connection);
186 if (!reader.readListReturn())
return false;
187 if (!reader.readBool(
_return)) {
200 yarp::os::idl::WireWriter writer(connection);
201 if (!writer.writeListHeader(3))
return false;
202 if (!writer.writeTag(
"get_object_persistence",1,3))
return false;
207 yarp::os::idl::WireReader reader(connection);
208 if (!reader.readListReturn())
return false;
209 if (!reader.readString(
_return)) {
221 yarp::os::idl::WireWriter writer(connection);
222 if (!writer.writeListHeader(1))
return false;
223 if (!writer.writeTag(
"pause",1,1))
return false;
228 yarp::os::idl::WireReader reader(connection);
229 if (!reader.readListReturn())
return false;
237 yarp::os::idl::WireWriter writer(connection);
238 if (!writer.writeListHeader(1))
return false;
239 if (!writer.writeTag(
"resume",1,1))
return false;
244 yarp::os::idl::WireReader reader(connection);
245 if (!reader.readListReturn())
return false;
253 yarp().setOwner(*
this);
259 if (!
yarp().canWrite()) {
260 yError(
"Missing server method '%s'?",
"bool iol2opc_IDL::train_object(const std::string& name)");
262 bool ok =
yarp().write(helper,helper);
269 if (!
yarp().canWrite()) {
270 yError(
"Missing server method '%s'?",
"bool iol2opc_IDL::remove_object(const std::string& name)");
272 bool ok =
yarp().write(helper,helper);
279 if (!
yarp().canWrite()) {
280 yError(
"Missing server method '%s'?",
"bool iol2opc_IDL::remove_all()");
282 bool ok =
yarp().write(helper,helper);
288 helper.
init(old_name,new_name);
289 if (!
yarp().canWrite()) {
290 yError(
"Missing server method '%s'?",
"bool iol2opc_IDL::change_name(const std::string& old_name, const std::string& new_name)");
292 bool ok =
yarp().write(helper,helper);
299 if (!
yarp().canWrite()) {
300 yError(
"Missing server method '%s'?",
"bool iol2opc_IDL::set_object_persistence(const std::string& sw)");
302 bool ok =
yarp().write(helper,helper);
309 if (!
yarp().canWrite()) {
310 yError(
"Missing server method '%s'?",
"std::string iol2opc_IDL::get_object_persistence()");
312 bool ok =
yarp().write(helper,helper);
318 if (!
yarp().canWrite()) {
319 yError(
"Missing server method '%s'?",
"void iol2opc_IDL::pause()");
321 yarp().write(helper,helper);
326 if (!
yarp().canWrite()) {
327 yError(
"Missing server method '%s'?",
"void iol2opc_IDL::resume()");
329 yarp().write(helper,helper);
333 yarp::os::idl::WireReader reader(connection);
334 reader.expectAccept();
335 if (!reader.readListHeader()) { reader.fail();
return false; }
336 std::string tag = reader.readTag();
337 bool direct = (tag==
"__direct__");
338 if (direct) tag = reader.readTag();
339 while (!reader.isError()) {
341 if (tag ==
"train_object") {
343 if (!reader.readString(name)) {
348 _return = train_object(name);
349 yarp::os::idl::WireWriter writer(reader);
350 if (!writer.isNull()) {
351 if (!writer.writeListHeader(1))
return false;
352 if (!writer.writeBool(_return))
return false;
357 if (tag ==
"remove_object") {
359 if (!reader.readString(name)) {
364 _return = remove_object(name);
365 yarp::os::idl::WireWriter writer(reader);
366 if (!writer.isNull()) {
367 if (!writer.writeListHeader(1))
return false;
368 if (!writer.writeBool(_return))
return false;
373 if (tag ==
"remove_all") {
375 _return = remove_all();
376 yarp::os::idl::WireWriter writer(reader);
377 if (!writer.isNull()) {
378 if (!writer.writeListHeader(1))
return false;
379 if (!writer.writeBool(_return))
return false;
384 if (tag ==
"change_name") {
385 std::string old_name;
386 std::string new_name;
387 if (!reader.readString(old_name)) {
391 if (!reader.readString(new_name)) {
396 _return = change_name(old_name,new_name);
397 yarp::os::idl::WireWriter writer(reader);
398 if (!writer.isNull()) {
399 if (!writer.writeListHeader(1))
return false;
400 if (!writer.writeBool(_return))
return false;
405 if (tag ==
"set_object_persistence") {
407 if (!reader.readString(sw)) {
412 _return = set_object_persistence(sw);
413 yarp::os::idl::WireWriter writer(reader);
414 if (!writer.isNull()) {
415 if (!writer.writeListHeader(1))
return false;
416 if (!writer.writeBool(_return))
return false;
421 if (tag ==
"get_object_persistence") {
423 _return = get_object_persistence();
424 yarp::os::idl::WireWriter writer(reader);
425 if (!writer.isNull()) {
426 if (!writer.writeListHeader(1))
return false;
427 if (!writer.writeString(_return))
return false;
432 if (tag ==
"pause") {
434 yarp::os::idl::WireWriter writer(reader);
435 if (!writer.isNull()) {
436 if (!writer.writeListHeader(0))
return false;
441 if (tag ==
"resume") {
443 yarp::os::idl::WireWriter writer(reader);
444 if (!writer.isNull()) {
445 if (!writer.writeListHeader(0))
return false;
451 std::string functionName;
452 if (!reader.readString(functionName)) {
453 functionName =
"--all";
455 std::vector<std::string>
_return=help(functionName);
456 yarp::os::idl::WireWriter writer(reader);
457 if (!writer.isNull()) {
458 if (!writer.writeListHeader(2))
return false;
459 if (!writer.writeTag(
"many",1, 0))
return false;
460 if (!writer.writeListBegin(BOTTLE_TAG_INT32, static_cast<uint32_t>(_return.size())))
return false;
461 std::vector<std::string> ::iterator _iterHelp;
462 for (_iterHelp = _return.begin(); _iterHelp != _return.end(); ++_iterHelp)
464 if (!writer.writeString(*_iterHelp))
return false;
466 if (!writer.writeListEnd())
return false;
471 if (reader.noMore()) { reader.fail();
return false; }
472 std::string next_tag = reader.readTag();
473 if (next_tag==
"")
break;
474 tag = tag +
"_" + next_tag;
480 bool showAll=(functionName==
"--all");
481 std::vector<std::string> helpString;
483 helpString.push_back(
"*** Available commands:");
484 helpString.push_back(
"train_object");
485 helpString.push_back(
"remove_object");
486 helpString.push_back(
"remove_all");
487 helpString.push_back(
"change_name");
488 helpString.push_back(
"set_object_persistence");
489 helpString.push_back(
"get_object_persistence");
490 helpString.push_back(
"pause");
491 helpString.push_back(
"resume");
492 helpString.push_back(
"help");
495 if (functionName==
"train_object") {
496 helpString.push_back(
"bool train_object(const std::string& name) ");
497 helpString.push_back(
"Add a new object to the object-recognition database ");
498 helpString.push_back(
"based on the selected blob. If the object is already ");
499 helpString.push_back(
"existing, its recognition is improved. ");
500 helpString.push_back(
"@param name is the object name ");
501 helpString.push_back(
"@return true/false on success/failure. ");
503 if (functionName==
"remove_object") {
504 helpString.push_back(
"bool remove_object(const std::string& name) ");
505 helpString.push_back(
"Remove object with a given name from the object-recognition ");
506 helpString.push_back(
"database. ");
507 helpString.push_back(
"@param name is the object name ");
508 helpString.push_back(
"@return true/false on success/failure. ");
510 if (functionName==
"remove_all") {
511 helpString.push_back(
"bool remove_all() ");
512 helpString.push_back(
"Remove all objects from the object-recognition ");
513 helpString.push_back(
"database. ");
514 helpString.push_back(
"@return true/false on success/failure. ");
516 if (functionName==
"change_name") {
517 helpString.push_back(
"bool change_name(const std::string& old_name, const std::string& new_name) ");
518 helpString.push_back(
"Change the name of an object ");
519 helpString.push_back(
"@param old_name is the object which name is to be changed ");
520 helpString.push_back(
"@param new_name is the new object name ");
521 helpString.push_back(
"@return true/false on success/failure. ");
523 if (functionName==
"set_object_persistence") {
524 helpString.push_back(
"bool set_object_persistence(const std::string& sw) ");
525 helpString.push_back(
"Enable/disable object persistence. ");
526 helpString.push_back(
"@param sw can be \"on\"|\"off\". ");
527 helpString.push_back(
"@return true/false on success/failure. ");
529 if (functionName==
"get_object_persistence") {
530 helpString.push_back(
"std::string get_object_persistence() ");
531 helpString.push_back(
"Return current status of object persistence. ");
532 helpString.push_back(
"@return \"on\"|\"off\". ");
534 if (functionName==
"pause") {
535 helpString.push_back(
"void pause() ");
536 helpString.push_back(
"Pause module ");
538 if (functionName==
"resume") {
539 helpString.push_back(
"void resume() ");
540 helpString.push_back(
"Resume module ");
542 if (functionName==
"help") {
543 helpString.push_back(
"std::vector<std::string> help(const std::string& functionName=\"--all\")");
544 helpString.push_back(
"Return list of available commands, or help message for a specific function");
545 helpString.push_back(
"@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
546 helpString.push_back(
"@return list of strings (one string per line)");
549 if ( helpString.empty()) helpString.push_back(
"Command not found");
virtual bool remove_all()
Remove all objects from the object-recognition database.
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool write(yarp::os::ConnectionWriter &connection) const override
void init(const std::string &sw)
virtual void pause()
Pause module.
virtual bool read(yarp::os::ConnectionReader &connection) override
void init(const std::string &name)
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool train_object(const std::string &name)
Add a new object to the object-recognition database based on the selected blob.
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool read(yarp::os::ConnectionReader &connection) override
void init(const std::string &old_name, const std::string &new_name)
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool set_object_persistence(const std::string &sw)
Enable/disable object persistence.
virtual std::vector< std::string > help(const std::string &functionName="--all")
void init(const std::string &name)
virtual bool change_name(const std::string &old_name, const std::string &new_name)
Change the name of an object.
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool remove_object(const std::string &name)
Remove object with a given name from the object-recognition database.
virtual void resume()
Resume module.
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual bool read(yarp::os::ConnectionReader &connection) override
virtual bool write(yarp::os::ConnectionWriter &connection) const override
virtual std::string get_object_persistence()
Return current status of object persistence.