- Some fixes to the hipadaba code.

SKIPPED:
	psi/libpsi.a
	psi/hardsup/libhlib.a
	psi/tecs/libtecsl.a
This commit is contained in:
koennecke
2007-02-02 05:48:07 +00:00
parent b335751bde
commit faec15b5f6
4 changed files with 77 additions and 43 deletions

Binary file not shown.

View File

@ -1,3 +1,5 @@
exe batchpath ./
exe syspath ./
# Motor omegam # Motor omegam
omegam sign 1.000000 omegam sign 1.000000
omegam SoftZero 0.000000 omegam SoftZero 0.000000
@ -98,7 +100,7 @@ twothetad ignorefault 0.000000
twothetad AccessCode 2.000000 twothetad AccessCode 2.000000
twothetad movecount 10.000000 twothetad movecount 10.000000
# Counter counter # Counter counter
counter SetPreset 60000000.000000 counter SetPreset 600000000.000000
counter SetMode Monitor counter SetMode Monitor
banana CountMode monitor banana CountMode monitor
banana preset 60000.000000 banana preset 60000.000000
@ -227,5 +229,5 @@ email UNKNOWN
email setAccess 2 email setAccess 2
sample_mur 0.000000 sample_mur 0.000000
sample_mur setAccess 2 sample_mur setAccess 2
exe batchpath ./ lastdatafile UNKNOWN
exe syspath ./ lastdatafile setAccess 2

View File

@ -20,6 +20,8 @@
"event", "event",
"warning", "warning",
"error", "error",
"hdbvalue",
"hdbevent",
NULL }; NULL };
static int iNoCodes = 10; static int iNoCodes = 10;
#endif #endif

View File

@ -29,6 +29,11 @@
/*== there can be only hipadaba in SICS, some globals to care for that == */ /*== there can be only hipadaba in SICS, some globals to care for that == */
static pHdb root = NULL; static pHdb root = NULL;
static pSicsPoll poller = NULL; static pSicsPoll poller = NULL;
typedef enum {
normal_protocol,
json_protocol,
} Protocol;
char *trim(char *str);
/*=============== common callback functions used for SICS ===========================*/ /*=============== common callback functions used for SICS ===========================*/
static int SICSCheckPermissionCallback(void *userData, void *callData, pHdb node, static int SICSCheckPermissionCallback(void *userData, void *callData, pHdb node,
hdbValue v){ hdbValue v){
@ -150,50 +155,70 @@ typedef struct {
commandContext context; commandContext context;
}HdbCBInfo; }HdbCBInfo;
static int isJSON(SConnection *pCon) { static Protocol isJSON(SConnection *pCon) {
char proName[128]; char proName[128];
void *pData; void *pData;
if(SCinMacro(pCon)){ if(SCinMacro(pCon)){
return 0; return normal_protocol;
} }
pData = FindCommandData(pServ->pSics, "protocol","Protocol"); pData = FindCommandData(pServ->pSics, "protocol","Protocol");
ProtocolGet(pCon, pData, proName, 128); ProtocolGet(pCon, pData, proName, 128);
if (strcmp(proName, "json") == 0) if (strcmp(proName, "json") == 0)
return 1; return json_protocol;
else else
return 0; return normal_protocol;
} }
int formatNameValue(int jsonSet, char *name, char *value, pDynString result) { /* Format a name,value pair according to the given protocol */
if (name == NULL) { int formatNameValue(Protocol protocol, char *name, char *value, pDynString result, int hdtype) {
if (jsonSet) { char *char_arr, *ptr;
} else {
} switch(protocol) {
} else if (value == NULL) { case normal_protocol:
if (jsonSet) {
DynStringInsert(result,"\": ", 0);
DynStringInsert(result,name,0);
DynStringInsert(result,"{\"", 0);
DynStringConcat(result,"}");
} else {
DynStringInsert(result," =",0);
DynStringInsert(result,name,0);
}
} else {
if (jsonSet) {
DynStringCopy(result,"{\"");
DynStringConcat(result,name);
DynStringConcat(result,"\": ");
DynStringConcat(result,value);
DynStringConcat(result,"}");
} else {
DynStringCopy(result,name); DynStringCopy(result,name);
DynStringConcat(result," = "); DynStringConcat(result," = ");
DynStringConcat(result,value); DynStringConcat(result,value);
break;
case json_protocol:
switch(hdtype){
case HIPNONE:
break;
case HIPINT:
case HIPFLOAT:
DynStringCopy(result,"{\"");
DynStringConcat(result,name);
DynStringConcat(result,"\": ");
DynStringConcat(result,value);
DynStringConcat(result,"}");
break;
case HIPTEXT:
DynStringCopy(result,"{\"");
DynStringConcat(result,name);
DynStringConcat(result,"\": \"");
DynStringConcat(result,value);
DynStringConcat(result,"\"}");
break;
case HIPINTAR:
case HIPINTVARAR:
case HIPFLOATAR:
case HIPFLOATVARAR:
char_arr = ptr = strdup(trim(value));
while(*ptr != '\0') {
if (isspace(*ptr))
*ptr=',';
ptr++;
}
DynStringCopy(result,"{\"");
DynStringConcat(result,name);
DynStringConcat(result,"\": [ ");
DynStringConcat(result,char_arr);
DynStringConcat(result," ]}");
if (char_arr != NULL ) free(char_arr);
break;
}
} }
} return protocol;
return jsonSet;
} }
/*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/
@ -203,7 +228,8 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
pDynString printedData = NULL; pDynString printedData = NULL;
pDynString result = NULL; pDynString result = NULL;
char *pPath = NULL; char *pPath = NULL;
int protocol = 0, outCode; Protocol protocol = normal_protocol;
int outCode;
cbInfo = (HdbCBInfo *)userData; cbInfo = (HdbCBInfo *)userData;
pPath = GetHipadabaPath(node); pPath = GetHipadabaPath(node);
@ -224,12 +250,12 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
*/ */
return 1; return 1;
} }
formatNameValue(protocol, pPath, GetCharArray(printedData), result); formatNameValue(protocol, pPath, GetCharArray(printedData), result, v.dataType);
SCWriteInContext(cbInfo->pCon,GetCharArray(result), SCWriteInContext(cbInfo->pCon,GetCharArray(result),
outCode,cbInfo->context); outCode,cbInfo->context);
DeleteDynString(printedData); DeleteDynString(printedData);
} else { } else {
formatNameValue(protocol,"!!datachange!!", pPath, result); formatNameValue(protocol, pPath,"!!datachange!!", result, HIPTEXT);
SCWriteInContext(cbInfo->pCon,GetCharArray(result), SCWriteInContext(cbInfo->pCon,GetCharArray(result),
outCode,cbInfo->context); outCode,cbInfo->context);
} }
@ -256,7 +282,8 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node,
char *path = NULL; char *path = NULL;
char buffer[1024]; char buffer[1024];
pDynString result = NULL; pDynString result = NULL;
int protocol = 0, outCode; Protocol protocol = normal_protocol;
int outCode;
result = CreateDynString(128,128); result = CreateDynString(128,128);
HdbCBInfo *cbInfo = (HdbCBInfo *)userData; HdbCBInfo *cbInfo = (HdbCBInfo *)userData;
@ -267,7 +294,7 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node,
outCode = eHdbEvent; outCode = eHdbEvent;
else else
outCode = eEvent; outCode = eEvent;
formatNameValue(protocol, "treechange", path, result); formatNameValue(protocol, "treechange", path, result, v.dataType);
SCWriteInContext(cbInfo->pCon,GetCharArray(result),outCode,cbInfo->context); SCWriteInContext(cbInfo->pCon,GetCharArray(result),outCode,cbInfo->context);
DeleteDynString(result); DeleteDynString(result);
free(path); free(path);
@ -1152,7 +1179,6 @@ void SaveSICSHipadaba(FILE *fd, pHdb node, char *prefix){
currentChild = node->child; currentChild = node->child;
while(currentChild != NULL){ while(currentChild != NULL){
if(currentChild->value.dataType != HIPNONE && !isSICSHdbRO(currentChild)){ if(currentChild->value.dataType != HIPNONE && !isSICSHdbRO(currentChild)){
GetHipadabaPar(currentChild,&v,NULL);
data = formatValue(currentChild->value); data = formatValue(currentChild->value);
if(data != NULL){ if(data != NULL){
fprintf(fd,"%s%s %s\n", prefix, currentChild->name, GetCharArray(data)); fprintf(fd,"%s%s %s\n", prefix, currentChild->name, GetCharArray(data));
@ -1742,10 +1768,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){ int argc, char *argv[]){
pHdb targetNode = NULL; pHdb targetNode = NULL;
hdbValue newValue; hdbValue newValue;
pDynString parData = NULL; pDynString parData = NULL, result = NULL;
char error[512], oriPath[512];; char error[512], oriPath[512];;
int i, status; int i, status;
int protocol = 0, outCode; Protocol protocol = normal_protocol;
int outCode;
if(argc < 2) { if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError); SCWrite(pCon,"ERROR: need path to node to print",eError);
@ -1769,9 +1796,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
else else
outCode = eEvent; outCode = eEvent;
formatNameValue(protocol, oriPath, NULL, parData); result = CreateDynString(128,128);
SCWrite(pCon,GetCharArray(parData),outCode); formatNameValue(protocol, oriPath, GetCharArray(parData), result, newValue.dataType);
SCWrite(pCon,GetCharArray(result),outCode);
DeleteDynString(parData); DeleteDynString(parData);
DeleteDynString(result);
ReleaseHdbValue(&newValue); ReleaseHdbValue(&newValue);
return 1; return 1;
@ -2075,7 +2104,8 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
pHdb node = NULL; pHdb node = NULL;
int pathArg = 1; int pathArg = 1;
pDynString listData = NULL; pDynString listData = NULL;
int protocol = 0, outCode; Protocol protocol = normal_protocol;
int outCode;
if(argc < 2) { if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError); SCWrite(pCon,"ERROR: need path to node to print",eError);