Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Keeps up the asset filters. More...
#include <cs_AssetFilterStore.h>
Public Member Functions | |
cs_ret_code_t | init () |
set _filterModificationInProgress to false. More... | |
bool | isReady () |
Returns true if this object is ready to be used. More... | |
bool | isInProgress () |
Whether changes are in progress. More... | |
uint8_t | getFilterCount () |
Get the number of filters. More... | |
AssetFilter | getFilter (uint8_t index) |
Get the Nth filter. More... | |
std::optional< uint8_t > | findFilterIndex (uint8_t filterId) |
Returns the index of the filter with given filterId, if any. More... | |
uint16_t | getMasterVersion () |
Get the current master version. More... | |
uint32_t | getMasterCrc () |
Get the current master CRC. More... | |
void | handleEvent (event_t &evt) |
Internal usage. 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 uint8_t | MAX_FILTER_IDS = 8 |
Max number of filters. More... | |
static constexpr size_t | FILTER_BUFFER_SIZE = 520 |
Max total size that the filters take up in RAM. More... | |
static constexpr int | MODIFICATION_IN_PROGRESS_TIMEOUT_SECONDS = 20 |
Time after last edit command (upload, remove), until "modification in progress" times out. More... | |
Private Member Functions | |
uint8_t * | allocateFilter (uint8_t filterId, size_t stateDataSize) |
Allocates RAM for a filter of given size, and adds it to the filters array. More... | |
bool | deallocateFilter (uint8_t filterId) |
Same as deallocateFilterByIndex, but looks up the filter by the filterId. More... | |
void | deallocateFilterByIndex (uint8_t parsingFilterIndex) |
Deallocates the filter at given index in the filters array. More... | |
CS_TYPE | getStateType (uint16_t filterDataSize) |
Get the State type, given the filter data size. More... | |
uint16_t | getStateSize (uint16_t filterDataSize) |
Get the size required for State, given the filter data size. More... | |
CS_TYPE | getNthStateType (uint8_t index) |
Used to loop over all asset filter state types. More... | |
uint8_t * | findFilter (uint8_t filterId) |
Returns a pointer to the filter with given filterId, or nullptr if not found. More... | |
size_t | getTotalHeapAllocatedSize () |
Returns the total amount of heap allocated for the filters. More... | |
cs_ret_code_t | handleUploadFilterCommand (const asset_filter_cmd_upload_filter_t &cmdData) |
Handle an upload command. More... | |
cs_ret_code_t | handleRemoveFilterCommand (const asset_filter_cmd_remove_filter_t &cmdData) |
Removes given filter immediately. More... | |
cs_ret_code_t | handleCommitFilterChangesCommand (const asset_filter_cmd_commit_filter_changes_t &cmdData) |
Commit the filters. More... | |
void | handleGetFilterSummariesCommand (cs_result_t &result) |
Writes the filter summary in the result. More... | |
void | onTick () |
void | startInProgress () |
To be called when about to modify filters. More... | |
void | endInProgress (uint16_t newMasterVersion, uint32_t newMasterCrc) |
To be called when filters are no longer being modified. More... | |
void | inProgressTimeout () |
Called when the modification in progress is timed out. More... | |
void | sendInProgressStatus () |
Send an internal event when isInProgress() may have changed. More... | |
cs_ret_code_t | commit (uint16_t masterVersion, uint32_t masterCrc, bool store) |
Commit current filters. More... | |
uint32_t | computeMasterCrc () |
Calculate the master CRC and return it (not stored). More... | |
bool | validateFilters () |
Checks for all filters if the allocated filter data size is equal to the computed size based on its contents. More... | |
void | computeFilterCrcs () |
Computes the CRC of the filters, and sets it in the filter. More... | |
void | storeFilters () |
Store filters to flash. More... | |
void | loadFromFlash () |
Load filters and version from flash. More... | |
void | loadFromFlash (CS_TYPE type) |
Load filters of a specific type (size) from flash. More... | |
void | markFiltersCommitted () |
Sets flags.committed to true. More... | |
Private Attributes | |
uint8_t * | _filters [MAX_FILTER_IDS] = {} |
List of pointers to the allocated buffers for the filters. More... | |
uint8_t | _filtersCount = 0 |
Number of allocated filters in the filters array. More... | |
uint16_t | _masterVersion = 0 |
Keeps track of the version of the filters. More... | |
uint32_t | _masterCrc |
CRC over all the filter IDs and CRCs. More... | |
uint16_t | _modificationInProgressCountdown = 0 |
When this value is not 0, the filters are being modified. More... | |
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 up the asset filters.
|
private |
Allocates RAM for a filter of given size, and adds it to the filters array.
[in] | filterId | ID of the filter. |
[in] | stateDataSize | Size of the filter data used in State, result of getStateSize(filter data size). |
Returns nullptr on failure, pointer to the buffer on success.
|
private |
Commit current filters.
When all checks pass:
|
private |
Computes the CRC of the filters, and sets it in the filter.
|
private |
Calculate the master CRC and return it (not stored).
Assumes filter CRCs are already calculated.
|
private |
Same as deallocateFilterByIndex, but looks up the filter by the filterId.
Returns true when id is found and filter is deallocated, false else.
|
private |
Deallocates the filter at given index in the filters array.
If a gap is created in the array, this method moves all filters with an index above the given one down one index to close this gap.
|
private |
To be called when filters are no longer being modified.
|
private |
Returns a pointer to the filter with given filterId, or nullptr if not found.
std::optional< uint8_t > AssetFilterStore::findFilterIndex | ( | uint8_t | filterId | ) |
Returns the index of the filter with given filterId, if any.
AssetFilter AssetFilterStore::getFilter | ( | uint8_t | index | ) |
Get the Nth filter.
uint8_t AssetFilterStore::getFilterCount | ( | ) |
Get the number of filters.
uint32_t AssetFilterStore::getMasterCrc | ( | ) |
Get the current master CRC.
uint16_t AssetFilterStore::getMasterVersion | ( | ) |
Get the current master version.
|
private |
Used to loop over all asset filter state types.
Returns CONFIG_DO_NOT_USE for invalid index.
|
private |
Get the size required for State, given the filter data size.
|
private |
Get the State type, given the filter data size.
Returns CONFIG_DO_NOT_USE for invalid size.
|
private |
Returns the total amount of heap allocated for the filters.
|
private |
Commit the filters.
|
virtual |
Internal usage.
Implements EventListener.
|
private |
Writes the filter summary in the result.
|
private |
Removes given filter immediately.
Flags this crownstone as 'filter modification in progress'.
|
private |
Handle an upload command.
Allocates filter if not already done. Removes existing filter if it was committed. TOOD: remove existing filter if total size is different?
|
virtual |
set _filterModificationInProgress to false.
Reimplemented from Component.
|
private |
Called when the modification in progress is timed out.
bool AssetFilterStore::isInProgress | ( | ) |
Whether changes are in progress.
Meaning someone is actively modifying the filters, and a commit is expected to be done soon.
bool AssetFilterStore::isReady | ( | ) |
Returns true if this object is ready to be used.
I.e. the store is not in progress of updates and master version is non-zero.
|
private |
Load filters and version from flash.
|
private |
Load filters of a specific type (size) from flash.
|
private |
Sets flags.committed to true.
|
private |
|
private |
Send an internal event when isInProgress() may have changed.
|
private |
To be called when about to modify filters.
|
private |
Store filters to flash.
|
private |
Checks for all filters if the allocated filter data size is equal to the computed size based on its contents.
|
private |
List of pointers to the allocated buffers for the filters.
The filters in this array are always sorted by filterId. Null pointers will always be at the back of the array, so you can stop iterating when you encounter a null pointer.
To access a filter, construct an accessor object of type TrackingFilter for the given buffer.
|
private |
Number of allocated filters in the filters array.
|
private |
CRC over all the filter IDs and CRCs.
This is updated by the commit command if it matches.
|
private |
Keeps track of the version of the filters.
When this value is 0, the filters are invalid.
|
private |
When this value is not 0, the filters are being modified.
Reduced by 1 every tick.
|
staticconstexpr |
Max total size that the filters take up in RAM.
Set to: TypeSize(CS_TYPE::STATE_ASSET_FILTER_512) + sizeof(asset_filter_runtime_data_t)
|
staticconstexpr |
Max number of filters.
|
staticconstexpr |
Time after last edit command (upload, remove), until "modification in progress" times out.