COSA
An Object-Oriented Platform for Arduino Programming
Registry Class Reference

#include <Registry.hh>

Collaboration diagram for Registry:
Collaboration graph

Classes

class  Action
 
struct  action_t
 
struct  blob_t
 
struct  item_list_t
 
struct  item_t
 
class  Iterator
 

Public Types

enum  type_t {
  ITEM = 0, ITEM_LIST = 1, ACTION = 2, BLOB = 3,
  APPL = 4
}
 
enum  storage_t { IN_PROGMEM = 0, IN_SRAM = 1, IN_EEMEM = 2 }
 
typedef const item_titem_P
 
typedef const item_Pitem_vec_P
 
typedef const item_list_titem_list_P
 
typedef const action_taction_P
 
typedef const blob_tblob_P
 

Public Member Functions

int get_value (blob_P blob, void *buf, size_t len)
 
template<class T >
bool get_value (blob_P blob, T *value)
 
int set_value (blob_P blob, const void *buf, size_t len)
 
template<class T >
bool set_value (blob_P blob, const T *value)
 
 Registry (item_list_P root, EEPROM::Device *eeprom=NULL)
 
item_P lookup (const uint8_t *path=NULL, size_t count=0)
 
void print (IOStream &outs, const uint8_t *path, size_t count)
 
int apply (const uint8_t *path, size_t count, void *buf, size_t len)
 

Static Public Member Functions

static type_t get_type (item_P item)
 
static str_P get_name (item_P item)
 
static storage_t get_storage (item_P item)
 
static bool is_readonly (item_P item)
 
static item_list_P to_list (item_P item)
 
static int get_length (item_list_P list)
 
static action_P to_action (item_P item)
 
static int run (action_P action, void *buf, size_t size)
 
static blob_P to_blob (item_P item)
 

Static Public Attributes

static const uint8_t STORAGE_MASK = 0x7f
 
static const uint8_t READONLY = 0x80
 
static const size_t PATH_MAX = 8
 

Detailed Description

Cosa Configuration Registry. Allow path (x0.x1..xn) access to registry items. Supports actions and binary objects in tree structure. The binary object is a mapping from program memory to data stored in SRAM, PROGMEM or EEMEM. The low level access is type-less. Applications may add run-time data-types by extending the item type system. Any type tag larger than BLOB may be used.

Definition at line 36 of file Registry.hh.

Member Typedef Documentation

typedef const action_t* Registry::action_P

Pointer to action item in program memory.

Definition at line 226 of file Registry.hh.

typedef const blob_t* Registry::blob_P

Pointer to blob registry item in program memory.

Definition at line 264 of file Registry.hh.

Pointer to item list in program memory.

Definition at line 133 of file Registry.hh.

typedef const item_t* Registry::item_P

Pointer to item in program memory.

Definition at line 74 of file Registry.hh.

typedef const item_P* Registry::item_vec_P

Pointer to vector of item pointers in program memory.

Definition at line 77 of file Registry.hh.

Member Enumeration Documentation

Storage type tags.

Enumerator
IN_PROGMEM 

In program memory.

IN_SRAM 

In data memory.

IN_EEMEM 

In eeprom.

Definition at line 52 of file Registry.hh.

Registry item type tags.

Enumerator
ITEM 

Item descriptor.

ITEM_LIST 

List of items.

ACTION 

Action function.

BLOB 

General binary object.

APPL 

Application binary object.

Definition at line 41 of file Registry.hh.

Constructor & Destructor Documentation

Registry::Registry ( item_list_P  root,
EEPROM::Device eeprom = NULL 
)
inline

Construct registery root object.

Parameters
[in]rootitem list.
[in]eepromdevice driver (default internal EEPROM).

Definition at line 340 of file Registry.hh.

Member Function Documentation

int Registry::apply ( const uint8_t *  path,
size_t  count,
void *  buf,
size_t  len 
)
inline

Lookup registry item for given path and if the item is an action call the run() member function with the given argument block. Return error code(-1) if the path is not valid otherwise return value from run().

Parameters
[in]pathregistry index sequence.
[in]countnumber of bytes in path.
[in,out]bufpointer to argument/result block.
[in]lenof argument block.
Returns
negative error code or return value from action.

Definition at line 367 of file Registry.hh.

static int Registry::get_length ( item_list_P  list)
inlinestatic

Return number of items in item vector or negative error code.

Parameters
[in]listpointer to item list in program memory.
Returns
number of items.

Definition at line 153 of file Registry.hh.

static str_P Registry::get_name ( item_P  item)
inlinestatic

Return pointer to name string given pointer to item in program memory.

Parameters
[in]itempointer to item in program memory.
Returns
pointer to string in program memory.

Definition at line 95 of file Registry.hh.

static storage_t Registry::get_storage ( item_P  item)
inlinestatic

Return item storage type given pointer to item in program memory.

Parameters
[in]itempointer to item in program memory.
Returns
storage type.

Definition at line 106 of file Registry.hh.

static type_t Registry::get_type ( item_P  item)
inlinestatic

Return item type given pointer to item in program memory.

Parameters
[in]itempointer to item in program memory.
Returns
item type.

Definition at line 84 of file Registry.hh.

int Registry::get_value ( blob_P  blob,
void *  buf,
size_t  len 
)

Copy blob value into given buffer with given maximum size (len). Return number of bytes copied into buffer or negative error code (EINVAL if illegal parameter, ENOBUFS if the buffer is too small for the stored data, ENXIO if storage is not recognized).

Parameters
[in]blobpointer to blob in program memory.
[out]bufpointer to buffer for value.
[in]lennumber of bytes maximum in buffer.
Returns
number of bytes or negative error code.

Definition at line 97 of file Registry.cpp.

template<class T >
bool Registry::get_value ( blob_P  blob,
T *  value 
)
inline

Template function to copy blob value into given value storage of given type. Returns true(1) if successful otherwise false(0).

Parameters
[in]Ttype of variable to copy.
[in]blobpointer to blob in program memory.
[out]valuebuffer.
Returns
boolean.

Definition at line 299 of file Registry.hh.

static bool Registry::is_readonly ( item_P  item)
inlinestatic

Return true if the item storage is readonly otherwise false.

Parameters
[in]itempointer to item in program memory.
Returns
bool.

Definition at line 117 of file Registry.hh.

Registry::item_P Registry::lookup ( const uint8_t *  path = NULL,
size_t  count = 0 
)

Lookup registry item for given path. Returns pointer to item if found otherwise NULL. Default parameters will give root item.

Parameters
[in]pathregistry index sequence (Default NULL).
[in]countnumber of bytes in path (Default 0).
Returns
item pointer or NULL.

Definition at line 24 of file Registry.cpp.

void Registry::print ( IOStream outs,
const uint8_t *  path,
size_t  count 
)

Definition at line 54 of file Registry.cpp.

int Registry::run ( action_P  action,
void *  buf,
size_t  size 
)
static

Run the action item with the given argument block and given number of bytes. Return number of bytes in buffer (return value) or negative error code (EINVAL if illegal parameter, ENXIO if no object defined).

Parameters
[in]actionitem.
[in,out]bufargument/result buffer.
[in]sizenumber of bytes argument.
Returns
number of bytes result or negative error code.

Definition at line 82 of file Registry.cpp.

int Registry::set_value ( blob_P  blob,
const void *  buf,
size_t  len 
)

Copy value in given buffer of given maximum size (len) to blob. Return number of bytes copied from buffer or negative error code (EINVAL if illegal parameter, EACCES if the blob is readonly, ENOBUFS if the buffer is too small for the stored data, ENXIO if storage is not recognized). The storage type must be SRAM or EEMEM.

Parameters
[in]blobpointer to blob in program memory.
[in]bufpointer to buffer with new value.
[in]lennumber of bytes maximum in buffer.
Returns
number of bytes or negative error code.

Definition at line 124 of file Registry.cpp.

template<class T >
bool Registry::set_value ( blob_P  blob,
const T *  value 
)
inline

Template function to copy given value of given type to blob. Return true(1) if successful otherwise false(0). The storage type must be SRAM or EEMEM.

Parameters
[in]Tvalue type.
[in]blobpointer to blob in program memory.
[in]valuevalue to set.
Returns
boolean.

Definition at line 327 of file Registry.hh.

static action_P Registry::to_action ( item_P  item)
inlinestatic

Type check given item pointer and convert to an action pointer. Returns a pointer to action item in program memory if successful otherwise NULL. This function provides run-time type checking.

Parameters
[in]itempointer to item in program memory.
Returns
pointer to action in program memory.

Definition at line 235 of file Registry.hh.

static blob_P Registry::to_blob ( item_P  item)
inlinestatic

Type check given item pointer and convert to a blob pointer. Returns pointer to blob registry item in program memory if successful otherwise NULL. This function provides run-time type checking.

Parameters
[in]itempointer to item in program memory.
Returns
pointer to blob in program memory.

Definition at line 274 of file Registry.hh.

static item_list_P Registry::to_list ( item_P  item)
inlinestatic

Type check given item pointer and convert it to an item list. Return pointer to item list in program memory if successful otherwise NULL. This function provides run-time type checking.

Parameters
[in]itempointer to item in program memory.
Returns
pointer to item list in program memory.

Definition at line 142 of file Registry.hh.

Member Data Documentation

const size_t Registry::PATH_MAX = 8
static

Max length of a path.

Definition at line 333 of file Registry.hh.

const uint8_t Registry::READONLY = 0x80
static

Mask readonly bit of item attributes.

Definition at line 62 of file Registry.hh.

const uint8_t Registry::STORAGE_MASK = 0x7f
static

Mask storage bits of item attributes.

Definition at line 59 of file Registry.hh.


The documentation for this class was generated from the following files: