- Reworked the connection object and the IO system
- Reworked the support for TRICS - Added a second generation motor
This commit is contained in:
104
exeman.c
104
exeman.c
@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* Implementation file for the exe buffer buffer manager.
|
||||
*
|
||||
@ -225,6 +226,12 @@ static int runBatchBuffer(pExeMan self, SConnection *pCon,
|
||||
if(!SCMatchRights(pCon,usUser)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(self->runCon != NULL && self->runCon != pCon){
|
||||
SCWrite(pCon,"ERROR: another batch buffer is already runnig", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
filePath = locateBatchBuffer(self,name);
|
||||
if(filePath == NULL){
|
||||
snprintf(pBueffel,255,"ERROR: batch buffer %s not found in path",
|
||||
@ -320,9 +327,8 @@ int exeHdbNode(pHdb exeNode, SConnection *pCon){
|
||||
pExeBuf buffer = NULL;
|
||||
hdbValue v;
|
||||
int status;
|
||||
commandContext cc;
|
||||
writeFunc oldWrite;
|
||||
|
||||
SConnection *conCon = NULL;
|
||||
|
||||
/*
|
||||
* clear log buffer
|
||||
*/
|
||||
@ -337,8 +343,12 @@ int exeHdbNode(pHdb exeNode, SConnection *pCon){
|
||||
* prepare context
|
||||
*/
|
||||
name = GetHipadabaPath(log);
|
||||
cc = SCGetContext(pCon);
|
||||
strncpy(cc.deviceID, name,255);
|
||||
conCon = SCCopyConnection(pCon);
|
||||
if(conCon == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory in exehdbNode", eError);
|
||||
return 0;
|
||||
}
|
||||
strncpy(conCon->deviceID, name,255);
|
||||
strncpy(bufferNode,name,511);
|
||||
|
||||
/*
|
||||
@ -365,12 +375,9 @@ int exeHdbNode(pHdb exeNode, SConnection *pCon){
|
||||
exeBufAppend(buffer,v.v.text);
|
||||
|
||||
strncpy(bufferNode,name,511);
|
||||
oldWrite = SCGetWriteFunc(pCon);
|
||||
SCSetWriteFunc(pCon,SCHdbWrite);
|
||||
SCPushContext2(pCon,cc);
|
||||
status = exeBufProcess(buffer,pServ->pSics,pCon,NULL,0);
|
||||
SCSetWriteFunc(pCon,oldWrite);
|
||||
SCPopContext(pCon);
|
||||
SCSetWriteFunc(conCon,SCHdbWrite);
|
||||
status = exeBufProcess(buffer,pServ->pSics,conCon,NULL,0);
|
||||
SCDeleteConnection(conCon);
|
||||
exeBufDelete(buffer);
|
||||
free(name);
|
||||
if(strlen(log->value.v.text) < 2){
|
||||
@ -388,13 +395,16 @@ static int runHdbBuffer(pExeMan self, SConnection *pCon,
|
||||
pHdb node = NULL;
|
||||
hdbValue v;
|
||||
int status;
|
||||
commandContext cc;
|
||||
writeFunc oldWrite;
|
||||
|
||||
SConnection *conCon = NULL;
|
||||
|
||||
if(!SCMatchRights(pCon,usUser)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(self->runCon != NULL && self->runCon != pCon){
|
||||
SCWrite(pCon,"ERROR: another bacth buffer is still running", eError);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* clear log buffer
|
||||
*/
|
||||
@ -409,8 +419,8 @@ static int runHdbBuffer(pExeMan self, SConnection *pCon,
|
||||
/*
|
||||
* prepare context
|
||||
*/
|
||||
cc = SCGetContext(pCon);
|
||||
strcpy(cc.deviceID, pBueffel);
|
||||
conCon = SCCopyConnection(pCon);
|
||||
strcpy(conCon->deviceID, pBueffel);
|
||||
|
||||
/*
|
||||
* load commands into buffer
|
||||
@ -437,15 +447,14 @@ static int runHdbBuffer(pExeMan self, SConnection *pCon,
|
||||
exeBufAppend(buffer,v.v.text);
|
||||
|
||||
strncpy(bufferNode,name,511);
|
||||
oldWrite = SCGetWriteFunc(pCon);
|
||||
SCSetWriteFunc(pCon,SCHdbWrite);
|
||||
SCPushContext2(pCon,cc);
|
||||
SCSetWriteFunc(conCon,SCHdbWrite);
|
||||
self->exeStackPtr++;
|
||||
self->runCon = conCon;
|
||||
DynarPut(self->exeStack,self->exeStackPtr,buffer);
|
||||
status = exeBufProcess(buffer,pSics,pCon,self->pCall,self->echo);
|
||||
status = exeBufProcess(buffer,pSics,conCon,self->pCall,self->echo);
|
||||
self->exeStackPtr--;
|
||||
SCSetWriteFunc(pCon,oldWrite);
|
||||
SCPopContext(pCon);
|
||||
self->runCon = NULL;
|
||||
SCDeleteConnection(conCon);
|
||||
return status;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
@ -519,6 +528,9 @@ typedef struct {
|
||||
/*------------------------------------------------------------------*/
|
||||
static void killExeInfo(void *pData){
|
||||
pExeInfo self = (pExeInfo)pData;
|
||||
if(self->pCon != NULL){
|
||||
SCDeleteConnection(self->pCon);
|
||||
}
|
||||
if(self != NULL){
|
||||
free(self);
|
||||
}
|
||||
@ -533,32 +545,41 @@ static pExeInfo makeExeInfo(SConnection *pCon, pExeMan self){
|
||||
eError);
|
||||
return NULL;
|
||||
}
|
||||
pNew->pCon = pCon;
|
||||
memset(pNew,0,sizeof(exeInfo));
|
||||
pNew->pCon = SCCopyConnection(pCon);
|
||||
if(pNew->pCon == NULL){
|
||||
SCWrite(pCon,
|
||||
"ERROR: failed to allocate info structure for registering callbacks",
|
||||
eError);
|
||||
return NULL;
|
||||
}
|
||||
pNew->exe = self;
|
||||
return pNew;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int BufferCallback(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc){
|
||||
static int BufferCallback(int iEvent, void *pEvent, void *pUser){
|
||||
pExeInfo self = (pExeInfo)pUser;
|
||||
char *name = (char *)pEvent;
|
||||
char pBueffel[132];
|
||||
|
||||
if(!SCisConnected(self->pCon)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(iEvent == BATCHSTART){
|
||||
snprintf(pBueffel,131,"BATCHSTART=%s",name);
|
||||
SCWriteInContext(self->pCon,pBueffel,eWarning,cc);
|
||||
SCWrite(self->pCon,pBueffel,eLog);
|
||||
return 1;
|
||||
}
|
||||
if(iEvent == BATCHEND){
|
||||
snprintf(pBueffel,131,"BATCHEND=%s",name);
|
||||
SCWriteInContext(self->pCon,pBueffel,eWarning,cc);
|
||||
SCWrite(self->pCon,pBueffel,eLog);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int LineCallBack(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc){
|
||||
static int LineCallBack(int iEvent, void *pEvent, void *pUser){
|
||||
pExeInfo self = (pExeInfo)pUser;
|
||||
char pBueffel[256];
|
||||
int start, end, lineno;
|
||||
@ -566,6 +587,11 @@ static int LineCallBack(int iEvent, void *pEvent, void *pUser,
|
||||
pExeBuf buf = NULL;
|
||||
|
||||
assert(self);
|
||||
|
||||
if(!SCisConnected(self->pCon)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(iEvent == BATCHAREA){
|
||||
DynarGet(self->exe->exeStack,self->exe->exeStackPtr,&pPtr);
|
||||
buf = (pExeBuf)pPtr;
|
||||
@ -573,7 +599,7 @@ static int LineCallBack(int iEvent, void *pEvent, void *pUser,
|
||||
exeBufRange(buf,&start,&end,&lineno);
|
||||
snprintf(pBueffel,255,"%s.range = %d = %d",exeBufName(buf),
|
||||
start,end);
|
||||
SCWriteInContext(self->pCon,pBueffel,eWarning,cc);
|
||||
SCWrite(self->pCon,pBueffel,eLog);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -588,15 +614,12 @@ static void registerCallbacks(SConnection *pCon, SicsInterp *pSics,
|
||||
if(info == NULL){
|
||||
return;
|
||||
}
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),BATCHSTART, BufferCallback,
|
||||
lID = RegisterCallback(self->pCall,BATCHSTART, BufferCallback,
|
||||
info, killExeInfo);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),BATCHEND, BufferCallback,
|
||||
lID = RegisterCallback(self->pCall, BATCHEND, BufferCallback,
|
||||
info, NULL);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),BATCHAREA, LineCallBack,
|
||||
lID = RegisterCallback(self->pCall, BATCHAREA, LineCallBack,
|
||||
info, NULL);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static void unregisterCallbacks(SConnection *pCon, pExeMan self){
|
||||
@ -607,7 +630,6 @@ static void unregisterCallbacks(SConnection *pCon, pExeMan self){
|
||||
lID = SCgetCallbackID(pCon,self->pCall);
|
||||
if(lID >= 0){
|
||||
RemoveCallback(self->pCall,lID);
|
||||
SCUnregisterID(pCon,lID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1148,7 +1170,7 @@ static int execQueue(pExeMan self, SConnection *pCon, SicsInterp *pSics){
|
||||
pExeBuf buf = NULL;
|
||||
int status;
|
||||
|
||||
if(self->exeStackPtr >= 0){
|
||||
if(self->exeStackPtr >= 0 || (self->runCon != NULL && self->runCon != pCon) ){
|
||||
SCWrite(pCon,
|
||||
"ERROR: cannot start queue while batch buffers are still running",eError);
|
||||
return 0;
|
||||
@ -1157,6 +1179,7 @@ static int execQueue(pExeMan self, SConnection *pCon, SicsInterp *pSics){
|
||||
return 0;
|
||||
}
|
||||
|
||||
self->runCon = pCon;
|
||||
while(LLDnodePtr2First(self->runList) != 0){
|
||||
LLDnodeDataTo(self->runList,&buf);
|
||||
LLDnodeDelete(self->runList);
|
||||
@ -1164,6 +1187,7 @@ static int execQueue(pExeMan self, SConnection *pCon, SicsInterp *pSics){
|
||||
if(buf == NULL){
|
||||
SCWrite(pCon,
|
||||
"ERROR: serious trouble, buffer not in queue, inform programmer",eError);
|
||||
self->runCon = NULL;
|
||||
return 0;
|
||||
}
|
||||
DynarPut(self->exeStack,self->exeStackPtr,buf);
|
||||
@ -1171,9 +1195,11 @@ static int execQueue(pExeMan self, SConnection *pCon, SicsInterp *pSics){
|
||||
self->exeStackPtr--;
|
||||
if(SCGetInterrupt(pCon) >= eAbortBatch){
|
||||
SCWrite(pCon,"ERROR: queue processing interrupted",eError);
|
||||
self->runCon = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
self->runCon = 0;
|
||||
return 1;
|
||||
}
|
||||
/*========================== interpreter action =======================*/
|
||||
@ -1280,7 +1306,7 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}else if(strcmp(argv[1],"clear") == 0){
|
||||
clearQueue(self);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
return 1;
|
||||
}else if(strcmp(argv[1],"queue") == 0){
|
||||
printQueue(self,pCon);
|
||||
SCSendOK(pCon);
|
||||
|
Reference in New Issue
Block a user