1
|
#include <iostream>
|
2
|
|
3
|
#include <boost/cstdint.hpp>
|
4
|
|
5
|
#include "cca/processing/all.h"
|
6
|
#include "cca/timing/PeriodicBeat.h"
|
7
|
|
8
|
#include "rsc/logging/LoggerFactory.h"
|
9
|
|
10
|
using namespace std;
|
11
|
using namespace boost;
|
12
|
using namespace cca;
|
13
|
using namespace rsc;
|
14
|
using namespace rsc::logging;
|
15
|
|
16
|
class Ping: public Node {
|
17
|
public:
|
18
|
Ping(const std::string &cname) :
|
19
|
Node(cname), ip(), op(), processed(false) {
|
20
|
ip = InputPort<uint64_t>::create();
|
21
|
registerPort("in", ip);
|
22
|
op = OutputPort<uint64_t>::create();
|
23
|
registerPort("out", op);
|
24
|
}
|
25
|
~Ping() {
|
26
|
}
|
27
|
void onProcess() {
|
28
|
std::cout << "Node '" << this->getName() << "' started processing." << std::endl;
|
29
|
sleep(1);
|
30
|
std::cout << "Node '" << this->getName() << "' finished processing." << std::endl;
|
31
|
|
32
|
OutputPort<uint64_t>::DataPtr foo(new uint64_t(17));
|
33
|
op->publish(foo);
|
34
|
}
|
35
|
protected:
|
36
|
bool processed;
|
37
|
InputPort<uint64_t>::Ptr ip;
|
38
|
OutputPort<uint64_t>::Ptr op;
|
39
|
};
|
40
|
|
41
|
int main() {
|
42
|
LoggerFactory::getInstance().reconfigure(Logger::LEVEL_WARN);
|
43
|
|
44
|
NodePtr ping = NodePtr(new Ping("Node 1"));
|
45
|
ping->setProcessingStrategy(Timed::samplerate(1));
|
46
|
ping->configureInputPort("in", PortConfiguration::LOCAL("/nowhere"));
|
47
|
ping->configureOutputPort("out", PortConfiguration::LOCAL("/ping"));
|
48
|
std::cout << ping->print() << std::endl;
|
49
|
|
50
|
NodePtr ping2 = NodePtr(new Ping("Node 2"));
|
51
|
ping2->setProcessingStrategy(PortTriggered::port("in"));
|
52
|
ping2->configureInputPort("in", PortConfiguration::LOCAL("/ping"));
|
53
|
ping2->configureOutputPort("out", PortConfiguration::LOCAL("/dev/null"));
|
54
|
std::cout << ping2->print() << std::endl;
|
55
|
|
56
|
|
57
|
std::cout << ">>> Sending tick to 'Node 1'" << std::endl;
|
58
|
ping->tick();
|
59
|
|
60
|
std::cout << ">>> CCA circuit (node 1 and node 2) is done, continue own "
|
61
|
"processing." << std::endl;
|
62
|
|
63
|
sleep(1);
|
64
|
|
65
|
return EXIT_SUCCESS;
|
66
|
}
|