Elma
An event loop manager for embedded systems
 All Classes Files Functions Enumerations
Public Types | Public Member Functions | Friends | List of all members
elma::Process Class Referenceabstract

An abstract base class for processes. More...

#include <process.h>

Inheritance diagram for elma::Process:
Inheritance graph
[legend]

Public Types

enum  status_type { UNINITIALIZED, STOPPED, RUNNING }
 

Public Member Functions

 Process ()
 Default constructor. Names process "no name".
 
 Process (std::string name)
 Constructor that takes a name for the process. More...
 
virtual void init ()=0
 
virtual void start ()=0
 
virtual void update ()=0
 
virtual void stop ()=0
 
string name ()
 
status_type status ()
 
high_resolution_clock::duration period ()
 
int num_updates ()
 
time_point< high_resolution_clock > start_time ()
 
high_resolution_clock::duration last_update ()
 
high_resolution_clock::duration previous_update ()
 
Channelchannel (string name)
 Access a channel with the given name. More...
 
double milli_time ()
 The time since the last update in millisconds, as a double. More...
 
double delta ()
 The most recent amount of time between updates. More...
 
void watch (string event_name, std::function< void(Event &)> handler)
 
void emit (const Event &event)
 
void http_get (std::string url, std::function< void(json &)> handler)
 

Friends

class Manager
 

Detailed Description

An abstract base class for processes.

Derived classes should imlement the init, start, update, and stop methods. For example, here is a process that prints out a message every time its update method is called.

#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() << ": "
<< "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 24 of file process.h.

Member Enumeration Documentation

Status of the process, as managed by a Manager. Get the status using the status() getter.

Definition at line 32 of file process.h.

Constructor & Destructor Documentation

elma::Process::Process ( std::string  name)
inline

Constructor that takes a name for the process.

Parameters
nameThe name of the process

Definition at line 41 of file process.h.

Member Function Documentation

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

Access a channel with the given name.

Parameters
nameThe name of the channel
Returns
A reference to the channel

Definition at line 11 of file process.cc.

double elma::Process::delta ( )

The most recent amount of time between updates.

A common use of this method is in the update() method for Euler integration as in xnew = x + delta() * f(x)

Returns
The most recent delta, in milliseconds

Definition at line 54 of file process.cc.

virtual void elma::Process::init ( )
pure virtual

Initialization method. This method should be overridden by derived classes. It will usually be called once, after all processes and communication objects have been added to the manager, but before the Manager starts running.

Implemented in elma::StateMachine.

high_resolution_clock::duration elma::Process::last_update ( )
inline

Getter

Returns
The duration of time between the start time and the most recent time the Manager called the update() method.

Definition at line 93 of file process.h.

double elma::Process::milli_time ( )

The time since the last update in millisconds, as a double.

Returns
The time since the last update, in milliseconds

Definition at line 43 of file process.cc.

string elma::Process::name ( )
inline

Getter

Returns
The name of the process.

Definition at line 72 of file process.h.

int elma::Process::num_updates ( )
inline

Getter

Returns
The number of updates since the process was last started by the Manager.

Definition at line 84 of file process.h.

high_resolution_clock::duration elma::Process::period ( )
inline

Getter

Returns
The period of the process.

Definition at line 80 of file process.h.

high_resolution_clock::duration elma::Process::previous_update ( )
inline

Getter

Returns
The duration of time between the start time and the second most recent time the Manager called the update() method.

Definition at line 98 of file process.h.

virtual void elma::Process::start ( )
pure virtual

Start method. This method should be overridden by derived classes. It will be called just before the manager starts running. It may be called multiple times, if the manager is started and stopped.

Implemented in elma::StateMachine.

time_point<high_resolution_clock> elma::Process::start_time ( )
inline

Getter

Returns
The time the process was last started by the Manager.

Definition at line 88 of file process.h.

status_type elma::Process::status ( )
inline

Getter

Returns
The status of the process

Definition at line 76 of file process.h.

virtual void elma::Process::stop ( )
pure virtual

Stop method. This method should be overridden by derived classes. It will be called just after the manager stops running. It may be called multiple times, if the manager is started and stopped.

Implemented in elma::StateMachine.

virtual void elma::Process::update ( )
pure virtual

Update method. This method should be overridden by derived classes. It will be called repeatedly by the manager at a frequency determined by the period used when the process is scheduled with the Manager (see Manager::schedule).

Implemented in elma::StateMachine.


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