Elma
An event loop manager for embedded systems
channel.cc
1 #include <iostream>
2 #include <stdexcept>
3 #include "elma.h"
4 
5 namespace elma {
6 
10  Channel& Channel::send(json value) {
11  _queue.push_front(value);
12  while ( _queue.size() > capacity() ) {
13  _queue.pop_back();
14  }
15  return *this;
16  }
17 
21  _queue.clear();
22  return *this;
23  }
24 
28  json Channel::latest() {
29  if ( _queue.size() == 0 ) {
30  throw Exception("Tried to get the latest value in an empty channel.");
31  }
32  return _queue.front();
33  }
34 
39  if ( _queue.size() == 0 ) {
40  throw Exception("Tried to get the earliest value in an empty channel.");
41  }
42  return _queue.back();
43  }
44 
45 }
json latest()
Definition: channel.cc:28
Channel & flush()
Definition: channel.cc:20
json earliest()
Definition: channel.cc:38
Channel & send(json)
Definition: channel.cc:10
An exception class for Elma.
Definition: exceptions.h:13
A channel for sending double values to and from Process objects.
Definition: channel.h:21
Definition: channel.cc:5
int capacity()
Definition: channel.h:57