$search
00001 #include <rtt/os/main.h> 00002 #include <reporting/ConsoleReporting.hpp> 00003 #include <taskbrowser/TaskBrowser.hpp> 00004 00005 #include <rtt/marsh/Marshalling.hpp> 00006 #include <rtt/extras/SlaveActivity.hpp> 00007 #include <rtt/Activity.hpp> 00008 #include <rtt/Port.hpp> 00009 00010 using namespace std; 00011 using namespace Orocos; 00012 using namespace RTT; 00013 00014 class TestTaskContext 00015 : public TaskContext 00016 { 00017 Property<string> hello; 00018 OutputPort<std::vector<double> > dwport; 00019 InputPort<double> drport; 00020 Attribute<double> input; 00021 00022 public: 00023 TestTaskContext(std::string name) 00024 : TaskContext(name), 00025 hello("Hello", "The hello thing", "World"), 00026 dwport("D2Port"), 00027 drport("D1Port"), 00028 input("input",3.33) 00029 { 00030 this->properties()->addProperty( hello ); 00031 this->ports()->addPort( drport ); 00032 this->ports()->addPort( dwport ); 00033 this->addAttribute( input ); 00034 00035 // write initial value. 00036 std::vector<double> init(10, 1.0); 00037 dwport.setDataSample( init ); 00038 this->setPeriod(0.1); 00039 start(); 00040 } 00041 00042 void updateHook() { 00043 std::vector<double> init(10, input.get() ); 00044 dwport.write( init ); 00045 input.set( input.get() + 1 ); 00046 if (input.get() > 100 ) 00047 input.set( 0 ); 00048 } 00049 }; 00050 00051 class TestTaskContext2 00052 : public TaskContext 00053 { 00054 Property<string> hello; 00055 OutputPort<double> dwport; 00056 InputPort<std::vector<double> > drport; 00057 Attribute<double> input; 00058 00059 public: 00060 TestTaskContext2(std::string name) 00061 : TaskContext(name), 00062 hello("Hello", "The hello thing", "World"), 00063 dwport("D1Port"), 00064 drport("D2Port"), 00065 input("input", 5.55) 00066 { 00067 this->properties()->addProperty( hello ); 00068 this->ports()->addPort( drport ); 00069 this->ports()->addPort( dwport ); 00070 this->addAttribute( input ); 00071 this->setPeriod(0.2); 00072 start(); 00073 } 00074 00075 void updateHook() { 00076 dwport.write( input.get() ); 00077 input.set( input.get() + 1 ); 00078 if (input.get() > 100 ) 00079 input.set( 0 ); 00080 } 00081 }; 00082 00083 int ORO_main( int argc, char** argv) 00084 { 00085 // Set log level more verbose than default, 00086 // such that we can see output : 00087 if ( Logger::log().getLogLevel() < Logger::Info ) { 00088 Logger::log().setLogLevel( Logger::Info ); 00089 log(Info) << argv[0] 00090 << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog(); 00091 } 00092 00093 ConsoleReporting rc("Reporting"); 00094 TestTaskContext gtc("MyPeer"); 00095 TestTaskContext2 gtc2("MyPeer2"); 00096 00097 TestTaskContext2 gtc3("MySoloPeer"); 00098 00099 rc.addPeer( >c ); 00100 rc.addPeer( >c2 ); 00101 rc.addPeer( >c3 ); 00102 gtc.connectPorts( >c2 ); 00103 00104 TaskBrowser tb( &rc ); 00105 00106 // Reporter's activity: not real-time ! 00107 rc.setActivity( new Activity(ORO_SCHED_OTHER, 0, 1.0) ); 00108 00109 rc.getProvider<Marshalling>("marshalling")->loadProperties("reporter.cpf"); 00110 rc.configure(); 00111 00112 cout <<endl<< " This demo allows reporting of Components." << endl; 00113 cout << " Use 'reportComponent(\"MyPeer\")' and/or 'reportComponent(\"MyPeer2\")'" <<endl; 00114 cout << " Then invoke 'start()' and 'stop()'" <<endl; 00115 cout << " Other methods (type 'this') are available as well."<<endl; 00116 00117 tb.loop(); 00118 00119 rc.stop(); 00120 00121 return 0; 00122 } 00123