- First implementation of Hdbqueue

- First implementation of new object model for SICS
This commit is contained in:
koennecke
2007-08-03 15:12:10 +00:00
parent 3170314457
commit 31a48d2155
21 changed files with 1035 additions and 101 deletions

View File

@@ -25,6 +25,7 @@
#include <stptok.h>
#include "protocol.h"
#include <splitter.h>
#include "sicsobj.h"
/*== there can be only hipadaba in SICS, some globals to care for that == */
static pHdb root = NULL;
@@ -102,12 +103,18 @@ static int SICSDriveCallback(void *userData, void *callData, pHdb node,
hdbValue v){
SConnection *pCon = NULL;
pDummy dum = NULL;
char pSicsdev[80];
pCon = (SConnection *)callData;
dum = (pDummy)userData;
assert(pCon != NULL && dum != NULL);
return StartDevice(pServ->pExecutor,node->name,dum->pDescriptor,
userData, pCon, (float)v.v.doubleValue);
if(GetHdbProperty(node,"sicsdev",pSicsdev,79)){
return StartDevice(pServ->pExecutor,pSicsdev,dum->pDescriptor,
userData, pCon, (float)v.v.doubleValue);
} else {
return StartDevice(pServ->pExecutor,node->name,dum->pDescriptor,
userData, pCon, (float)v.v.doubleValue);
}
}
/*---------------------------------------------------------------------------------------*/
pHdbCallback MakeSICSDriveCallback(void *sicsObject){
@@ -145,6 +152,37 @@ static int SICSReadDriveCallback(void *userData, void *callData, pHdb node,
}
return 1;
}
/*--------------------------------------------------------------------------*/
static int SICSFuncCallback(void *userData, void *callData, pHdb node,
hdbValue v){
pHdb par[64], current = NULL;
int nPar = 0;
SICSOBJFunc func = NULL;
assert(node->value.dataType == HIPFUNC);
if(userData == NULL || callData == NULL){
printf("Great Badness in calling SICSFuncCallback\n");
return 0;
}
current = node->child;
while(current != NULL){
par[nPar] = current;
nPar++;
current = current->next;
}
func = (SICSOBJFunc)node->value.v.obj;
if(func != NULL){
return func((pSICSOBJ)userData,(SConnection *)callData, par,nPar);
} else {
printf("Great Badness in calling SICSFuncCallback\n");
return 0;
}
}
/*---------------------------------------------------------------------------*/
pHdbCallback MakeSICSFuncCallback(void *obj){
return MakeHipadabaCallback(SICSFuncCallback, obj,NULL,-1,-1);
}
/*--------------------------------------------------------------------------------------*/
pHdbCallback MakeSICSReadDriveCallback(void *sicsObject){
return MakeHipadabaCallback(SICSReadDriveCallback, sicsObject,NULL,-1,-1);
@@ -220,7 +258,50 @@ int formatNameValue(Protocol protocol, char *name, char *value, pDynString resul
}
return protocol;
}
/*----------------------------------------------------------------------------*/
static int sendZippedNodeData(pHdb node, SConnection *pCon){
hdbValue newValue;
int i, *iData = NULL;
char *path = NULL;
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(node, &newValue, pCon);
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]);
}
SCWriteZipped(pCon,path, 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 sendZippedData",eError);
free(path);
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,path, iData,
newValue.arrayLength*sizeof(int));
free(iData);
break;
default:
SCWrite(pCon,"ERROR: zipped writing not supported for this datatype",
eError);
free(path);
return 0;
}
free(path);
ReleaseHdbValue(&newValue);
return 1;
}
/*----------------------------------------------------------------------------------------*/
static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
hdbValue v){
@@ -229,7 +310,8 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
pDynString result = NULL;
char *pPath = NULL;
Protocol protocol = normal_protocol;
int outCode, macro;
int outCode, macro, status;
char value[80];
cbInfo = (HdbCBInfo *)userData;
pPath = GetHipadabaPath(node);
@@ -244,6 +326,19 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
*/
macro = SCinMacro(cbInfo->pCon);
SCsetMacro(cbInfo->pCon,0);
/**
* if transfer = zip always transfer data in zipped form
*/
if(GetHdbProperty(node,"transfer",value,80) == 1){
if(strstr(value,"zip") != NULL){
SCPushContext2(cbInfo->pCon,cbInfo->context);
status = sendZippedNodeData(node, cbInfo->pCon);
SCPopContext(cbInfo->pCon);
SCsetMacro(cbInfo->pCon,macro);
free(pPath);
return status;
}
}
if(v.arrayLength < 100){
printedData = formatValue(v);
if(pPath == NULL || printedData == NULL || result == NULL){
@@ -1313,6 +1408,7 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
double dValue;
char number[80];
char *pPtr = NULL;
CommandList *pCom = NULL;
switch(v->dataType){
case HIPNONE:
@@ -1385,6 +1481,16 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
v->v.floatArray[i] = dValue;
}
break;
case HIPOBJ:
pCom = FindCommand(pServ->pSics,data);
if(pCom == NULL && pCom->pData != NULL){
snprintf(error,errlen,"object %s NOT found", data);
return 0;
}
v->v.obj = pCom->pData;
break;
case HIPFUNC:
break;
default:
assert(0);
break;
@@ -1404,6 +1510,8 @@ static char *hdbTypes[] = {"none",
"floatar",
"intvarar",
"floatvarar",
"object",
"func",
NULL};
/*-------------------------------------------------------------------------*/
static int convertHdbType(char *text){
@@ -1689,7 +1797,7 @@ static int SetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0;
}
if(!cloneHdbValue(&targetNode->value,&newValue)){
SCWrite(pCon,"ERROR: out of mmeory cloning node",
SCWrite(pCon,"ERROR: out of memory cloning node",
eError);
return 0;
}
@@ -1761,6 +1869,7 @@ static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return 0;
}
} else {
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(targetNode,&newValue,pCon);
}
status = UpdateHipadabaPar(targetNode,newValue,pCon);
@@ -1771,6 +1880,25 @@ static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
return status;
}
/*-----------------------------------------------------------------------------*/
static int ZipGetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb targetNode = NULL;
char error[512], oriPath[512];
int status;
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;
}
return sendZippedNodeData(targetNode,pCon);
}
/*---------------------------------------------------------------------------*/
static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pHdb targetNode = NULL;
@@ -1780,6 +1908,7 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
int i, status;
Protocol protocol = normal_protocol;
int outCode;
char value[80];
if(argc < 2) {
SCWrite(pCon,"ERROR: need path to node to print",eError);
@@ -1791,6 +1920,14 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
if(targetNode == NULL){
return 0;
}
/*
* if transfer = zip, redirect to zip
*/
if(GetHdbProperty(targetNode,"transfer", value,80) == 1){
if(strstr(value,"zip") != NULL){
return ZipGetHdbNode(pCon,pSics,pData,argc,argv);
}
}
memset(&newValue,0,sizeof(hdbValue));
GetHipadabaPar(targetNode, &newValue, pCon);
parData = formatValue(newValue);
@@ -1812,59 +1949,6 @@ 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;
@@ -2316,6 +2400,63 @@ static int ChainHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
SCSendOK(pCon);
return 1;
}
/* --------------------------------------------------------------------------
* This is actually SCInvoke but without advancing the context. I think this
* is only of local use. It makes sure that commands executed as Hipadaba
* commands get logged properly.
*/
static int HDBInvoke(SConnection *self, SicsInterp *pInter, char *pCommand)
{
int iRet;
long lLen;
const char *pResult = NULL;
char *pBuffer = NULL, *pFile = NULL;
char pBueffel[80];
int i, iSpace;
assert(pInter);
/* print command to log files */
for( i = 0; i < self->iFiles; i++)
{
if(self->pFiles[i])
{
fprintf(self->pFiles[i],"SICS>> %s\n",pCommand);
}
}
/* print to command log if user or manager */
if(SCGetRights(self) <= usUser)
{
if(self->pSock != NULL)
{
sprintf(pBueffel,"sock %d>>",self->pSock->sockid);
}
}
/* invoke */
self->inUse++;
self->eInterrupt = eContinue;
self->parameterChange = 0;
/*
get first word of command
*/
iRet = InterpExecute(pInter,self,pCommand);
if(self->parameterChange == 1)
{
/*
automatically save changed parameters
*/
pFile = IFindOption(pSICSOptions,"statusfile");
if(pFile != NULL)
{
WriteSicsStatus(pInter,pFile,0);
self->parameterChange = 0;
}
}
self->inUse--;
return iRet;
}
/*---------------------------------------------------------------------------*/
static int CommandSetCallback(void *userData, void *callData, pHdb node,
hdbValue v){
@@ -2348,7 +2489,7 @@ static int CommandSetCallback(void *userData, void *callData, pHdb node,
}
current = current->next;
}
status = SCInvoke(pCon, pServ->pSics,GetCharArray(cmd));
status = HDBInvoke(pCon,pServ->pSics, GetCharArray(cmd));
DeleteDynString(cmd);
return status;
} else {