Embedded Artistry Framework
Embedded Systems C++ Framework
Classes | Typedefs | Enumerations | Variables
Framework Platform Infrastructure

Interfaces and components for building a virtual platform. More...

Collaboration diagram for Framework Platform Infrastructure:

Classes

class  embvm::EventBase
 Base class for events. More...
 
class  embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle
 Handle for an event subscription. More...
 
class  embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >
 Global Event Manager class. More...
 
class  embvm::EventQueue< TEvent, TQueueSize >
 Keep a queue of events. More...
 
class  embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >
 Base class for Platform definitions. More...
 
class  embvm::PlatformDispatcher< TDispatchQueue >
 Add a dispatch queue to the VirtualPlatform through inheritance. More...
 
class  embvm::PlatformEventManagement< TEventCenter >
 Add an event manager to the VirtualPlatform through inheritance. More...
 

Typedefs

using embvm::Signal_t = uint32_t
 Signal type which is used for function inputs. More...
 
template<const size_t TSize, const size_t TThreadCnt = 1, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::StaticEventQueue = embutil::StaticDispatchQueue< TSize, TThreadCnt, TFunc >
 This alias represents a static dispatch queue which can be used with the event manager Primarily this alias is used to prevent users from needing to declare a long type declaration just because of the need to increase inplace_function<>'s size. More...
 
using embvm::DynamicEventCenter = EventCenter< 0, 0 >
 Declare an EventCenter that uses dynamic memory allocation. More...
 
template<const size_t TMaxEvents = 16, const size_t TMaxSubscribersPerEvent = 4>
using embvm::StaticEventCenter = EventCenter< TMaxEvents, TMaxSubscribersPerEvent >
 Declare a DriverRegistry that uses static memory allocation. More...
 

Enumerations

enum  embvm::Signal {
  embvm::Event_Invalid = 0, embvm::Event_ProcessorInitd, embvm::Event_HwPlatformInitd, embvm::Event_PlatformInitd,
  embvm::Event_EXTENSION_START
}
 Default framework event signal definitions. More...
 

Variables

static constexpr size_t embvm::EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE = (sizeof(void*) * 8)
 Maximum size of the Event center callback functor object. More...
 

Detailed Description

Interfaces and components for building a virtual platform.


Class Documentation

◆ embvm::EventBase

class embvm::EventBase

Base class for events.

The EventBase class represents a signal with no associated data Templated to allow use of any signal definition type within the framework

You can define custom events with data by inheriting from this class:

class TestEventWithData : public EventBase<MySignal_t>
{
public:
TestEventWithData() : EventBase<MySignal_t>(eventWithData) {}
bool data = false;
};

You can then transform event base objects to your class (as long as the types match!)

void passEventWithDataCb(EventBase e)
{
assert(e.sig == eventWithData);
TestEventWithData* event = static_cast<TestEventWithData*>(&e);
eventUpdate = event->data;
}

Public Member Functions

 EventBase (Signal_t s=Event_Invalid) noexcept
 Default constructor. More...
 
type_safe::boolean safeToFree () const noexcept
 Check whether this event is safe to free. More...
 

Public Attributes

Signal_t sig = Event_Invalid
 Signal ID for this event. More...
 

Private Member Functions

 EventBase (Signal_t s, bool d) noexcept
 

Private Attributes

type_safe::boolean dynamic_ = false
 nullptr indicates this is statically allocated and should not be freed More...
 

Constructor & Destructor Documentation

◆ EventBase() [1/2]

embvm::EventBase::EventBase ( Signal_t  s = Event_Invalid)
inlineexplicitnoexcept

Default constructor.

Creates a static event base (e.g. on the stack)

Parameters
sThe signal which corresponds to this event

◆ EventBase() [2/2]

embvm::EventBase::EventBase ( Signal_t  s,
bool  d 
)
inlineprivatenoexcept

Member Function Documentation

◆ safeToFree()

type_safe::boolean embvm::EventBase::safeToFree ( ) const
inlinenoexcept

Check whether this event is safe to free.

Returns
true if the event was dynamically allocated, false if statically allocated (can't free)

References dynamic_.

Member Data Documentation

◆ dynamic_

type_safe::boolean embvm::EventBase::dynamic_ = false
private

nullptr indicates this is statically allocated and should not be freed

Referenced by safeToFree().

◆ sig

Signal_t embvm::EventBase::sig = Event_Invalid

Signal ID for this event.

◆ embvm::EventCenter::EventHandle

class embvm::EventCenter::EventHandle

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
class embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle

Handle for an event subscription.

EventHandle represents a handle to an event registration. EventHandles are created during the subscribe() process. The lifetime of the EventHandle controls the lifetime of the subscription: if the handle leaves scope, the subscription will be automatically revoked.

Template parameters simply match those in the original EventCenter declaration, since EventHandle is a class member.

Public Member Functions

EventHandleoperator= (EventHandle &&rhs) noexcept
 Move assignment operator. More...
 
 EventHandle (const EventHandle &)=delete
 Delete the copy constructor. More...
 
const EventHandleoperator= (const EventHandle &)=delete
 Delete the copy assignment operator. More...
 
 ~EventHandle () noexcept
 EventHandle destructor. More...
 
 operator bool () const noexcept
 Boolean operator returns true if the handle is valid, false otherwise. More...
 
const Signal_tsig () const noexcept
 Check the signal this subscription corresponds to. More...
 
void reset () noexcept
 Unregister the callback and invalidate the handle. More...
 

Private Types

using TEventHandle = typename decltype(events_)::mapped_type::iterator
 Convenience declaration: our handle is an iterator to the mapped type. More...
 

Private Member Functions

 EventHandle (EventCenter *owner, Signal_t sig, TEventHandle iter) noexcept
 EventHandle constructor. More...
 
 EventHandle (EventHandle &&rhs) noexcept
 Move constructor. More...
 
TEventHandle get () const noexcept
 Get the underlying handle. More...
 

Private Attributes

Signal_t sig_
 
TEventHandle handle_
 
bool is_valid_
 
EventCentermgr_
 

Friends

class EventCenter
 Event Center is able to invoke private EventHandle functions. More...
 

Member Typedef Documentation

◆ TEventHandle

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::TEventHandle = typename decltype(events_)::mapped_type::iterator
private

Convenience declaration: our handle is an iterator to the mapped type.

Constructor & Destructor Documentation

◆ EventHandle() [1/3]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::EventHandle ( const EventHandle )
delete

Delete the copy constructor.

◆ ~EventHandle()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::~EventHandle ( )
inlinenoexcept

EventHandle destructor.

On destruction, the handle will automatically unsubscribe itself from the event.

◆ EventHandle() [2/3]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::EventHandle ( EventCenter owner,
Signal_t  sig,
TEventHandle  iter 
)
inlineexplicitprivatenoexcept

EventHandle constructor.

Parameters
ownerThe EventCenter which owns this EventHandle
sigThe signal which the subscriber is interested in
iterThe handle object

◆ EventHandle() [3/3]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::EventHandle ( EventHandle &&  rhs)
inlineprivatenoexcept

Move constructor.

Member Function Documentation

◆ get()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
TEventHandle embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::get ( ) const
inlineprivatenoexcept

Get the underlying handle.

Returns
The underlying handle storage object

◆ operator bool()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::operator bool ( ) const
inlinenoexcept

Boolean operator returns true if the handle is valid, false otherwise.

◆ operator=() [1/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
EventHandle& embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::operator= ( EventHandle &&  rhs)
inlinenoexcept

◆ operator=() [2/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
const EventHandle& embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::operator= ( const EventHandle )
delete

Delete the copy assignment operator.

◆ reset()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
void embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::reset ( )
inlinenoexcept

Unregister the callback and invalidate the handle.

◆ sig()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
const Signal_t& embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::sig ( ) const
inlinenoexcept

Check the signal this subscription corresponds to.

Returns
the signal object which matches this handle

Friends And Related Function Documentation

◆ EventCenter

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
friend class EventCenter
friend

Event Center is able to invoke private EventHandle functions.

Member Data Documentation

◆ handle_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
TEventHandle embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::handle_
private

◆ is_valid_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
bool embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::is_valid_
private

◆ mgr_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
EventCenter* embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::mgr_
private

◆ sig_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
Signal_t embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle::sig_
private

◆ embvm::EventCenter

class embvm::EventCenter

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
class embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >

Global Event Manager class.

Allows you to subscribe and unsubscribe to/from events. Allows you to post signals and events. Calls are dispatched. You must keep your handle alive when you register for a callback. Handles will be automatically cleaned up when they go out of scope!

Allowed: publishing and signaling from an interrupt. Not allowed: subscribing or unsubscribing from an interrupt.

This class provides support for both dynamic memory allocation and static memory allocation. The default TMaxEvents and TMaxSubscribersPerEvent settings (0) indicate dynamic memory.

Note
Total static memory usage is (TMaxEvents * TMaxSubscribersPerEvent * sizeof(event))
Template Parameters
TMaxEventsThe maximum number of events to store in the queue. 0 indicates dynamic memory allocation will be used; all other numbers use static memory.
TMaxSubscribersPerEventThe maximum number of subscribers that can register for each event. 0 indicates dynamic memory allocation will be used; all other numbers use static memory.
TFuncThe function object type for the DispatcherFunc.

Public Types

using sig_t = Signal_t
 Underlying signal type. More...
 
using cb_t = stdext::inplace_function< void(embvm::EventBase)>
 Callback type. More...
 

Public Member Functions

 EventCenter () noexcept
 Default EventCenter constructor. More...
 
 EventCenter (const DispatcherFunc &dispatcher) noexcept
 Construct EventCenter with a dispatcher. More...
 
 ~EventCenter ()=default
 Default destructor. More...
 
 EventCenter (const EventCenter &)=delete
 Deleted copy constructor. More...
 
const EventCenteroperator= (const EventCenter &)=delete
 Deleted copy assignment operator. More...
 
 EventCenter (EventCenter &&)=delete
 Deleted move constructor. More...
 
EventCenteroperator= (EventCenter &&)=delete
 Deleted move assignment operator. More...
 
embvm::EventBase createSignal (Signal_t sig=Signal::Event_Invalid) noexcept
 Create an event on the stack. More...
 
size_t numSubscribedEvents () noexcept
 Check how many event types are registered. More...
 
size_t numSubscribers (Signal_t sig) noexcept
 Check how many subscribers are listening to a specific event. More...
 
EventCenter::EventHandle subscribe (Signal_t sig, const cb_t &cb) noexcept
 Subscribe to an event. More...
 
EventCenter::EventHandle subscribe (Signal_t sig, cb_t &&cb) noexcept
 Subscribe to an event. More...
 
void unsubscribe (EventCenter::EventHandle &handle) noexcept
 Unsubscribe from listening for an event. More...
 
void signal (Signal_t sig) noexcept
 Signal an event. More...
 
void publish (embvm::EventBase event) noexcept
 Publish an event. More...
 

Private Types

using DispatcherFunc = stdext::inplace_function< void(const TFunc &)>
 The function prototype for the Dispatcher. More...
 
typedef std::conditional<(TMaxSubscribersPerEvent==0), std::list< cb_t >, etl::list< cb_t, TMaxSubscribersPerEvent > >::type TListType
 Type for storing lists of event subscribers. More...
 
typedef std::conditional<(TMaxEvents==0), std::map< Signal_t, TListType >, etl::map< Signal_t, TListType, TMaxEvents > >::type TMapType
 Type for storing event subscription lists. More...
 

Private Member Functions

void EventCenterDispatch (const TFunc &op) noexcept
 EventCenter Default Dispatch Function. More...
 

Private Attributes

TMapType events_
 The map which stores event subscriptions. More...
 
std::mutex mutex_
 Mutex which protects. More...
 
const DispatcherFunc dispatcher_
 Dispatcher function which will handle callbacks. More...
 

Member Typedef Documentation

◆ cb_t

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::cb_t = stdext::inplace_function<void(embvm::EventBase)>

Callback type.

◆ DispatcherFunc

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::DispatcherFunc = stdext::inplace_function<void(const TFunc&)>
private

The function prototype for the Dispatcher.

The dispacher uses inplace_function regardless of static or dynamic memory allocation.

◆ sig_t

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::sig_t = Signal_t

Underlying signal type.

◆ TListType

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
typedef std::conditional<(TMaxSubscribersPerEvent == 0), std::list<cb_t>, etl::list<cb_t, TMaxSubscribersPerEvent> >::type embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::TListType
private

Type for storing lists of event subscribers.

TListType is either std::list or etl::list depending on static or dynamic memory allocations. For static allocations, TListType is capped at TMaxSubscribersPerEvent.

◆ TMapType

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
typedef std::conditional<(TMaxEvents == 0), std::map<Signal_t, TListType>, etl::map<Signal_t, TListType, TMaxEvents> >::type embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::TMapType
private

Type for storing event subscription lists.

TMapType is either std::map or etl::map depending on static or dynamic memory allocations. For static allocations, TMapType is capped at TMaxEvents. The map key is the signal ID.

Constructor & Destructor Documentation

◆ EventCenter() [1/4]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventCenter ( )
inlinenoexcept

Default EventCenter constructor.

Creating an EventCenter without a dispatcher will result in the manager invoking the functions.

◆ EventCenter() [2/4]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventCenter ( const DispatcherFunc dispatcher)
inlineexplicitnoexcept

Construct EventCenter with a dispatcher.

Specify a function to dispatch all of the event callbacks to. Used with a dispatch queue, or other type of system event queue.

◆ ~EventCenter()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::~EventCenter ( )
default

Default destructor.

◆ EventCenter() [3/4]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventCenter ( const EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc > &  )
delete

Deleted copy constructor.

◆ EventCenter() [4/4]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventCenter ( EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc > &&  )
delete

Deleted move constructor.

Member Function Documentation

◆ createSignal()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
embvm::EventBase embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::createSignal ( Signal_t  sig = Signal::Event_Invalid)
inlinenoexcept

Create an event on the stack.

Returns
A stack allocated event with the specified signal ID

◆ EventCenterDispatch()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
void embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventCenterDispatch ( const TFunc &  op)
inlineprivatenoexcept

EventCenter Default Dispatch Function.

If no external dispatcher is provided, event center has one which just executes the operation by default.

◆ numSubscribedEvents()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
size_t embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::numSubscribedEvents ( )
inlinenoexcept

Check how many event types are registered.

Returns
The count of event types which have been subscribed to by listeners.

References embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_.

◆ numSubscribers()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
size_t embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::numSubscribers ( Signal_t  sig)
inlinenoexcept

Check how many subscribers are listening to a specific event.

Parameters
sigThe type of event to check.
Returns
The number of subscribers listening for the specified event.

References embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_.

◆ operator=() [1/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
const EventCenter& embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::operator= ( const EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
EventCenter& embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::operator= ( EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc > &&  )
delete

Deleted move assignment operator.

◆ publish()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
void embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::publish ( embvm::EventBase  event)
inlinenoexcept

Publish an event.

Signals to the system that an event has occurred. All subscribers will have their callback function invoked and will be passed the input event.

Parameters
eventThe event object that will be shared with the subscribers

References embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::dispatcher_, and embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_.

◆ signal()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
void embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::signal ( Signal_t  sig)
inlinenoexcept

Signal an event.

Signals to the system that an event has occurred. All subscribers will have their callback function invoked.

Parameters
sigThe event type to signal

References embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::dispatcher_, and embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_.

◆ subscribe() [1/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
EventCenter::EventHandle embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::subscribe ( Signal_t  sig,
const cb_t cb 
)
inlinenoexcept

Subscribe to an event.

Subscribes to an event with a callback function. The callback will be invoked whenever an event of the specified type is signalled.

Parameters
sigThe type of event to listen for.
cbThe function which will be called when the event occurs.
Returns
Handle representing event subscription. The user must keep the handle within scope. Once the handle goes out of scope, the subscription will be automatically unregistered.

References assert, embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_, and embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::mutex_.

◆ subscribe() [2/2]

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
EventCenter::EventHandle embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::subscribe ( Signal_t  sig,
cb_t &&  cb 
)
inlinenoexcept

Subscribe to an event.

Subscribes to an event with a callback function. The callback will be invoked whenever an event of the specified type is signalled.

Parameters
sigThe type of event to listen for.
cbThe function which will be called when the event occurs.
Returns
Handle representing event subscription. The user must keep the handle within scope. Once the handle goes out of scope, the subscription will be automatically unregistered.

References assert, embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_, and embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::mutex_.

◆ unsubscribe()

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
void embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::unsubscribe ( EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::EventHandle handle)
inlinenoexcept

Unsubscribe from listening for an event.

Removes the subscription to the event. An unsubscribe request uses the EventHandle which was returned by subscribe(). Unsubscribe also happens automatically when the EventHandle goes out of scope.

Parameters
handleThe handle to the subscription, which was returned by subscribe()

References embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::events_, and embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::mutex_.

Member Data Documentation

◆ dispatcher_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
const DispatcherFunc embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::dispatcher_
private

◆ events_

◆ mutex_

template<const size_t TMaxEvents = 0, const size_t TMaxSubscribersPerEvent = 0, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
std::mutex embvm::EventCenter< TMaxEvents, TMaxSubscribersPerEvent, TFunc >::mutex_
private

◆ embvm::EventQueue

class embvm::EventQueue

template<typename TEvent, size_t TQueueSize = 0>
class embvm::EventQueue< TEvent, TQueueSize >

Keep a queue of events.

Manage a queue of events of a specified type. The EventQueue can utilize both static and dynamic memory allocation strategies.

Template Parameters
TEventThe event type which this queue manages. Can be embvm::EventBase, or a derived event with data.
TQueueSizeThe maximum size of the event queue. Size 0 indicates dynamic memory will be used. All other sizes will enable static memory allocation.

Public Member Functions

 EventQueue ()=default
 Default constructor. More...
 
 ~EventQueue ()=default
 Default destructor. More...
 
 EventQueue (const EventQueue &)=delete
 Deleted copy constructor. More...
 
const EventQueueoperator= (const EventQueue &)=delete
 Deleted copy assignment operator. More...
 
 EventQueue (EventQueue &&)=default
 Default move constructor. More...
 
EventQueueoperator= (EventQueue &&)=default
 Default move assignment operator. More...
 
bool empty () const noexcept
 Check if the queue is empty. More...
 
size_t size () const noexcept
 Check the size of the queue. More...
 
void push (TEvent e) noexcept
 Add an event to the queue. More...
 
TEvent & front () const noexcept
 Get the front element of the queue, without popping. More...
 
TEvent pop () noexcept
 Pop the front element from the queue. More...
 

Private Types

using TQueueType = typename std::conditional<(TQueueSize==0), std::queue< TEvent >, etl::queue< TEvent, TQueueSize > >::type
 The type of the underlying queue. More...
 

Private Attributes

TQueueType q_
 The underlying event queue storage. More...
 

Member Typedef Documentation

◆ TQueueType

template<typename TEvent , size_t TQueueSize = 0>
using embvm::EventQueue< TEvent, TQueueSize >::TQueueType = typename std::conditional<(TQueueSize == 0), std::queue<TEvent>, etl::queue<TEvent, TQueueSize> >::type
private

The type of the underlying queue.

Size 0 indicates dynamic memory usage (std::queue), other sizes indicate static memory.

Constructor & Destructor Documentation

◆ EventQueue() [1/3]

template<typename TEvent , size_t TQueueSize = 0>
embvm::EventQueue< TEvent, TQueueSize >::EventQueue ( )
default

Default constructor.

◆ ~EventQueue()

template<typename TEvent , size_t TQueueSize = 0>
embvm::EventQueue< TEvent, TQueueSize >::~EventQueue ( )
default

Default destructor.

◆ EventQueue() [2/3]

template<typename TEvent , size_t TQueueSize = 0>
embvm::EventQueue< TEvent, TQueueSize >::EventQueue ( const EventQueue< TEvent, TQueueSize > &  )
delete

Deleted copy constructor.

◆ EventQueue() [3/3]

template<typename TEvent , size_t TQueueSize = 0>
embvm::EventQueue< TEvent, TQueueSize >::EventQueue ( EventQueue< TEvent, TQueueSize > &&  )
default

Default move constructor.

Member Function Documentation

◆ empty()

template<typename TEvent , size_t TQueueSize = 0>
bool embvm::EventQueue< TEvent, TQueueSize >::empty ( ) const
inlinenoexcept

Check if the queue is empty.

Returns
true if the queue is empty, false if it has data.

References embvm::EventQueue< TEvent, TQueueSize >::q_.

◆ front()

template<typename TEvent , size_t TQueueSize = 0>
TEvent& embvm::EventQueue< TEvent, TQueueSize >::front ( ) const
inlinenoexcept

Get the front element of the queue, without popping.

Returns
a reference to the front element.

References embvm::EventQueue< TEvent, TQueueSize >::q_.

◆ operator=() [1/2]

template<typename TEvent , size_t TQueueSize = 0>
const EventQueue& embvm::EventQueue< TEvent, TQueueSize >::operator= ( const EventQueue< TEvent, TQueueSize > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<typename TEvent , size_t TQueueSize = 0>
EventQueue& embvm::EventQueue< TEvent, TQueueSize >::operator= ( EventQueue< TEvent, TQueueSize > &&  )
default

Default move assignment operator.

◆ pop()

template<typename TEvent , size_t TQueueSize = 0>
TEvent embvm::EventQueue< TEvent, TQueueSize >::pop ( )
inlinenoexcept

Pop the front element from the queue.

Returns
the front element from the queue.
Postcondition
The element has been removed from the queue.

References embvm::EventQueue< TEvent, TQueueSize >::q_.

◆ push()

template<typename TEvent , size_t TQueueSize = 0>
void embvm::EventQueue< TEvent, TQueueSize >::push ( TEvent  e)
inlinenoexcept

Add an event to the queue.

Parameters
eThe event to add to the queue for processing.

References embvm::EventQueue< TEvent, TQueueSize >::q_.

◆ size()

template<typename TEvent , size_t TQueueSize = 0>
size_t embvm::EventQueue< TEvent, TQueueSize >::size ( ) const
inlinenoexcept

Check the size of the queue.

Returns
the number of events currently enqueued.

References embvm::EventQueue< TEvent, TQueueSize >::q_.

Member Data Documentation

◆ q_

◆ embvm::VirtualPlatformBase

class embvm::VirtualPlatformBase

template<typename TPlatform, class TDriverRegistry>
class embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >

Base class for Platform definitions.

Platforms should derive from this base class, and optionally from other platform base classes which provide optional functionality (see embvm::PlatformEventManagement<>, embvm::PlatformDispatcher<>).

The platform base is templated off of the driver registry type, in order to Allow users to utilize their custom driver types with the platform.

Template Parameters
TPlatformThe derived CRTP class which defines the consumer's platform.
TDriverRegistryThe type of the platform's DriverRegistry. DriverRegistry type is specified to enable consumers to use custom driver types.
Inheritance diagram for embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >:
Inheritance graph

Public Member Functions

 VirtualPlatformBase (const VirtualPlatformBase &)=delete
 Deleted copy constructor. More...
 
const VirtualPlatformBaseoperator= (const VirtualPlatformBase &)=delete
 Deleted copy assignment operator. More...
 
 VirtualPlatformBase (VirtualPlatformBase &&)=delete
 Deleted move constructor. More...
 
VirtualPlatformBaseoperator= (VirtualPlatformBase &&)=delete
 Deleted move assignment operator. More...
 
void init () noexcept
 Initialize the platform. More...
 
void initProcessor () noexcept
 Initialize the processor. More...
 
void initHWPlatform () noexcept
 Initialize the hardware platform. More...
 
constexpr const std::string_view & name () const noexcept
 Access the platform's name. More...
 
constexpr const char * name_cstr () const noexcept
 Access the platform name as a cstring for C API compatibility. More...
 
auto findDriver (const std::string_view &name) noexcept
 Access a device driver in the registry by name. More...
 
auto findDriver (embvm::DriverType_t type) noexcept
 Access a device driver in the registry by type. More...
 
template<class TDriverClass >
auto findDriver () noexcept
 Access a device driver in the registry by type, cast as the appropriate base class. More...
 
template<class TDriverClass >
auto findDriver (const std::string_view &name) noexcept
 Access a device driver in the registry by name, cast as the appropriate base class. More...
 
auto findAllDrivers (embvm::DriverType_t type) noexcept
 Get a list of all device drivers in the registry by type. More...
 
template<class TDriverClass >
auto findAllDrivers () noexcept
 Get a list of all device drivers in the registry by type, cast as the appropriate base class. More...
 
size_t driverCount () const noexcept
 Get the count of drivers registered with the platform. More...
 

Static Public Member Functions

static TPlatform & inst () noexcept
 Get the global platform instance. More...
 
static void earlyInitHook () noexcept
 Call early-initialization code. More...
 
static void initOS () noexcept
 Initialize the OS. More...
 
static void initOS (void(*main_thread)()) noexcept
 Initialize the with a function to use as the main thread. More...
 
static void registerDriver (const std::string_view &name, embvm::DriverBase *driver) noexcept
 Platform-level API for registering a new device driver. More...
 
static void unregisterDriver (const std::string_view &name, embvm::DriverBase *driver) noexcept
 Platform-level API for unregistering a new device driver. More...
 

Protected Member Functions

 VirtualPlatformBase (const char *name) noexcept
 Create a virtual platform base using a C-string. More...
 
 VirtualPlatformBase (const std::string &name) noexcept
 Create a virtual platform base using a std::string name. More...
 
 VirtualPlatformBase (const std::string_view &name) noexcept
 Create a virtual platform base using a std::string_view name. More...
 
 ~VirtualPlatformBase ()=default
 Default destructor. More...
 

Protected Attributes

const std::string_view name_
 

Static Private Member Functions

static TDriverRegistry & driverRegistry () noexcept
 Access the platform DriverRegistry instance. More...
 

Constructor & Destructor Documentation

◆ VirtualPlatformBase() [1/5]

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::VirtualPlatformBase ( const VirtualPlatformBase< TPlatform, TDriverRegistry > &  )
delete

Deleted copy constructor.

◆ VirtualPlatformBase() [2/5]

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::VirtualPlatformBase ( VirtualPlatformBase< TPlatform, TDriverRegistry > &&  )
delete

Deleted move constructor.

◆ VirtualPlatformBase() [3/5]

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::VirtualPlatformBase ( const char *  name)
inlineexplicitprotectednoexcept

Create a virtual platform base using a C-string.

  • Parameters
    nameThe name of the platform.

◆ VirtualPlatformBase() [4/5]

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::VirtualPlatformBase ( const std::string &  name)
inlineexplicitprotectednoexcept

Create a virtual platform base using a std::string name.

Parameters
nameThe name of the platform. Note: VirtualPlatformBase() uses a std::string_view, so the std::string must remain valid

◆ VirtualPlatformBase() [5/5]

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::VirtualPlatformBase ( const std::string_view &  name)
inlineexplicitprotectednoexcept

Create a virtual platform base using a std::string_view name.

Parameters
nameThe name of the platform.

◆ ~VirtualPlatformBase()

template<typename TPlatform, class TDriverRegistry>
embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::~VirtualPlatformBase ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ driverCount()

template<typename TPlatform, class TDriverRegistry>
size_t embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::driverCount ( ) const
inlinenoexcept

Get the count of drivers registered with the platform.

returns Number of drivers currently registered with the platform DriverRegistry.

◆ driverRegistry()

◆ earlyInitHook()

template<typename TPlatform, class TDriverRegistry>
static void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::earlyInitHook ( )
inlinestaticnoexcept

Call early-initialization code.

Call early initialization code, which is to be run before C runtime initialization, memory relocations, OS initialization, etc. This call is used to handle early setup code that the rest of the initialization process might depend on, such as DRAM initialization.

This function forwards the call to the derived class for the actual implementation.

◆ findAllDrivers() [1/2]

template<typename TPlatform, class TDriverRegistry>
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findAllDrivers ( embvm::DriverType_t  type)
inlinenoexcept

Get a list of all device drivers in the registry by type.

The type will be returned as the appropriate base class (instead of embvm::DriverBase).

This call forwards the information to the DriverRegistry instance.

Parameters
typeThe type of driver being requested (embvm::i2c::master, SystemClock).
Returns
A list of embvm::DriverBase instances. If no matching types are found, an empty list will be returned. The caller must cast to the appropriate type.

◆ findAllDrivers() [2/2]

template<typename TPlatform, class TDriverRegistry>
template<class TDriverClass >
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findAllDrivers ( )
inlinenoexcept

Get a list of all device drivers in the registry by type, cast as the appropriate base class.

The type will be returned as the appropriate base class (instead of embvm::DriverBase).

This call forwards the information to the DriverRegistry instance.

Template Parameters
TDriverClassThe class of driver being requested (embvm::i2c::master, SystemClock).
Returns
A list of driver instances cast as TDriverClass types. If no matching types are found, an empty list will be returned.

◆ findDriver() [1/4]

template<typename TPlatform, class TDriverRegistry>
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findDriver ( const std::string_view &  name)
inlinenoexcept

Access a device driver in the registry by name.

Find a driver by name.

This call forwards the information to the DriverRegistry instance.

Returns
An optional_ref to the embvm::DriverBase instance. If no instance is found, the optional reference will be invalid. The caller must cast to the appropriate type.

◆ findDriver() [2/4]

template<typename TPlatform, class TDriverRegistry>
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findDriver ( embvm::DriverType_t  type)
inlinenoexcept

Access a device driver in the registry by type.

Find a driver by type. If multiple drivers are found for a type, the first one found will be returned.

This call forwards the information to the DriverRegistry instance.

Returns
An optional_ref to the embvm::DriverBase instance. If no instance is found, the optional reference will be invalid. The caller must cast to the appropriate type.

◆ findDriver() [3/4]

template<typename TPlatform, class TDriverRegistry>
template<class TDriverClass >
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findDriver ( )
inlinenoexcept

Access a device driver in the registry by type, cast as the appropriate base class.

If multiple drivers are found for a type, the first one found will be returned. The type will be returned as the appropriate base class (instead of embvm::DriverBase).

This call forwards the information to the DriverRegistry instance.

Template Parameters
TDriverClassThe class of driver being requested (embvm::i2c::master, SystemClock).
Returns
an type_safe::optional_ref cast to the TDriverClass type. If the driver was not found, the optional_ref will be empty.

◆ findDriver() [4/4]

template<typename TPlatform, class TDriverRegistry>
template<class TDriverClass >
auto embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::findDriver ( const std::string_view &  name)
inlinenoexcept

Access a device driver in the registry by name, cast as the appropriate base class.

The type will be returned as the appropriate base class (instead of embvm::DriverBase).

This call forwards the information to the DriverRegistry instance.

Template Parameters
TDriverClassThe class of driver being requested (embvm::i2c::master, SystemClock).
Returns
an type_safe::optional_ref cast to the TDriverClass type. If the driver was not found, the optional_ref will be empty.

◆ init()

template<typename TPlatform, class TDriverRegistry>
void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::init ( )
inlinenoexcept

Initialize the platform.

This function is responsible for initializing the platform.

This function forwards the call to the derived class for the actual implementation.

◆ initHWPlatform()

template<typename TPlatform, class TDriverRegistry>
void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::initHWPlatform ( )
inlinenoexcept

Initialize the hardware platform.

Performs steps necessary to initialize the hardware platform for use by the platform. In many cases, this call should just invoke the hardware platform's init() function. Control of this function is placed in the platform layer to allow for platform-specific customization & initialization of the hardware platform in situations where non-default values are used.

This function forwards the call to the derived class for the actual implementation.

◆ initOS() [1/2]

template<typename TPlatform, class TDriverRegistry>
static void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::initOS ( )
inlinestaticnoexcept

Initialize the OS.

Performs steps necessary to initialize the OS for use by the platform. Control of this function is placed in the platform layer to allow for platform-specific customization & initialization of the OS, since each OS has different startup requirements

This function forwards the call to the derived class for the actual implementation.

◆ initOS() [2/2]

template<typename TPlatform, class TDriverRegistry>
static void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::initOS ( void(*)()  main_thread)
inlinestaticnoexcept

Initialize the with a function to use as the main thread.

Performs steps necessary to initialize the OS for use by the platform. Control of this function is placed in the platform layer to allow for platform-specific customization & initialization of the OS, since each OS has different startup requirements

This function forwards the call to the derived class for the actual implementation.

Parameters
main_threada function pointer to use as the main thread routine. This version of initOS should be used for OSes such as FreeRTOS which kill execution of the current thread when the scheduler is started.

◆ initProcessor()

template<typename TPlatform, class TDriverRegistry>
void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::initProcessor ( )
inlinenoexcept

Initialize the processor.

Performs steps necessary to initialize the processor for use by the platform. In many cases, this call should just invoke the processor's init() function. Control of this function is placed in the platform layer to allow for platform-specific customization & initialization of the processor in situations where non-default values are used.

This function forwards the call to the derived class for the actual implementation.

◆ inst()

template<typename TPlatform, class TDriverRegistry>
static TPlatform& embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::inst ( )
inlinestaticnoexcept

Get the global platform instance.

Static declaration of the VirtualPlatformBase instance. We use this function to avoid the static initializatio order 'fiasco'. See more: https://isocpp.org/wiki/faq/ctors#static-init-order

◆ name()

template<typename TPlatform, class TDriverRegistry>
constexpr const std::string_view& embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::name ( ) const
inlinenoexcept

◆ name_cstr()

template<typename TPlatform, class TDriverRegistry>
constexpr const char* embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::name_cstr ( ) const
inlinenoexcept

Access the platform name as a cstring for C API compatibility.

Returns
Platform name as a C-string.

◆ operator=() [1/2]

template<typename TPlatform, class TDriverRegistry>
const VirtualPlatformBase& embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::operator= ( const VirtualPlatformBase< TPlatform, TDriverRegistry > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<typename TPlatform, class TDriverRegistry>
VirtualPlatformBase& embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::operator= ( VirtualPlatformBase< TPlatform, TDriverRegistry > &&  )
delete

Deleted move assignment operator.

◆ registerDriver()

template<typename TPlatform, class TDriverRegistry>
static void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::registerDriver ( const std::string_view &  name,
embvm::DriverBase driver 
)
inlinestaticnoexcept

Platform-level API for registering a new device driver.

Register a device driver with the platform's driver registry.

This call forwards the information to the DriverRegistry instance.

Parameters
nameThe name (used as a key) the driver will be registered under.
driverPointer to the embvm::DriverBase object. A pointer is used because there are any number of potential derived classes which will be tracked. To prevent slicing, a pointer to the base class is stored.

◆ unregisterDriver()

template<typename TPlatform, class TDriverRegistry>
static void embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::unregisterDriver ( const std::string_view &  name,
embvm::DriverBase driver 
)
inlinestaticnoexcept

Platform-level API for unregistering a new device driver.

Unregister a device driver with the platform's driver registry.

This call forwards the information to the DriverRegistry instance.

Parameters
nameThe name of the driver to remove.
driverPointer to the embvm::DriverBase object being removed.

Member Data Documentation

◆ name_

template<typename TPlatform, class TDriverRegistry>
const std::string_view embvm::VirtualPlatformBase< TPlatform, TDriverRegistry >::name_
protected

◆ embvm::PlatformDispatcher

class embvm::PlatformDispatcher

template<class TDispatchQueue>
class embvm::PlatformDispatcher< TDispatchQueue >

Add a dispatch queue to the VirtualPlatform through inheritance.

Your platform can inherit from this class to add dispatching APIs a the platform level. This template is specialized based on the class of Dispatch Queue you want to create.

Example declaration:

Template Parameters
TDispatchQueueThe type declaration for the underlying dispatch queue. This is user specified because each platform will have its own specific dispatch queue configuration.
Inheritance diagram for embvm::PlatformDispatcher< TDispatchQueue >:
Inheritance graph

Public Member Functions

 PlatformDispatcher (size_t threads=1) noexcept
 Construct a platform dispatcher. More...
 
 PlatformDispatcher (const char *name, size_t threads=1) noexcept
 Construct a platform dispatcher with a C-string name. More...
 
 PlatformDispatcher (const std::string &name, size_t threads=1) noexcept
 Construct a platform dispatcher with a C-string name. More...
 
 PlatformDispatcher (const std::string_view &name, size_t threads=1) noexcept
 Construct a platform dispatcher with a std::string_views name. More...
 
auto getBoundDispatch () noexcept
 Get std::bind object corresponding dispatch(const&) function. More...
 
auto getBoundMoveDispatch () noexcept
 Get std::bind object corresponding dispatch(&&) function. More...
 
void dispatch (const TFunc &op) noexcept
 Dispatch an operation. More...
 
void dispatch (TFunc &&op) noexcept
 Dispatch an operation. More...
 

Protected Attributes

TDispatchQueue dispatch_queue_
 

Private Types

using TFunc = typename TDispatchQueue::DispatchFunc_t
 

Member Typedef Documentation

◆ TFunc

template<class TDispatchQueue>
using embvm::PlatformDispatcher< TDispatchQueue >::TFunc = typename TDispatchQueue::DispatchFunc_t
private

Constructor & Destructor Documentation

◆ PlatformDispatcher() [1/4]

template<class TDispatchQueue>
embvm::PlatformDispatcher< TDispatchQueue >::PlatformDispatcher ( size_t  threads = 1)
inlineexplicitnoexcept

Construct a platform dispatcher.

Parameters
threadsThe number of threads the dispatch queue will use.

◆ PlatformDispatcher() [2/4]

template<class TDispatchQueue>
embvm::PlatformDispatcher< TDispatchQueue >::PlatformDispatcher ( const char *  name,
size_t  threads = 1 
)
inlineexplicitnoexcept

Construct a platform dispatcher with a C-string name.

Parameters
nameThe name for the dispatch queue.
threadsThe number of threads the dispatch queue will use.

◆ PlatformDispatcher() [3/4]

template<class TDispatchQueue>
embvm::PlatformDispatcher< TDispatchQueue >::PlatformDispatcher ( const std::string &  name,
size_t  threads = 1 
)
inlineexplicitnoexcept

Construct a platform dispatcher with a C-string name.

Parameters
nameThe name for the dispatch queue.
threadsThe number of threads the dispatch queue will use

◆ PlatformDispatcher() [4/4]

template<class TDispatchQueue>
embvm::PlatformDispatcher< TDispatchQueue >::PlatformDispatcher ( const std::string_view &  name,
size_t  threads = 1 
)
inlineexplicitnoexcept

Construct a platform dispatcher with a std::string_views name.

Parameters
nameThe name for the dispatch queue.
threadsThe number of threads the dispatch queue will use

Member Function Documentation

◆ dispatch() [1/2]

template<class TDispatchQueue>
void embvm::PlatformDispatcher< TDispatchQueue >::dispatch ( const TFunc op)
inlinenoexcept

Dispatch an operation.

Dispatch an operation to the queue. Forwards the function object to the underlying dispatch queue.

Parameters
opThe function object containing the operation that will be dispatched to the queue.

◆ dispatch() [2/2]

template<class TDispatchQueue>
void embvm::PlatformDispatcher< TDispatchQueue >::dispatch ( TFunc &&  op)
inlinenoexcept

Dispatch an operation.

Dispatch an operation to the queue. Forwards the function object to the underlying dispatch queue.

Parameters
opThe function object containing the operation that will be dispatched to the queue.

◆ getBoundDispatch()

template<class TDispatchQueue>
auto embvm::PlatformDispatcher< TDispatchQueue >::getBoundDispatch ( )
inlinenoexcept

Get std::bind object corresponding dispatch(const&) function.

If you need to get the function dispatch(const&) variant for use with another class, (e.g., passing dispatch() as a callback), use this function.

Returns
A std::bind object corresponding to the dispatch(const&) function.

◆ getBoundMoveDispatch()

template<class TDispatchQueue>
auto embvm::PlatformDispatcher< TDispatchQueue >::getBoundMoveDispatch ( )
inlinenoexcept

Get std::bind object corresponding dispatch(&&) function.

If you need to get the function dispatch(&&) variant for use with another class, (e.g., passing dispatch() as a callback), use this function.

Returns
A std::bind object corresponding to the dispatch(&&) function.

Member Data Documentation

◆ dispatch_queue_

◆ embvm::PlatformEventManagement

class embvm::PlatformEventManagement

template<class TEventCenter>
class embvm::PlatformEventManagement< TEventCenter >

Add an event manager to the VirtualPlatform through inheritance.

Your platform can inherit from this class to add event APIs a the platform level This template is specialized based on the class of EventCenter you want to create

Example declaration:

public PlatformEventManagement<PlatformEventCenter>`
Template Parameters
TEventCenterThe class of EventCenter you want to use with the Platform Event Manager.
Inheritance diagram for embvm::PlatformEventManagement< TEventCenter >:
Inheritance graph

Public Member Functions

auto subscribeToEvent (event_sig_t sig, const event_cb_t &cb) noexcept
 Subscribe to an event. More...
 
auto subscribeToEvent (event_sig_t sig, event_cb_t &&cb) noexcept
 
void unsubscribeFromEvent (typename TEventCenter::EventHandle &handle) noexcept
 Unsubscribe from an event. More...
 
void signal (event_sig_t sig) noexcept
 Forwards a signal to the event manager. More...
 
void publishEvent (EventBase event) noexcept
 Forwards an event to the event manager. More...
 

Protected Attributes

TEventCenter event_manager_
 The instance of the event manager that belongs to the platform. More...
 

Private Types

using event_sig_t = typename TEventCenter::sig_t
 Convenience alias for the signal type. More...
 
using event_cb_t = typename TEventCenter::cb_t
 Convenience alias for the callback type. More...
 

Member Typedef Documentation

◆ event_cb_t

template<class TEventCenter>
using embvm::PlatformEventManagement< TEventCenter >::event_cb_t = typename TEventCenter::cb_t
private

Convenience alias for the callback type.

◆ event_sig_t

template<class TEventCenter>
using embvm::PlatformEventManagement< TEventCenter >::event_sig_t = typename TEventCenter::sig_t
private

Convenience alias for the signal type.

Member Function Documentation

◆ publishEvent()

template<class TEventCenter>
void embvm::PlatformEventManagement< TEventCenter >::publishEvent ( EventBase  event)
inlinenoexcept

Forwards an event to the event manager.

Parameters
eventThe event to publish to the platform event manager.

◆ signal()

template<class TEventCenter>
void embvm::PlatformEventManagement< TEventCenter >::signal ( event_sig_t  sig)
inlinenoexcept

Forwards a signal to the event manager.

Parameters
sigThe signal to raise to the platform event manager.

◆ subscribeToEvent() [1/2]

template<class TEventCenter>
auto embvm::PlatformEventManagement< TEventCenter >::subscribeToEvent ( event_sig_t  sig,
const event_cb_t cb 
)
inlinenoexcept

Subscribe to an event.

Parameters
sigThe signal to subscribe to.
cbThe callback function to invoke when the signal is raised.
Returns
A handle to the event subscription. The handle must remain within scope for the subscription to be valid. Whent he handle leaves scope, the

◆ subscribeToEvent() [2/2]

template<class TEventCenter>
auto embvm::PlatformEventManagement< TEventCenter >::subscribeToEvent ( event_sig_t  sig,
event_cb_t &&  cb 
)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ unsubscribeFromEvent()

template<class TEventCenter>
void embvm::PlatformEventManagement< TEventCenter >::unsubscribeFromEvent ( typename TEventCenter::EventHandle &  handle)
inlinenoexcept

Unsubscribe from an event.

Parameters
handleThe event handle to unsubscribe.

Member Data Documentation

◆ event_manager_

Typedef Documentation

◆ DynamicEventCenter

using embvm::DynamicEventCenter = typedef EventCenter<0, 0>

Declare an EventCenter that uses dynamic memory allocation.

A EventCenter utilizes dynamic memory allocation and can grow to the limit that memory allows. This type is useful for host-based simulation platforms, as well as embedded platforms which allow dynamic memory allocation.

◆ Signal_t

using embvm::Signal_t = typedef uint32_t

Signal type which is used for function inputs.

This type is preferred because users are able to define their own signal types.

◆ StaticEventCenter

template<const size_t TMaxEvents = 16, const size_t TMaxSubscribersPerEvent = 4>
using embvm::StaticEventCenter = typedef EventCenter<TMaxEvents, TMaxSubscribersPerEvent>

Declare a DriverRegistry that uses static memory allocation.

The size and memory allocation of the StaticDriverRegistry is known at compile-time. No dynamic memory allocations are used.

Template Parameters
TMaxEventsThe maximum number of events to store in the queue. 0 indicates dynamic memory allocation will be used; all other numbers use static memory.
TMaxSubscribersPerEventThe maximum number of subscribers that can register for each event. 0 indicates dynamic memory allocation will be used; all other numbers use static memory.

◆ StaticEventQueue

template<const size_t TSize, const size_t TThreadCnt = 1, typename TFunc = stdext::inplace_function<void(), EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE>>
using embvm::StaticEventQueue = typedef embutil::StaticDispatchQueue<TSize, TThreadCnt, TFunc>

This alias represents a static dispatch queue which can be used with the event manager Primarily this alias is used to prevent users from needing to declare a long type declaration just because of the need to increase inplace_function<>'s size.

Template Parameters
TSizethe maximum number of entries in the dispatch queue
TThreadCntthe number of threads to use in the dispatch queue
TFuncthe function object that will be stored in the queue

Enumeration Type Documentation

◆ Signal

Default framework event signal definitions.

These default signals carry no data.

To add your own event types, create an enum in your project code and use Event_EXTENSION_START as the first value.

Enumerator
Event_Invalid 
Event_ProcessorInitd 
Event_HwPlatformInitd 
Event_PlatformInitd 
Event_EXTENSION_START 

Variable Documentation

◆ EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE

constexpr size_t embvm::EVENT_CENTER_REQD_STATIC_FUNCTION_SIZE = (sizeof(void*) * 8)
static

Maximum size of the Event center callback functor object.