Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

EventQueue Class Reference

EventQueue. More...

#include <EventQueue.h>

Inherits NonCopyable< EventQueue >.

Public Member Functions

 EventQueue (unsigned size=EVENTS_QUEUE_SIZE, unsigned char *buffer=NULL)
 Create an EventQueue.
 ~EventQueue ()
 Destroy an EventQueue.
void dispatch (int ms=-1)
 Dispatch events.
void dispatch_forever ()
 Dispatch events without a timeout.
void break_dispatch ()
 Break out of a running event loop.
unsigned tick ()
 Millisecond counter.
bool cancel (int id)
 Cancel an in-flight event.
template<typename F , typename A >
bool cancel (UserAllocatedEvent< F, A > *event)
 Cancel an in-flight user allocated event.
int time_left (int id)
 Query how much time is left for delayed event.
template<typename F , typename A >
int time_left (UserAllocatedEvent< F, A > *event)
 Query how much time is left for delayed UserAllocatedEvent.
void background (mbed::Callback< void(int)> update)
 Background an event queue onto a single-shot timer-interrupt.
int chain (EventQueue *target)
 Chain an event queue onto another event queue.
template<typename F , typename... Args>
int call (F f, Args...args)
 Calls an event on the queue.
template<typename T , typename R , typename... Args>
int call (T *obj, R(T::*method)(Args...args), Args...args)
 Calls an event on the queue.
template<typename F , typename... Args>
int call_in (int ms, Args...args)
 Calls an event on the queue after a specified delay.
template<typename T , typename R , typename... Args>
int call_in (int ms, T *obj, R(T::*method)(Args...args), Args...args)
 Calls an event on the queue after a specified delay.
template<typename F , typename... Args>
int call_every (int ms, F f, Args...args)
 Calls an event on the queue periodically.
template<typename T , typename R , typename... Args>
int call_every (int ms, T *obj, R(T::*method)(Args...args), Args...args)
 Calls an event on the queue periodically.
template<typename R , typename... BoundArgs, typename... ContextArgs, typename... Args>
Event< void(Args...)> event (R(*func)(BoundArgs..., Args...), ContextArgs...context_args)
 Creates an event bound to the event queue.
template<typename T , typename R , typename... BoundArgs, typename... ContextArgs, typename... Args>
Event< void(Args...)> event (T *obj, R(T::*method)(BoundArgs..., Args...), ContextArgs...context_args)
 Creates an event bound to the event queue.
template<typename R , typename... BoundArgs, typename... ContextArgs, typename... Args>
Event< void(Args...)> event (mbed::Callback< R(BoundArgs..., Args...)> cb, ContextArgs...context_args)
 Creates an event bound to the event queue.
template<typename F , typename... ArgTs>
UserAllocatedEvent< F, void(ArgTs...)> make_user_allocated_event (F f, ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
UserAllocatedEvent
< mbed::Callback< void(ArgTs...)>
, void(ArgTs...)> 
make_user_allocated_event (T *obj, R(T::*method)(ArgTs...args), ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename F >
int call (F f)
 Calls an event on the queue.
template<typename F , typename... ArgTs>
int call (F f, ArgTs...args)
 Calls an event on the queue.
template<typename T , typename R , typename... ArgTs>
int call (T *obj, R(T::*method)(ArgTs...), ArgTs...args)
 Calls an event on the queue.
template<typename T , typename R , typename... ArgTs>
int call (const T *obj, R(T::*method)(ArgTs...) const, ArgTs...args)
 Calls an event on the queue.
template<typename T , typename R , typename... ArgTs>
int call (volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs...args)
 Calls an event on the queue.
template<typename T , typename R , typename... ArgTs>
int call (const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs...args)
 Calls an event on the queue.
template<typename F >
int call_in (int ms, F f)
 Calls an event on the queue after a specified delay.
template<typename F , typename... ArgTs>
int call_in (int ms, F f, ArgTs...args)
 Calls an event on the queue after a specified delay.
template<typename T , typename R , typename... ArgTs>
int call_in (int ms, T *obj, R(T::*method)(ArgTs...), ArgTs...args)
 Calls an event on the queue after a specified delay.
template<typename T , typename R , typename... ArgTs>
int call_in (int ms, const T *obj, R(T::*method)(ArgTs...) const, ArgTs...args)
 Calls an event on the queue after a specified delay.
template<typename T , typename R , typename... ArgTs>
int call_in (int ms, volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs...args)
 Calls an event on the queue after a specified delay.
template<typename T , typename R , typename... ArgTs>
int call_in (int ms, const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs...args)
 Calls an event on the queue after a specified delay.
template<typename F >
int call_every (int ms, F f)
 Calls an event on the queue periodically.
template<typename F , typename... ArgTs>
int call_every (int ms, F f, ArgTs...args)
 Calls an event on the queue periodically.
template<typename T , typename R , typename... ArgTs>
int call_every (int ms, T *obj, R(T::*method)(ArgTs...), ArgTs...args)
 Calls an event on the queue periodically.
template<typename T , typename R , typename... ArgTs>
int call_every (int ms, const T *obj, R(T::*method)(ArgTs...) const, ArgTs...args)
 Calls an event on the queue periodically.
template<typename T , typename R , typename... ArgTs>
int call_every (int ms, volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs...args)
 Calls an event on the queue periodically.
template<typename T , typename R , typename... ArgTs>
int call_every (int ms, const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs...args)
 Calls an event on the queue periodically.
template<typename R , typename... ArgTs>
Event< void(ArgTs...)> event (R(*func)(ArgTs...))
 Creates an event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(ArgTs...))
 Creates an event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(ArgTs...) const)
 Creates an event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(ArgTs...) volatile)
 Creates an event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
Event< void(ArgTs...)> event (const volatile T *obj, R(T::*method)(ArgTs...) const volatile)
 Creates an event bound to the event queue.
template<typename R , typename... ArgTs>
Event< void(ArgTs...)> event (mbed::Callback< R(ArgTs...)> cb)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (R(*func)(B0, ArgTs...), C0 c0)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(B0, ArgTs...), C0 c0)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(B0, ArgTs...) const, C0 c0)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, C0 c0)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, C0 c0)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename C0 , typename... ArgTs>
Event< void(ArgTs...)> event (mbed::Callback< R(B0, ArgTs...)> cb, C0 c0)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (R(*func)(B0, B1, ArgTs...), C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(B0, B1, ArgTs...), C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(B0, B1, ArgTs...) const, C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename C0 , typename C1 , typename... ArgTs>
Event< void(ArgTs...)> event (mbed::Callback< R(B0, B1, ArgTs...)> cb, C0 c0, C1 c1)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (R(*func)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename B2 , typename C0 , typename C1 , typename C2 , typename... ArgTs>
Event< void(ArgTs...)> event (mbed::Callback< R(B0, B1, B2, ArgTs...)> cb, C0 c0, C1 c1, C2 c2)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (R(*func)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
template<typename T , typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
template<typename R , typename B0 , typename B1 , typename B2 , typename B3 , typename C0 , typename C1 , typename C2 , typename C3 , typename... ArgTs>
Event< void(ArgTs...)> event (mbed::Callback< R(B0, B1, B2, B3, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> event (R(*func)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> event (T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> event (const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> event (volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> 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)
 Creates an event bound to the event queue.
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>
Event< void(ArgTs...)> event (mbed::Callback< R(B0, B1, B2, B3, B4, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
 Creates an event bound to the event queue.
template<typename F , typename... ArgTs>
UserAllocatedEvent< F, void(ArgTs...)> make_user_allocated_event (F f, ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
UserAllocatedEvent
< mbed::Callback< void(ArgTs...)>
, void(ArgTs...)> 
make_user_allocated_event (T *obj, R(T::*method)(ArgTs...args), ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
UserAllocatedEvent
< mbed::Callback< void(ArgTs...)>
, void(ArgTs...)> 
make_user_allocated_event (const T *obj, R(T::*method)(ArgTs...args) const, ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
UserAllocatedEvent
< mbed::Callback< void(ArgTs...)>
, void(ArgTs...)> 
make_user_allocated_event (volatile T *obj, R(T::*method)(ArgTs...args) volatile, ArgTs...args)
 Creates an user allocated event bound to the event queue.
template<typename T , typename R , typename... ArgTs>
UserAllocatedEvent
< mbed::Callback< void(ArgTs...)>
, void(ArgTs...)> 
make_user_allocated_event (const volatile T *obj, R(T::*method)(ArgTs...args) const volatile, ArgTs...args)
 Creates an user allocated event bound to the event queue.

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

EventQueue.

Flexible event queue for dispatching events

Definition at line 60 of file events/EventQueue.h.


Constructor & Destructor Documentation

EventQueue ( unsigned  size = EVENTS_QUEUE_SIZE,
unsigned char *  buffer = NULL 
)

Create an EventQueue.

Create an event queue. The event queue either allocates a buffer of the specified size with malloc or uses the user provided buffer or uses 1B dummy buffer if 0 size passed.

0 size queue is a special purpose queue to dispatch static events only (see UserAllocatedEvent). Such a queue gives the guarantee that no dynamic memory allocation will take place while queue creation and events posting & dispatching.

Parameters:
sizeSize of buffer to use for events in bytes (default to EVENTS_QUEUE_SIZE) If 0 provided then 1B dummy buffer is used
bufferPointer to buffer to use for events (default to NULL)

Definition at line 24 of file EventQueue.cpp.

~EventQueue (  )

Destroy an EventQueue.

Definition at line 39 of file EventQueue.cpp.


Member Function Documentation

void background ( mbed::Callback< void(int)>  update )

Background an event queue onto a single-shot timer-interrupt.

When updated, the event queue will call the provided update function with a timeout indicating when the queue should be dispatched. A negative timeout will be passed to the update function when the timer-interrupt is no longer needed.

Passing a null function disables the existing update function.

The background function allows an event queue to take advantage of hardware timers or other event loops, allowing an event queue to be ran in the background without consuming the foreground thread.

Parameters:
updateFunction called to indicate when the queue should be dispatched
void break_dispatch (  )

Break out of a running event loop.

Forces the specified event queue's dispatch loop to terminate. Pending events may finish executing, but no new events will be executed.

Definition at line 49 of file EventQueue.cpp.

int call ( f,
Args...  args 
)

Calls an event on the queue.

The specified callback will be executed in the context of the event queue's dispatch loop.

The call function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
fFunction to execute in the context of the dispatch loop
argsArguments to pass to the callback
Returns:
A unique id that represents the posted event and can be passed to cancel, or an id of 0 if there is not enough memory to allocate the event. Returned id will remain valid until event has finished executing.
     #include "mbed.h"

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // events are simple callbacks
         queue.call(printf, "called immediately\n");

         // the dispatch method executes events
         queue.dispatch();
     }
int call ( f )

Calls an event on the queue.

The specified callback is executed in the context of the event queue's dispatch loop.

The call function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
fFunction to execute in the context of the dispatch loop
Returns:
A unique ID that represents the posted event and can be passed to cancel, or an ID of 0 if there is not enough memory to allocate the event. Returned ID remains valid until event has finished executing.
     #include "mbed.h"

     int main()
     {
         EventQueue queue;

         Callback<void(int)> cb(handler);

         // Create event on the eventqueue with a separate callback object
         Event<void(int)> e = queue.event(cb);
         e.post(1);
         queue.dispatch();
     }

Definition at line 745 of file events/EventQueue.h.

int call ( f,
ArgTs...  args 
)

Calls an event on the queue.

See also:
EventQueue::call
Parameters:
fFunction to execute in the context of the dispatch loop
argsArguments to pass to the callback

Definition at line 764 of file events/EventQueue.h.

int call ( T *  obj,
R(T::*)(Args...args)  method,
Args...  args 
)

Calls an event on the queue.

The specified callback is executed in the context of the event queue's dispatch loop.

The call function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
objObject to call with the member function
methodMember function to execute in the context of the dispatch loop
argsArguments to pass to the callback
Returns:
A unique ID that represents the posted event and can be passed to cancel, or an ID of 0 if there is not enough memory to allocate the event. Returned ID remains valid until event has finished executing.
     #include "mbed.h"

     class EventHandler {
         int _id;
     public:
         EventHandler(int id) : _id(id) { }

         void handler(int c) {
             printf("ID: %d Param: %d\r\n", _id, c);
         }
     };

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // Create EventHandler object with state
         EventHandler handler_cb(1);

         // events are simple callbacks, call object method
         // with provided parameter
         queue.call(&handler_cb, &EventHandler::handler, 2);

         // the dispath method executes events
         queue.dispatch();
     }
int call ( T *  obj,
R(T::*)(ArgTs...)  method,
ArgTs...  args 
)

Calls an event on the queue.

See also:
EventQueue::call

Definition at line 773 of file events/EventQueue.h.

int call ( const T *  obj,
R(T::*)(ArgTs...) const   method,
ArgTs...  args 
)

Calls an event on the queue.

See also:
EventQueue::call

Definition at line 782 of file events/EventQueue.h.

int call ( volatile T *  obj,
R(T::*)(ArgTs...) volatile  method,
ArgTs...  args 
)

Calls an event on the queue.

See also:
EventQueue::call

Definition at line 791 of file events/EventQueue.h.

int call ( const volatile T *  obj,
R(T::*)(ArgTs...) const volatile  method,
ArgTs...  args 
)

Calls an event on the queue.

See also:
EventQueue::call

Definition at line 800 of file events/EventQueue.h.

int call_every ( int  ms,
T *  obj,
R(T::*)(Args...args)  method,
Args...  args 
)

Calls an event on the queue periodically.

Note:
The first call_every event occurs after the specified delay. To create a periodic event that fires immediately,
See also:
Event.

The specified callback is executed in the context of the event queue's dispatch loop.

The call_every function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
msPeriod of the event in milliseconds
objObject to call with the member function
methodMember function to execute in the context of the dispatch loop
argsArguments to pass to the callback
     #include "mbed.h"

     class EventHandler {
         int _id;
     public:
         EventHandler(int id) : _id(id) { }

         void handler(int c) {
             printf("ID: %d Param: %d\r\n", _id, c);
         }
     };

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // Create EventHandler object with state
         EventHandler handler_cb(5);

         // events are simple callbacks, call object method every 2 seconds
         // with provided parameter
         queue.call_every(2000, &handler_cb, &EventHandler::handler, 6);

         // the dispatch method executes events
         queue.dispatch();
     }
int call_every ( int  ms,
f 
)

Calls an event on the queue periodically.

Note:
The first call_every event occurs after the specified delay. To create a periodic event that fires immediately,
See also:
Event.

The specified callback will be executed in the context of the event queue's dispatch loop.

The call_every function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
fFunction to execute in the context of the dispatch loop
msPeriod of the event in milliseconds
Returns:
A unique id that represents the posted event and can be passed to cancel, or an id of 0 if there is not enough memory to allocate the event.

Definition at line 899 of file events/EventQueue.h.

int call_every ( int  ms,
f,
ArgTs...  args 
)

Calls an event on the queue periodically.

See also:
EventQueue::call_every
Parameters:
fFunction to execute in the context of the dispatch loop
argsArguments to pass to the callback
msPeriod of the event in milliseconds

Definition at line 920 of file events/EventQueue.h.

int call_every ( int  ms,
T *  obj,
R(T::*)(ArgTs...)  method,
ArgTs...  args 
)

Calls an event on the queue periodically.

See also:
EventQueue::call_every

Definition at line 929 of file events/EventQueue.h.

int call_every ( int  ms,
const T *  obj,
R(T::*)(ArgTs...) const   method,
ArgTs...  args 
)

Calls an event on the queue periodically.

See also:
EventQueue::call_every

Definition at line 938 of file events/EventQueue.h.

int call_every ( int  ms,
volatile T *  obj,
R(T::*)(ArgTs...) volatile  method,
ArgTs...  args 
)

Calls an event on the queue periodically.

See also:
EventQueue::call_every

Definition at line 947 of file events/EventQueue.h.

int call_every ( int  ms,
const volatile T *  obj,
R(T::*)(ArgTs...) const volatile  method,
ArgTs...  args 
)

Calls an event on the queue periodically.

See also:
EventQueue::call_every

Definition at line 956 of file events/EventQueue.h.

int call_every ( int  ms,
f,
Args...  args 
)

Calls an event on the queue periodically.

Note:
The first call_every event occurs after the specified delay. To create a periodic event that fires immediately,
See also:
Event.

The specified callback is executed in the context of the event queue's dispatch loop.

The call_every function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
msPeriod of the event in milliseconds
fFunction to execute in the context of the dispatch loop
argsArguments to pass to the callback
Returns:
A unique ID that represents the posted event and can be passed to cancel, or an ID of 0 if there is not enough memory to allocate the event.
     #include "mbed.h"

     class EventHandler {
         int _id;
     public:
         EventHandler(int id) : _id(id) { }

         void handler(int c) {
             printf("ID: %d Param: %d\r\n", _id, c);
         }
     };

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // events are simple callbacks, call every 2 seconds
         queue.call_every(2000, printf, "Calling every 2 seconds\n");

         // the dispatch method executes events
         queue.dispatch();
     }
int call_in ( int  ms,
const volatile T *  obj,
R(T::*)(ArgTs...) const volatile  method,
ArgTs...  args 
)

Calls an event on the queue after a specified delay.

See also:
EventQueue::call_in

Definition at line 876 of file events/EventQueue.h.

int call_in ( int  ms,
volatile T *  obj,
R(T::*)(ArgTs...) volatile  method,
ArgTs...  args 
)

Calls an event on the queue after a specified delay.

See also:
EventQueue::call_in

Definition at line 867 of file events/EventQueue.h.

int call_in ( int  ms,
Args...  args 
)

Calls an event on the queue after a specified delay.

The specified callback is executed in the context of the event queue's dispatch loop.

The call_in function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
msTime to delay in milliseconds
argsArguments to pass to the callback
Returns:
A unique ID that represents the posted event and can be passed to cancel, or an ID of 0 if there is not enough memory to allocate the event.
     #include "mbed.h"

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // events are simple callbacks
         queue.call_in(2000, printf, "called in 2 seconds\n");

         // the dispatch methods executes events
         queue.dispatch();
     }
int call_in ( int  ms,
f 
)

Calls an event on the queue after a specified delay.

The specified callback will be executed in the context of the event queue's dispatch loop.

The call_in function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
msTime to delay in milliseconds
fFunction to execute in the context of the dispatch loop
Returns:
A unique id that represents the posted event and can be passed to cancel, or an id of 0 if there is not enough memory to allocate the event.

Definition at line 820 of file events/EventQueue.h.

int call_in ( int  ms,
f,
ArgTs...  args 
)

Calls an event on the queue after a specified delay.

See also:
EventQueue::call_in
Parameters:
msTime to delay in milliseconds
fFunction to execute in the context of the dispatch loop
argsArguments to pass to the callback

Definition at line 840 of file events/EventQueue.h.

int call_in ( int  ms,
T *  obj,
R(T::*)(Args...args)  method,
Args...  args 
)

Calls an event on the queue after a specified delay.

The specified callback is executed in the context of the event queue's dispatch loop.

The call_in function is IRQ safe and can act as a mechanism for moving events out of IRQ contexts.

Parameters:
msTime to delay in milliseconds
objObject to call with the member function
methodMember function to execute in the context of the dispatch loop
argsArguments to pass to the callback
Returns:
A unique ID that represents the posted event and can be passed to cancel, or an ID of 0 if there is not enough memory to allocate the event.
     #include "mbed.h"

     class EventHandler {
         int _id;
     public:
         EventHandler(int id) : _id(id) { }

         void handler(int c) {
             printf("ID: %d Param: %d\r\n", _id, c);
         }
     };

     int main() {
         // creates a queue with the default size
         EventQueue queue;

         // Create EventHandler object with state
         EventHandler handler_cb(3);

         // events are simple callbacks, call object method in 2 seconds
         // with provided parameter
         queue.call_in(2000, &handler_cb, &EventHandler::handler, 4);

         // the dispatch method executes events
         queue.dispatch();
     }
int call_in ( int  ms,
T *  obj,
R(T::*)(ArgTs...)  method,
ArgTs...  args 
)

Calls an event on the queue after a specified delay.

See also:
EventQueue::call_in

Definition at line 849 of file events/EventQueue.h.

int call_in ( int  ms,
const T *  obj,
R(T::*)(ArgTs...) const   method,
ArgTs...  args 
)

Calls an event on the queue after a specified delay.

See also:
EventQueue::call_in

Definition at line 858 of file events/EventQueue.h.

bool cancel ( int  id )

Cancel an in-flight event.

Attempts to cancel an event referenced by the unique id returned from one of the call functions. It is safe to call cancel after an event has already been dispatched.

id must be valid i.e. event must have not finished executing.

The cancel function is IRQ safe.

If called while the event queue's dispatch loop is active in another thread, the cancel function does not guarantee that the event will not execute after it returns, as the event may have already begun executing. A call made from the same thread as the dispatch loop will always succeed with a valid id.

Parameters:
idUnique id of the event
Returns:
true if event was successfully cancelled false if event was not cancelled (invalid id or executing already begun)

Definition at line 59 of file EventQueue.cpp.

bool cancel ( UserAllocatedEvent< F, A > *  event )

Cancel an in-flight user allocated event.

Attempts to cancel an UserAllocatedEvent referenced by its address It is safe to call cancel after an event has already been dispatched.

Event must be valid i.e. event must have not finished executing and must have been bound to this queue.

The cancel function is IRQ safe.

If called while the event queue's dispatch loop is active in another thread, the cancel function does not guarantee that the event will not execute after it returns, as the event may have already begun executing. A call made from the same thread as the dispatch loop will always succeed with a valid id.

Parameters:
eventAddress of the event
Returns:
true if event was successfully cancelled false if event was not cancelled (invalid queue or executing already begun)

Definition at line 171 of file events/EventQueue.h.

int chain ( EventQueue target )

Chain an event queue onto another event queue.

After chaining a queue to a target, calling dispatch on the target queue will also dispatch events from this queue. The queues use their own buffers and events must be handled independently.

A null queue as the target will unchain the existing queue.

The chain function allows multiple event queues to be composed, sharing the context of a dispatch loop while still being managed independently

Parameters:
targetQueue that will dispatch this queue's events as a part of its dispatch loop
Returns:
Zero on success and negative error code value if chaining fails

Definition at line 80 of file EventQueue.cpp.

void dispatch ( int  ms = -1 )

Dispatch events.

Executes events until the specified milliseconds have passed. If ms is negative, the dispatch function will dispatch events indefinitely or until break_dispatch is called on this queue.

When called with a finite timeout, the dispatch function is guaranteed to terminate. When called with a timeout of 0, the dispatch function does not wait and is IRQ safe.

Parameters:
msTime to wait for events in milliseconds, a negative value will dispatch events indefinitely (default to -1)

Definition at line 44 of file EventQueue.cpp.

void dispatch_forever (  )

Dispatch events without a timeout.

This is equivalent to EventQueue::dispatch with no arguments, but avoids overload ambiguities when passed as a callback.

See also:
EventQueue::dispatch

Definition at line 108 of file events/EventQueue.h.

Event<void(Args...)> event ( R(*)(BoundArgs..., Args...)  func,
ContextArgs...  context_args 
)

Creates an event bound to the event queue.

Constructs an event bound to the specified event queue. The specified callback acts as the target for the event and is executed in the context of the event queue's dispatch loop once posted.

Parameters:
funcFunction to execute when the event is dispatched
context_argsArguments to pass to the callback
Returns:
Event that dispatches on the specific queue
     #include "mbed.h"

     void handler(int c) {
         printf("Param: %d\r\n", c);
     }

     int main()
     {
         EventQueue queue;

         // Create event with parameter
         Event<void()>    e  = queue.event(handler, 1);
         e();

         // Create event and post parameter later
         Event<void(int)> e2 = queue.event(handler);

         // Post the event with paramter 8
         e.post(8);

         // The dispatch method executes events
         queue.dispatch();

         e2.post(2);

         queue.dispatch();
     }
Event<void(Args...)> event ( T *  obj,
R(T::*)(BoundArgs..., Args...)  method,
ContextArgs...  context_args 
)

Creates an event bound to the event queue.

Constructs an event bound to the specified event queue. The specified callback acts as the target for the event and is executed in the context of the event queue's dispatch loop once posted.

Parameters:
objObject to call with the member function
methodMember function to execute in the context of the dispatch loop
context_argsArguments to pass to the callback
Returns:
Event that dispatches on the specific queue
     #include "mbed.h"

     class EventHandler {
         int _id;

     public:
         EventHandler(int id) : _id(id) { }

         void handler(int c) {
             printf("ID: %d Param: %d\r\n", _id, c);
         }
     };

     int main()
     {
         EventQueue queue;

         EventHandler handler_cb(10);

         // Create event on the eventqueue with a method callback
         Event<void(int)> e = queue.event(&handler_cb, &EventHandler::handler);

         // Post the event with paramter 8
         e.post(11);

         // The dispatch method executes events
         queue.dispatch();
     }
Event<void(Args...)> event ( mbed::Callback< R(BoundArgs..., Args...)>  cb,
ContextArgs...  context_args 
)

Creates an event bound to the event queue.

Constructs an event bound to the specified event queue. The specified callback acts as the target for the event and is executed in the context of the event queue's dispatch loop once posted.

Parameters:
cbCallback object
context_argsArguments to pass to the callback
Returns:
Event that dispatches on the specific queue
     #include "mbed.h"

     void handler(int c) {
         printf("Param: %d\r\n", c);
     }

     int main()
     {
         EventQueue queue;
         // Create callback object acting as a function
         // pointer to handler
         Callback<void(int)> cb(handler);

         // Pass the callback object to the eventqueue
         Event<void(int)> e = queue.event(cb);

         // Post the event with parameter 8
         e.post(9);

         // The dispatch method executes events
         q.dispatch();
     }
UserAllocatedEvent<F, void(ArgTs...)> make_user_allocated_event ( f,
ArgTs...  args 
)

Creates an user allocated event bound to the event queue.

Constructs an user allocated event bound to the specified event queue. The specified callback acts as the target for the event and is executed in the context of the event queue's dispatch loop once posted.

Parameters:
fFunction to execute when the event is dispatched
Returns:
Event that will dispatch on the specific queue
UserAllocatedEvent<mbed::Callback<void(ArgTs...)>, void(ArgTs...)> make_user_allocated_event ( T *  obj,
R(T::*)(ArgTs...args)  method,
ArgTs...  args 
)

Creates an user allocated event bound to the event queue.

See also:
EventQueue::make_user_allocated_event
unsigned tick (  )

Millisecond counter.

Returns the underlying tick of the event queue represented as the number of milliseconds that have passed since an arbitrary point in time. Intentionally overflows to 0 after 2^32-1.

Returns:
The underlying tick of the event queue in milliseconds

Definition at line 54 of file EventQueue.cpp.

int time_left ( UserAllocatedEvent< F, A > *  event )

Query how much time is left for delayed UserAllocatedEvent.

If the event is delayed, this function can be used to query how much time is left until the event is due to be dispatched.

Event must be valid i.e. event must have not finished executing and must have been bound to this queue.

This function is IRQ safe.

Parameters:
eventAddress of the event
Returns:
Remaining time in milliseconds or 0 if event is already due to be dispatched or is currently executing. Undefined if id is invalid.

Definition at line 217 of file events/EventQueue.h.

int time_left ( int  id )

Query how much time is left for delayed event.

If the event is delayed, this function can be used to query how much time is left until the event is due to be dispatched.

id must be valid i.e. event must have not finished executing.

This function is IRQ safe.

Parameters:
idUnique id of the event
Returns:
Remaining time in milliseconds or 0 if event is already due to be dispatched or is currently executing. Undefined if id is invalid.

Definition at line 64 of file EventQueue.cpp.