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;
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 updateHook() {
00073
00074 }
00075 public:
00076 OperationCaller<bool(std::string)> print;
00077
00082 Testcomp(std::string name) : RTT::TaskContext(name),
00083
00084 property("the_property", "the_property Description", "Hello World"),
00085 attribute("Hello World"),
00086 constant("Hello World"),
00087
00088 outport("the_results",true),
00089
00090 bufferport("the_buffer_port",ConnPolicy::buffer(13,ConnPolicy::LOCK_FREE,true) )
00091 {
00092
00093 #if 0
00094
00095 this->setActivity( new Activity(0, 0.01) );
00096 #endif
00097
00098 assert( property.ready() );
00099
00100
00101 this->properties()->addProperty( property);
00102
00103 this->addAttribute("the_attribute", attribute);
00104 this->addConstant("the_constant", constant);
00105
00106 this->ports()->addPort( outport ).doc("dummy test port");
00107 this->ports()->addPort( bufferport );
00108
00109 this->addOperation( "null_0", &Testcomp::null_0, this, OwnThread ).doc("'null_0' Description");
00110 this->addOperation( "op_0_ct", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ct', ClientThread variant");
00111 this->addOperation( "op_0_ot", &Testcomp::op_0, this, ClientThread ).doc("'op_0_ot', OwnThread variant");
00112 this->addOperation( "op_1", &Testcomp::op_1, this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
00113 this->addOperation( "op_2", &Testcomp::op_2, this, OwnThread).doc("'op_2' Description").arg("mes", "just any string.").arg("double", "just any double");
00114 this->addOperation( "op_1_out", &Testcomp::op_1_out, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
00115 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");
00116 this->addOperation( "op_1_out_retval", &Testcomp::op_1_out_retval, this, OwnThread).doc("'op_1_out' Description").arg("i", "any int");
00117 this->provides("printing")
00118 ->addOperation( "print", &Testcomp::op_1,
00119 this, OwnThread).doc("'op_1' Description").arg("mes", "just any string.");
00120
00121 this->requires("print_str")->addOperationCaller(print);
00122
00123 #if 0
00124 log(Info) << "**** Starting the 'Testcomp' component ****" <<endlog();
00125 this->start();
00126 #endif
00127 }
00128 };
00129 }
00130
00131 #include "ocl/Component.hpp"
00132 ORO_CREATE_COMPONENT( OCL::Testcomp )