testcomp.cpp
Go to the documentation of this file.
00001 
00006 #include <rtt/TaskContext.hpp>
00007 #include <rtt/Logger.hpp>
00008 #include <rtt/Property.hpp>
00009 #include <rtt/Attribute.hpp>
00010 #include <rtt/Operation.hpp>
00011 #include <rtt/Port.hpp>
00012 #include <rtt/Activity.hpp>
00013 
00014 #include <ocl/OCL.hpp>
00015 
00016 using namespace std;
00017 using namespace RTT;
00018 using namespace RTT::detail; // workaround in 2.0 transition phase.
00019 using namespace Orocos;
00020 
00021 namespace OCL
00022 {
00023         class Testcomp : public RTT::TaskContext
00024         {
00025         protected:
00026                 RTT::Property<std::string> property;
00027                 std::string attribute;
00028                 std::string constant;
00029 
00030                 RTT::OutputPort<std::string> outport;
00031                 RTT::InputPort<std::string> bufferport;
00032 
00033                 void null_0() {
00034                         log(Warning) << "in: void null_0" << endlog();
00035                 }
00036 
00037                 std::string op_0() {
00038                         log(Warning) << "in: std::string op_0" << endlog();
00039                         return "inside operation_0";
00040                 }
00041 
00042                 bool op_1(std::string s) {
00043                         log(Warning) << "in: bool op_1(std::string s) " << s << endlog();
00044                         return true;
00045                 }
00046 
00047                 double op_2(std::string s, double d) {
00048                         log(Warning) << "in: double op_2(std::string s, double d) " << s << d << endlog();
00049                         return d*2;
00050                 }
00051 
00052                 void op_1_out(int &i) {
00053                         log(Warning) << "in: void op_1_out(int &i) " << i << endlog();
00054                         i = i+1;
00055                         return;
00056                 }
00057 
00058                 void op_3_out(std::string &s, double &d, int &i) {
00059                         log(Warning) << "in: void op_3_out(std::string &s, double &d, int &i) " << s << d << i << endlog();
00060                         s = s + "-this-string-has-a-tail";
00061                         d = d * 2;
00062                         i = 4711;
00063                         return;
00064                 }
00065 
00066                 bool op_1_out_retval(int &i) {
00067                         log(Warning) << "in: bool op_1_out_retval(int &i) " << i << endlog();
00068                         i = i + 1;
00069                         return i%2;
00070                 }
00071 
00072                 void throw_exception()
00073                 {
00074                         throw std::runtime_error("Alas, its time to go.");
00075                 }
00076 
00077                 bool op1_uint8(unsigned char x)
00078                 {
00079                         if(x == 'x')
00080                                 return true;
00081                         else
00082                                 return false;
00083                 }
00084 
00085 
00086                 void updateHook() {
00087                         // log(Info) << "inside update_hook" << endlog();
00088                 }
00089         public:
00090                 OperationCaller<bool(std::string)> print;
00091 
00096                 Testcomp(std::string name) : RTT::TaskContext(name),
00097                           // Name, description, value
00098                           property("the_property", "the_property Description", "Hello World"),
00099                           attribute("Hello World"),
00100                           constant("Hello World"),
00101                           // Name, initial value
00102                           outport("the_results",true),
00103                           // Name, policy
00104                           bufferport("the_buffer_port",ConnPolicy::buffer(13,ConnPolicy::LOCK_FREE,true) )
00105                 {
00106 
00107 #if 0
00108                         // New activity with period 0.01s and priority 0.
00109                         this->setActivity( new Activity(0, 0.01) );
00110 #endif
00111                         // Check if all initialisation was ok:
00112                         assert( property.ready() );
00113 
00114                         // Now add it to the interface:
00115                         this->properties()->addProperty( property);
00116 
00117                         this->addAttribute("the_attribute", attribute);
00118                         this->addConstant("the_constant", constant);
00119 
00120                         this->ports()->addPort( outport ).doc("dummy test port");
00121                         this->ports()->addPort( bufferport );
00122 
00123                         this->addOperation( "null_0", &Testcomp::null_0, this, OwnThread ).doc("'null_0' Description");
00124                         this->addOperation( "op_0_ct", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ct', ClientThread variant");
00125                         this->addOperation( "op_0_ot", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ot', OwnThread variant");
00126                         this->addOperation( "op_1", &Testcomp::op_1, this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
00127                         this->addOperation( "op_2", &Testcomp::op_2, this, OwnThread).doc("'op_2' Description").arg("mes", "just any string.").arg("double", "just any double");
00128                         this->addOperation( "op_1_out", &Testcomp::op_1_out, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
00129                         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");
00130                         this->addOperation( "op_1_out_retval", &Testcomp::op_1_out_retval, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
00131 
00132                         this->addOperation( "op1_uint8", &Testcomp::op1_uint8, this, OwnThread).doc("'op1_uint8' Description").arg("x", "any char, try 'x'");
00133 
00134                         this->addOperation( "throw", &Testcomp::throw_exception, this, ClientThread).doc("This operation throws an exception");
00135                         this->provides("printing")
00136                                 ->addOperation( "print", &Testcomp::op_1,
00137                                                 this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
00138 
00139                         this->requires("print_str")->addOperationCaller(print);
00140 
00141 #if 0
00142                         log(Info) << "**** Starting the 'Testcomp' component ****" <<endlog();
00143                         this->start();
00144 #endif
00145                 }
00146         };
00147 }
00148 
00149 #include "ocl/Component.hpp"
00150 ORO_CREATE_COMPONENT( OCL::Testcomp )


ocl
Author(s): OCL Development Team
autogenerated on Thu Jan 2 2014 11:38:08