Embedded Artistry Framework
Embedded Systems C++ Framework
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Types | Private Attributes | List of all members
UnitTestPlatform Class Reference

This platform exists for use in the framework unit tests. More...

#include <platform.hpp>

Inheritance diagram for UnitTestPlatform:
Inheritance graph

Public Member Functions

 UnitTestPlatform () noexcept
 Default constructor with a supplied platform name. More...
 
 UnitTestPlatform (const char *name) noexcept
 Specify unit test platform by const char* to test the platform base APIs. More...
 
 UnitTestPlatform (const std::string &name) noexcept
 Specify unit test platform by std::string to test the platform base APIs. More...
 
 UnitTestPlatform (const std::string_view &name) noexcept
 Specify unit test platform by std::string_view to test the platform base APIs. More...
 
 ~UnitTestPlatform ()=default
 
void init_ () noexcept
 
void initProcessor_ () noexcept
 
void initHWPlatform_ () noexcept
 
auto hwPlatformName () noexcept
 
auto hwPlatformName_cstr () noexcept
 
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...
 
auto findDriver () noexcept
 Access a device driver in the registry by type, cast as the appropriate base class. More...
 
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...
 
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...
 
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...
 
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 PlatformEventCenter ::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...
 

Static Public Member Functions

static void earlyInitHook_ () noexcept
 
static UnitTestPlatforminst () 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 Attributes

const std::string_view name_
 
PlatformDispatchQueue dispatch_queue_
 
PlatformEventCenter event_manager_
 The instance of the event manager that belongs to the platform. More...
 

Private Types

using VirtualPlatform = embvm::VirtualPlatformBase< UnitTestPlatform, PlatformDriverRegistry >
 

Private Attributes

UnitTestHWPlatform hw_platform_
 

Detailed Description

This platform exists for use in the framework unit tests.

Member Typedef Documentation

◆ VirtualPlatform

Constructor & Destructor Documentation

◆ UnitTestPlatform() [1/4]

UnitTestPlatform::UnitTestPlatform ( )
inlinenoexcept

Default constructor with a supplied platform name.

◆ UnitTestPlatform() [2/4]

UnitTestPlatform::UnitTestPlatform ( const char *  name)
inlineexplicitnoexcept

Specify unit test platform by const char* to test the platform base APIs.

◆ UnitTestPlatform() [3/4]

UnitTestPlatform::UnitTestPlatform ( const std::string &  name)
inlineexplicitnoexcept

Specify unit test platform by std::string to test the platform base APIs.

◆ UnitTestPlatform() [4/4]

UnitTestPlatform::UnitTestPlatform ( const std::string_view &  name)
inlineexplicitnoexcept

Specify unit test platform by std::string_view to test the platform base APIs.

◆ ~UnitTestPlatform()

UnitTestPlatform::~UnitTestPlatform ( )
default

Member Function Documentation

◆ dispatch() [1/2]

void embvm::PlatformDispatcher< PlatformDispatchQueue >::dispatch ( const TFunc op)
inlinenoexceptinherited

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]

void embvm::PlatformDispatcher< PlatformDispatchQueue >::dispatch ( TFunc &&  op)
inlinenoexceptinherited

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.

◆ driverCount()

size_t embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::driverCount ( ) const
inlinenoexceptinherited

Get the count of drivers registered with the platform.

returns Number of drivers currently registered with the platform DriverRegistry.

◆ earlyInitHook()

static void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::earlyInitHook ( )
inlinestaticnoexceptinherited

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.

◆ earlyInitHook_()

static void UnitTestPlatform::earlyInitHook_ ( )
inlinestaticnoexcept

◆ findAllDrivers() [1/2]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findAllDrivers ( embvm::DriverType_t  type)
inlinenoexceptinherited

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]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findAllDrivers ( )
inlinenoexceptinherited

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]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findDriver ( const std::string_view &  name)
inlinenoexceptinherited

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]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findDriver ( embvm::DriverType_t  type)
inlinenoexceptinherited

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]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findDriver ( )
inlinenoexceptinherited

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]

auto embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::findDriver ( const std::string_view &  name)
inlinenoexceptinherited

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.

◆ getBoundDispatch()

auto embvm::PlatformDispatcher< PlatformDispatchQueue >::getBoundDispatch ( )
inlinenoexceptinherited

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()

auto embvm::PlatformDispatcher< PlatformDispatchQueue >::getBoundMoveDispatch ( )
inlinenoexceptinherited

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.

◆ hwPlatformName()

auto UnitTestPlatform::hwPlatformName ( )
inlinenoexcept

◆ hwPlatformName_cstr()

auto UnitTestPlatform::hwPlatformName_cstr ( )
inlinenoexcept

◆ init()

void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::init ( )
inlinenoexceptinherited

Initialize the platform.

This function is responsible for initializing the platform.

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

◆ init_()

void UnitTestPlatform::init_ ( )
inlinenoexcept

◆ initHWPlatform()

void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::initHWPlatform ( )
inlinenoexceptinherited

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.

◆ initHWPlatform_()

void UnitTestPlatform::initHWPlatform_ ( )
inlinenoexcept

◆ initOS() [1/2]

static void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::initOS ( )
inlinestaticnoexceptinherited

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]

static void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::initOS ( void(*)()  main_thread)
inlinestaticnoexceptinherited

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()

void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::initProcessor ( )
inlinenoexceptinherited

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.

◆ initProcessor_()

void UnitTestPlatform::initProcessor_ ( )
inlinenoexcept

◆ inst()

static UnitTestPlatform & embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::inst ( )
inlinestaticnoexceptinherited

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()

constexpr const std::string_view& embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::name ( ) const
inlinenoexceptinherited

Access the platform's name.

Returns
Platform name std::string_view reference.

◆ name_cstr()

constexpr const char* embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::name_cstr ( ) const
inlinenoexceptinherited

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

Returns
Platform name as a C-string.

◆ publishEvent()

void embvm::PlatformEventManagement< PlatformEventCenter >::publishEvent ( EventBase  event)
inlinenoexceptinherited

Forwards an event to the event manager.

Parameters
eventThe event to publish to the platform event manager.

◆ registerDriver()

static void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::registerDriver ( const std::string_view &  name,
embvm::DriverBase driver 
)
inlinestaticnoexceptinherited

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.

◆ signal()

void embvm::PlatformEventManagement< PlatformEventCenter >::signal ( event_sig_t  sig)
inlinenoexceptinherited

Forwards a signal to the event manager.

Parameters
sigThe signal to raise to the platform event manager.

◆ subscribeToEvent() [1/2]

auto embvm::PlatformEventManagement< PlatformEventCenter >::subscribeToEvent ( event_sig_t  sig,
const event_cb_t cb 
)
inlinenoexceptinherited

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]

auto embvm::PlatformEventManagement< PlatformEventCenter >::subscribeToEvent ( event_sig_t  sig,
event_cb_t &&  cb 
)
inlinenoexceptinherited

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

◆ unregisterDriver()

static void embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::unregisterDriver ( const std::string_view &  name,
embvm::DriverBase driver 
)
inlinestaticnoexceptinherited

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.

◆ unsubscribeFromEvent()

void embvm::PlatformEventManagement< PlatformEventCenter >::unsubscribeFromEvent ( typename PlatformEventCenter ::EventHandle &  handle)
inlinenoexceptinherited

Unsubscribe from an event.

Parameters
handleThe event handle to unsubscribe.

Member Data Documentation

◆ dispatch_queue_

◆ event_manager_

The instance of the event manager that belongs to the platform.

◆ hw_platform_

UnitTestHWPlatform UnitTestPlatform::hw_platform_
private

◆ name_

const std::string_view embvm::VirtualPlatformBase< UnitTestPlatform , PlatformDriverRegistry >::name_
protectedinherited

The documentation for this class was generated from the following file: