vars: added more functions.
This commit is contained in:
@@ -31,6 +31,7 @@ GWEN_TREE2_FUNCTIONS(AQH_VARS, AQH_Vars);
|
|||||||
static AQH_VARS *_newData(void);
|
static AQH_VARS *_newData(void);
|
||||||
static void _releaseData(AQH_VARS *vt);
|
static void _releaseData(AQH_VARS *vt);
|
||||||
static AQH_VARS *_newStringElement(char *s, AQH_VARS_DATATYPE dt);
|
static AQH_VARS *_newStringElement(char *s, AQH_VARS_DATATYPE dt);
|
||||||
|
static AQH_VARS *_getValueNodeByIdx(const AQH_VARS *vt, int idx);
|
||||||
static AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags);
|
static AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags);
|
||||||
static void *_pathHandlerFn(const char *entry, void *data, int idx, uint32_t flags);
|
static void *_pathHandlerFn(const char *entry, void *data, int idx, uint32_t flags);
|
||||||
static AQH_VARS *_getNodeByTypeAndName(const AQH_VARS *vt, AQH_VARS_DATATYPE dt, const char *name, int idx);
|
static AQH_VARS *_getNodeByTypeAndName(const AQH_VARS *vt, AQH_VARS_DATATYPE dt, const char *name, int idx);
|
||||||
@@ -290,19 +291,13 @@ const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const
|
|||||||
if (vt && idx>=0) {
|
if (vt && idx>=0) {
|
||||||
AQH_VARS *vtChild;
|
AQH_VARS *vtChild;
|
||||||
AQH_VARS *vtValue;
|
AQH_VARS *vtValue;
|
||||||
int i;
|
|
||||||
|
|
||||||
vtChild=_getPath(vt, path, AQH_PATH_FLAGS_PATHMUSTEXIST | AQH_PATH_FLAGS_VARIABLE);
|
vtChild=_getPath(vt, path, AQH_PATH_FLAGS_PATHMUSTEXIST | AQH_PATH_FLAGS_VARIABLE);
|
||||||
if (vtChild==NULL) {
|
if (vtChild==NULL) {
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "Path for var \"%s\" not found", path);
|
DBG_INFO(AQH_LOGDOMAIN, "Path for var \"%s\" not found", path);
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
vtValue=AQH_Vars_Tree2_GetFirstChild(vtChild);
|
vtValue=_getValueNodeByIdx(vtChild, idx);
|
||||||
i=idx;
|
|
||||||
while(vtValue && i) {
|
|
||||||
i--;
|
|
||||||
vtValue=AQH_Vars_Tree2_GetNext(vtValue);
|
|
||||||
}
|
|
||||||
if (vtValue)
|
if (vtValue)
|
||||||
return AQH_Vars_GetStringData(vtValue, defaultValue);
|
return AQH_Vars_GetStringData(vtValue, defaultValue);
|
||||||
}
|
}
|
||||||
@@ -311,6 +306,106 @@ const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_Vars_SetIntValue(AQH_VARS *vt, uint32_t flags, const char *path, int value)
|
||||||
|
{
|
||||||
|
if (vt) {
|
||||||
|
AQH_VARS *vtChild;
|
||||||
|
AQH_VARS *vtValue;
|
||||||
|
|
||||||
|
vtChild=_getPath(vt, path, flags | AQH_PATH_FLAGS_VARIABLE);
|
||||||
|
if (vtChild==NULL) {
|
||||||
|
DBG_ERROR(AQH_LOGDOMAIN, "Error getting path for var \"%s\"", path);
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
vtValue=AQH_Vars_CreateIntValue(value);
|
||||||
|
AQH_Vars_Tree2_AddChild(vtChild, vtValue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_Vars_GetIntValue(AQH_VARS *vt, const char *path, int idx, int defaultValue)
|
||||||
|
{
|
||||||
|
if (vt && idx>=0) {
|
||||||
|
AQH_VARS *vtChild;
|
||||||
|
AQH_VARS *vtValue;
|
||||||
|
|
||||||
|
vtChild=_getPath(vt, path, AQH_PATH_FLAGS_PATHMUSTEXIST | AQH_PATH_FLAGS_VARIABLE);
|
||||||
|
if (vtChild==NULL) {
|
||||||
|
DBG_INFO(AQH_LOGDOMAIN, "Path for var \"%s\" not found", path);
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
vtValue=_getValueNodeByIdx(vtChild, idx);
|
||||||
|
if (vtValue)
|
||||||
|
return AQH_Vars_GetIntData(vtValue, defaultValue);
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_Vars_SetDoubleValue(AQH_VARS *vt, uint32_t flags, const char *path, double value)
|
||||||
|
{
|
||||||
|
if (vt) {
|
||||||
|
AQH_VARS *vtChild;
|
||||||
|
AQH_VARS *vtValue;
|
||||||
|
|
||||||
|
vtChild=_getPath(vt, path, flags | AQH_PATH_FLAGS_VARIABLE);
|
||||||
|
if (vtChild==NULL) {
|
||||||
|
DBG_ERROR(AQH_LOGDOMAIN, "Error getting path for var \"%s\"", path);
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
vtValue=AQH_Vars_CreateDoubleValue(value);
|
||||||
|
AQH_Vars_Tree2_AddChild(vtChild, vtValue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double AQH_Vars_GetDoubleValue(AQH_VARS *vt, const char *path, int idx, double defaultValue)
|
||||||
|
{
|
||||||
|
if (vt && idx>=0) {
|
||||||
|
AQH_VARS *vtChild;
|
||||||
|
AQH_VARS *vtValue;
|
||||||
|
|
||||||
|
vtChild=_getPath(vt, path, AQH_PATH_FLAGS_PATHMUSTEXIST | AQH_PATH_FLAGS_VARIABLE);
|
||||||
|
if (vtChild==NULL) {
|
||||||
|
DBG_INFO(AQH_LOGDOMAIN, "Path for var \"%s\" not found", path);
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
vtValue=_getValueNodeByIdx(vtChild, idx);
|
||||||
|
if (vtValue)
|
||||||
|
return AQH_Vars_GetDoubleData(vtValue, defaultValue);
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_VARS *_getValueNodeByIdx(const AQH_VARS *vt, int idx)
|
||||||
|
{
|
||||||
|
if (vt && idx>=0) {
|
||||||
|
AQH_VARS *vtValue;
|
||||||
|
|
||||||
|
vtValue=AQH_Vars_Tree2_GetFirstChild(vt);
|
||||||
|
while(vtValue && idx) {
|
||||||
|
idx--;
|
||||||
|
vtValue=AQH_Vars_Tree2_GetNext(vtValue);
|
||||||
|
}
|
||||||
|
return vtValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags)
|
AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags)
|
||||||
{
|
{
|
||||||
return (AQH_VARS *)AQH_Path_Handle(s, (void*) vt, flags, "/", _pathHandlerFn);
|
return (AQH_VARS *)AQH_Path_Handle(s, (void*) vt, flags, "/", _pathHandlerFn);
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
|
|||||||
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value);
|
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value);
|
||||||
const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const char *defaultValue);
|
const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const char *defaultValue);
|
||||||
|
|
||||||
|
int AQH_Vars_SetIntValue(AQH_VARS *vt, uint32_t flags, const char *path, int value);
|
||||||
|
int AQH_Vars_GetIntValue(AQH_VARS *vt, const char *path, int idx, int defaultValue);
|
||||||
|
|
||||||
|
int AQH_Vars_SetDoubleValue(AQH_VARS *vt, uint32_t flags, const char *path, double value);
|
||||||
|
double AQH_Vars_GetDoubleValue(AQH_VARS *vt, const char *path, int idx, double defaultValue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user