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
00036 std::vector<double> init(10, 1.0);
00037 dwport.setDataSample( init );
00038 this->setPeriod(0.1);
00039 }
00040
00041 void updateHook() {
00042 std::vector<double> init(10, input.get() );
00043 dwport.write( init );
00044 }
00045 };
00046
00047 class TestTaskContext2
00048 : public TaskContext
00049 {
00050 Property<string> hello;
00051 OutputPort<double> dwport;
00052 InputPort<std::vector<double> > drport;
00053 Attribute<double> input;
00054
00055 public:
00056 TestTaskContext2(std::string name)
00057 : TaskContext(name),
00058 hello("Hello", "The hello thing", "World"),
00059 dwport("D1Port"),
00060 drport("D2Port"),
00061 input("input", 5.55)
00062 {
00063 this->properties()->addProperty( hello );
00064 this->ports()->addPort( drport );
00065 this->ports()->addPort( dwport );
00066 this->addAttribute( input );
00067 this->setPeriod(0.2);
00068 }
00069
00070 void updateHook() {
00071 dwport.write( input.get() );
00072 }
00073 };
00074
00075 int ORO_main( int argc, char** argv)
00076 {
00077
00078
00079 if ( Logger::log().getLogLevel() < Logger::Info ) {
00080 Logger::log().setLogLevel( Logger::Info );
00081 log(Info) << argv[0]
00082 << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog();
00083 }
00084
00085 ConsoleReporting rc("Reporting");
00086 TestTaskContext gtc("MyPeer");
00087 TestTaskContext2 gtc2("MyPeer2");
00088
00089 TestTaskContext2 gtc3("MySoloPeer");
00090
00091 rc.addPeer( >c );
00092 rc.addPeer( >c2 );
00093 rc.addPeer( >c3 );
00094 gtc.connectPorts( >c2 );
00095
00096 TaskBrowser tb( &rc );
00097
00098
00099 rc.setActivity( new Activity(ORO_SCHED_OTHER, 0, 1.0) );
00100
00101 rc.getProvider<Marshalling>("marshalling")->loadProperties("reporter.cpf");
00102 rc.configure();
00103
00104 cout <<endl<< " This demo allows reporting of Components." << endl;
00105 cout << " Use 'reportComponent(\"MyPeer\")' and/or 'reportComponent(\"MyPeer2\")'" <<endl;
00106 cout << " Then invoke 'start()' and 'stop()'" <<endl;
00107 cout << " Other methods (type 'this') are available as well."<<endl;
00108
00109 tb.loop();
00110
00111 rc.stop();
00112
00113 return 0;
00114 }
00115