icub-client
iol2opc_IDL.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 // This is an automatically generated file.
10 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
11 
12 #include <iol2opc_IDL.h>
13 #include <yarp/os/idl/WireTypes.h>
14 
15 
16 
17 class iol2opc_IDL_train_object : public yarp::os::Portable {
18 public:
19  std::string name;
20  bool _return;
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;
24 };
25 
26 class iol2opc_IDL_remove_object : public yarp::os::Portable {
27 public:
28  std::string name;
29  bool _return;
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;
33 };
34 
35 class iol2opc_IDL_remove_all : public yarp::os::Portable {
36 public:
37  bool _return;
38  void init();
39  virtual bool write(yarp::os::ConnectionWriter& connection) const override;
40  virtual bool read(yarp::os::ConnectionReader& connection) override;
41 };
42 
43 class iol2opc_IDL_change_name : public yarp::os::Portable {
44 public:
45  std::string old_name;
46  std::string new_name;
47  bool _return;
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;
51 };
52 
53 class iol2opc_IDL_set_object_persistence : public yarp::os::Portable {
54 public:
55  std::string sw;
56  bool _return;
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;
60 };
61 
62 class iol2opc_IDL_get_object_persistence : public yarp::os::Portable {
63 public:
64  std::string _return;
65  void init();
66  virtual bool write(yarp::os::ConnectionWriter& connection) const override;
67  virtual bool read(yarp::os::ConnectionReader& connection) override;
68 };
69 
70 class iol2opc_IDL_pause : public yarp::os::Portable {
71 public:
72  void init();
73  virtual bool write(yarp::os::ConnectionWriter& connection) const override;
74  virtual bool read(yarp::os::ConnectionReader& connection) override;
75 };
76 
77 class iol2opc_IDL_resume : public yarp::os::Portable {
78 public:
79  void init();
80  virtual bool write(yarp::os::ConnectionWriter& connection) const override;
81  virtual bool read(yarp::os::ConnectionReader& connection) override;
82 };
83 
84 bool iol2opc_IDL_train_object::write(yarp::os::ConnectionWriter& connection) const {
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;
89  return true;
90 }
91 
92 bool iol2opc_IDL_train_object::read(yarp::os::ConnectionReader& connection) {
93  yarp::os::idl::WireReader reader(connection);
94  if (!reader.readListReturn()) return false;
95  if (!reader.readBool(_return)) {
96  reader.fail();
97  return false;
98  }
99  return true;
100 }
101 
102 void iol2opc_IDL_train_object::init(const std::string& name) {
103  _return = false;
104  this->name = name;
105 }
106 
107 bool iol2opc_IDL_remove_object::write(yarp::os::ConnectionWriter& connection) const {
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;
112  return true;
113 }
114 
115 bool iol2opc_IDL_remove_object::read(yarp::os::ConnectionReader& connection) {
116  yarp::os::idl::WireReader reader(connection);
117  if (!reader.readListReturn()) return false;
118  if (!reader.readBool(_return)) {
119  reader.fail();
120  return false;
121  }
122  return true;
123 }
124 
125 void iol2opc_IDL_remove_object::init(const std::string& name) {
126  _return = false;
127  this->name = name;
128 }
129 
130 bool iol2opc_IDL_remove_all::write(yarp::os::ConnectionWriter& connection) const {
131  yarp::os::idl::WireWriter writer(connection);
132  if (!writer.writeListHeader(2)) return false;
133  if (!writer.writeTag("remove_all",1,2)) return false;
134  return true;
135 }
136 
137 bool iol2opc_IDL_remove_all::read(yarp::os::ConnectionReader& connection) {
138  yarp::os::idl::WireReader reader(connection);
139  if (!reader.readListReturn()) return false;
140  if (!reader.readBool(_return)) {
141  reader.fail();
142  return false;
143  }
144  return true;
145 }
146 
148  _return = false;
149 }
150 
151 bool iol2opc_IDL_change_name::write(yarp::os::ConnectionWriter& connection) const {
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;
157  return true;
158 }
159 
160 bool iol2opc_IDL_change_name::read(yarp::os::ConnectionReader& connection) {
161  yarp::os::idl::WireReader reader(connection);
162  if (!reader.readListReturn()) return false;
163  if (!reader.readBool(_return)) {
164  reader.fail();
165  return false;
166  }
167  return true;
168 }
169 
170 void iol2opc_IDL_change_name::init(const std::string& old_name, const std::string& new_name) {
171  _return = false;
172  this->old_name = old_name;
173  this->new_name = new_name;
174 }
175 
176 bool iol2opc_IDL_set_object_persistence::write(yarp::os::ConnectionWriter& connection) const {
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;
181  return true;
182 }
183 
184 bool iol2opc_IDL_set_object_persistence::read(yarp::os::ConnectionReader& connection) {
185  yarp::os::idl::WireReader reader(connection);
186  if (!reader.readListReturn()) return false;
187  if (!reader.readBool(_return)) {
188  reader.fail();
189  return false;
190  }
191  return true;
192 }
193 
194 void iol2opc_IDL_set_object_persistence::init(const std::string& sw) {
195  _return = false;
196  this->sw = sw;
197 }
198 
199 bool iol2opc_IDL_get_object_persistence::write(yarp::os::ConnectionWriter& connection) const {
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;
203  return true;
204 }
205 
206 bool iol2opc_IDL_get_object_persistence::read(yarp::os::ConnectionReader& connection) {
207  yarp::os::idl::WireReader reader(connection);
208  if (!reader.readListReturn()) return false;
209  if (!reader.readString(_return)) {
210  reader.fail();
211  return false;
212  }
213  return true;
214 }
215 
217  _return = "";
218 }
219 
220 bool iol2opc_IDL_pause::write(yarp::os::ConnectionWriter& connection) const {
221  yarp::os::idl::WireWriter writer(connection);
222  if (!writer.writeListHeader(1)) return false;
223  if (!writer.writeTag("pause",1,1)) return false;
224  return true;
225 }
226 
227 bool iol2opc_IDL_pause::read(yarp::os::ConnectionReader& connection) {
228  yarp::os::idl::WireReader reader(connection);
229  if (!reader.readListReturn()) return false;
230  return true;
231 }
232 
234 }
235 
236 bool iol2opc_IDL_resume::write(yarp::os::ConnectionWriter& connection) const {
237  yarp::os::idl::WireWriter writer(connection);
238  if (!writer.writeListHeader(1)) return false;
239  if (!writer.writeTag("resume",1,1)) return false;
240  return true;
241 }
242 
243 bool iol2opc_IDL_resume::read(yarp::os::ConnectionReader& connection) {
244  yarp::os::idl::WireReader reader(connection);
245  if (!reader.readListReturn()) return false;
246  return true;
247 }
248 
250 }
251 
253  yarp().setOwner(*this);
254 }
255 bool iol2opc_IDL::train_object(const std::string& name) {
256  bool _return = false;
258  helper.init(name);
259  if (!yarp().canWrite()) {
260  yError("Missing server method '%s'?","bool iol2opc_IDL::train_object(const std::string& name)");
261  }
262  bool ok = yarp().write(helper,helper);
263  return ok?helper._return:_return;
264 }
265 bool iol2opc_IDL::remove_object(const std::string& name) {
266  bool _return = false;
268  helper.init(name);
269  if (!yarp().canWrite()) {
270  yError("Missing server method '%s'?","bool iol2opc_IDL::remove_object(const std::string& name)");
271  }
272  bool ok = yarp().write(helper,helper);
273  return ok?helper._return:_return;
274 }
276  bool _return = false;
277  iol2opc_IDL_remove_all helper;
278  helper.init();
279  if (!yarp().canWrite()) {
280  yError("Missing server method '%s'?","bool iol2opc_IDL::remove_all()");
281  }
282  bool ok = yarp().write(helper,helper);
283  return ok?helper._return:_return;
284 }
285 bool iol2opc_IDL::change_name(const std::string& old_name, const std::string& new_name) {
286  bool _return = false;
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)");
291  }
292  bool ok = yarp().write(helper,helper);
293  return ok?helper._return:_return;
294 }
295 bool iol2opc_IDL::set_object_persistence(const std::string& sw) {
296  bool _return = false;
298  helper.init(sw);
299  if (!yarp().canWrite()) {
300  yError("Missing server method '%s'?","bool iol2opc_IDL::set_object_persistence(const std::string& sw)");
301  }
302  bool ok = yarp().write(helper,helper);
303  return ok?helper._return:_return;
304 }
306  std::string _return = "";
308  helper.init();
309  if (!yarp().canWrite()) {
310  yError("Missing server method '%s'?","std::string iol2opc_IDL::get_object_persistence()");
311  }
312  bool ok = yarp().write(helper,helper);
313  return ok?helper._return:_return;
314 }
316  iol2opc_IDL_pause helper;
317  helper.init();
318  if (!yarp().canWrite()) {
319  yError("Missing server method '%s'?","void iol2opc_IDL::pause()");
320  }
321  yarp().write(helper,helper);
322 }
324  iol2opc_IDL_resume helper;
325  helper.init();
326  if (!yarp().canWrite()) {
327  yError("Missing server method '%s'?","void iol2opc_IDL::resume()");
328  }
329  yarp().write(helper,helper);
330 }
331 
332 bool iol2opc_IDL::read(yarp::os::ConnectionReader& connection) {
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()) {
340  // TODO: use quick lookup, this is just a test
341  if (tag == "train_object") {
342  std::string name;
343  if (!reader.readString(name)) {
344  reader.fail();
345  return false;
346  }
347  bool _return;
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;
353  }
354  reader.accept();
355  return true;
356  }
357  if (tag == "remove_object") {
358  std::string name;
359  if (!reader.readString(name)) {
360  reader.fail();
361  return false;
362  }
363  bool _return;
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;
369  }
370  reader.accept();
371  return true;
372  }
373  if (tag == "remove_all") {
374  bool _return;
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;
380  }
381  reader.accept();
382  return true;
383  }
384  if (tag == "change_name") {
385  std::string old_name;
386  std::string new_name;
387  if (!reader.readString(old_name)) {
388  reader.fail();
389  return false;
390  }
391  if (!reader.readString(new_name)) {
392  reader.fail();
393  return false;
394  }
395  bool _return;
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;
401  }
402  reader.accept();
403  return true;
404  }
405  if (tag == "set_object_persistence") {
406  std::string sw;
407  if (!reader.readString(sw)) {
408  reader.fail();
409  return false;
410  }
411  bool _return;
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;
417  }
418  reader.accept();
419  return true;
420  }
421  if (tag == "get_object_persistence") {
422  std::string _return;
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;
428  }
429  reader.accept();
430  return true;
431  }
432  if (tag == "pause") {
433  pause();
434  yarp::os::idl::WireWriter writer(reader);
435  if (!writer.isNull()) {
436  if (!writer.writeListHeader(0)) return false;
437  }
438  reader.accept();
439  return true;
440  }
441  if (tag == "resume") {
442  resume();
443  yarp::os::idl::WireWriter writer(reader);
444  if (!writer.isNull()) {
445  if (!writer.writeListHeader(0)) return false;
446  }
447  reader.accept();
448  return true;
449  }
450  if (tag == "help") {
451  std::string functionName;
452  if (!reader.readString(functionName)) {
453  functionName = "--all";
454  }
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)
463  {
464  if (!writer.writeString(*_iterHelp)) return false;
465  }
466  if (!writer.writeListEnd()) return false;
467  }
468  reader.accept();
469  return true;
470  }
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;
475  }
476  return false;
477 }
478 
479 std::vector<std::string> iol2opc_IDL::help(const std::string& functionName) {
480  bool showAll=(functionName=="--all");
481  std::vector<std::string> helpString;
482  if(showAll) {
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");
493  }
494  else {
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. ");
502  }
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. ");
509  }
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. ");
515  }
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. ");
522  }
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. ");
528  }
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\". ");
533  }
534  if (functionName=="pause") {
535  helpString.push_back("void pause() ");
536  helpString.push_back("Pause module ");
537  }
538  if (functionName=="resume") {
539  helpString.push_back("void resume() ");
540  helpString.push_back("Resume module ");
541  }
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)");
547  }
548  }
549  if ( helpString.empty()) helpString.push_back("Command not found");
550  return helpString;
551 }
552 
553 
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
Definition: iol2opc_IDL.cpp:84
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
Definition: iol2opc_IDL.cpp:92
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.