This example shows the timed execution of one CCA node. Timed execution means, processing of the node is determined by the Timed Processing strategy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream>
#include "cca/Component.h"
#include "cca/processing/Timed.h"
#include "cca/timing/PeriodicBeat.h"
#include "rsc/logging/LoggerFactory.h"
using namespace std;
using namespace boost;
using namespace cca;
using namespace rsc;
using namespace rsc::logging;
class FooComp: public Component {
public:
FooComp(const std::string &cname) :
Component(cname), fooport() {
fooport = InputPort<std::string>::create();
registerPort("foo", fooport, Port::OPTIONAL);
}
~FooComp() {
}
void onProcess() {
std::cout << "onProcess()" << std::endl;
if (fooport->empty()) {
std::cout << "empty" << std::endl;
}
}
protected:
InputPort<std::string>::Ptr fooport;
};
int main() {
LoggerFactory::getInstance().reconfigure(Logger::LEVEL_DEBUG);
NodePtr comp = NodePtr(new FooComp("Timed Node"));
comp->setProcessingStrategy(Timed::samplerate(2));
std::cout << std::endl << comp->print() << std::endl;
BeatPtr beat = PeriodicBeat::create(10);
beat->registerReceiver(comp);
beat->run();
return EXIT_SUCCESS;
}
|