Go to the documentation of this file.00001
00008 #include <rtt/os/main.h>
00009
00010 #include <rtt/TaskContext.hpp>
00011 #include <taskbrowser/TaskBrowser.hpp>
00012 #include <rtt/Logger.hpp>
00013 #include <rtt/Property.hpp>
00014 #include <rtt/Attribute.hpp>
00015 #include <rtt/OperationCaller.hpp>
00016 #include <rtt/Port.hpp>
00017 #include <rtt/Activity.hpp>
00018
00019 #include <ocl/OCL.hpp>
00020
00021 using namespace std;
00022 using namespace RTT;
00023 using namespace RTT::detail;
00024 using namespace Orocos;
00025
00026 namespace OCL
00027 {
00028
00034 class HelloWorld
00035 : public RTT::TaskContext
00036 {
00037 protected:
00046 std::string property;
00047
00052 bool flag;
00056 std::string attribute;
00061 std::string constant;
00072 RTT::OutputPort<std::string> outport;
00076 RTT::InputPort<std::string> bufferport;
00082 std::string mymethod() {
00083 return "Hello World";
00084 }
00085
00089 bool sayWorld( const std::string& word) {
00090 cout <<"Saying Hello '"<<word<<"' in own thread." <<endl;
00091 if (word == "World")
00092 return true;
00093 return false;
00094 }
00095
00096 void updateHook() {
00097 if (flag) {
00098 cout <<"flag: " << flag <<endl;
00099 cout <<"the_property: "<< property <<endl;
00100 cout <<"the_attribute: "<< attribute <<endl;
00101 cout <<"the_constant: "<< constant <<endl;
00102 cout <<"Setting 'flag' back to false."<<endl;
00103 flag = false;
00104 }
00105
00106 outport.write("Hello World!");
00107
00108 std::string sample;
00109 while(bufferport.read(sample) == NewData) {
00110 log(Debug) << "Received " << sample << endlog();
00111 }
00112 }
00113 public:
00118 HelloWorld(std::string name)
00119 : RTT::TaskContext(name,PreOperational),
00120
00121 property("Hello Property"), flag(false),
00122 attribute("Hello Attribute"),
00123 constant("Hello Constant"),
00124
00125 outport("the_results",true),
00126
00127 bufferport("the_buffer_port",ConnPolicy::buffer(13,ConnPolicy::LOCK_FREE,true) )
00128 {
00129
00130 this->setActivity( new Activity(0, 0.1) );
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 this->properties()->addProperty("the_property", property).doc("A friendly property.");
00141
00142 this->addAttribute("flag", flag);
00143 this->addAttribute("the_attribute", attribute);
00144 this->addConstant("the_constant", constant);
00145
00146 this->ports()->addPort( outport );
00147 this->ports()->addPort( bufferport );
00148
00149 this->addOperation( "the_method", &HelloWorld::mymethod, this, ClientThread ).doc("'the_method' Description");
00150
00151 this->addOperation( "the_command", &HelloWorld::sayWorld, this, OwnThread).doc("'the_command' Description").arg("the_arg", "Use 'World' as argument to make the command succeed.");
00152
00153
00154
00155
00156 }
00157 };
00158 }
00159
00160
00161
00162
00163
00164 #ifndef OCL_COMPONENT_ONLY
00165
00166 int ORO_main(int argc, char** argv)
00167 {
00168 RTT::Logger::In in("main()");
00169
00170
00171
00172 if ( log().getLogLevel() < RTT::Logger::Info ) {
00173 log().setLogLevel( RTT::Logger::Info );
00174 log(Info) << argv[0] << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog();
00175 }
00176
00177 log(Info) << "**** Creating the 'Hello' component ****" <<endlog();
00178
00179 HelloWorld hello("Hello");
00180
00181 log(Info) << "**** Using the 'Hello' component ****" <<endlog();
00182
00183
00184 log(Info) << "**** Reading a RTT::Property: ****" <<endlog();
00185 RTT::Property<std::string> p = hello.properties()->getProperty("the_property");
00186 assert( p.ready() );
00187 log(Info) << " "<<p.getName() << " = " << p.value() <<endlog();
00188 #if 0
00189 log(Info) << "**** Sending a RTT::OperationCaller: ****" <<endlog();
00190 RTT::OperationCaller<bool(std::string)> c = hello.getOperation<bool(std::string)>("the_command");
00191 assert( c.ready() );
00192 log(Info) << " Sending RTT::OperationCaller : " << c.send("World")<<endlog();
00193
00194 log(Info) << "**** Calling a RTT::OperationCaller: ****" <<endlog();
00195 RTT::OperationCaller<std::string(void)> m = hello.getOperation<std::string(void)>("the_method");
00196 assert( m.ready() );
00197 log(Info) << " Calling RTT::OperationCaller : " << m() << endlog();
00198 #endif
00199 log(Info) << "**** Starting the TaskBrowser ****" <<endlog();
00200
00201 TaskBrowser browser( &hello );
00202
00203
00204 browser.loop();
00205
00206 return 0;
00207 }
00208
00209 #else
00210
00211 #include "ocl/Component.hpp"
00212 ORO_CREATE_COMPONENT( OCL::HelloWorld )
00213
00214 #endif