Sample code that uses EvrythngApi library.
Dependencies: EvrythngApi mbed
eventqueue.cpp@0:85d6be554642, 2012-08-30 (annotated)
- Committer:
- vladounet
- Date:
- Thu Aug 30 13:57:45 2012 +0000
- Revision:
- 0:85d6be554642
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vladounet | 0:85d6be554642 | 1 | /* |
vladounet | 0:85d6be554642 | 2 | * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich |
vladounet | 0:85d6be554642 | 3 | * www.evrythng.com |
vladounet | 0:85d6be554642 | 4 | * |
vladounet | 0:85d6be554642 | 5 | * --- DISCLAIMER --- |
vladounet | 0:85d6be554642 | 6 | * |
vladounet | 0:85d6be554642 | 7 | * EVRYTHNG provides this source code "as is" and without warranty of any kind, |
vladounet | 0:85d6be554642 | 8 | * and hereby disclaims all express or implied warranties, including without |
vladounet | 0:85d6be554642 | 9 | * limitation warranties of merchantability, fitness for a particular purpose, |
vladounet | 0:85d6be554642 | 10 | * performance, accuracy, reliability, and non-infringement. |
vladounet | 0:85d6be554642 | 11 | * |
vladounet | 0:85d6be554642 | 12 | * Author: Michel Yerly |
vladounet | 0:85d6be554642 | 13 | * |
vladounet | 0:85d6be554642 | 14 | */ |
vladounet | 0:85d6be554642 | 15 | #include "mbed.h" |
vladounet | 0:85d6be554642 | 16 | #include "eventqueue.h" |
vladounet | 0:85d6be554642 | 17 | #include <time.h> |
vladounet | 0:85d6be554642 | 18 | |
vladounet | 0:85d6be554642 | 19 | #include "util.h" |
vladounet | 0:85d6be554642 | 20 | |
vladounet | 0:85d6be554642 | 21 | void EventQueue::put(int64_t time, EventType type) |
vladounet | 0:85d6be554642 | 22 | { |
vladounet | 0:85d6be554642 | 23 | Event event; |
vladounet | 0:85d6be554642 | 24 | event.time = time; |
vladounet | 0:85d6be554642 | 25 | event.type = type; |
vladounet | 0:85d6be554642 | 26 | queue.push(event); |
vladounet | 0:85d6be554642 | 27 | } |
vladounet | 0:85d6be554642 | 28 | |
vladounet | 0:85d6be554642 | 29 | EventType EventQueue::waitNext(int64_t currentTime) |
vladounet | 0:85d6be554642 | 30 | { |
vladounet | 0:85d6be554642 | 31 | Event event = queue.top(); |
vladounet | 0:85d6be554642 | 32 | queue.pop(); |
vladounet | 0:85d6be554642 | 33 | int64_t w = event.time - currentTime; |
vladounet | 0:85d6be554642 | 34 | if (w > 0) wait_ms(w); |
vladounet | 0:85d6be554642 | 35 | return event.type; |
vladounet | 0:85d6be554642 | 36 | } |
vladounet | 0:85d6be554642 | 37 | |
vladounet | 0:85d6be554642 | 38 | bool EventQueue::empty() |
vladounet | 0:85d6be554642 | 39 | { |
vladounet | 0:85d6be554642 | 40 | return queue.empty(); |
vladounet | 0:85d6be554642 | 41 | } |
vladounet | 0:85d6be554642 | 42 | |
vladounet | 0:85d6be554642 | 43 | int EventQueue::size() |
vladounet | 0:85d6be554642 | 44 | { |
vladounet | 0:85d6be554642 | 45 | return queue.size(); |
vladounet | 0:85d6be554642 | 46 | } |