Elma
An event loop manager for embedded systems
basic.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <chrono>
3 #include "elma.h"
4 
6 
7 using namespace std::chrono;
8 using namespace elma;
9 
10 namespace basic_example {
11 
13 
16  class BasicProcess : public Process {
17  public:
18 
21  BasicProcess(std::string name) : Process(name) {}
22 
24  void init() {}
25 
27  void start() {}
28 
30  void update() {
31  std::cout << name() << ": "
32  << milli_time()
33  << "ms\n";
34  }
35 
37  void stop() {}
38  };
39 
40 }
41 
42 int main() {
43 
44  Manager m; // Make a manager
45  basic_example:: BasicProcess p("A"), q("B"); // Make two processes
46 
47  m.schedule(p, 1_ms) // Schedule the first to run every millisecond
48  .schedule(q, 5_ms) // Schedule the second to run every 5 milliseconds
49  .init() // Initialize the manager (which calls init for the processes)
50  .run(11_ms); // Run for 11 milliseconds
51 
52 }
The Process Manager class.
Definition: manager.h:27
Manager & schedule(Process &process, high_resolution_clock::duration period)
Definition: manager.cc:13
void init()
Nothing to do to initialize.
Definition: basic.cc:24
void start()
Nothing to do to start.
Definition: basic.cc:27
Manager & run(high_resolution_clock::duration runtime)
Definition: manager.cc:190
Example: A very basic process class. See the file examples/basic.cc for usage.
Definition: basic.cc:16
Manager & init()
Definition: manager.cc:109
void stop()
Nothing to do to stop.
Definition: basic.cc:37
BasicProcess(std::string name)
Definition: basic.cc:21
void update()
The update method just prints out some useful information.
Definition: basic.cc:30
Definition: channel.cc:5
An abstract base class for processes.
Definition: process.h:24