Unify Framework Lib 1.6.0
attribute_store_helper.c File Reference
#include "attribute_store_helper.h"
#include "attribute_store_type_registration.h"
#include "sl_log.h"
#include <stdbool.h>
#include <float.h>
#include <math.h>
#include <string.h>

Functions

bool attribute_store_is_value_defined (attribute_store_node_t node, attribute_store_node_value_state_t value_state)
 Indicate whether a value is defined in the attribute store. More...
 
bool attribute_store_is_reported_defined (attribute_store_node_t node)
 Indicate whether the reported value of a node is defined in the attribute store. More...
 
bool attribute_store_is_desired_defined (attribute_store_node_t node)
 Indicate whether the desired value of a node is defined in the attribute store. More...
 
bool attribute_store_is_value_matched (attribute_store_node_t node)
 Indicate whether reported and desired values are matched in the attribute store. More...
 
sl_status_t attribute_store_set_desired_as_reported (attribute_store_node_t node)
 Set the Desired value to the same as the Reported value. More...
 
sl_status_t attribute_store_set_reported_as_desired (attribute_store_node_t node)
 Set the Reported value to the same as the Desired value. More...
 
void attribute_store_undefine_reported (attribute_store_node_t node)
 Set the Reported value to "undefined" (0 size no value) More...
 
sl_status_t attribute_store_set_reported (attribute_store_node_t node, const void *value, uint8_t value_size)
 Set the Reported value of an Attribute Store node. More...
 
sl_status_t attribute_store_get_reported (attribute_store_node_t node, void *value, size_t expected_size)
 Reads the reported value of an attribute store node. More...
 
static uint8_t sanitize_string_to_local_buffer (const char *string)
 Sanitizes a char* pointer and copies a C string into the static received_value. More...
 
sl_status_t attribute_store_set_reported_string (attribute_store_node_t node, const char *string)
 Safely copies a String in the Attribute Store. More...
 
sl_status_t attribute_store_set_desired_string (attribute_store_node_t node, const char *string)
 Safely copies a String in the Attribute Store. More...
 
sl_status_t attribute_store_concatenate_to_reported_string (attribute_store_node_t node, const char *string)
 Safely concatenate a string to a String attribute in the Attribute Store. More...
 
sl_status_t attribute_store_append_to_reported (attribute_store_node_t node, const uint8_t *array, uint8_t extra_array_length)
 Safely append a new byte array to a byte array attribute in the Attribute Store. More...
 
static sl_status_t attribute_store_get_string (attribute_store_node_t node, char *string, size_t maximum_size, attribute_store_node_value_state_t value_state)
 Helper function that fetches the Reported or Desired value of a string. More...
 
sl_status_t attribute_store_get_reported_string (attribute_store_node_t node, char *string, size_t maximum_size)
 Safely retrieves a String from the Attribute Store. More...
 
sl_status_t attribute_store_get_desired_string (attribute_store_node_t node, char *string, size_t maximum_size)
 Safely retrieves a String from the Attribute Store. More...
 
sl_status_t attribute_store_get_desired_else_reported_string (attribute_store_node_t node, char *string, size_t maximum_size)
 Safely retrieves a String from the Attribute Store. More...
 
void attribute_store_undefine_desired (attribute_store_node_t node)
 Set the Desired value to "undefined" (0 size no value) More...
 
sl_status_t attribute_store_set_desired (attribute_store_node_t node, const void *value, uint8_t value_size)
 Set the Desired value of an Attribute Store node. More...
 
sl_status_t attribute_store_get_desired (attribute_store_node_t node, void *value, size_t expected_size)
 Reads the desired value of an attribute store node. More...
 
sl_status_t attribute_store_get_desired_else_reported (attribute_store_node_t node, void *value, size_t expected_size)
 Reads the desired value of an attribute store node, or the reported if desired is undefined. More...
 
sl_status_t attribute_store_copy_value (attribute_store_node_t source_node, attribute_store_node_t destination_node, attribute_store_node_value_state_t value_state)
 Copy the value from a node to another. More...
 
sl_status_t attribute_store_read_value (attribute_store_node_t node, attribute_store_node_value_state_t value_state, void *read_value, size_t expected_size)
 Read an arbitrary sized value from the attribute store and writes it to a pointer. More...
 
sl_status_t attribute_store_set_child_reported (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Adds if missing and sets the value of the first child of a node with a given type. and writes its reported value. More...
 
sl_status_t attribute_store_set_all_children_reported (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Sets the value of the all children of a node with a given type. and writes their reported value. More...
 
sl_status_t attribute_store_set_child_desired (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Adds if missing and sets the value of the first child of a node with a given type. and writes its desired value. More...
 
sl_status_t attribute_store_get_child_reported (attribute_store_node_t parent, attribute_store_type_t type, void *value, size_t expected_size)
 Finds the reported value of the first child of a node with a given type. More...
 
sl_status_t attribute_store_set_child_reported_only_if_missing (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Adds and sets the reported value of the first child of a node with a given type only if it did not exist. More...
 
sl_status_t attribute_store_set_child_reported_only_if_exists (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Sets the value of the child node, only if the child node already exists in the Attribute Store. More...
 
sl_status_t attribute_store_set_child_reported_only_if_undefined (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Finds the first child of a node and and sets the reported value only if it undefined. More...
 
sl_status_t attribute_store_set_child_desired_only_if_exists (attribute_store_node_t parent, attribute_store_type_t type, const void *value, uint8_t value_size)
 Sets the value of the child node, only if the child node already exists in the Attribute Store. More...
 
void attribute_store_walk_tree (attribute_store_node_t top, void(*function)(attribute_store_node_t))
 Visit all nodes in the tree. More...
 
void attribute_store_walk_tree_with_return_value (attribute_store_node_t top, sl_status_t(*function)(attribute_store_node_t))
 Visit all nodes in the tree, applying a function. More...
 
void attribute_store_add_if_missing (attribute_store_node_t parent_node, const attribute_store_type_t attributes[], uint32_t count)
 Add multiple nodes to a parent if they are not already present. More...
 
sl_status_t attribute_store_register_callback_by_type_to_array (attribute_store_node_changed_callback_t callback_function, const attribute_store_type_t types[], uint32_t types_count)
 Loop helper that register the same callback function for many attribute types. More...
 
sl_status_t attribute_store_delete_all_children (attribute_store_node_t node)
 Removes all children of an attribute store node. More...
 
sl_status_t attribute_store_set_number (attribute_store_node_t node, number_t value, attribute_store_node_value_state_t value_state)
 Helper function that sets the Reported or Desired value of a number. More...
 
sl_status_t attribute_store_set_reported_number (attribute_store_node_t node, number_t value)
 Sets a numerical value for an Attribute Store node. More...
 
sl_status_t attribute_store_set_desired_number (attribute_store_node_t node, number_t value)
 Sets a numerical value for an Attribute Store node. More...
 
number_t attribute_store_get_number (attribute_store_node_t node, attribute_store_node_value_state_t value_state)
 Helper function that sets the Reported or Desired value of a number. More...
 
number_t attribute_store_get_reported_number (attribute_store_node_t node)
 Gets a numerical value from an Attribute Store node. More...
 
number_t attribute_store_get_desired_number (attribute_store_node_t node)
 Gets a numerical value from an Attribute Store node. More...
 
attribute_store_node_t attribute_store_emplace (attribute_store_node_t parent_node, attribute_store_type_t type, const void *value, uint8_t value_size)
 Adds a child with a given reported value under a parent node, if it does not already exist. More...
 
attribute_store_node_t attribute_store_emplace_desired (attribute_store_node_t parent_node, attribute_store_type_t type, const void *value, uint8_t value_size)
 Adds a child with a given desired value under a parent node, if it does not already exist. More...
 
attribute_store_node_t attribute_store_create_child_if_missing (attribute_store_node_t node, attribute_store_type_t type)
 Finds and returns the first child with a type under a node, creates it if missing. More...
 
uint8_t attribute_store_get_reported_size (attribute_store_node_t node)
 Returns the size of the reported value of a node. More...
 
uint8_t attribute_store_get_desired_size (attribute_store_node_t node)
 Returns the size of the desired value of a node. More...
 
uint8_t attribute_store_get_desired_else_reported_size (attribute_store_node_t node)
 Returns the size of the desired value of a node, and if 0, returns the size of the reported value instead. More...
 

Variables

static uint8_t received_value [ATTRIBUTE_STORE_MAXIMUM_VALUE_LENGTH]
 
static uint8_t received_value_size = 0
 

Function Documentation

◆ attribute_store_get_string()

static sl_status_t attribute_store_get_string ( attribute_store_node_t  node,
char *  string,
size_t  maximum_size,
attribute_store_node_value_state_t  value_state 
)
static

Helper function that fetches the Reported or Desired value of a string.

Note: Does not work with the DESIRED_OR_REPORTED attribute value type.

Parameters
nodeAttribute Store node to read the value from
stringPointer where to store the read value
maximum_sizeMaximum capacity of the pointer.
value_stateAttribute value state, reported or desired.
Returns
sl_status_t

◆ sanitize_string_to_local_buffer()

static uint8_t sanitize_string_to_local_buffer ( const char *  string)
static

Sanitizes a char* pointer and copies a C string into the static received_value.

Parameters
stringC string to be sanitized and copied into the received_value buffer.
Returns
The length of the string stored in received_value

Variable Documentation

◆ received_value

uint8_t received_value[ATTRIBUTE_STORE_MAXIMUM_VALUE_LENGTH]
static

◆ received_value_size

uint8_t received_value_size = 0
static