FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
Contains the API around Future implementation. More...
Classes | |
class | AbstractFakeFuture |
Base class for all FakeFuture s. More... | |
class | AbstractFuture |
Base class for all Future s. More... | |
class | AbstractFuturesGroup |
Abstract class to allow aggregation of several futures. More... | |
class | FakeFuture |
Actual FakeFuture, it has the exact same API as Future and can be used in lieu of Future. More... | |
class | Future |
Represent a value to be obtained, in some asynchronous way, in the future. More... | |
Enumerations | |
enum class | FutureStatus : uint8_t { NOT_READY = 0 , READY , ERROR , INVALID } |
Status of a Future. More... | |
enum class | FutureNotification : uint8_t { NONE = 0 , STATUS = 1 , OUTPUT = 2 , BOTH = 3 } |
Notification(s) dispatched by a Future. More... | |
Contains the API around Future implementation.
A Future allows you to pass and get values across different units of executions (threads, or more likely on AVR MCU, the main program and an ISR).
Concepts applied in this API:
void
, i.e. no value)Future.get()
methodThere are two hierarchies of futures:
AbstractFuture
AbstractFakeFuture
The main difference is that fake futures must be filled in immediately (not piece after piece, e.g. through an ISR).
In general you won't need fake futures in your program, but these exist to fit some FastArduino API (I2C) that can work in either asynchronous or synchronous mode. In synchronous mode, the cost of "real futures" (code size and execution speed) is not needed, but in order to fulfill internal requirements to work with a future API, we have implemented fake futures too, with the same API as real ones.
Futures can be listened to through a special, virtual-free, mechanism. Futures can send notfications to dedicated listeners. There are 2 kinds of notifications that a future may dispatch:
FutureNotification::STATUS
: a notification is dispatched whenever the future status changesFutureNotification::OUTPUT
: a notification is dispatched whenever the future outpur buffer changes A combination of both is possible.Listeners to future notification are instances of classes that must:
interrupt::register_handler()
at construction time and interrupt::unregister_handler()
at destruction timeREGISTER_FUTURE_STATUS_LISTENERS()
, REGISTER_FUTURE_OUTPUT_LISTENERS()
or both (if they want to be notified of both kinds of notifications)on_status_change(const F&, FutureStatus)
or on_output_change(const F&)
methods (F is either AbstractFuture
or AbstractFakeFuture
, based on which future ind you want to use)public
in the class or, if not, the class must use DECL_FUTURE_LISTENERS_FRIEND
in its definition, so that FastArduino notification dispatch mechanism can call those methodsREGISTER_FUTURE_STATUS_LISTENERS()
(resp. REGISTER_FUTURE_OUTPUT_LISTENERS
). Doing otherwise will result in link errors.REGISTER_FUTURE_STATUS_NO_LISTENERS()
, REGISTER_FUTURE_OUTPUT_NO_LISTENERS()
or REGISTER_FUTURE_NO_LISTENERS()
. Doing otherwise will result in a link failure.Here is a simple usage example of this API, using PCINT0 interrupt to take a "snapshot" of 6 input buttons connected to all PORTB pins, after one of them has changed level:
|
strong |
Status of a Future.
A Future follows a strict lifecycle by passing through the various statuses defined here.
Enumerator | |
---|---|
NOT_READY | The status of a Future immediately after it has been constructed. The Future will keep this status until:
|
READY | The status of a Future once its output value has been fully set by a provider.
|
ERROR | The status of a Future once a value provider has reported an error to it.
|
INVALID | The status of a Future that has been moved, if it was |
|
strong |
Notification(s) dispatched by a Future.
This is passed to Future constructor and detrmines whether the instantiated Future will dispatch of its own notification changes.
Enumerator | |
---|---|
NONE | No notification is dispatched by the Future. |
STATUS | Notification is dispatched whenever the Future status changes. |
OUTPUT | Notification is dispatched whenever the Future output buffer gets filled, even partly. |
BOTH | Notification is dispatched whenever the Future status changes or the Future output buffer gets filled, even partly. |