17#ifndef USER_ALLOCATED_EVENT_H
18#define USER_ALLOCATED_EVENT_H
20#include "events/EventQueue.h"
21#include "platform/mbed_assert.h"
22#include "platform/mbed_atomic.h"
29template <
typename F,
typename A>
30class UserAllocatedEvent;
70template <
typename F,
typename... ArgTs>
73 typedef EventQueue::context<F, ArgTs...> C;
84 constexpr UserAllocatedEvent(F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(), _post_ref()
98 constexpr UserAllocatedEvent(
EventQueue *queue, F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(&queue->_equeue), _post_ref()
186 return post_on(queue);
241 return _post_ref > 0 ? equeue_cancel_user_allocated(_equeue, &_e) :
false;
260 equeue_event_delay(&_e + 1, _delay);
261 equeue_event_period(&_e + 1, _period);
262 equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
266 bool post_on(EventQueue *queue)
272 _equeue = &(queue->_equeue);
274 equeue_event_delay(&_e + 1, _delay);
275 equeue_event_period(&_e + 1, _period);
276 equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
280 static void event_dtor(
void *p)
282 UserAllocatedEvent<F, void(ArgTs...)> *instance = (UserAllocatedEvent<F, void(ArgTs...)> *)(((
equeue_event *)p) - 1);
287 constexpr static equeue_event get_default_equeue_event()
289 return equeue_event{ 0, 0, 0, NULL, NULL, NULL, 0, -1, &UserAllocatedEvent::event_dtor, NULL };
297 template <
typename T,
typename R>
304 template <
typename T,
typename R>
311 template <
typename T,
typename R>
318 template <
typename T,
typename R>
325 template <
typename T,
typename R>
332 template <
typename T,
typename R>
339 template <
typename T,
typename R>
340 constexpr UserAllocatedEvent(
const volatile T *obj, R(T::*method)(ArgTs...)
const volatile, ArgTs... args) :
346 template <
typename T,
typename R>
353template <
typename F,
typename... ArgTs>
359template <
typename T,
typename R,
typename... ArgTs>
365template <
typename T,
typename R,
typename... ArgTs>
371template <
typename T,
typename R,
typename... ArgTs>
377template <
typename T,
typename R,
typename... ArgTs>
393template <
typename F,
typename... ArgTs>
408template <
typename T,
typename R,
typename... ArgTs>
423template <
typename T,
typename R,
typename... ArgTs>
438template <
typename T,
typename R,
typename... ArgTs>
453template <
typename T,
typename R,
typename... ArgTs>
constexpr UserAllocatedEvent(EventQueue *q, const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs... args)
Create an event.
~UserAllocatedEvent()
Destructor for events.
constexpr UserAllocatedEvent(EventQueue *q, volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs... args)
Create an event.
constexpr UserAllocatedEvent(const T *obj, R(T::*method)(ArgTs...) const, ArgTs... args)
Create an event.
void operator()()
Posts an event onto the underlying event queue, returning void.
void delay(int delay)
Configure the delay of an event.
constexpr UserAllocatedEvent(F f, ArgTs... args)
Create an event.
void call_on(EventQueue *queue)
Posts an event onto the event queue passed as argument, returning void.
bool try_call()
Posts an event onto the underlying event queue.
void period(int period)
Configure the period of an event.
constexpr UserAllocatedEvent(T *obj, R(T::*method)(ArgTs...), ArgTs... args)
Create an event.
constexpr UserAllocatedEvent(const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs... args)
Create an event.
constexpr UserAllocatedEvent(volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs... args)
Create an event.
bool try_call_on(EventQueue *queue)
Posts an event onto the event queue passed as argument,.
void call()
Posts an event onto the underlying event queue, returning void.
constexpr UserAllocatedEvent(EventQueue *queue, F f, ArgTs... args)
Create an event.
constexpr UserAllocatedEvent(EventQueue *q, T *obj, R(T::*method)(ArgTs...), ArgTs... args)
Create an event.
constexpr UserAllocatedEvent(EventQueue *q, const T *obj, R(T::*method)(ArgTs...) const, ArgTs... args)
Create an event.
bool cancel()
Cancels posted event.
Callback class based on template specialization.
UserAllocatedEvent< F, void(ArgTs...)> make_user_allocated_event(F f, ArgTs... args)
Creates an user allocated event bound to the event queue.
constexpr UserAllocatedEvent< F, void(ArgTs...)> make_user_allocated_event(F f, ArgTs... args)
Creates a UserAllocatedEvent object, deducing the target type from the types of arguments.