- Added asynchronous IO code from ANSTO
- Added new ACT protocol - Extended sicshdbadapter to cover counters and status to put the status into Hipadaba - Fixes to napi5.c - Exe now supports hdbrun which allows to write output for a buffer into hdb node.
This commit is contained in:
144
exeman.c
144
exeman.c
@ -22,7 +22,9 @@
|
||||
#include "exebuf.h"
|
||||
#include "exeman.i"
|
||||
#include "exeman.h"
|
||||
|
||||
#include "sicshipadaba.h"
|
||||
#include "commandlog.h"
|
||||
#include "protocol.h"
|
||||
/*-------------------------------------------------------------------*/
|
||||
static void KillExeMan(void *data){
|
||||
pExeMan self = (pExeMan)data;
|
||||
@ -252,6 +254,134 @@ static int runBatchBuffer(pExeMan self, SConnection *pCon,
|
||||
return status;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static char bufferNode[512];
|
||||
|
||||
static int SCHdbWrite(SConnection *self, char *message, int outCode){
|
||||
pHdb node = NULL;
|
||||
char pBueffel[512];
|
||||
commandContext cc;
|
||||
hdbValue v;
|
||||
pDynString val = NULL;
|
||||
writeFunc defWrite = NULL;
|
||||
|
||||
|
||||
cc = SCGetContext(self);
|
||||
node = GetHipadabaNode(GetHipadabaRoot(),cc.deviceID);
|
||||
if(node == NULL || strstr(cc.deviceID,bufferNode) == NULL){
|
||||
/*
|
||||
* this means the deviceId is wrong and the output is for another
|
||||
* operation.
|
||||
*/
|
||||
defWrite = GetProtocolWriteFunc(self);
|
||||
if(defWrite == NULL){
|
||||
defWrite = SCNormalWrite;
|
||||
}
|
||||
defWrite(self,message,outCode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SCFileWrite(self,message,outCode);
|
||||
|
||||
if(SCinMacro(self) && (outCode != eError && outCode != eWarning) ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
v = MakeHdbText(strdup(""));
|
||||
GetHipadabaPar(node,&v,NULL);
|
||||
v.dataType = HIPTEXT;
|
||||
val = CreateDynString(128,128);
|
||||
if(val == NULL){
|
||||
WriteToCommandLog("INTERNAL ERROR>>",
|
||||
"No memory to append to log in SCHdbWrite");
|
||||
return 0;
|
||||
}
|
||||
if(v.v.text != NULL){
|
||||
DynStringConcat(val,v.v.text);
|
||||
if(strrchr(v.v.text,(int)'\n') == NULL && strlen(v.v.text) > 2){
|
||||
DynStringConcatChar(val,'\n');
|
||||
}
|
||||
}
|
||||
DynStringConcat(val,message);
|
||||
if(strrchr(message,(int)'\n') == NULL && strlen(message) > 2){
|
||||
DynStringConcatChar(val,'\n');
|
||||
}
|
||||
if(v.v.text != NULL){
|
||||
free(v.v.text);
|
||||
}
|
||||
v.v.text = GetCharArray(val);
|
||||
UpdateHipadabaPar(node,v,NULL);
|
||||
DeleteDynString(val);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int runHdbBuffer(pExeMan self, SConnection *pCon,
|
||||
SicsInterp *pSics, char *name){
|
||||
char pBueffel[512];
|
||||
pExeBuf buffer = NULL;
|
||||
pHdb node = NULL;
|
||||
hdbValue v;
|
||||
int status;
|
||||
commandContext cc;
|
||||
writeFunc oldWrite;
|
||||
|
||||
if(!SCMatchRights(pCon,usUser)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* clear log buffer
|
||||
*/
|
||||
snprintf(pBueffel,511,"%s/log",name);
|
||||
node = GetHipadabaNode(GetHipadabaRoot(),pBueffel);
|
||||
if(node == NULL){
|
||||
SCWrite(pCon,"ERROR: Hdb node not found or in wrong format",eError);
|
||||
return 0;
|
||||
}
|
||||
v = MakeHdbText(strdup(""));
|
||||
UpdateHipadabaPar(node,v,pCon);
|
||||
/*
|
||||
* prepare context
|
||||
*/
|
||||
cc = SCGetContext(pCon);
|
||||
strcpy(cc.deviceID, pBueffel);
|
||||
|
||||
/*
|
||||
* load commands into buffer
|
||||
*/
|
||||
snprintf(pBueffel,511,"%s/commands",name);
|
||||
node = GetHipadabaNode(GetHipadabaRoot(),pBueffel);
|
||||
if(node == NULL){
|
||||
SCWrite(pCon,"ERROR: Hdb node not found or in wrong format",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GetHipadabaPar(node,&v,pCon);
|
||||
if(v.dataType != HIPTEXT || v.v.text == NULL){
|
||||
SCWrite(pCon,"ERROR: Hdb node is of wrong type or contains no data",eError);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
buffer = exeBufCreate(name);
|
||||
if(!buffer){
|
||||
SCWrite(pCon,"ERROR: out of memory creating batch buffer",eError);
|
||||
return 0;
|
||||
}
|
||||
exeBufAppend(buffer,v.v.text);
|
||||
|
||||
strncpy(bufferNode,name,511);
|
||||
oldWrite = SCGetWriteFunc(pCon);
|
||||
SCSetWriteFunc(pCon,SCHdbWrite);
|
||||
SCPushContext2(pCon,cc);
|
||||
self->exeStackPtr++;
|
||||
DynarPut(self->exeStack,self->exeStackPtr,buffer);
|
||||
status = exeBufProcess(buffer,pSics,pCon,self->pCall,self->echo);
|
||||
self->exeStackPtr--;
|
||||
SCSetWriteFunc(pCon,oldWrite);
|
||||
SCPopContext(pCon);
|
||||
return status;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
int runExeBatchBuffer(void *pData, SConnection *pCon,
|
||||
SicsInterp *pSics, char *name){
|
||||
int status, oldEcho;
|
||||
@ -1090,10 +1220,20 @@ int ExeManagerWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
SCPrintf(pCon, eValue, "exe echo = %d", self->echo);
|
||||
}
|
||||
return 1;
|
||||
}else if(strcmp(argv[1],"runhdb") == 0){
|
||||
if (argc < 2) {
|
||||
SCWrite(pCon,"ERROR: require path to root of queue node",eError);
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
status = runHdbBuffer(self,pCon,pSics,argv[2]);
|
||||
if(self->exeStackPtr < 0){
|
||||
SCWrite(pCon,"EXE TERMINATED",eWarning);
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
status = runBatchBuffer(self,pCon,pSics,pBufferName);
|
||||
if(self->exeStackPtr < 0){
|
||||
SCWrite(pCon,"EXE TERMINATED",eWarning);
|
||||
SCWrite(pCon,"EXE TERMINATED",eWarning);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user