From eb6b037aac56617392341cd15509252d8b06d0c4 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Mon, 30 Oct 2006 12:58:25 +1100 Subject: [PATCH] Using new eHdb hipadaba output code. r1204 | ffr | 2006-10-30 12:58:25 +1100 (Mon, 30 Oct 2006) | 2 lines --- Scommon.h | 3 +- outcode.c | 3 +- protocol.c | 2 +- sicshipadaba.c | 119 +++++++------------------------------------------ 4 files changed, 20 insertions(+), 107 deletions(-) diff --git a/Scommon.h b/Scommon.h index 6b466d14..7cc639c1 100644 --- a/Scommon.h +++ b/Scommon.h @@ -50,7 +50,8 @@ typedef enum { eFinish, eEvent, eWarning, - eError + eError, + eHdb } OutCode; #include "interrupt.h" diff --git a/outcode.c b/outcode.c index e52f6f58..7d3810e5 100644 --- a/outcode.c +++ b/outcode.c @@ -20,6 +20,7 @@ "event", "warning", "error", + "hdb", NULL }; - static int iNoCodes = 10; + static int iNoCodes = 11; #endif diff --git a/protocol.c b/protocol.c index a7ef6f2d..b6693769 100644 --- a/protocol.c +++ b/protocol.c @@ -632,7 +632,7 @@ struct json_object *mkJSON_Object(SConnection *pCon, char *pBuffer, int iOut) json_object_object_add(msg_json, "flag", json_object_new_string(pCode[iOut])); break; } - if (iOut == eValue || iOut == eEvent) { + if (iOut == eHdb) { tmp_json = json_tokener_parse(pBuffer); if (is_error(msg_json)) { linenum = __LINE__; goto reporterr; } } else { diff --git a/sicshipadaba.c b/sicshipadaba.c index e958c4b9..fb40227e 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -158,7 +158,7 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node, result = CreateDynString(128,128); if(pPath == NULL || printedData == NULL || result == NULL){ SCWriteInContext(cbInfo->pCon,"ERROR: out of memory formatting data" , - eEvent,cbInfo->context); + eError,cbInfo->context); /* * no need to interrupt something because writing data to a client does * not work @@ -182,7 +182,7 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node, } SCWriteInContext(cbInfo->pCon,GetCharArray(result), - eEvent,cbInfo->context); + eHdb,cbInfo->context); free(pPath); DeleteDynString(result); DeleteDynString(printedData); @@ -754,7 +754,7 @@ int ProcessSICSHdbPar(pHdb root, SConnection *pCon, if(printPrefix != NULL){ DynStringInsert(parData,printPrefix,0); } - SCWrite(pCon,GetCharArray(parData),eValue); + SCWrite(pCon,GetCharArray(parData),eHdb); DeleteDynString(parData); ReleaseHdbValue(&input); return 1; @@ -1409,30 +1409,18 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, pDynString parData = NULL; char error[512], oriPath[512];; int i, status; - int pathArg = 1, fmtArg=1; - char *usage ="ERROR:valid arguments are [-json] nodepath"; + int pathArg = 1; + char *usage ="ERROR: Requires argument"; -/*XXX switch (argc) { case 2: pathArg = 1; - currFmtStyle = plain; - break; - case 3: - pathArg = 2; - if(strcmp(argv[1],"-json") == 0){ - currFmtStyle = json; - } else { - SCWrite(pCon,usage,eError); - return 0; - } break; default: SCWrite(pCon,usage,eError); return 0; break; } -*/ strncpy(oriPath,argv[pathArg], 511); targetNode = locateSICSNode(pSics,pCon,argv[pathArg]); @@ -1441,37 +1429,16 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, } memset(&newValue,0,sizeof(hdbValue)); GetHipadabaPar(targetNode, &newValue, pCon); - - switch (currFmtStyle) { - case cli: - parData = formatClientValue(oriPath,newValue,0); - break; - case json: - parData = formatJSONValue(oriPath,newValue,0); - break; - case plain: - default: - parData = formatValue(newValue); - } + parData = formatJSONValue(oriPath,newValue,0); if(parData == NULL){ SCWrite(pCon,"ERROR: out of memory formatting data",eError); return 0; } - switch (currFmtStyle) { - case cli: - break; - case json: - DynStringInsert(parData,"{", 0); - DynStringConcat(parData,"}"); - break; - case plain: - default: - DynStringInsert(parData," =",0); - DynStringInsert(parData,oriPath,0); - } - SCWrite(pCon,GetCharArray(parData),eValue); + DynStringInsert(parData,"{", 0); + DynStringConcat(parData,"}"); + SCWrite(pCon,GetCharArray(parData),eHdb); DeleteDynString(parData); ReleaseHdbValue(&newValue); @@ -1636,70 +1603,32 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]){ pHdb node = NULL; pDynString listData = NULL; - int pathArg = 1, fmtArg=1; - char *usage ="ERROR:valid arguments are [-json] nodepath"; + int pathArg = 1; + char *usage ="ERROR: Requires argument"; -/*XXX switch (argc) { case 2: pathArg = 1; - currFmtStyle = plain; - break; - case 3: - pathArg = 2; - if(strcmp(argv[1],"-json") == 0){ - currFmtStyle = json; - } else { - SCWrite(pCon,usage,eError); - return 0; - } break; default: SCWrite(pCon,usage,eError); return 0; break; } -*/ -/*XXX - if(strchr(argv[1],'-') != NULL){ - pathArg = 2; - if(argc < 3){ - SCWrite(pCon,"ERROR: need path to node to print",eError); - return 0; - } - } -*/ + node = locateSICSNode(pSics,pCon,argv[pathArg]); if(node == NULL){ return 0; } strtolower(argv[pathArg]); -/*XXX if (argc == 3) { - if(strcmp(argv[1],"-val") == 0){ - listData = formatListWithVal(node); - } else if(strcmp(argv[1],"-cli") == 0 || currFmtStyle == cli){ - listData = formatClientList(node); - } - } else { */ - switch (currFmtStyle) { - case cli: - listData = formatClientList(node); - break; - case json: - listData = formatJSONList(node); - break; - case plain: - default: - listData = formatPlainList(node); - } - //} + listData = formatJSONList(node); if(listData == NULL){ SCWrite(pCon,"ERROR: failed to format list", eError); return 0; } - SCWrite(pCon,GetCharArray(listData),eValue); + SCWrite(pCon,GetCharArray(listData),eHdb); DeleteDynString(listData); return 1; } @@ -1720,23 +1649,12 @@ static int AutoNotifyHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, pHdb node = NULL; int id, status; int pathArg = 1, idArg=2; - char *usage ="ERROR:valid arguments are [-json] nodepath id"; + char *usage ="ERROR:valid arguments are "; switch (argc) { case 3: pathArg = 1; idArg = 2; - currFmtStyle = json; - break; - case 4: - /* pathArg = 2; - idArg = 3; - if(strcmp(argv[1],"-json") == 0){ - currFmtStyle = json; - } else { - SCWrite(pCon,usage,eError); - return 0; - }*/ break; default: SCWrite(pCon,usage,eError); @@ -1744,13 +1662,6 @@ static int AutoNotifyHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, break; } - /*XXX - if(argc < 3) { - SCWrite(pCon,"ERROR: need path and id in order to add notify", - eError); - return 0; - } - */ node = locateSICSNode(pSics,pCon,argv[pathArg]); if(node == NULL){ return 0;