- Reworked the connection object and the IO system

- Reworked the support for TRICS
- Added a second generation motor
This commit is contained in:
koennecke
2009-02-03 08:05:39 +00:00
parent f6d595665e
commit 361ee9ebea
119 changed files with 16455 additions and 3674 deletions

View File

@@ -17,6 +17,8 @@
* interpreter interface.
*
* Refactored to new callback system, Markus Zolliker, Mark Koennecke, March 2008
*
* Added start and finished messages to commands. Mark Koennecke, November 2008
*/
#include <stdlib.h>
#include <string.h>
@@ -47,6 +49,8 @@ char *trim(char *str);
static char killID[] = {"killID"};
static char killInternalID[] = {"killInternalID"};
static char killPtr[] = {"killPtr"};
static char startID[] = {"start"};
static char stopID[] = {"stop"};
/*----------------------------------------------------------------------------------*/
pHdbIDMessage GetKillIDMessage(pHdbMessage message){
if(message->type == killID){
@@ -68,7 +72,38 @@ pHdbPtrMessage GetKillPtrMessage(pHdbMessage message){
}
return NULL;
}
/*-----------------------------------------------------------------------------------*/
pHdbMessage GetHdbStartMessage(pHdbMessage message){
if(message->type == startID){
return (pHdbMessage)message;
}
return NULL;
}
/*-----------------------------------------------------------------------------------*/
pHdbMessage GetHdbStopMessage(pHdbMessage message){
if(message->type == stopID){
return (pHdbMessage)message;
}
return NULL;
}
/*-----------------------------------------------------------------------------------*/
void SendHdbStatusMessage(pHdb node, char *status){
pHdbMessage pRes = NULL;
pRes = malloc(sizeof(hdbMessage));
if(pRes == NULL){
return;
}
if(strcmp(status,"start") == 0){
pRes->type = startID;
} else if(strcmp(status,"stop") == 0){
pRes->type = stopID;
} else {
/* someone is trying to create an non existent message */
assert(0);
}
InvokeCallbackChain(node,pRes);
free(pRes);
}
/*=============== common callback functions used for SICS ===========================*/
static hdbCallbackReturn SICSCheckPermissionCallback(pHdb node, void *userData,
pHdbMessage message){
@@ -274,8 +309,10 @@ static hdbCallbackReturn SICSFuncCallback(pHdb node, void *userData,
}
func = (SICSOBJFunc)node->value.v.func;
if(func != NULL){
SendHdbStatusMessage(node, "start");
status = func((pSICSOBJ)userData,(SConnection *)mm->callData,
node, par,nPar);
SendHdbStatusMessage(node, "stop");
} else {
printf("Great Badness in calling SICSFuncCallback\n");
return hdbAbort;
@@ -297,7 +334,6 @@ pHdbCallback MakeSICSReadDriveCallback(void *sicsObject){
/*---------------------------------------------------------------------------------------*/
typedef struct {
SConnection *pCon;
commandContext context;
int ID;
int internalID;
}HdbCBInfo;
@@ -438,6 +474,7 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
pHdbIDMessage idm = NULL;
pHdbPtrMessage cmm = NULL;
pHdbDataMessage mm = NULL;
SConnection *tstCon;
cbInfo = (HdbCBInfo *)userData;
@@ -459,15 +496,41 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
}
}
if((cmm = GetKillPtrMessage(message)) != NULL){
if(cmm->pPtr == cbInfo->pCon){
tstCon = cmm->pPtr;
if(tstCon != NULL && tstCon->ident == cbInfo->pCon->ident){
return hdbKill;
} else {
return hdbContinue;
}
}
/**
* handle start and stop messages
*/
if(GetHdbStartMessage(message) != NULL){
pPath = GetHipadabaPath(node);
result = CreateDynString(128,128);
DynStringConcat(result, pPath);
DynStringConcat(result," STARTED");
SCWrite(cbInfo->pCon, GetCharArray(result), eEvent);
DeleteDynString(result);
free(pPath);
return hdbContinue;
}
if(GetHdbStopMessage(message) != NULL){
pPath = GetHipadabaPath(node);
result = CreateDynString(128,128);
DynStringConcat(result, pPath);
DynStringConcat(result," FINISHED");
SCWrite(cbInfo->pCon, GetCharArray(result), eEvent);
DeleteDynString(result);
free(pPath);
return hdbContinue;
}
/*
* react only on update messages
* Deal with update messages
*/
if((mm = GetHdbUpdateMessage(message)) == NULL){
return hdbContinue;
@@ -481,20 +544,12 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
outCode = eEvent;
/*
* we want our notifications to come even when called from a macro
*/
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);
DeleteDynString(result);
return hdbContinue;
@@ -503,9 +558,8 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
if(mm->v->arrayLength < 100){
printedData = formatValue(*(mm->v), node);
if(pPath == NULL || printedData == NULL || result == NULL){
SCWriteInContext(cbInfo->pCon,"ERROR: out of memory formatting data" ,
eEvent,cbInfo->context);
SCsetMacro(cbInfo->pCon,macro);
SCWrite(cbInfo->pCon,"ERROR: out of memory formatting data" ,
eEvent);
/*
* no need to interrupt something because writing data to a client does
* not work
@@ -514,33 +568,46 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
}
formatNameValue(protocol, pPath, GetCharArray(printedData), result,
mm->v->dataType);
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
outCode,cbInfo->context);
SCWrite(cbInfo->pCon,GetCharArray(result),
outCode);
DeleteDynString(printedData);
} else {
formatNameValue(protocol, pPath,"!!datachange!!", result, HIPTEXT);
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
outCode,cbInfo->context);
SCWrite(cbInfo->pCon,GetCharArray(result),
outCode);
}
SCsetMacro(cbInfo->pCon,macro);
free(pPath);
DeleteDynString(result);
return hdbContinue;
}
/*-----------------------------------------------------------------------------------------*/
static void cbKill(void *pData){
HdbCBInfo *cbInfo = (HdbCBInfo *)pData;
if(cbInfo == NULL){
return;
}
if(cbInfo->pCon != NULL){
SCDeleteConnection(cbInfo->pCon);
}
free(cbInfo);
}
/*-----------------------------------------------------------------------------------------*/
pHdbCallback MakeNotifyCallback(SConnection *pCon, int id){
HdbCBInfo *cbInfo = NULL;
HdbCBInfo *cbInfo = NULL;
cbInfo = malloc(sizeof(HdbCBInfo));
if(cbInfo == NULL){
return NULL;
}
cbInfo->pCon = pCon;
cbInfo->context = SCGetContext(pCon);
cbInfo->pCon = SCCopyConnection(pCon);
if(cbInfo->pCon == NULL){
return NULL;
}
SCsetMacro(cbInfo->pCon,0);
cbInfo->ID = id;
cbInfo->internalID = -1;
return MakeHipadabaCallback(SICSNotifyCallback, cbInfo,free);
return MakeHipadabaCallback(SICSNotifyCallback, cbInfo,cbKill);
}
/*-------------------------------------------------------------------------*/
static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
@@ -553,6 +620,7 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
pHdbIDMessage idm = NULL;
pHdbPtrMessage cmm = NULL;
pHdbTreeChangeMessage tm = NULL;
SConnection *tstCon = NULL;
HdbCBInfo *cbInfo = (HdbCBInfo *)userData;
@@ -574,7 +642,8 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
}
}
if((cmm = GetKillPtrMessage(message)) != NULL){
if(cmm->pPtr == cbInfo->pCon){
tstCon = cmm->pPtr;
if(tstCon != NULL && tstCon->ident == cbInfo->pCon->ident){
return hdbKill;
} else {
return hdbContinue;
@@ -588,7 +657,7 @@ 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);
SCWrite(cbInfo->pCon,"ERROR: out of memory in TreeChangeCallback",outCode);
return hdbAbort;
}
path = GetHipadabaPath(node);
@@ -597,7 +666,7 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
else
outCode = eEvent;
formatNameValue(protocol, "treechange", path, result, node->value.dataType);
SCWriteInContext(cbInfo->pCon,GetCharArray(result),outCode,cbInfo->context);
SCWrite(cbInfo->pCon,GetCharArray(result),outCode);
DeleteDynString(result);
free(path);
}
@@ -611,10 +680,12 @@ pHdbCallback MakeTreeChangeCallback(SConnection *pCon, int id){
if(cbInfo == NULL){
return NULL;
}
cbInfo->pCon = pCon;
cbInfo->context = SCGetContext(pCon);
cbInfo->pCon = SCCopyConnection(pCon);
if(cbInfo->pCon == NULL){
return NULL;
}
cbInfo->ID = id;
return MakeHipadabaCallback(TreeChangeCallback, cbInfo,free);
return MakeHipadabaCallback(TreeChangeCallback, cbInfo,cbKill);
}
/*----------------------------------------------------------------------------------------*/
static hdbCallbackReturn SICSScriptWriteCallback(pHdb node, void *userData,
@@ -1740,7 +1811,13 @@ pDynString formatValue(hdbValue v, pHdb node){
snprintf(number,30,format, v.v.floatArray[i]);
DynStringConcat(result,number);
}
break;
break;
case HIPFUNC:
DynStringConcat(result,"FUNCTION");
break;
case HIPOBJ:
DynStringConcat(result,"OBJECT");
break;
}
return result;
}
@@ -2281,7 +2358,7 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
if ((protocol = isJSON(pCon)) == 1)
outCode = eHdbEvent;
else
outCode = eEvent;
outCode = eValue;
result = CreateDynString(128,128);
formatNameValue(protocol, oriPath, GetCharArray(parData), result, newValue.dataType);
@@ -2322,7 +2399,7 @@ static int GetHdbVal(SConnection *pCon, SicsInterp *pSics, void *pData,
if ((protocol = isJSON(pCon)) == 1)
outCode = eHdbEvent;
else
outCode = eEvent;
outCode = eValue;
SCWrite(pCon,GetCharArray(parData), outCode);
DeleteDynString(parData);
ReleaseHdbValue(&newValue);
@@ -2610,7 +2687,7 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
outCode = eHdbEvent;
} else {
listData = formatPlainList(node);
outCode = eEvent;
outCode = eValue;
}
}
if(listData == NULL){
@@ -2801,6 +2878,7 @@ static int ChainHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
assert(pInter);
/* print command to log files */
/*
for( i = 0; i < self->iFiles; i++)
{
if(self->pFiles[i])
@@ -2808,7 +2886,8 @@ static int ChainHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
fprintf(self->pFiles[i],"SICS>> %s\n",pCommand);
}
}
*/
/* print to command log if user or manager */
if(SCGetRights(self) <= usUser)
{
@@ -2841,10 +2920,14 @@ static hdbCallbackReturn CommandSetCallback(pHdb node, void *userData,
pHdbDataMessage mm = NULL;
hdbValue v;
/**
* TODO: this is a duplicate: resolve. It is still here because the old
* Hipadaba configuration commands still work
*/
if((mm = GetHdbSetMessage(message)) == NULL){
return hdbContinue;
}
pCon = (SConnection *)pCon;
pCon = (SConnection *)mm->callData;
v = *(mm->v);
if(pCon == NULL){
@@ -2871,7 +2954,9 @@ static hdbCallbackReturn CommandSetCallback(pHdb node, void *userData,
}
current = current->next;
}
SendHdbStatusMessage(node,"start");
status = HDBInvoke(pCon,pServ->pSics, GetCharArray(cmd));
SendHdbStatusMessage(node,"stop");
DeleteDynString(cmd);
if(status == 1){
return hdbContinue;