mbed_example
/
events_ex_3
mbed events example
main.cpp@0:fca134a32b61, 2017-09-07 (annotated)
- Committer:
- sarahmarshy
- Date:
- Thu Sep 07 16:01:39 2017 +0000
- Revision:
- 0:fca134a32b61
Initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 0:fca134a32b61 | 1 | #include "mbed_events.h" |
sarahmarshy | 0:fca134a32b61 | 2 | #include <stdio.h> |
sarahmarshy | 0:fca134a32b61 | 3 | |
sarahmarshy | 0:fca134a32b61 | 4 | /** |
sarahmarshy | 0:fca134a32b61 | 5 | Event queues easily align with module boundaries, where internal state can be |
sarahmarshy | 0:fca134a32b61 | 6 | implicitly synchronized through event dispatch. Multiple modules can use |
sarahmarshy | 0:fca134a32b61 | 7 | independent event queues, but still be composed through the EventQueue::chain function. |
sarahmarshy | 0:fca134a32b61 | 8 | **/ |
sarahmarshy | 0:fca134a32b61 | 9 | |
sarahmarshy | 0:fca134a32b61 | 10 | int main() { |
sarahmarshy | 0:fca134a32b61 | 11 | // Create some event queues with pending events |
sarahmarshy | 0:fca134a32b61 | 12 | EventQueue a; |
sarahmarshy | 0:fca134a32b61 | 13 | a.call(printf, "hello from a!\n"); |
sarahmarshy | 0:fca134a32b61 | 14 | |
sarahmarshy | 0:fca134a32b61 | 15 | EventQueue b; |
sarahmarshy | 0:fca134a32b61 | 16 | b.call(printf, "hello from b!\n"); |
sarahmarshy | 0:fca134a32b61 | 17 | |
sarahmarshy | 0:fca134a32b61 | 18 | EventQueue c; |
sarahmarshy | 0:fca134a32b61 | 19 | c.call(printf, "hello from c!\n"); |
sarahmarshy | 0:fca134a32b61 | 20 | |
sarahmarshy | 0:fca134a32b61 | 21 | // Chain c and b onto a's event queue. Both c and b will be dispatched |
sarahmarshy | 0:fca134a32b61 | 22 | // in the context of a's dispatch function. |
sarahmarshy | 0:fca134a32b61 | 23 | c.chain(&a); |
sarahmarshy | 0:fca134a32b61 | 24 | b.chain(&a); |
sarahmarshy | 0:fca134a32b61 | 25 | |
sarahmarshy | 0:fca134a32b61 | 26 | // Dispatching a will in turn dispatch b and c, printing hello from |
sarahmarshy | 0:fca134a32b61 | 27 | // all three queues |
sarahmarshy | 0:fca134a32b61 | 28 | a.dispatch(); |
sarahmarshy | 0:fca134a32b61 | 29 | } |