Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Keeps track of the behaviours that are active on this crownstone. More...
#include <cs_BehaviourStore.h>
Public Member Functions | |
BehaviourStore (BehaviourStore &other)=delete | |
BehaviourStore (BehaviourStore &&other)=delete | |
BehaviourStore ()=default | |
virtual void | handleEvent (event_t &evt) |
handles events concerning updates of the active behaviours on this crownstone. More... | |
std::array< Behaviour *, MaxBehaviours > & | getActiveBehaviours () |
cs_ret_code_t | init () override |
Initialize store from flash. More... | |
virtual | ~BehaviourStore () |
ErrorCodesGeneral | addBehaviour (Behaviour *behaviour) |
Add behaviour to the ActiveBehaviours if there is space. More... | |
ErrorCodesGeneral | replaceBehaviour (uint8_t index, Behaviour *behaviour) |
Add behaviour to the ActiveBehaviours if there is space. More... | |
Behaviour * | getBehaviour (uint8_t index) |
uint8_t | findEmptyIndex () |
returns MaxBehaviours if not found. More... | |
![]() | |
EventListener () | |
virtual | ~EventListener () |
unregisters the listener. More... | |
virtual void | handleEvent (event_t &event)=0 |
Handle events. More... | |
void | listen () |
Registers this with the EventDispatcher. More... | |
![]() | |
template<class T > | |
T * | getComponent (Component *requester=nullptr) |
Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More... | |
virtual cs_ret_code_t | init () |
Components can implement this if they need to get references to sibling or if they need to do specific initialization. More... | |
void | parentAllChildren () |
utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More... | |
virtual | ~Component ()=default |
Static Public Attributes | |
static constexpr size_t | MaxBehaviours = 50 |
Private Member Functions | |
ErrorCodesGeneral | addBehaviour (uint8_t *buf, cs_buffer_size_t bufSize, uint8_t &index) |
Add behaviour to a new index. More... | |
ErrorCodesGeneral | removeBehaviour (uint8_t index) |
Remove the behaviour at [index]. More... | |
void | clearActiveBehavioursArray () |
Clear all behaviours - usefull for a clean start of the test suite. More... | |
uint32_t | calculateMasterHash () |
Calculate the hash over all behaviours. More... | |
void | storeMasterHash () |
Calculate master hash and store it in State. More... | |
BehaviourMutation | handleSaveBehaviour (event_t &evt) |
Deserializes the behaviour from event data, and allocate new instance of correct type on the heap. More... | |
BehaviourMutation | handleReplaceBehaviour (event_t &evt) |
Deserializes the behaviour from event data, and allocate new instance of correct type on the heap. More... | |
BehaviourMutation | handleRemoveBehaviour (event_t &evt) |
void | handleGetBehaviour (event_t &evt) |
void | handleGetBehaviourIndices (event_t &evt) |
void | storeUpdate (uint8_t index, SwitchBehaviour::Type type, uint8_t *buf, cs_buffer_size_t bufSize) |
call state store for the given switch type and update masterhash. More... | |
void | storeUpdate (uint8_t index, Behaviour *behaviour) |
call state store for the given behaviour and update masterhash. More... | |
Behaviour * | allocateBehaviour (uint8_t index, SwitchBehaviour::Type type, uint8_t *buf, cs_buffer_size_t bufSize) |
Heap allocate an instance of given type from the buffer. More... | |
void | assignBehaviour (uint8_t index, Behaviour *behaviour) |
Assign it to activateBehaviour[index] and print it. More... | |
ErrorCodesGeneral | checkSizeAndType (SwitchBehaviour::Type type, cs_buffer_size_t bufSize) |
If type is not a valid behaviour type: ERR_WRONG_PARAMETER If bufSize does not match expected size: ERR_WRONG_PAYLOAD_LENGTH Else: ERR_SUCCESS. More... | |
size_t | getBehaviourSize (SwitchBehaviour::Type type) |
returns 0 for unknown types, else the obvious. More... | |
void | dispatchBehaviourMutationEvent (BehaviourMutation mutation) |
ErrorCodesGeneral | replaceParameterValidation (event_t &evt, uint8_t index, SwitchBehaviour::Type type) |
template<class BehaviourType > | |
void | LoadBehavioursFromMemory (CS_TYPE BehaviourCsType) |
Private Attributes | |
std::array< Behaviour *, MaxBehaviours > | activeBehaviours = {} |
Friends | |
class | TestAccess< BehaviourStore > |
Additional Inherited Members | |
![]() | |
virtual std::vector< Component * > | getChildren () |
Components with children can override this method to return them. More... | |
cs_ret_code_t | initChildren () |
void | setParent (Component *p) |
Children that are instantiated later can also be added individually. More... | |
Keeps track of the behaviours that are active on this crownstone.
|
delete |
|
delete |
|
default |
|
virtual |
ErrorCodesGeneral BehaviourStore::addBehaviour | ( | Behaviour * | behaviour | ) |
Add behaviour to the ActiveBehaviours if there is space.
If null, nothing happens.
The object pointed to by behaviour
must to be allocated on the heap. Its lifetime will be managed by BehaviourStore and will be destroyed and deleted if/when necessary, for example when replaceBehaviour is called.
|
private |
Add behaviour to a new index.
Does not check if similar behaviour already exists.
[in] | buf | Buffer with the behaviour. |
[in] | bufSize | Size of the buffer. |
[out] | index | Index at which the behaviour was added, only set on success. |
|
private |
Heap allocate an instance of given type from the buffer.
Notes:
|
private |
Assign it to activateBehaviour[index] and print it.
|
private |
Calculate the hash over all behaviours.
|
private |
If type
is not a valid behaviour type: ERR_WRONG_PARAMETER If bufSize
does not match expected size: ERR_WRONG_PAYLOAD_LENGTH Else: ERR_SUCCESS.
|
private |
Clear all behaviours - usefull for a clean start of the test suite.
Does not edit the persisted values, so expect discrepancies with flash until all behaviours in flash are overwritten.
|
private |
uint8_t BehaviourStore::findEmptyIndex | ( | ) |
returns MaxBehaviours if not found.
|
inline |
Behaviour * BehaviourStore::getBehaviour | ( | uint8_t | index | ) |
|
private |
returns 0 for unknown types, else the obvious.
|
virtual |
handles events concerning updates of the active behaviours on this crownstone.
Implements EventListener.
|
private |
|
private |
|
private |
|
private |
Deserializes the behaviour from event data, and allocate new instance of correct type on the heap.
Does not check for prior existence.
|
private |
Deserializes the behaviour from event data, and allocate new instance of correct type on the heap.
Checks if an identical behaviour already exists. (I.e. serialized equality.)
|
overridevirtual |
Initialize store from flash.
Reimplemented from Component.
|
private |
|
private |
Remove the behaviour at [index].
If [index] is out of bounds, or no behaviour exists at [index], false is returned. Else, true.
ErrorCodesGeneral BehaviourStore::replaceBehaviour | ( | uint8_t | index, |
Behaviour * | behaviour | ||
) |
Add behaviour to the ActiveBehaviours if there is space.
If null, previous behaviour will be deleted. This method takes ownership over the allocated resource (removeBehaviour may delete it.)
|
private |
|
private |
Calculate master hash and store it in State.
|
private |
call state store for the given behaviour and update masterhash.
|
private |
call state store for the given switch type and update masterhash.
|
friend |
|
private |
|
staticconstexpr |