Soletta™ Framework
|
Memory mapped persistence storage (like NVRAM or EEPROM) API on Soletta. More...
Data Structures | |
struct | sol_memmap_entry |
A memory map entry. More... | |
struct | sol_memmap_map |
Memory map basic struct. More... | |
Macros | |
#define | CREATE_BLOB(_val) |
Macro to create a struct sol_blob with value passed as argument. More... | |
#define | CREATE_BUFFER(_val) |
Macro to create a struct sol_buffer with value passed as argument and flags SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED and SOL_BUFFER_FLAGS_NO_NUL_BYTE. More... | |
#define | SOL_MEMMAP_BOOL_ENTRY(_name, _offset, _bit_offset) SOL_MEMMAP_ENTRY_BIT_SIZE(_name, _offset, 1, _bit_offset, 1) |
Macro to declare a sol_memmap_entry variable for boolean. More... | |
#define | SOL_MEMMAP_ENTRY(_name, _offset, _size) SOL_MEMMAP_ENTRY_BIT_SIZE(_name, _offset, _size, 0, 0) |
Macro to declare a sol_memmap_entry variable without bit_offset and bit_size. More... | |
#define | SOL_MEMMAP_ENTRY_BIT_SIZE(_name, _offset, _size, _bit_offset, _bit_size) static struct sol_memmap_entry _name = { .offset = (_offset), .size = (_size), .bit_size = (_bit_size), .bit_offset = (_bit_offset) } |
Macro to declare a sol_memmap_entry variable setting fields with values passed by argument. More... | |
#define | SOL_MEMMAP_VERSION_ENTRY "_version" |
Name of property which contains stored map version. More... | |
Typedefs | |
typedef struct sol_memmap_entry | sol_memmap_entry |
A memory map entry. More... | |
typedef struct sol_memmap_map | sol_memmap_map |
Memory map basic struct. More... | |
Functions | |
int | sol_memmap_add_map (const struct sol_memmap_map *map) |
Add a map to internal list of available maps. More... | |
uint32_t | sol_memmap_get_timeout (const struct sol_memmap_map *map) |
Get map timeout. More... | |
static int | sol_memmap_read_bool (const char *name, bool *value) |
Reads a boolean contents. More... | |
static int | sol_memmap_read_double (const char *name, double *value) |
Reads a double contents. More... | |
static int | sol_memmap_read_drange (const char *name, struct sol_drange *value) |
Reads a drange contents. More... | |
static int | sol_memmap_read_int32 (const char *name, int32_t *value) |
Reads an int32_t contents. More... | |
static int | sol_memmap_read_irange (const char *name, struct sol_irange *value) |
Reads an irange content. More... | |
int | sol_memmap_read_raw (const char *name, struct sol_buffer *buffer) |
Read storage contents to buffer. More... | |
static int | sol_memmap_read_string (const char *name, char **value) |
Reads a string contents. More... | |
static int | sol_memmap_read_uint8 (const char *name, uint8_t *value) |
Read an uint8_t contents. More... | |
int | sol_memmap_remove_map (const struct sol_memmap_map *map) |
Removes a previously added map from internal list of available maps. More... | |
int | sol_memmap_set_timeout (struct sol_memmap_map *map, uint32_t timeout) |
Defines map timeout to actually perform write. More... | |
static int | sol_memmap_write_bool (const char *name, bool value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes a bool contents to storage. More... | |
static int | sol_memmap_write_double (const char *name, double value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes a double contents to storage. More... | |
static int | sol_memmap_write_drange (const char *name, struct sol_drange *value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes an drange contents to storage. More... | |
static int | sol_memmap_write_int32 (const char *name, int32_t value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes an int32_t contents to storage. More... | |
static int | sol_memmap_write_irange (const char *name, struct sol_irange *value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes an irange contents to storage. More... | |
int | sol_memmap_write_raw (const char *name, struct sol_blob *blob, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes buffer contents to storage. More... | |
static int | sol_memmap_write_string (const char *name, const char *value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes a string contents to storage. More... | |
static int | sol_memmap_write_uint8 (const char *name, uint8_t value, void(*cb)(void *data, const char *name, struct sol_blob *blob, int status), const void *data) |
Writes an uint8_t contents to storage. More... | |
Memory mapped persistence storage (like NVRAM or EEPROM) API on Soletta.
A map must be provided, either directly via sol_memmap_add_map() or by informing a JSON file to Soletta runner or generator. This map needs to contain a property _version
(SOL_MEMMAP_VERSION_ENTRY
), which will store version of map stored. This API will refuse to work if stored map is different from map version. Note that _version
field is a uint8_t
and that versions should start on 1, so Soletta will know if dealing with a totally new storage. It also considers 255 (0xff) as a non-value, so fit new EEPROMs. Note that a map may define a timeout value to perform writes. This way, writings can be grouped together, as all writing operations will be performed at timeout end. That said, it's important to note that when writing is performed, no order is guaranteed for different keys, i.e., writing to 'a' and 'b' can be performed, at timeout end, as 'b' and 'a'
#define CREATE_BLOB | ( | _val | ) |
Macro to create a struct sol_blob with value passed as argument.
Referenced by sol_memmap_write_bool(), sol_memmap_write_double(), sol_memmap_write_drange(), sol_memmap_write_int32(), sol_memmap_write_irange(), and sol_memmap_write_uint8().
#define CREATE_BUFFER | ( | _val | ) |
Macro to create a struct sol_buffer with value passed as argument and flags SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED and SOL_BUFFER_FLAGS_NO_NUL_BYTE.
Referenced by sol_memmap_read_bool(), sol_memmap_read_double(), sol_memmap_read_drange(), sol_memmap_read_int32(), sol_memmap_read_irange(), and sol_memmap_read_uint8().
#define SOL_MEMMAP_BOOL_ENTRY | ( | _name, | |
_offset, | |||
_bit_offset | |||
) | SOL_MEMMAP_ENTRY_BIT_SIZE(_name, _offset, 1, _bit_offset, 1) |
Macro to declare a sol_memmap_entry variable for boolean.
So size and bit_size are set to 1
.
#define SOL_MEMMAP_ENTRY | ( | _name, | |
_offset, | |||
_size | |||
) | SOL_MEMMAP_ENTRY_BIT_SIZE(_name, _offset, _size, 0, 0) |
Macro to declare a sol_memmap_entry variable without bit_offset and bit_size.
#define SOL_MEMMAP_ENTRY_BIT_SIZE | ( | _name, | |
_offset, | |||
_size, | |||
_bit_offset, | |||
_bit_size | |||
) | static struct sol_memmap_entry _name = { .offset = (_offset), .size = (_size), .bit_size = (_bit_size), .bit_offset = (_bit_offset) } |
Macro to declare a sol_memmap_entry variable setting fields with values passed by argument.
#define SOL_MEMMAP_VERSION_ENTRY "_version" |
Name of property which contains stored map version.
typedef struct sol_memmap_entry sol_memmap_entry |
A memory map entry.
typedef struct sol_memmap_map sol_memmap_map |
Memory map basic struct.
This struct holds informations about a memory map.
int sol_memmap_add_map | ( | const struct sol_memmap_map * | map | ) |
Add a map to internal list of available maps.
As Soletta will keep a reference to this map, it should be kept alive during memmap usage.
map | map to be add. |
0
on success, a negative number on failure. uint32_t sol_memmap_get_timeout | ( | const struct sol_memmap_map * | map | ) |
Get map timeout.
map | map to get its timeout |
|
inlinestatic |
Reads a boolean contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
|
inlinestatic |
Reads a double contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
|
inlinestatic |
Reads a drange contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
|
inlinestatic |
Reads an int32_t contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
|
inlinestatic |
Reads an irange content.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
int sol_memmap_read_raw | ( | const char * | name, |
struct sol_buffer * | buffer | ||
) |
Read storage contents to buffer.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
buffer | buffer where result will be read into, according to its entry on map. |
return 0
on success, a negative number on failure
Referenced by sol_memmap_read_bool(), sol_memmap_read_double(), sol_memmap_read_drange(), sol_memmap_read_int32(), sol_memmap_read_irange(), sol_memmap_read_string(), and sol_memmap_read_uint8().
|
inlinestatic |
Reads a string contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References sol_buffer_fini(), SOL_BUFFER_INIT_EMPTY, sol_buffer_steal(), and sol_memmap_read_raw().
|
inlinestatic |
Read an uint8_t contents.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | where result will be read into, according to its entry |
return 0
on success, a negative number on failure
References CREATE_BUFFER, and sol_memmap_read_raw().
int sol_memmap_remove_map | ( | const struct sol_memmap_map * | map | ) |
Removes a previously added map from internal list of available maps.
map | map to be removed. |
0
on success, a negative number on failure. int sol_memmap_set_timeout | ( | struct sol_memmap_map * | map, |
uint32_t | timeout | ||
) |
Defines map timeout to actually perform write.
map | map to have its timeout changed |
timeout | new timeout, in milliseconds. |
0
on success, a negative number on failure.
|
inlinestatic |
Writes a bool contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().
|
inlinestatic |
Writes a double contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().
|
inlinestatic |
Writes an drange contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().
|
inlinestatic |
Writes an int32_t contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().
|
inlinestatic |
Writes an irange contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().
int sol_memmap_write_raw | ( | const char * | name, |
struct sol_blob * | blob, | ||
void(*)(void *data, const char *name, struct sol_blob *blob, int status) | cb, | ||
const void * | data | ||
) |
Writes buffer contents to storage.
Note that as writing operations are asynchronous, to check if it completely succeeded, one needs to register a callback that will inform writing result. A negative status on callback means failure; -ECANCELED for instance, means that another write to the same property took place before this one was completed.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
blob | blob that will be written, according to its entry on map. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
Referenced by sol_memmap_write_bool(), sol_memmap_write_double(), sol_memmap_write_drange(), sol_memmap_write_int32(), sol_memmap_write_irange(), sol_memmap_write_string(), and sol_memmap_write_uint8().
|
inlinestatic |
Writes a string contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References sol_blob_new(), SOL_BLOB_TYPE_DEFAULT, sol_blob_unref(), sol_memmap_write_raw(), SOL_NULL_CHECK, and SOL_NULL_CHECK_GOTO.
|
inlinestatic |
Writes an uint8_t contents to storage.
This funcion uses the function sol_memmap_write_raw() internally, so the same behaviour must be considered.
name | name of property. must be present in one of maps previoulsy added via sol_memmap_add_map() (if present in more than one, behaviour is undefined) |
value | the variable containing the value to be written. |
cb | callback to be called when writing finishes. It contains status of writing: if failed, is lesser than zero. |
data | user data to be sent to callback cb |
return 0
on success, a negative number on failure
References CREATE_BLOB, sol_blob_unref(), and sol_memmap_write_raw().