21 #ifndef COSA_REGISTRY_HH 22 #define COSA_REGISTRY_HH 47 } __attribute__((packed));
56 } __attribute__((packed));
96 __attribute__((always_inline))
98 return ((
str_P) pgm_read_word(&item->name));
107 __attribute__((always_inline))
109 return ((
storage_t) (pgm_read_byte(&item->attr) & STORAGE_MASK));
118 __attribute__((always_inline))
120 return ((pgm_read_byte(&item->attr) & READONLY) != 0);
143 __attribute__((always_inline))
154 __attribute__((always_inline))
157 return ((
int) pgm_read_byte(&list->length));
174 m_vec((item_vec_P) pgm_read_word(&list->list)),
175 m_length((uint8_t) pgm_read_byte(&list->length)),
183 __attribute__((always_inline))
186 return ((item_P) pgm_read_word(&m_vec[m_next++]));
193 __attribute__((always_inline))
214 virtual int run(
void* buf,
size_t size) = 0;
236 __attribute__((always_inline))
251 static int run(action_P action,
void* buf,
size_t size);
289 int get_value(blob_P blob,
void* buf,
size_t len);
301 return (
get_value(blob, value,
sizeof(T)) ==
sizeof(T));
316 int set_value(blob_P blob,
const void* buf,
size_t len);
327 template<
class T>
bool set_value(blob_P blob,
const T* value)
329 return (
set_value(blob, value,
sizeof(T)) ==
sizeof(T));
342 m_eeprom(eeprom ==
NULL ? &
EEPROM::Device::eeprom : eeprom)
352 item_P
lookup(
const uint8_t* path =
NULL,
size_t count = 0);
354 void print(
IOStream& outs,
const uint8_t* path,
size_t count);
367 int apply(
const uint8_t* path,
size_t count,
void* buf,
size_t len)
408 #define REGISTRY_BEGIN(var,name) \ 409 const char var ## _name[] __PROGMEM = name; \ 410 const Registry::item_P var ## _list[] __PROGMEM = { 418 #define REGISTRY_LIST_ITEM(var) &var.item, 419 #define REGISTRY_BLOB_ITEM(var) &var ## _blob.item, 420 #define REGISTRY_ACTION_ITEM(var) &var ## _action.item, 426 #define REGISTRY_END(var) \ 428 const Registry::item_list_t var __PROGMEM = { \ 430 Registry::ITEM_LIST, \ 431 (str_P) var ## _name, \ 432 Registry::IN_PROGMEM | Registry::READONLY \ 434 membersof(var ## _list), \ 443 #define REGISTRY_ACTION(var,name) \ 444 const char var ## _name[] __PROGMEM = name; \ 445 const Registry::action_t var ## _action __PROGMEM = { \ 448 (str_P) var ## _name, \ 449 Registry::IN_SRAM | Registry::READONLY \ 462 #define REGISTRY_BLOB(var,name,mem,readonly) \ 463 const char var ## _blob_name[] __PROGMEM = name; \ 464 const Registry::blob_t var ## _blob __PROGMEM = { \ 467 (str_P) var ## _blob_name, \ 468 Registry::IN_ ## mem | (readonly << 7) \ 483 #define REGISTRY_BLOB_VAR(type,var,name,value,readonly) \ 484 static type var = value; \ 485 REGISTRY_BLOB(var,name,SRAM,readonly) 495 #define REGISTRY_BLOB_STRUCT(type,var,name,readonly) \ 497 REGISTRY_BLOB(var,name,SRAM,readonly) 507 #define REGISTRY_BLOB_PSTR(var,name,value) \ 508 static const char var[] __PROGMEM = value; \ 509 REGISTRY_BLOB(var,name,PROGMEM,true) item_P lookup(const uint8_t *path=NULL, size_t count=0)
type_t type
Item type tag(ITEM).
item_vec_P list
Item vector in program memory.
static blob_P to_blob(item_P item)
const item_P * item_vec_P
size_t size
Size of object.
static const size_t PATH_MAX
bool get_value(blob_P blob, T *value)
static int get_length(item_list_P list)
static item_list_P to_list(item_P item)
static const uint8_t READONLY
item_t item
Item header(ITEM_LIST).
str_P name
Name string in program memory.
item_t item
Item header(>= BLOB).
int apply(const uint8_t *path, size_t count, void *buf, size_t len)
Application binary object.
const item_list_t * item_list_P
int get_value(blob_P blob, void *buf, size_t len)
const class prog_str * str_P
void print(IOStream &outs, const uint8_t *path, size_t count)
Iterator(item_list_P list)
Action * obj
Pointer to action handler instance.
bool set_value(blob_P blob, const T *value)
void * value
Pointer to value.
static type_t get_type(item_P item)
static str_P get_name(item_P item)
IOStream & operator<<(IOStream &outs, Registry::item_P item)
uint8_t length
Item vector length (for boundary checking).
static storage_t get_storage(item_P item)
const action_t * action_P
static int run(action_P action, void *buf, size_t size)
static const uint8_t STORAGE_MASK
Registry(item_list_P root, EEPROM::Device *eeprom=NULL)
static bool is_readonly(item_P item)
static action_P to_action(item_P item)
item_t item
Item header(ACTION).
int set_value(blob_P blob, const void *buf, size_t len)