20 #include "events/EventQueue.h" 21 #include "platform/mbed_assert.h" 45 template <
typename... ArgTs>
60 _event =
static_cast<struct event *
>(
61 equeue_alloc(&q->_equeue,
sizeof(
struct event) +
sizeof(F)));
64 _event->equeue = &q->_equeue;
69 _event->post = &Event::event_post<F>;
70 _event->dtor = &Event::event_dtor<F>;
72 new (_event + 1) F(f);
95 new (
this)
Event(that);
107 if (_event->ref == 0) {
108 _event->dtor(_event);
109 equeue_dealloc(_event->equeue, _event);
121 _event->delay = delay;
132 _event->period = period;
155 _event->id = _event->post(_event, args...);
175 return call(args...);
183 static void thunk(
void *func, ArgTs... args)
185 return static_cast<Event *
>(func)->call(args...);
202 equeue_cancel(_event->equeue, _event->id);
215 int (*post)(
struct event *, ArgTs... args);
216 void (*dtor)(
struct event *);
222 template <
typename F>
223 static int event_post(
struct event *e, ArgTs... args)
225 typedef EventQueue::context<F, ArgTs...> C;
226 void *p = equeue_alloc(e->equeue,
sizeof(C));
231 new (p) C(*(F *)(e + 1), args...);
232 equeue_event_delay(p, e->delay);
233 equeue_event_period(p, e->period);
234 equeue_event_dtor(p, &EventQueue::function_dtor<C>);
235 return equeue_post(e->equeue, &EventQueue::function_call<C>, p);
238 template <
typename F>
239 static void event_dtor(
struct event *e)
241 ((F *)(e + 1))->~F();
253 template <
typename F,
typename... ContextArgTs>
255 Event(q,
EventQueue::context<F, ContextArgTs...>(f, context_args...)) { }
260 template <
typename T,
typename R,
typename B0>
267 template <
typename T,
typename R,
typename B0>
274 template <
typename T,
typename R,
typename B0>
281 template <
typename T,
typename R,
typename B0>
282 Event(
EventQueue *q,
const volatile T *obj, R(T::*method)(B0, ArgTs...)
const volatile, B0 b0) :
288 template <
typename T,
typename R,
typename B0,
typename B1>
295 template <
typename T,
typename R,
typename B0,
typename B1>
296 Event(
EventQueue *q,
const T *obj, R(T::*method)(B0, B1, ArgTs...)
const, B0 b0, B1 b1) :
302 template <
typename T,
typename R,
typename B0,
typename B1>
303 Event(
EventQueue *q,
volatile T *obj, R(T::*method)(B0, B1, ArgTs...)
volatile, B0 b0, B1 b1) :
309 template <
typename T,
typename R,
typename B0,
typename B1>
310 Event(
EventQueue *q,
const volatile T *obj, R(T::*method)(B0, B1, ArgTs...)
const volatile, B0 b0, B1 b1) :
316 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2>
317 Event(
EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, ArgTs...), B0 b0, B1 b1, B2 b2) :
323 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2>
324 Event(
EventQueue *q,
const T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
const, B0 b0, B1 b1, B2 b2) :
330 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2>
331 Event(
EventQueue *q,
volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
volatile, B0 b0, B1 b1, B2 b2) :
337 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2>
338 Event(
EventQueue *q,
const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
const volatile, B0 b0, B1 b1, B2 b2) :
344 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3>
345 Event(
EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3) :
351 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3>
352 Event(
EventQueue *q,
const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
const, B0 b0, B1 b1, B2 b2, B3 b3) :
358 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3>
359 Event(
EventQueue *q,
volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
volatile, B0 b0, B1 b1, B2 b2, B3 b3) :
365 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3>
366 Event(
EventQueue *q,
const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
const volatile, B0 b0, B1 b1, B2 b2, B3 b3) :
372 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4>
373 Event(
EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
379 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4>
380 Event(
EventQueue *q,
const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
386 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4>
387 Event(
EventQueue *q,
volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
393 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4>
394 Event(
EventQueue *q,
const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
403 template <
typename R,
typename... ArgTs>
406 return Event<void(ArgTs...)>(
this, func);
409 template <
typename T,
typename R,
typename... ArgTs>
415 template <
typename T,
typename R,
typename... ArgTs>
421 template <
typename T,
typename R,
typename... ArgTs>
427 template <
typename T,
typename R,
typename... ArgTs>
433 template <
typename R,
typename... ArgTs>
436 return Event<void(ArgTs...)>(
this, cb);
439 template <
typename R,
typename B0,
typename C0,
typename... ArgTs>
442 return Event<void(ArgTs...)>(
this, func, c0);
445 template <
typename T,
typename R,
typename B0,
typename C0,
typename... ArgTs>
451 template <
typename T,
typename R,
typename B0,
typename C0,
typename... ArgTs>
457 template <
typename T,
typename R,
typename B0,
typename C0,
typename... ArgTs>
463 template <
typename T,
typename R,
typename B0,
typename C0,
typename... ArgTs>
464 Event<void(ArgTs...)>
EventQueue::event(
const volatile T *obj, R(T::*method)(B0, ArgTs...)
const volatile, C0 c0)
469 template <
typename R,
typename B0,
typename C0,
typename... ArgTs>
472 return Event<void(ArgTs...)>(
this, cb, c0);
475 template <
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
478 return Event<void(ArgTs...)>(
this, func, c0, c1);
481 template <
typename T,
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
487 template <
typename T,
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
488 Event<void(ArgTs...)>
EventQueue::event(
const T *obj, R(T::*method)(B0, B1, ArgTs...)
const, C0 c0, C1 c1)
493 template <
typename T,
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
494 Event<void(ArgTs...)>
EventQueue::event(
volatile T *obj, R(T::*method)(B0, B1, ArgTs...)
volatile, C0 c0, C1 c1)
499 template <
typename T,
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
500 Event<void(ArgTs...)>
EventQueue::event(
const volatile T *obj, R(T::*method)(B0, B1, ArgTs...)
const volatile, C0 c0, C1 c1)
505 template <
typename R,
typename B0,
typename B1,
typename C0,
typename C1,
typename... ArgTs>
508 return Event<void(ArgTs...)>(
this, cb, c0, c1);
511 template <
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
514 return Event<void(ArgTs...)>(
this, func, c0, c1, c2);
517 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
523 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
524 Event<void(ArgTs...)>
EventQueue::event(
const T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
const, C0 c0, C1 c1, C2 c2)
529 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
530 Event<void(ArgTs...)>
EventQueue::event(
volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
volatile, C0 c0, C1 c1, C2 c2)
535 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
536 Event<void(ArgTs...)>
EventQueue::event(
const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...)
const volatile, C0 c0, C1 c1, C2 c2)
541 template <
typename R,
typename B0,
typename B1,
typename B2,
typename C0,
typename C1,
typename C2,
typename... ArgTs>
544 return Event<void(ArgTs...)>(
this, cb, c0, c1, c2);
547 template <
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
550 return Event<void(ArgTs...)>(
this, func, c0, c1, c2, c3);
553 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
554 Event<void(ArgTs...)>
EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
559 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
560 Event<void(ArgTs...)>
EventQueue::event(
const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
const, C0 c0, C1 c1, C2 c2, C3 c3)
565 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
566 Event<void(ArgTs...)>
EventQueue::event(
volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
volatile, C0 c0, C1 c1, C2 c2, C3 c3)
571 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
572 Event<void(ArgTs...)>
EventQueue::event(
const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...)
const volatile, C0 c0, C1 c1, C2 c2, C3 c3)
577 template <
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename C0,
typename C1,
typename C2,
typename C3,
typename... ArgTs>
580 return Event<void(ArgTs...)>(
this, cb, c0, c1, c2, c3);
583 template <
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
584 Event<void(ArgTs...)>
EventQueue::event(R(*func)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
586 return Event<void(ArgTs...)>(
this, func, c0, c1, c2, c3, c4);
589 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
590 Event<void(ArgTs...)>
EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
595 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
596 Event<void(ArgTs...)>
EventQueue::event(
const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
601 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
602 Event<void(ArgTs...)>
EventQueue::event(
volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
607 template <
typename T,
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
608 Event<void(ArgTs...)>
EventQueue::event(
const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...)
const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
613 template <
typename R,
typename B0,
typename B1,
typename B2,
typename B3,
typename B4,
typename C0,
typename C1,
typename C2,
typename C3,
typename C4,
typename... ArgTs>
614 Event<void(ArgTs...)>
EventQueue::event(
mbed::Callback<R(B0, B1, B2, B3, B4, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
616 return Event<void(ArgTs...)>(
this, cb, c0, c1, c2, c3, c4);
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, B0 b0, B1 b1)
Create an event.
int post(ArgTs...args) const
Posts an event onto the underlying event queue.
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
void cancel() const
Cancels the most recently posted event.
Event & operator=(const Event &that)
Assignment operator for events.
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Event(const Event &e)
Copy constructor for events.
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, ArgTs...), B0 b0, B1 b1)
Create an event.
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, B0 b0)
Create an event.
static void thunk(void *func, ArgTs...args)
Static thunk for passing as C-style function.
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2)
Create an event.
Event(EventQueue *q, const T *obj, R(T::*method)(B0, ArgTs...) const, B0 b0)
Create an event.
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Event(EventQueue *q, F f)
Create an event.
void call(ArgTs...args) const
Posts an event onto the underlying event queue, returning void.
void delay(int delay)
Configure the delay of an event.
Event(EventQueue *q, T *obj, R(T::*method)(B0, ArgTs...), B0 b0)
Create an event.
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, ArgTs...), B0 b0, B1 b1, B2 b2)
Create an event.
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, B0 b0, B1 b1)
Create an event.
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, ArgTs...) const, B0 b0, B1 b1)
Create an event.
Event(EventQueue *q, F f, ContextArgTs...context_args)
Create an event.
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, B0 b0, B1 b1, B2 b2)
Create an event.
void operator()(ArgTs...args) const
Posts an event onto the underlying event queue, returning void.
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, B0 b0, B1 b1, B2 b2)
Create an event.
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Event< void(Args...)> event(R(*func)(BoundArgs..., Args...), ContextArgs...context_args)
Creates an event bound to the event queue.
void period(int period)
Configure the period of an event.
Callback class based on template specialization.
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, B0 b0)
Create an event.
~Event()
Destructor for events.