Example: Timed ExecutionΒΆ

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. At first a new node is defined, which inherits from the CCA base node class (lines 15-25).
  2. In the main function of this example we create a node and configure it to be timed (line 30-32, see Timed Processing).
  3. To run the program we need to send a timing signal to the node. We create a beat and assign the node to it (lines 34-35).

Note: You can inspect the application with the RSB Logger, since the output scope is configured to also send over a remote transport. This should show an event with 1Hz on the /ping scope. The input port is configured to be only local, because otherwise the node would receive every event twice (over the locla and the remote transport).

 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
#include <iostream>

#include "cca/Node.h"
#include "cca/processing/all.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 CCANode {
public:
    FooComp(const std::string &cname) :
    	CCANode(cname) {
    }
    ~FooComp() {
    }
    void onProcess() {
    	std::cout << "onProcess()" << std::endl;
    }
};

int main() {
	LoggerFactory::getInstance().reconfigure(Logger::LEVEL_DEBUG);

    CCANodePtr comp = CCANodePtr(new FooComp("Timed Node"));
    comp->setProcessingStrategy(TimedProcessing::create(2));
    std::cout << std::endl << *(comp->componentInfo()) << std::endl;

    BeatPtr beat = PeriodicBeat::create(10);
    beat->registerReceiver(comp);

    beat->run();

    return EXIT_SUCCESS;
}

Table of Contents

Related Documentation

This Page