First version of remoteobject. In the implementation of this, the following

sub problems were solved:
- sicsget was not reporting geterrors on nodes properly
- rwpuffer contained dirt after wrap
- property change events were added to hipadaba
- Some tuning of SICS output
- The number of codes was wrong in outcode.c
This commit is contained in:
2015-03-17 11:41:18 +01:00
parent fb19bf9bf6
commit 2eef24bf3c
13 changed files with 1117 additions and 12 deletions

View File

@ -1016,7 +1016,6 @@ int SCPureSockWrite(SConnection * self, char *buffer, int iOut)
return 1;
}
/*--------------------------------------------------------------------------
special for ClientLog. Do not use elsewhere without check
----------------------------------------------------------------------------*/
@ -1044,6 +1043,18 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut)
if(pPtr != pBueffel){
free(pPtr);
}
} else if(self->iProtocolID == 2) {
if (strlen(buffer) + 30 > 1024) {
pPtr = (char *) malloc((strlen(buffer) + 30) * sizeof(char));
memset(pPtr, 0, strlen(buffer) + 20);
} else {
pPtr = pBueffel;
}
sprintf(pPtr,"%s@@%s",buffer,pCode[iOut]);
testAndWriteSocket(self, pPtr, iOut);
if(pPtr != pBueffel){
free(pPtr);
}
} else {
testAndWriteSocket(self, buffer, iOut);
}

View File

@ -22,6 +22,7 @@ static char update[] = { "update" };
static char treeChange[] = { "treeChange" };
static char dataSearch[] = { "dataSearch" };
static char killNode[] = { "killNode" };
static char propertyChange[] = { "propertyChange" };
/*------------------------------------------------------------------------*/
pHdbDataMessage GetHdbSetMessage(pHdbMessage toTest)
@ -77,6 +78,15 @@ pHdbMessage GetHdbKillNodeMessage(pHdbMessage toTest)
return NULL;
}
/*-------------------------------------------------------------------------*/
pHdbPropertyChange GetPropertyChangeMessage(pHdbMessage toTest)
{
if (toTest->type == propertyChange) {
return (pHdbPropertyChange)toTest;
}
return NULL;
}
/*================== internal functions ===================================*/
void DeleteCallbackChain(pHdb node)
{
@ -1140,6 +1150,8 @@ static int calcDataLength(pHdb node, int testLength)
/*============================= Property Functions ==========================*/
void SetHdbProperty(pHdb node, char *key, char *value)
{
hdbPropertyChange propMes;
if (node != NULL && key != NULL && node->properties != NULL) {
if (value == NULL) {
StringDictDelete(node->properties, key);
@ -1148,6 +1160,10 @@ void SetHdbProperty(pHdb node, char *key, char *value)
} else {
StringDictAddPair(node->properties, key, value);
}
propMes.type = propertyChange;
propMes.key = key;
propMes.value = value;
InvokeCallbackChain(node,(pHdbMessage)&propMes);
}
}

View File

@ -26,6 +26,8 @@
* Added support for properties, Mark Koennecke, January 2007
*
* Refactored callback handling, Markus Zolliker, Mark Koennecke, March 2008
*
* Added property chnage events. Mark Koennecke, February 2015
*/
#ifndef HIPADABA
#define HIPADABA
@ -75,7 +77,8 @@ typedef struct __hipadaba {
pStringDict properties;
} Hdb, *pHdb;
/*-------------- return values for callback functions -------------------------*/
typedef enum { hdbContinue,
typedef enum {
hdbContinue,
hdbAbort,
hdbKill
} hdbCallbackReturn;
@ -101,6 +104,12 @@ typedef struct {
void *result;
} hdbDataSearch, *pHdbDataSearch;
/*-------------------------------------------------------------------------------*/
typedef struct {
char *type;
char *key;
char *value;
} hdbPropertyChange, *pHdbPropertyChange;
/*-------------------------------------------------------------------------------*/
typedef hdbCallbackReturn(*hdbCallbackFunction) (pHdb currentNode,
void *userData,
pHdbMessage message);
@ -156,6 +165,14 @@ pHdbDataSearch GetHdbDataSearchMessage(pHdbMessage toTest);
* pointer if it is.
*/
pHdbMessage GetHdbKillNodeMessage(pHdbMessage toTest);
/**
* Test a message if it is a property change message
* @param toTest The message to test.
* @return NULL if the message is no property chnage message or a message
* pointer if it is.
*/
pHdbPropertyChange GetPropertyChangeMessage(pHdbMessage toTest);
/*======================== Function protoypes: hdbData ========================*/
/**
* make a hdbValue with the given datatype and length

View File

@ -46,7 +46,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
rwpuffer.o asynnet.o background.o countersec.o hdbtable.o velosec.o \
histmemsec.o sansbc.o sicsutil.o strlutil.o genbinprot.o trace.o\
singlebinb.o taskobj.o sctcomtask.o tasmono.o multicountersec.o \
messagepipe.o sicsget.o
messagepipe.o sicsget.o remoteobject.o
MOTOROBJ = motor.o simdriv.o
COUNTEROBJ = countdriv.o simcter.o counter.o

View File

@ -375,7 +375,7 @@ static float SecMotorGetValue(void *pData, SConnection * pCon)
assert(pData);
status = GetHdbProperty(self->pDescriptor->parNode,"geterror", error,sizeof(error));
if(status == 1 && strcmp(error,"none") != 0) {
SCPrintf(pCon,eValue,"ERROR: Failed to read %s with %s", self->name, error);
SCPrintf(pCon,eError,"ERROR: Failed to read %s with %s", self->name, error);
return -9999999.99;
}
status = GetHipadabaPar(self->pDescriptor->parNode, &v, pCon);
@ -465,7 +465,7 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData,
pHdb child = NULL;
pMotor self = NULL;
float fHard, fVal, sign, zero;
char pBueffel[512], pError[132];
char pBueffel[512], pError[132], *pPtr = NULL;
int status;
self = (pMotor) userData;
@ -526,6 +526,8 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData,
ServerWriteGlobal(pBueffel, eError);
SCSetInterrupt(pCon, eAbortBatch);
self->pDrivInt->iErrorCount = 0;
child = GetHipadabaNode(self->pDescriptor->parNode, "status");
UpdateHipadabaPar(child, MakeHdbText("run"), pCon);
return hdbAbort;
}
@ -547,6 +549,12 @@ static hdbCallbackReturn SecMotorCallback(pHdb node, void *userData,
if (mm != NULL) {
pCon = (SConnection *) mm->callData;
SecMotorGetPar(self, "hardposition", &fVal);
child = GetHipadabaNode(self->pDescriptor->parNode, "hardposition");
if((pPtr = GetHdbProp(child,"geterror")) != NULL){
SetHdbProperty(node,"geterror",pPtr);
} else {
SetHdbProperty(node,"geterror",NULL);
}
fVal = hardToSoftPosition(self, fVal);
node->value.v.doubleValue = fVal;
mm->v->v.doubleValue = fVal;
@ -561,6 +569,7 @@ static hdbCallbackReturn HardUpdateCallback(pHdb node, void *userData,
pHdbMessage message)
{
pHdbDataMessage mm = NULL;
pHdbPropertyChange pm = NULL;
pMotor self = (pMotor) userData;
float fVal;
hdbValue v;
@ -575,6 +584,18 @@ static hdbCallbackReturn HardUpdateCallback(pHdb node, void *userData,
UpdateHipadabaPar(self->pDescriptor->parNode, v, mm->callData);
return hdbContinue;
}
/*
forward geterror
*/
pm = GetPropertyChangeMessage(message);
if(pm != NULL){
if(strstr(pm->key,"geterror") != NULL){
SetHdbProperty(self->pDescriptor->parNode,pm->key, pm->value);
}
}
return hdbContinue;
}

View File

@ -221,7 +221,6 @@ int InitServer(char *file, pServer * pServ)
printf("Cannot find InterruptPort number in options file %s\n",
"This value is required!");
DeleteInterp(self->pSics);
IFDeleteOptions(pSICSOptions);
return 0;
}
iRet = sscanf(pText, "%d", &iPort);
@ -234,6 +233,8 @@ int InitServer(char *file, pServer * pServ)
}
/* install a secret fully priviledged entry point for ME */
AddUser("Achterbahn", "Kiel", usInternal);
/* install a secret entry point for remote objects */
AddUser("RemoteMaster","3ed4c656a15f0aa45e02fd5ec429225bb93b762e7eb06cc81a0b4f6c35c76184",usInternal);
/* install environment monitor */
self->pMonitor = GetEnvMon(self->pSics);

1
ofac.c
View File

@ -48,6 +48,7 @@ static void InitGeneral(void)
INIT(AddSyncedProt);
INIT(MakeTrace);
INIT(InitTaskOBJ);
INIT(RemoteObjectInit);
INIT(SiteInit); /* site specific initializations */
}

View File

@ -26,5 +26,5 @@ static char *pCode[] = {
"logerror",
NULL
};
static int iNoCodes = 13;
static int iNoCodes = 15;
#endif

View File

@ -290,7 +290,7 @@ static int ProtocolSet(SConnection * pCon, Protocol * pPro, char *pProName)
SCSetWriteFunc(pCon, SCWriteJSON_String);
SCSetWriteFunc(pMaster, SCWriteJSON_String);
break;
case 5:
case 5: /* ACT */
SCSetWriteFunc(pMaster, SCACTWrite);
SCSetWriteFunc(pCon, SCACTWrite);
break;

1008
remoteobject.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -131,5 +131,6 @@ void RemoveRWBufferData(prwBuffer self, int count)
if (self->startPtr >= self->endPtr) {
self->startPtr = 0;
self->endPtr = 0;
memset(self->data,0,self->length*sizeof(char));
}
}

View File

@ -89,7 +89,11 @@ static int SICSGetCommand(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0;
}
} else {
SCPrintf(pCon,eError,"ERROR: value for %s not found", argv[1]);
if(v.dataType == HIPTEXT && strstr(v.v.text,"ERROR") != NULL){
SCPrintf(pCon,eError,v.v.text);
} else {
SCPrintf(pCon,eError,"ERROR: value for %s not found", argv[1]);
}
return 0;
}
ReleaseHdbValue(&v);
@ -326,10 +330,20 @@ static int GetHdbFunc(void *ms, void *userData)
{
pSSGMessage self = (pSSGMessage)ms;
pHdb node = NULL;
char *geterror = NULL, error[512];
hdbValue ve;
node = FindHdbNode(NULL,self->name,NULL);
if(node != NULL){
cloneHdbValue(&node->value, self->v);
geterror = GetHdbProp(node,"geterror");
if(geterror != NULL){
snprintf(error,sizeof(error),"ERROR: %s",geterror);
ve = MakeHdbText(strdup(error));
cloneHdbValue(&ve, self->v);
ReleaseHdbValue(&ve);
} else {
cloneHdbValue(&node->value, self->v);
}
self->success = 1;
return MPSTOP;
} else {
@ -381,14 +395,28 @@ static int GetDrivableFunc(void *ms, void *userData)
pIDrivable pDriv = NULL;
float fVal;
hdbValue v;
int oldMacro;
data = FindCommandData(pServ->pSics, self->name,NULL);
if(data != NULL){
pDriv = GetDrivableInterface(data);
if(pDriv != NULL){
/*
All this macro flag handling is there to get hold of a
error message stored in the Tcl interpreter if there is
one.
*/
oldMacro = SCinMacro(pServ->dummyCon);
SCsetMacro(pServ->dummyCon,1);
fVal = pDriv->GetValue(data,pServ->dummyCon);
v = MakeHdbFloat(fVal);
self->success = 1;
SCsetMacro(pServ->dummyCon,oldMacro);
if(fVal < -900000) {
v = MakeHdbText(Tcl_GetStringResult(InterpGetTcl(pServ->pSics)));
self->success = 0;
} else {
v = MakeHdbFloat(fVal);
self->success = 1;
}
cloneHdbValue(&v,self->v);
return MPSTOP;
}

View File

@ -339,6 +339,7 @@ static int MakeCommandNode(pHdb parent, char *name, SConnection * pCon,
node->value.v.text = strdup(argv[3]);
node->value.arrayLength = strlen(argv[3]);
SetHdbProperty(node, "sicscommand", argv[3]);
SetHdbProperty(node, "scriptcommand", "yes");
kalle = MakeHipadabaCallback(CommandSetCallback, NULL, NULL);
if (kalle == NULL) {