Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::RegistryFrontend Class Reference

This is the front-end for the registry to store and load the configuration. Its methods are type unsafe since the type is determined by the entry setted. It does check the data types but its job is mainly the one of get and set for the given ConfigurationId, the value of the entry. It also exposes methods for go into a "safe" state during armed state / flight. Finally there are methods to visit the entire configuration (forEach). More...

#include <RegistryFrontend.h>

Public Types

using EntryFunc = std::function<void(ConfigurationId, EntryStructsUnion&)>
 

Public Member Functions

 RegistryFrontend (std::unique_ptr< RegistryBackend > backend=std::make_unique< DummyBackend >())
 Registry front end constructor. Initializes the configuration of the underlying objects and reserves 1KB for the vectors and map data structures.
 
RegistryError start ()
 Start function to start frontend and other objects, such as ActiveObjects, needed to write to backend, and the backend itself.
 
void arm ()
 Disables the memory registry set and allocations. To be use when the rocket itself is armed and during flight.
 
void disarm ()
 Enable set methods and memory allocations.
 
void forEach (const EntryFunc &predicate)
 Executes immediately the predicate for each to the configuration applying the callback with the id and EntryStructsUnion union as parameter for each configured entry in the configuration.
 
bool isEntryConfigured (const ConfigurationId configurationIndex)
 Verify if there is an existing entry given its enum entry.
 
bool isEmpty ()
 Verify that the configuration is empty or exists some setted entries.
 
template<typename T >
RegistryError getUnsafe (const ConfigurationId configurationIndex, T &outValue)
 Gets the value for a given configuration entry.
 
template<typename T >
getOrSetDefaultUnsafe (const ConfigurationId configurationIndex, T defaultValue)
 Gets the value for a specified configuration entry. Otherwise returns default and try to set the default value.
 
template<typename T >
RegistryError setUnsafe (ConfigurationId configurationIndex, T value)
 Sets the value for the configuration entry with the specified enum.
 
RegistryError load ()
 Loads from the backend the configuration.
 
RegistryError save ()
 Saves the configuration to the backend.
 
void clear ()
 Clear the configuration actually saved, resetting to empty configuration.
 

Detailed Description

This is the front-end for the registry to store and load the configuration. Its methods are type unsafe since the type is determined by the entry setted. It does check the data types but its job is mainly the one of get and set for the given ConfigurationId, the value of the entry. It also exposes methods for go into a "safe" state during armed state / flight. Finally there are methods to visit the entire configuration (forEach).

Definition at line 48 of file RegistryFrontend.h.

Member Typedef Documentation

◆ EntryFunc

Definition at line 51 of file RegistryFrontend.h.

Constructor & Destructor Documentation

◆ RegistryFrontend()

Boardcore::RegistryFrontend::RegistryFrontend ( std::unique_ptr< RegistryBackend > backend = std::make_unique<DummyBackend>())

Registry front end constructor. Initializes the configuration of the underlying objects and reserves 1KB for the vectors and map data structures.

Definition at line 27 of file RegistryFrontend.cpp.

Member Function Documentation

◆ arm()

void Boardcore::RegistryFrontend::arm ( )

Disables the memory registry set and allocations. To be use when the rocket itself is armed and during flight.

Definition at line 44 of file RegistryFrontend.cpp.

◆ clear()

void Boardcore::RegistryFrontend::clear ( )

Clear the configuration actually saved, resetting to empty configuration.

Note
Does affect the underlying backend.
Attention
It does not directly delete the backend saved copy, save should be used to trigger such action

Definition at line 108 of file RegistryFrontend.cpp.

◆ disarm()

void Boardcore::RegistryFrontend::disarm ( )

Enable set methods and memory allocations.

Note
To be used when the rocket is NOT in an "armed" state and while on ground.

Definition at line 50 of file RegistryFrontend.cpp.

◆ forEach()

void Boardcore::RegistryFrontend::forEach ( const EntryFunc & predicate)

Executes immediately the predicate for each to the configuration applying the callback with the id and EntryStructsUnion union as parameter for each configured entry in the configuration.

Parameters
predicateThe predicate function to execute for each configuration entry

Definition at line 56 of file RegistryFrontend.cpp.

◆ getOrSetDefaultUnsafe()

template<typename T >
T Boardcore::RegistryFrontend::getOrSetDefaultUnsafe ( const ConfigurationId configurationIndex,
T defaultValue )
inline

Gets the value for a specified configuration entry. Otherwise returns default and try to set the default value.

Template Parameters
TThe value data type to be returned and eventually set.
Parameters
configurationIndexIdentifies the configuration entry with its enumeration value
defaultValueThe default value to be returned and set (eventually) in case of non-existing configuration entry
Returns
The value saved for the configuration entry in the configuration or the default value if there is no such entry in the configuration

Definition at line 155 of file RegistryFrontend.h.

◆ getUnsafe()

template<typename T >
RegistryError Boardcore::RegistryFrontend::getUnsafe ( const ConfigurationId configurationIndex,
T & outValue )
inline

Gets the value for a given configuration entry.

Note
It does change the given variable with the correct value if existing
Template Parameters
TThe value data type for such configuration entry
Parameters
configurationIndexIdentifies the configuration entry with its enumeration value
outValuethe specified configuration entry value
Returns
OK in case of successful insertion.
ENTRY_NOT_FOUND In case the entry is not found in the configuration
INCORRECT_TYPE If the setted data type not corresponds with the given value data type

Checks that the value type corresponds to the set type and finds the entry

Definition at line 127 of file RegistryFrontend.h.

◆ isEmpty()

bool Boardcore::RegistryFrontend::isEmpty ( )

Verify that the configuration is empty or exists some setted entries.

Returns
True if the configuration has no entries. False otherwise

Definition at line 84 of file RegistryFrontend.cpp.

◆ isEntryConfigured()

bool Boardcore::RegistryFrontend::isEntryConfigured ( const ConfigurationId configurationIndex)

Verify if there is an existing entry given its enum entry.

Parameters
configurationIndexThe configuration entry ID for which we verify the entry is configured.
Returns
True if such configuration entry exists in the configuration otherwise False.

Definition at line 76 of file RegistryFrontend.cpp.

◆ load()

RegistryError Boardcore::RegistryFrontend::load ( )

Loads from the backend the configuration.

Note
The operation overrides configurations but maintains the ones that are not present in the backend configuration
Returns
OK if the configuration exists in memory and is not corrupted
MALFORMED_SERIALIZED_VECTOR if the vector has a bad format (see serializer)
CHECKSUM_FAIL In case the saved Checksum is incorrect (see serializer)
NO_SUCH_TYPE In case there are unspecified type ids (see serializer)
WRONG_ENDIANESS In case the endianess of serialization not corresponds (see serializer)

Definition at line 63 of file RegistryFrontend.cpp.

◆ save()

RegistryError Boardcore::RegistryFrontend::save ( )

Saves the configuration to the backend.

Attention
: The save will be inhibited in case of "armed" state in order to avoid unwanted allocations to the serializationVector during flight.
Returns
OK if could save correctly
MALFORMED_SERIALIZED_DATA if the vector not have the appropriate length (see serializer)
CHECKSUM_FAIL In case the saved Checksum not corresponds (see serializer)
NO_SUCH_TYPE In case there are unspecified type ids (see serializer)

Definition at line 90 of file RegistryFrontend.cpp.

◆ setUnsafe()

template<typename T >
RegistryError Boardcore::RegistryFrontend::setUnsafe ( ConfigurationId configurationIndex,
T value )
inline

Sets the value for the configuration entry with the specified enum.

Note
The set applies only to frontend, the change does not apply to backend, save should be triggered manually to do so
Template Parameters
TThe configuration value datatype
Parameters
configurationIndexThe ID of the configuration entry to set
valueThe value to be set for the specified configuration entry
Returns
OK if it was possible to set the configurationEntry.
ARMED If the registry is in an armed state, therefore setting a configuration is forbidden

Definition at line 185 of file RegistryFrontend.h.

◆ start()

RegistryError Boardcore::RegistryFrontend::start ( )

Start function to start frontend and other objects, such as ActiveObjects, needed to write to backend, and the backend itself.

Definition at line 35 of file RegistryFrontend.cpp.


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