- Fixed a massive memory leak in Hipadaba

- Extended the Hdb adapter to support SICSdata
- Made the simulated histogram memory driver work properly when
  data has been set.
- Implemented the hfactory command
- Removed hdbcommand which was never finsihed
This commit is contained in:
koennecke
2008-05-08 09:27:48 +00:00
parent 7d2b0c5104
commit e46334eddf
20 changed files with 1167 additions and 901 deletions

View File

@@ -350,20 +350,35 @@ static int sendZippedNodeData(pHdb node, SConnection *pCon){
int i, *iData = NULL;
char *path = NULL;
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(node, &newValue, pCon);
newValue = node->value;
path = GetHipadabaPath(node);
switch(newValue.dataType){
case HIPINTAR:
case HIPINTVARAR:
for(i = 0; i < newValue.arrayLength; i++){
newValue.v.intArray[i] = htonl(newValue.v.intArray[i]);
if(newValue.v.intArray == NULL){
free(path);
return 0;
}
iData = (int *)malloc(newValue.arrayLength*sizeof(int));
if(iData == NULL){
SCWrite(pCon,"ERROR: out of memory in sendZippedData",eError);
free(path);
return 0;
}
SCWriteZipped(pCon,path, newValue.v.intArray,
memset(iData,0,newValue.arrayLength*sizeof(int));
for(i = 0; i < newValue.arrayLength; i++){
iData[i] = htonl(newValue.v.intArray[i]);
}
SCWriteZipped(pCon,path, iData,
newValue.arrayLength*sizeof(int));
free(iData);
break;
case HIPFLOATAR:
case HIPFLOATVARAR:
if(newValue.v.floatArray == NULL){
free(path);
return 0;
}
iData = (int *)malloc(newValue.arrayLength*sizeof(int));
if(iData == NULL){
SCWrite(pCon,"ERROR: out of memory in sendZippedData",eError);
@@ -385,7 +400,6 @@ static int sendZippedNodeData(pHdb node, SConnection *pCon){
return 0;
}
free(path);
ReleaseHdbValue(&newValue);
return 1;
}
/*----------------------------------------------------------------------------------------*/
@@ -517,7 +531,6 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
pHdbPtrMessage cmm = NULL;
pHdbTreeChangeMessage tm = NULL;
result = CreateDynString(128,128);
HdbCBInfo *cbInfo = (HdbCBInfo *)userData;
/*
@@ -550,6 +563,11 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
}
if(cbInfo != NULL && cbInfo->pCon != NULL){
result = CreateDynString(128,128);
if(result == NULL){
SCWriteInContext(cbInfo->pCon,"ERROR: out of memory in TreeChangeCallback",outCode,cbInfo->context);
return hdbAbort;
}
path = GetHipadabaPath(node);
if ((protocol = isJSON(cbInfo->pCon)) == 1)
outCode = eHdbEvent;
@@ -1248,7 +1266,7 @@ pHdb FindHdbParent(char *rootpath, char *relpath, char **namePtr, SConnection *p
slash = strchr(element+6, '/');
if (slash != NULL) *slash = '\0'; /* split off object name */
pDes = FindCommandDescriptor(pServ->pSics, element);
pDes = FindCommandDescriptor(pServ->pSics, element+6);
if (pDes == NULL) {
SCPrintf(pCon, eError, "ERROR: object %s not found", element);
return NULL;
@@ -1692,7 +1710,7 @@ pDynString formatValue(hdbValue v, pHdb node){
break;
case HIPFLOATAR:
case HIPFLOATVARAR:
if (!GetHdbProperty(node, "fmt", format+1, sizeof format -2)) {
if (GetHdbProperty(node, "fmt", format+1, sizeof format -2)) {
format[0]=' ';
} else {
strcpy(format, " %.6g");
@@ -2072,7 +2090,7 @@ static int SetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
pDynString parData = NULL;
char error[512];
int i, status;
if(!SCMatchRights(pCon,usUser)){
return 0;
}
@@ -2083,6 +2101,7 @@ static int SetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0;
}
targetNode = FindHdbNode(NULL,argv[1],pCon);
if(targetNode == NULL){
return 0;
@@ -2179,7 +2198,8 @@ static int ZipGetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
pHdb targetNode = NULL;
char error[512], oriPath[512];
int status;
hdbValue newValue;
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node",eError);
return 0;
@@ -2190,6 +2210,9 @@ static int ZipGetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
if(targetNode == NULL){
return 0;
}
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(targetNode, &newValue, pCon);
ReleaseHdbValue(&newValue);
return sendZippedNodeData(targetNode,pCon);
}
/*---------------------------------------------------------------------------*/
@@ -2204,6 +2227,12 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int outCode;
char value[80];
/*
if(strstr(argv[1],"values") != NULL){
printf("Found!!\n");
}
*/
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError);
return 0;
@@ -3060,11 +3089,15 @@ void killSICSHipadaba(){
root = NULL;
}
/*---------------------------------------------------------------------------*/
extern int HdbNodeFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]); /* from sicshdbfactory.c */
/*---------------------------------------------------------------------------*/
int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
root = MakeHipadabaNode("/",HIPNONE,0);
AddCommand(pSics,"hmake", MakeHdbNode, NULL, NULL);
AddCommand(pSics,"hfactory", HdbNodeFactory, NULL, NULL);
AddCommand(pSics,"hmakescript", MakeHdbScriptNode, NULL, NULL);
AddCommand(pSics,"hattach", SICSHdbAdapter, NULL, NULL);
AddCommand(pSics,"hdel", DeleteHdbNode, NULL, NULL);