Elma
An event loop manager for embedded systems
 All Classes Files Functions Enumerations
Public Member Functions | List of all members
elma::Manager Class Reference

The Process Manager class. More...

#include <manager.h>

Public Member Functions

 Manager ()
 Default constructor.
 
Managerschedule (Process &process, high_resolution_clock::duration period)
 
Managerall (std::function< void(Process &)> f)
 
Managerinit ()
 
Managerstart ()
 
Managerupdate ()
 
Managerstop ()
 
Managerrun (high_resolution_clock::duration)
 
high_resolution_clock::time_point start_time ()
 
high_resolution_clock::duration elapsed ()
 
Manageradd_channel (Channel &)
 
Channelchannel (string)
 
Managerwatch (string event_name, std::function< void(Event &)> handler)
 
Manageremit (const Event &event)
 
Clientclient ()
 

Detailed Description

The Process Manager class.

Example usage:

#include <iostream>
#include <chrono>
#include "elma.h"
using namespace std::chrono;
using namespace elma;
class MyProcess : public Process {
public:
MyProcess(std::string name) : Process(name) {}
void init() {}
void start() {}
void update() {
std::cout << name() << ": "
<< milli_time()
<< "ms\n";
}
void stop() {}
};
int main() {
MyProcess p("A"), q("B");
m.schedule(p, 1_ms)
.schedule(q, 5_ms)
.init()
.run(11_ms);
}

Definition at line 26 of file manager.h.

Member Function Documentation

Manager & elma::Manager::add_channel ( Channel channel)

Add a channel to the manager

Parameters
Thechannel to be added
Returns
A reference to the manager, for chaining

Definition at line 26 of file manager.cc.

Manager & elma::Manager::all ( std::function< void(Process &)>  f)

Apply a function to all processes.

Parameters
fThe function to apply. It should take a reference to a process and return void.
Returns
A reference to the manager, for chaining

Definition at line 83 of file manager.cc.

Channel & elma::Manager::channel ( string  name)

Retrieve a reference to an existing channel. Throws an error if no such channel exists.

Returns
The channel requested.

Definition at line 33 of file manager.cc.

high_resolution_clock::duration elma::Manager::elapsed ( )
inline

Getter

Returns
The duration of time since the manager was most recently started

Definition at line 49 of file manager.h.

Manager & elma::Manager::emit ( const Event event)

Emit an event associated with a name. Typically, a process would emit events in its update() method using something like the following code"

emit(Event("name", value));

where value is any jsonable value. For example, you can write

emit(Event("velocity", 3.41));
Parameters
eventThe Event to be emitted
Returns
A reference to the manager for chaining.

Definition at line 68 of file manager.cc.

Manager & elma::Manager::init ( )

Initialize all processes. Usually called before run()

Returns
A reference to the manager, for chaining

Definition at line 92 of file manager.cc.

Manager & elma::Manager::run ( high_resolution_clock::duration  runtime)

Run the manager for the specified amount of time.

Parameters
Thedesired amount of time to run
Returns
A reference to the manager, for chaining

Definition at line 122 of file manager.cc.

Manager & elma::Manager::schedule ( Process process,
high_resolution_clock::duration  period 
)

Add a Process to the manager, to be run at a certain frequency.

Parameters
processThe process to be scheduled, usually derived from the Process abstract base class
periodThe desired duration of time between updates
Returns
A reference to the manager, for chaining

Definition at line 11 of file manager.cc.

Manager & elma::Manager::start ( )

Start all processes. Usually not called directly.

Returns
A reference to the manager, for chaining

Definition at line 98 of file manager.cc.

high_resolution_clock::time_point elma::Manager::start_time ( )
inline

Getter

Returns
The time the Manager was most recently started

Definition at line 45 of file manager.h.

Manager & elma::Manager::stop ( )

Stop all processes. Usually not called directly.

Returns
A reference to the manager, for chaining

Definition at line 104 of file manager.cc.

Manager & elma::Manager::update ( )

Update all processes if enough time has passed. Usually not called directly.

Returns
A reference to the manager, for chaining

Definition at line 110 of file manager.cc.

Manager & elma::Manager::watch ( string  event_name,
std::function< void(Event &)>  handler 
)

Watch for an event associated with the given name. For watching events, you would typically register event handlers in your process' init() method. For example,

watch("velocity", [this](Event& e) {
std::cout << "got velocity " << e.value() << std::endl;
})
Parameters
event_nameThe name of the event A function or lambda that takes an event and returns nothing.

Definition at line 51 of file manager.cc.


The documentation for this class was generated from the following files: