From 826b13d8904a7c6a9b54ba7d7629f911f94d9f51 Mon Sep 17 00:00:00 2001 From: koennecke Date: Tue, 19 Dec 2006 14:30:29 +0000 Subject: [PATCH] - Fixed a bug in splitter.c - Added hupdate and hzipget to Hipadaba --- sicshipadaba.c | 142 +++++++++++++++++++++++++++++++++++++++++++------ splitter.c | 4 +- 2 files changed, 129 insertions(+), 17 deletions(-) diff --git a/sicshipadaba.c b/sicshipadaba.c index d4cca7a2..47554464 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -152,25 +152,32 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node, cbInfo = (HdbCBInfo *)userData; pPath = GetHipadabaPath(node); - printedData = formatValue(v); result = CreateDynString(128,128); - if(pPath == NULL || printedData == NULL || result == NULL){ - SCWriteInContext(cbInfo->pCon,"ERROR: out of memory formatting data" , - eEvent,cbInfo->context); - /* - * no need to interrupt something because writing data to a client does - * not work - */ - return 1; - } - DynStringCopy(result,pPath); - DynStringConcat(result," = "); - DynStringConcat(result,GetCharArray(printedData)); - SCWriteInContext(cbInfo->pCon,GetCharArray(result), + if(v.arrayLength < 100){ + printedData = formatValue(v); + if(pPath == NULL || printedData == NULL || result == NULL){ + SCWriteInContext(cbInfo->pCon,"ERROR: out of memory formatting data" , eEvent,cbInfo->context); + /* + * no need to interrupt something because writing data to a client does + * not work + */ + return 1; + } + DynStringCopy(result,pPath); + DynStringConcat(result," = "); + DynStringConcat(result,GetCharArray(printedData)); + SCWriteInContext(cbInfo->pCon,GetCharArray(result), + eEvent,cbInfo->context); + DeleteDynString(printedData); + } else { + DynStringCopy(result,"!!datachange!! = "); + DynStringConcat(result,pPath); + SCWriteInContext(cbInfo->pCon,GetCharArray(result), + eEvent,cbInfo->context); + } free(pPath); DeleteDynString(result); - DeleteDynString(printedData); return 1; } @@ -1591,6 +1598,56 @@ static int SetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, } return status; } +/*---------------------------------------------------------------------------*/ +static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb targetNode = NULL; + hdbValue newValue; + pDynString parData = NULL; + char error[512]; + int i, status; + + if(!SCMatchRights(pCon,usUser)){ + return 0; + } + + if(argc < 3) { + SCWrite(pCon,"ERROR: insufficient number of arguments to UpdateHdbNode", + eError); + return 0; + } + + targetNode = locateSICSNode(pSics,pCon,argv[1]); + if(targetNode == NULL){ + return 0; + } + if(!cloneHdbValue(&targetNode->value,&newValue)){ + SCWrite(pCon,"ERROR: out of mmeory cloning node", + eError); + return 0; + } + parData = CreateDynString(64,64); + if(parData == NULL){ + SCWrite(pCon,"ERROR: out of memory reading parameter",eError); + return 0; + } + for(i = 2; i < argc; i++){ + DynStringConcat(parData," "); + DynStringConcat(parData, argv[i]); + } + strcpy(error,"ERROR: "); + if(!readHdbValue(&newValue, GetCharArray(parData), + error+7,512-7)){ + SCWrite(pCon,error, eError); + return 0; + } + status = UpdateHipadabaPar(targetNode,newValue,pCon); + ReleaseHdbValue(&newValue); + if(status == 1){ + SCSendOK(pCon); + } + return status; +} /*-----------------------------------------------------------------------------*/ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]){ @@ -1625,6 +1682,59 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, return 1; } +/*-----------------------------------------------------------------------------*/ +static int ZipGetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb targetNode = NULL; + hdbValue newValue; + char error[512], oriPath[512]; + int i, status; + int *iData = NULL; + + if(argc < 2) { + SCWrite(pCon,"ERROR: need path to node",eError); + return 0; + } + + strncpy(oriPath,argv[1], 511); + targetNode = locateSICSNode(pSics,pCon,argv[1]); + if(targetNode == NULL){ + return 0; + } + memset(&newValue,0,sizeof(hdbValue)); + GetHipadabaPar(targetNode, &newValue, pCon); + switch(newValue.dataType){ + case HIPINTAR: + case HIPINTVARAR: + for(i = 0; i < newValue.arrayLength; i++){ + newValue.v.intArray[i] = htonl(newValue.v.intArray[i]); + } + SCWriteZipped(pCon,oriPath, newValue.v.intArray, + newValue.arrayLength*sizeof(int)); + break; + case HIPFLOATAR: + case HIPFLOATVARAR: + iData = (int *)malloc(newValue.arrayLength*sizeof(int)); + if(iData == NULL){ + SCWrite(pCon,"ERROR: out of memory in ZipGetHdbNode",eError); + return 0; + } + memset(iData,0,newValue.arrayLength*sizeof(int)); + for(i = 0; i < newValue.arrayLength; i++){ + iData[i] = htonl((int)newValue.v.floatArray[i]*65536.); + } + SCWriteZipped(pCon,oriPath, iData, + newValue.arrayLength*sizeof(int)); + free(iData); + break; + default: + SCWrite(pCon,"ERROR: zipped writing not supported for this datatype", + eError); + return 0; + } + ReleaseHdbValue(&newValue); + return 1; +} /*--------------------------------------------------------------------------*/ static int countChildren(pHdb node){ pHdb current = NULL; @@ -2150,7 +2260,9 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData, AddCommand(pSics,"hattach", SICSHdbAdapter, NULL, NULL); AddCommand(pSics,"hdel", DeleteHdbNode, NULL, NULL); AddCommand(pSics,"hset", SetHdbNode, NULL, NULL); + AddCommand(pSics,"hupdate", UpdateHdbNode, NULL, NULL); AddCommand(pSics,"hget", GetHdbNode, NULL, NULL); + AddCommand(pSics,"hzipget",ZipGetHdbNode, NULL, NULL); AddCommand(pSics,"hlist", ListHdbNode, NULL, NULL); AddCommand(pSics,"hnotify", AutoNotifyHdbNode, NULL, NULL); AddCommand(pSics,"hdelcb", RemoveHdbCallback, NULL, NULL); diff --git a/splitter.c b/splitter.c index 96a4e896..09543881 100644 --- a/splitter.c +++ b/splitter.c @@ -114,7 +114,7 @@ typedef enum _CharType {eSpace, eNum,eeText,eQuote} CharType; { TokenList *pList = NULL; TokenList *pCurrent; - char pBueffel[132]; + char pBueffel[256]; char *pChar; CharType eWhat; int i, n; @@ -141,7 +141,7 @@ typedef enum _CharType {eSpace, eNum,eeText,eQuote} CharType; { i = 0; pChar++; - while( (isEnd(*pChar) != 2) && (CheckSpecial(pChar) != eQuote)) + while( (isEnd(*pChar) != 2) && (CheckSpecial(pChar) != eQuote) && i < 250) { if (*pChar == '\\') { pBueffel[i] = Tcl_Backslash(pChar, &n);