Mbed OS Reference
Loading...
Searching...
No Matches
UserAllocatedEvent< F, void(ArgTs...)> Class Template Reference

UserAllocatedEvent. More...

#include <UserAllocatedEvent.h>

Public Member Functions

constexpr UserAllocatedEvent (F f, ArgTs... args)
 Create an event.
 
constexpr UserAllocatedEvent (EventQueue *queue, F f, ArgTs... args)
 Create an event.
 
 ~UserAllocatedEvent ()
 Destructor for events.
 
void call ()
 Posts an event onto the underlying event queue, returning void.
 
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.
 
bool try_call_on (EventQueue *queue)
 Posts an event onto the event queue passed as argument,.
 
void operator() ()
 Posts an event onto the underlying event queue, returning void.
 
void delay (int delay)
 Configure the delay of an event.
 
void period (int period)
 Configure the period of an event.
 
bool cancel ()
 Cancels posted event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (T *obj, R(T::*method)(ArgTs...), ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (EventQueue *q, T *obj, R(T::*method)(ArgTs...), ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (const T *obj, R(T::*method)(ArgTs...) const, ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (EventQueue *q, const T *obj, R(T::*method)(ArgTs...) const, ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (EventQueue *q, volatile T *obj, R(T::*method)(ArgTs...) volatile, ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs... args)
 Create an event.
 
template<typename T , typename R >
constexpr UserAllocatedEvent (EventQueue *q, const volatile T *obj, R(T::*method)(ArgTs...) const volatile, ArgTs... args)
 Create an event.
 

Detailed Description

template<typename F, typename... ArgTs>
class events::UserAllocatedEvent< F, void(ArgTs...)>

UserAllocatedEvent.

Representation of an static event for fine-grain dispatch control.

UserAllocatedEvent provides mechanism for event posting and dispatching without utilization of queue internal memory. It embeds all underlying event data and doesn't require any memory allocation while posting and dispatching. All of these makes it cannot fail due to memory exhaustion while posting

Usage:

#include "mbed.h"
void handler(int data) { ... }
class Device {
public:
void handler(int data) { ... }
};
Device dev;
// queue with not internal storage for dynamic events
// accepts only user allocated events
static EventQueue queue(0);
// Create events
static auto e1 = make_user_allocated_event(&dev, Device::handler, 2);
static auto e2 = queue.make_user_allocated_event(handler, 3);
int main()
{
e1.call_on(&queue);
e2.call();
queue.dispatch(1);
}
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.

Definition at line 71 of file UserAllocatedEvent.h.

Constructor & Destructor Documentation

◆ UserAllocatedEvent() [1/10]

template<typename F , typename... ArgTs>
constexpr UserAllocatedEvent ( f,
ArgTs...  args 
)
constexpr

Create an event.

Constructs an event. 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
argsArguments to bind to the callback

Definition at line 84 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [2/10]

template<typename F , typename... ArgTs>
constexpr UserAllocatedEvent ( EventQueue queue,
f,
ArgTs...  args 
)
constexpr

Create an event.

Constructs an event. 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
queueEvent queue to dispatch on
fFunction to execute when the event is dispatched
argsArguments to bind to the callback

Definition at line 98 of file UserAllocatedEvent.h.

◆ ~UserAllocatedEvent()

template<typename F , typename... ArgTs>
~UserAllocatedEvent ( )

Destructor for events.

Definition at line 107 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [3/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( T *  obj,
R(T::*)(ArgTs...)  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 298 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [4/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( EventQueue q,
T *  obj,
R(T::*)(ArgTs...)  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 305 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [5/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( const T *  obj,
R(T::*)(ArgTs...) const  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 312 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [6/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( EventQueue q,
const T *  obj,
R(T::*)(ArgTs...) const  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 319 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [7/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( volatile T *  obj,
R(T::*)(ArgTs...) volatile  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 326 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [8/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( EventQueue q,
volatile T *  obj,
R(T::*)(ArgTs...) volatile  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 333 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [9/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( const volatile T *  obj,
R(T::*)(ArgTs...) const volatile  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 340 of file UserAllocatedEvent.h.

◆ UserAllocatedEvent() [10/10]

template<typename F , typename... ArgTs>
template<typename T , typename R >
constexpr UserAllocatedEvent ( EventQueue q,
const volatile T *  obj,
R(T::*)(ArgTs...) const volatile  method,
ArgTs...  args 
)
constexpr

Create an event.

See also
UserAllocatedEvent::UserAllocatedEvent

Definition at line 347 of file UserAllocatedEvent.h.

Member Function Documentation

◆ call()

template<typename F , typename... ArgTs>
void call ( )

Posts an event onto the underlying event queue, returning void.

The event is posted to the underlying queue and is executed in the context of the event queue's dispatch loop.

This call cannot fail due queue memory exhaustion because it doesn't allocate any memory

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

Definition at line 125 of file UserAllocatedEvent.h.

◆ call_on()

template<typename F , typename... ArgTs>
void call_on ( EventQueue queue)

Posts an event onto the event queue passed as argument, returning void.

The event is posted to the event queue passed as argument and is executed in the context of the event queue's dispatch loop.

This call cannot fail due queue memory exhaustion because it doesn't allocate any memory

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

Parameters
queueEvent queue to dispatch on. Will replace earlier bound EventQueue.

Definition at line 147 of file UserAllocatedEvent.h.

◆ try_call()

template<typename F , typename... ArgTs>
bool try_call ( )

Posts an event onto the underlying event queue.

The event is posted to the event queue passed as argument and is executed in the context of the event queue's dispatch loop.

This call cannot fail due queue memory exhaustion because it doesn't allocate any memory

Returns
False if the event was already posted true otherwise

Definition at line 166 of file UserAllocatedEvent.h.

◆ try_call_on()

template<typename F , typename... ArgTs>
bool try_call_on ( EventQueue queue)

Posts an event onto the event queue passed as argument,.

The event is posted to the underlying queue and is executed in the context of the event queue's dispatch loop.

This call cannot fail due queue memory exhaustion because it doesn't allocate any memory

Parameters
queueEvent queue to dispatch on. Will replace earlier bound EventQueue.
Returns
False if the event was already posted true otherwise

Definition at line 184 of file UserAllocatedEvent.h.

◆ operator()()

template<typename F , typename... ArgTs>
void operator() ( )

Posts an event onto the underlying event queue, returning void.

The event is posted to the underlying queue and is executed in the context of the event queue's dispatch loop.

This call cannot fail due queue memory exhaustion because it doesn't allocate any memory

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

Definition at line 201 of file UserAllocatedEvent.h.

◆ delay()

template<typename F , typename... ArgTs>
void delay ( int  delay)

Configure the delay of an event.

Parameters
delayMillisecond delay before dispatching the event

Definition at line 210 of file UserAllocatedEvent.h.

◆ period()

template<typename F , typename... ArgTs>
void period ( int  period)

Configure the period of an event.

Parameters
periodMillisecond period for repeatedly dispatching an event

Definition at line 220 of file UserAllocatedEvent.h.

◆ cancel()

template<typename F , typename... ArgTs>
bool cancel ( )

Cancels posted event.

Attempts to cancel posted event. It is not safe to call cancel after an event has already been dispatched.

The cancel function is IRQ safe.

If called while the event queue's dispatch loop is active, the cancel function does not guarantee that the event will not execute after it returns, as the event may have already begun executing.

Returns
true if event was successfully cancelled

Definition at line 239 of file UserAllocatedEvent.h.