FossilOrigin-Name: e68d9b046b5b19112b8c37d63642202ba74c57d927cb4519d0da57e0b0e11698bsdmakefiles
parent
d316d956f8
commit
d1363a2e14
@ -0,0 +1,53 @@ |
||||
|
||||
|
||||
#include "cw.h" |
||||
|
||||
|
||||
static const cw_KTVEnum_t * get_enum(const cw_KTVEnum_t * e, int val){ |
||||
int i; |
||||
for (i=0; e[i].type != NULL; i++ ){ |
||||
if (e[i].value==val){ |
||||
return &(e[i]); |
||||
} |
||||
} |
||||
return NULL; |
||||
} |
||||
|
||||
int cw_in_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params, |
||||
uint8_t * elem_data, int elem_len) |
||||
{ |
||||
int val; |
||||
int l,f; |
||||
const cw_KTVEnum_t * e; |
||||
const cw_KTVIndexed_t * ie; |
||||
|
||||
char key[CW_KTV_MAX_KEY_LEN]; |
||||
struct cw_ElemHandler thandler; |
||||
|
||||
ie = handler->type; |
||||
|
||||
val = cw_get_byte(elem_data+ie->idxpos); |
||||
e = get_enum(ie->type,val); |
||||
|
||||
f=0; |
||||
if (ie->idxpos==0){ |
||||
l=1; |
||||
f=1; |
||||
} |
||||
if (ie->idxpos==elem_len-1){ |
||||
l=1; |
||||
} |
||||
|
||||
if (e!=NULL){ |
||||
sprintf(key,"%s/%s",handler->key,e->name); |
||||
} |
||||
else{ |
||||
sprintf(key,"%s/%u",handler->key,val); |
||||
} |
||||
|
||||
|
||||
thandler.type=e->type; |
||||
thandler.key=key; |
||||
return e->fun_in(&thandler,params,elem_data+f,elem_len-l); |
||||
|
||||
} |
@ -0,0 +1,54 @@ |
||||
#include "cw.h" |
||||
|
||||
int cw_out_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params |
||||
, uint8_t * dst) |
||||
{ |
||||
char key[CW_KTV_MAX_KEY_LEN]; |
||||
int i; |
||||
cw_KTV_t * result; |
||||
int len,start; |
||||
uint8_t * ob; |
||||
const cw_KTVIndexed_t *ie; |
||||
cw_KTVEnum_t * e; |
||||
struct cw_ElemHandler thandler; |
||||
|
||||
ie = handler->type; |
||||
|
||||
|
||||
i = 0; |
||||
ob = dst; |
||||
|
||||
e = ie->type; |
||||
|
||||
for(i=0; e[i].name!=NULL; i++) { |
||||
sprintf(key,"%s/%s",handler->key,e[i].name); |
||||
result = cw_ktv_base_exists(params->conn->local_cfg,key); |
||||
if (result==NULL) |
||||
continue; |
||||
start = params->conn->header_len(handler); |
||||
len = 0; |
||||
if (ie->idxpos==0) |
||||
len = 1; |
||||
|
||||
if (e[i].fun_out==NULL) |
||||
len += result->type->put(result,ob+start+len); |
||||
else |
||||
len += cw_ktv_write_struct(params->conn->local_cfg,e[i].type,key,ob+start+len); |
||||
|
||||
/* thandler.type=e[i].type;
|
||||
thandler.key=key; |
||||
len += e->fun_out(&thandler,params,ob+start+len); |
||||
*/ |
||||
cw_set_byte(ob+start+ie->idxpos,e[i].value); |
||||
if (ie->idxpos==len) |
||||
len++; |
||||
|
||||
ob += params->conn->write_header(handler,ob,len); |
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
return ob-dst; |
||||
|
||||
} |
Loading…
Reference in new issue