Zigbee Protocol Controller 1.6.0
datastore.c File Reference
#include "datastore.h"
#include "datastore_internals.h"
#include "sl_log.h"
#include "sl_status.h"
#include <sqlite3.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>

Macros

#define LOG_TAG   "datastore"
 

Enumerations

enum  datastore_value_type_t { DATASTORE_VALUE_TYPE_INT , DATASTORE_VALUE_TYPE_BLOB }
 

Functions

sl_status_t datastore_table_init ()
 Generic datastore table initialization. More...
 
static sl_status_t datastore_fetch_internal (const datastore_key_t key, void *value, unsigned int *size, datastore_value_type_t value_type)
 Fetch from the datastore. More...
 
static sl_status_t datastore_store_internal (const datastore_key_t key, const void *value, unsigned int size, datastore_value_type_t value_type)
 Internal function to handle storing to the datastore. More...
 
static bool datastore_contains_internal (const char *table, const datastore_key_t key)
 Test if a table contains a key. More...
 
sl_status_t datastore_start_transaction ()
 start a datastore transaction More...
 
sl_status_t datastore_commit_transaction ()
 commit an open transaction More...
 
sl_status_t datastore_store_int (const datastore_key_t key, int64_t value)
 Store integer in the persistent datastore. More...
 
sl_status_t datastore_fetch_int (const datastore_key_t key, int64_t *value)
 Fetch integer from the persistent datastore. More...
 
sl_status_t datastore_store_arr (const datastore_key_t key, const uint8_t *value, unsigned int size)
 Store array in the persistent datastore. More...
 
sl_status_t datastore_fetch_arr (const datastore_key_t key, uint8_t *value, unsigned int *size)
 Fetch array from the persistent datastore. More...
 
bool datastore_contains_int (const datastore_key_t key)
 Check if the datastore contains an int value for given key. More...
 
bool datastore_contains_arr (const datastore_key_t key)
 Check if the datastore contains an array value for given key. More...
 
bool datastore_is_initialized ()
 Checks if the datastore is initialized and can be used. More...
 

Variables

static bool ongoing_transaction = false
 

Macro Definition Documentation

◆ LOG_TAG

#define LOG_TAG   "datastore"

Enumeration Type Documentation

◆ datastore_value_type_t

Enumerator
DATASTORE_VALUE_TYPE_INT 
DATASTORE_VALUE_TYPE_BLOB 

Function Documentation

◆ datastore_contains_internal()

static bool datastore_contains_internal ( const char *  table,
const datastore_key_t  key 
)
static

Test if a table contains a key.

Parameters
tableTable to look in
keyKey to look for
Returns
true key is found
false key is not found

◆ datastore_fetch_internal()

static sl_status_t datastore_fetch_internal ( const datastore_key_t  key,
void *  value,
unsigned int *  size,
datastore_value_type_t  value_type 
)
static

Fetch from the datastore.

Parameters
keyKey to fetch data for
valuePointer to where to store data
sizeIf value_type is DATASTORE_VALUE_TYPE_INT this is ignored If value_type is DATASTORE_VALUE_TYPE_BLOB In: the size of value, Out: Number of bytes written to value
value_typetype of data to fetch
Returns
sl_status_t SL_STATUS_OK success, SL_STATUS_NOT_FOUND key is not found, SL_STATUS_WOULD_OVERFLOW data is larger than size (only for blob) SL_STATUS_FAIL other failure,

◆ datastore_store_internal()

static sl_status_t datastore_store_internal ( const datastore_key_t  key,
const void *  value,
unsigned int  size,
datastore_value_type_t  value_type 
)
static

Internal function to handle storing to the datastore.

Parameters
keyKey to store data for
valuePointer to data to store
sizeIf value_type is DATASTORE_VALUE_TYPE_INT this is ignored If value_type is DATASTORE_VALUE_TYPE_BLOB, size of value
value_typetype of data to store
Returns
sl_status_t SQLITE_OK on success, SL_STATUS_FAIL on failure

◆ datastore_table_init()

sl_status_t datastore_table_init ( )

Generic datastore table initialization.

Returns
SL_STATUS_OK on success
SL_STATUS_FAIL on failure

Variable Documentation

◆ ongoing_transaction

bool ongoing_transaction = false
static