#include #include #include #include #include #include #include using namespace std; using namespace RTT; using namespace Orocos; namespace MyNamespace { const int N = 100; class MyComponent : public TaskContext { private: int m_n; protected: BufferPort bufferport_in; BufferPort bufferport_out; public: MyComponent(std::string name, int n) : TaskContext(name), m_n(n), bufferport_in("the_buffer_port_in", 20, " "), bufferport_out("the_buffer_port_out", 20, " ") { if ( n != 0 ) this->ports()->addPort(&bufferport_in, "Buffered Data Port IN"); if ( n != N-1 ) this->ports()->addPort(&bufferport_out, "Buffered Data Port OUT"); } bool configureHook() { return true; } void updateHook() { static int si = 0; if ( m_n == 0 ) { std::stringstream s; si++; if ( si > 2 && si < 5 ) { s << "Message:" << si; log(Info) << getName() << "***** BEGIN *****" << endlog(); if ( bufferport_out.Push(s.str()) == true ) { log(Info) << getName() << "Push" << s.str() << endlog(); } else { cerr << "Push refused !!!" << endl; } } } else { std::string toto; if ( bufferport_in.Pop(toto) == true ) { log(Info) << getName() << "Receives " << toto << endlog(); if ( m_n != N -1 ) { if ( bufferport_out.Push(toto) == true ) { log(Info) << getName() << "Push" << toto << endlog(); } else { cerr << "Push refused !!!" << endl; } } else { log(Info) << getName() << "***** END *****" << endlog(); } } } } }; } using namespace MyNamespace; int ORO_main(int argc, char** argv) { Logger::In in("main()"); vector vectorMyComponent; MyComponent *p_myComponent; // Set log level more verbose than default, // such that we can see output : if ( log().getLogLevel() < Logger::Info ) { log().setLogLevel( Logger::Info ); log(Info) << argv[0] << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<engine() ); // Start the component: // p_helloWorld->start(); vectorMyComponent.push_back(p_myComponent); ; // ???? } for ( int i = 1; i < N; i++ ) { MyComponent *p1; MyComponent *p2; // make components i-1 and i peers p1 = vectorMyComponent[i-1]; p2 = vectorMyComponent[i]; assert(p1!=NULL); assert(p2!=NULL); p1->addPeer(p2); // connect port PortInterface *pi1, *pi2; pi1 = p1->ports()->getPort("the_buffer_port_out"); pi2 = p2->ports()->getPort("the_buffer_port_in"); assert(pi1!=NULL); assert(pi2!=NULL); if ( pi1->connectTo(pi2) == true ) { log(Info) << "Connection port ok " << i-1 << "-" << i << endl; } // add peer from 0 to i, to be able to browse from 0 to everywhere p1=vectorMyComponent[0]; p1->addPeer(p2); } for ( int i =0; i < N; i++) { vectorMyComponent[i]->start(); } log(Info) << "**** Starting the TaskBrowser ****" <