testcomp.cpp
Go to the documentation of this file.
1 
6 #include <rtt/TaskContext.hpp>
7 #include <rtt/Logger.hpp>
8 #include <rtt/Property.hpp>
9 #include <rtt/Attribute.hpp>
10 #include <rtt/Operation.hpp>
11 #include <rtt/Port.hpp>
12 #include <rtt/Activity.hpp>
13 
14 #include <ocl/OCL.hpp>
15 
16 using namespace std;
17 using namespace RTT;
18 using namespace RTT::detail; // workaround in 2.0 transition phase.
19 using namespace Orocos;
20 
21 namespace OCL
22 {
23  class Testcomp : public RTT::TaskContext
24  {
25  protected:
27  std::string attribute;
28  std::string constant;
29 
32 
33  void null_0() {
34  log(Warning) << "in: void null_0" << endlog();
35  }
36 
37  std::string op_0() {
38  log(Warning) << "in: std::string op_0" << endlog();
39  return "inside operation_0";
40  }
41 
42  bool op_1(std::string s) {
43  log(Warning) << "in: bool op_1(std::string s) " << s << endlog();
44  return true;
45  }
46 
47  double op_2(std::string s, double d) {
48  log(Warning) << "in: double op_2(std::string s, double d) " << s << d << endlog();
49  return d*2;
50  }
51 
52  void op_1_out(int &i) {
53  log(Warning) << "in: void op_1_out(int &i) " << i << endlog();
54  i = i+1;
55  return;
56  }
57 
58  void op_3_out(std::string &s, double &d, int &i) {
59  log(Warning) << "in: void op_3_out(std::string &s, double &d, int &i) " << s << d << i << endlog();
60  s = s + "-this-string-has-a-tail";
61  d = d * 2;
62  i = 4711;
63  return;
64  }
65 
66  bool op_1_out_retval(int &i) {
67  log(Warning) << "in: bool op_1_out_retval(int &i) " << i << endlog();
68  i = i + 1;
69  return i%2;
70  }
71 
73  {
74  throw std::runtime_error("Alas, its time to go.");
75  }
76 
77  bool op1_uint8(unsigned char x)
78  {
79  if(x == 'x')
80  return true;
81  else
82  return false;
83  }
84 
85 
86  void updateHook() {
87  // log(Info) << "inside update_hook" << endlog();
88  }
89  public:
91 
96  Testcomp(std::string name) : RTT::TaskContext(name),
97  // Name, description, value
98  property("the_property", "the_property Description", "Hello World"),
99  attribute("Hello World"),
100  constant("Hello World"),
101  // Name, initial value
102  outport("the_results",true),
103  // Name, policy
104  bufferport("the_buffer_port",ConnPolicy::buffer(13,ConnPolicy::LOCK_FREE,true) )
105  {
106 
107 #if 0
108  // New activity with period 0.01s and priority 0.
109  this->setActivity( new Activity(0, 0.01) );
110 #endif
111  // Check if all initialisation was ok:
112  assert( property.ready() );
113 
114  // Now add it to the interface:
115  this->properties()->addProperty( property);
116 
117  this->addAttribute("the_attribute", attribute);
118  this->addConstant("the_constant", constant);
119 
120  this->ports()->addPort( outport ).doc("dummy test port");
121  this->ports()->addPort( bufferport );
122 
123  this->addOperation( "null_0", &Testcomp::null_0, this, OwnThread ).doc("'null_0' Description");
124  this->addOperation( "op_0_ct", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ct', ClientThread variant");
125  this->addOperation( "op_0_ot", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ot', OwnThread variant");
126  this->addOperation( "op_1", &Testcomp::op_1, this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
127  this->addOperation( "op_2", &Testcomp::op_2, this, OwnThread).doc("'op_2' Description").arg("mes", "just any string.").arg("double", "just any double");
128  this->addOperation( "op_1_out", &Testcomp::op_1_out, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
129  this->addOperation( "op_3_out", &Testcomp::op_3_out, this, OwnThread).doc("'op_3_out' Description").arg("mes", "just any string.").arg("double", "just any double").arg("i", "just any int");
130  this->addOperation( "op_1_out_retval", &Testcomp::op_1_out_retval, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
131 
132  this->addOperation( "op1_uint8", &Testcomp::op1_uint8, this, OwnThread).doc("'op1_uint8' Description").arg("x", "any char, try 'x'");
133 
134  this->addOperation( "throw", &Testcomp::throw_exception, this, ClientThread).doc("This operation throws an exception");
135  this->provides("printing")
136  ->addOperation( "print", &Testcomp::op_1,
137  this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
138 
139  this->requires("print_str")->addOperationCaller(print);
140 
141 #if 0
142  log(Info) << "**** Starting the 'Testcomp' component ****" <<endlog();
143  this->start();
144 #endif
145  }
146  };
147 }
148 
149 #include "ocl/Component.hpp"
RTT::Property< std::string > property
Definition: testcomp.cpp:26
RTT::InputPort< std::string > bufferport
Definition: testcomp.cpp:31
std::string constant
Definition: testcomp.cpp:28
void op_1_out(int &i)
Definition: testcomp.cpp:52
OwnThread
std::string attribute
Definition: testcomp.cpp:27
OperationCaller< bool(std::string)> print
Definition: testcomp.cpp:90
void null_0()
Definition: testcomp.cpp:33
void updateHook()
Definition: testcomp.cpp:86
void op_3_out(std::string &s, double &d, int &i)
Definition: testcomp.cpp:58
Info
bool op_1_out_retval(int &i)
Definition: testcomp.cpp:66
Warning
Testcomp(std::string name)
Definition: testcomp.cpp:96
std::string op_0()
Definition: testcomp.cpp:37
void throw_exception()
Definition: testcomp.cpp:72
bool op_1(std::string s)
Definition: testcomp.cpp:42
ClientThread
RTT::OutputPort< std::string > outport
Definition: testcomp.cpp:30
ORO_CREATE_COMPONENT(OCL::logging::Log4cxxAppender)
bool op1_uint8(unsigned char x)
Definition: testcomp.cpp:77
double op_2(std::string s, double d)
Definition: testcomp.cpp:47


ocl
Author(s): OCL Development Team
autogenerated on Mon Mar 23 2020 04:47:19