- Cleaned all old dtatus setting code

This commit is contained in:
2014-07-18 14:02:57 +02:00
parent 6a47bd9441
commit f5e797dd6a
17 changed files with 14 additions and 93 deletions

View File

@ -1521,8 +1521,6 @@ int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen)
SCWrite(pCon, pPrompt, eWarning);
master = SCfindMaster(pCon);
eOld = GetStatus();
SetStatus(eInput);
CostaUnlock(master->pStack);
while (1) {
/*
@ -1542,14 +1540,12 @@ int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen)
/* do we have data ? */
iRet = CostaPop(master->pStack, &pPtr);
if (iRet == 1) {
SetStatus(eOld);
CostaLock(master->pStack);
strlcpy(pResult, pPtr, iLen);
WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr);
return 1;
}
}
SetStatus(eOld);
CostaLock(master->pStack);
return 0;
}
@ -1570,8 +1566,6 @@ int SCPromptTMO(SConnection * pCon, char *pPrompt, char *pResult, int iLen, int
SCWrite(pCon, pPrompt, eWarning);
master = SCfindMaster(pCon);
eOld = GetStatus();
SetStatus(eInput);
CostaUnlock(master->pStack);
for(i = 0; i < timeout; i++) {
/*
@ -1591,14 +1585,12 @@ int SCPromptTMO(SConnection * pCon, char *pPrompt, char *pResult, int iLen, int
/* do we have data ? */
iRet = CostaPop(master->pStack, &pPtr);
if (iRet == 1) {
SetStatus(eOld);
CostaLock(master->pStack);
strlcpy(pResult, pPtr, iLen);
WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr);
return 1;
}
}
SetStatus(eOld);
CostaLock(master->pStack);
return 0;
}

View File

@ -409,8 +409,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
return 0;
}
eOld = GetStatus();
SetStatus(eCounting);
/* set Preset */
SetCounterPreset(self, fPreset);
@ -423,7 +421,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
iRet = StartDevice(GetExecutor(), self->name, self->pDes, self, pCon,
level, fPreset);
if (!iRet) {
SetStatus(eOld);
SCWrite(pCon, "Counting aborted", eError);
return 0;
}
@ -444,7 +441,6 @@ int DoCount(pCounter self, float fPreset, SConnection * pCon, int iBlock)
SCWrite(pCon, "Counting finished", eValue);
iRet = 1;
}
SetStatus(eOld);
return iRet;
}
/*-------------------------------------------------------------------------*/

View File

@ -295,7 +295,6 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes,
taskID = StartDriveTask(pData, pCon, name, fNew);
if(taskID > 0 && self->instStatus != eCounting){
self->instStatus = eDriving;
SetStatus(eDriving);
}
if(taskID > 0 && self->drivePrint == 1){
oldVal = pDrivInt->GetValue(pData, pCon);
@ -307,7 +306,6 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes,
taskID = StartCountTask(pData,pCon,name);
if(taskID > 0){
self->instStatus = eCounting;
SetStatus(eCounting);
}
} else {
SCPrintf(pCon,eLogError, "ERROR: type unkonw, cannot start %s", name);
@ -530,7 +528,6 @@ int PauseExecution(pExeList self)
if(IsCounting(self)){
TaskSignalGroup(self->pTask, IPAUSE, &interrupt, self->waitID);
TaskSignalGroup(self->pTask, IPAUSE, &interrupt, self->runID);
SetStatus(ePaused);
}
return 1;
@ -559,7 +556,6 @@ int ContinueExecution(pExeList self)
if(GetStatus() == ePaused){
TaskSignalGroup(self->pTask, CONTINUE, &interrupt, self->waitID);
TaskSignalGroup(self->pTask, CONTINUE, &interrupt, self->runID);
SetStatus(eCounting);
}
return 1;
}
@ -716,7 +712,6 @@ int Success(SConnection * pCon, SicsInterp * pSics, void *pData,
pExeList self = (pExeList)pData;
eOld = GetStatus();
SetStatus(eRunning);
if(argc > 1){
if(strcmp(argv[1],"RUNDRIVE") == 0){
@ -758,7 +753,6 @@ int Success(SConnection * pCon, SicsInterp * pSics, void *pData,
SCWrite(pCon, "Level done", eValue);
iRet = 1;
}
SetStatus(eEager);
return iRet;
}
/*-------------------------------------------------------------------------*/
@ -894,7 +888,6 @@ int DevExecTask(void *pData)
self->lTask = -1;
self->iRun = 0;
self->instStatus = eEager;
SetStatus(eEager);
/*
This is sort of unclean. Setting DEVERROR has to be done in the
device task function as it is the only one that knows about this.

13
drive.c
View File

@ -302,19 +302,16 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
/* interprete arguments as pairs name value and try to start */
SetStatus(eDriving);
for (i = 1; i < argc; i += 2) {
if (argv[i + 1] == NULL) {
snprintf(pBueffel, 511, "ERROR: no value found for driving %s", argv[i]);
SCWrite(pCon, pBueffel, eError);
SetStatus(eOld);
return 0;
}
iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget);
if (iRet == TCL_ERROR) {
SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError);
StopExe(GetExecutor(), "ALL");
SetStatus(eOld);
return 0;
}
iRet = Start2Run(pCon, pSics, argv[i], RUNDRIVE, dTarget);
@ -328,7 +325,6 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
SCWrite(pCon, pBueffel, eError);
StopExe(GetExecutor(), "ALL");
SetStatus(eOld);
return 0;
}
}
@ -351,17 +347,14 @@ int DriveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
sprintf(pBueffel, "Driving finished with problem");
SCWrite(pCon, pBueffel, eError);
ClearExecutor(GetExecutor());
SetStatus(eOld);
return 0;
} else if (iRet == DEVINT) {
sprintf(pBueffel, "ERROR: Driving Interrupted!");
SCWrite(pCon, pBueffel, eError);
ClearExecutor(GetExecutor());
SetStatus(eOld);
return 0;
}
SCWrite(pCon, "Driving finished sucessfully", eValue);
SetStatus(eOld);
return 1;
}
@ -399,19 +392,16 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
}
/* interprete arguments as pairs name value and try to start */
SetStatus(eDriving);
for (i = 1; i < argc; i += 2) {
if (argv[i + 1] == NULL) {
snprintf(pBueffel,511, "ERROR: no value found for driving %s", argv[i]);
SCWrite(pCon, pBueffel, eError);
SetStatus(eOld);
return 0;
}
iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget);
if (iRet == TCL_ERROR) {
SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError);
StopExe(GetExecutor(), "ALL");
SetStatus(eOld);
return 0;
}
iRet = Start2Run(pCon, pSics, argv[i], RUNRUN, dTarget);
@ -420,7 +410,6 @@ int RunWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
argv[i + 1]);
SCWrite(pCon, pBueffel, eError);
StopExe(GetExecutor(), "ALL");
SetStatus(eOld);
return 0;
}
}
@ -466,14 +455,12 @@ int MoveWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argv[i + 1] == NULL) {
snprintf(pBueffel,511, "ERROR: no value found for driving %s", argv[i]);
SCWrite(pCon, pBueffel, eError);
SetStatus(eOld);
return 0;
}
iRet = Tcl_GetDouble(tcl_interp, argv[i + 1], &dTarget);
if (iRet == TCL_ERROR) {
SCWrite(pCon, Tcl_GetStringResult(tcl_interp), eError);
StopExe(GetExecutor(), "ALL");
SetStatus(eOld);
return 0;
}
obj = FindCommandData(pSics,argv[i],NULL);

View File

@ -80,12 +80,9 @@ static long EVIDrive(void *pData, SConnection * pCon, float fVal)
assert(pCon);
if (self->runScript != NULL) {
savedStatus = GetStatus();
SetStatus(eBatch);
pTcl = InterpGetTcl(pServ->pSics);
snprintf(pBueffel, sizeof(pBueffel), "%s %f", self->runScript, fVal);
iRet = Tcl_Eval(pTcl, pBueffel);
SetStatus(savedStatus);
if (iRet != TCL_OK) {
SCPrintf(pCon, eError,
"ERROR: %s while processing runscript for %s",
@ -423,7 +420,6 @@ static int ErrPause(void *pData)
}
/* OK now, continue */
SetStatus(eEager);
self->iWarned = 0;
ContinueExecution(pExe);
return 1;

View File

@ -323,7 +323,6 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics,
DeleteDynString(command);
if (SCGetInterrupt(pCon) >= eAbortBatch) {
SCWrite(pCon, "ERROR: batch processing interrupted", eError);
SetStatus(eEager);
if (pCall != NULL) {
InvokeCallBack(pCall, BATCHEND, self->name);
}
@ -375,7 +374,6 @@ int exeBufProcessErrList(pExeBuf self, SicsInterp * pSics,
DeleteDynString(command);
if (SCGetInterrupt(pCon) >= eAbortBatch) {
SCWrite(pCon, "ERROR: batch processing interrupted", eError);
SetStatus(eEager);
return 0;
} else {
SCSetInterrupt(pCon, eContinue);

View File

@ -240,7 +240,6 @@ static int DriveTaskFunc(void *data)
} else {
ExeInterest(pServ->pExecutor,taskData->name, "finished with problem");
}
SetStatus(eEager);
return 0;
}
/*--------------------------------------------------------------------------*/
@ -370,16 +369,6 @@ static int CountTaskFunc(void *data)
assert(taskData != NULL);
status = taskData->pCount->CheckCountStatus(taskData->obj,taskData->pCon);
if(status == HWBusy) {
SetStatus(eCounting);
return 1;
} else if(status == HWNoBeam){
SetStatus(eOutOfBeam);
return 1;
} else if(status == HWPause){
SetStatus(ePaused);
return 1;
}
taskData->pCount->TransferData(taskData->obj, taskData->pCon);

View File

@ -474,8 +474,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData,
}
/* handle status first */
eOld = GetStatus();
SetStatus(eBatch);
SICSLogWrite("Evaluating in MacroFileEval", eValue);
SICSLogWrite(argv[1], eValue);
@ -500,7 +498,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData,
Tcl_DStringAppend(&command, pBueffel, -1);
pCom = Tcl_DStringValue(&command);
if (Tcl_CommandComplete(pCom)) {
SetStatus(eEager);
FirstWord(pCom, pBueffel);
if (FindCommand(pInter, pBueffel) != NULL) {
snprintf(pBueffel,sizeof(pBueffel)-1, "%s:%d>> %s", pFile, iLine, pCom);
@ -512,7 +509,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData,
iLine++;
}
iRet = Tcl_Eval(pTcl, pCom);
SetStatus(eBatch);
if (iRet != TCL_OK) {
/* write TCL error and check for total interrupt */
if (Tcl_GetVar(pTcl, SICSERROR, TCL_GLOBAL_ONLY) == NULL) { /* Tcl error */
@ -537,7 +533,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData,
fclose(fp);
Tcl_DStringFree(&command);
SCWrite(pCon, "ERROR: batch processing interrupted", eError);
SetStatus(eEager);
return 0;
} else {
SCSetInterrupt(pCon, eContinue);
@ -555,7 +550,6 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData,
/* clean up */
fclose(fp);
Tcl_DStringFree(&command);
SetStatus(eOld);
SCSendOK(pCon);
return 1;
}

View File

@ -318,20 +318,16 @@ static int isMultiMasterRunning(pCounter self, SConnection *pCon, int *status)
UpdateHipadabaPar(stopTime,MakeHdbInt(time(NULL)),pCon);
SecCounterSetError(self,"Master counter errror");
*status = HWBusy;
ClearFixedStatus(eCounting);
break;
case HWPause:
UpdateHipadabaPar(myStatus,MakeHdbText("paused"),pCon);
*status = HWPause;
SetStatusFixed(ePaused);
break;
case HWNoBeam:
UpdateHipadabaPar(myStatus,MakeHdbText("nobeam"),pCon);
*status = HWNoBeam;
SetStatusFixed(eOutOfBeam);
break;
default:
SetStatusFixed(eCounting);
*status = HWBusy;
UpdateHipadabaPar(myStatus,MakeHdbText("run"),pCon);
if (self->iCallbackCounter > 20) {
@ -414,7 +410,6 @@ static void multiEndCounting(pCounter self, SConnection *pCon)
InvokeCallBack(self->pCall, COUNTEND, NULL);
ReleaseCountLock(self->pCountInt);
MultiSecTransfer(self,pCon);
ClearFixedStatus(eEager);
}
/*-------------------------------------------------------------------------------------*/
@ -432,7 +427,6 @@ static int MultiSecStatus(void *pData, SConnection * pCon)
}
if(areSlavesRunning(self,pCon, &status)){
SetStatusFixed(eCounting);
return status;
}

View File

@ -458,14 +458,10 @@ int UserWait(SConnection * pCon, SicsInterp * pSics, void *pData,
return 1;
}
eOld = GetStatus();
SetStatus(eUserWait);
sWait.dFinish = DoubleTime() + (double)fVal;
sWait.iEnd = 0;
lID = TaskRegisterN(pTask,"wait", WaitTask, WaitSignal, NULL, &sWait, 1);
TaskWait(pTask, lID);
SetStatus(eOld);
if (SCGetInterrupt(pCon) != eContinue) {
TaskWait(pTask, lID); if (SCGetInterrupt(pCon) != eContinue) {
return 0;
} else {
return 1;

View File

@ -143,11 +143,17 @@ int SetSICSInterrupt(SConnection * pCon, SicsInterp * pSics, void *pData,
return 1;
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------
This method does nothing anymore. Status is now calculated from the state
of SICS and no longer explicitly set. I left the code in because I am to
lazy to find all use cases and eliminate them
M.K. 07/2014
--------------------------------------------------------------------------*/
int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
int iInt;
int iInt = 0;
char pBueffel[132];
assert(pCon);
@ -174,7 +180,7 @@ int SetSICSStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
/* actually do a job */
strtolower(argv[1]);
iInt = SetStatusFromText(argv[1]);
/* iInt = SetStatusFromText(argv[1]); */
if (iInt) {
SCSendOK(pCon);
return 1;

View File

@ -13,6 +13,10 @@
Reworked restore to keep parameters from uninitialized devices
Mark Koennecke, November 2007
Reworked to determine the status from the state of the machine rather then
from explicit sets on a global variable. Which caused trouble, trouble and more
trouble. Mark Koennecke, July 2015
Copyright:
Labor fuer Neutronenstreuung

View File

@ -27,19 +27,7 @@ typedef enum {
} Status;
/* for status display */
void SetStatus(Status eNew);
int SetStatusFromText(char *text);
void KillStatus(void *pData);
/**
* set a status and disallow any further changes to the status. This serves
* in order to prevent massive message flows to the client from status
* changes while processing synchronisation files
*/
void SetStatusFixed(Status eNew);
/**
* clear a fixed status again, status will be updated again.
*/
void ClearFixedStatus(Status eNew);
Status GetStatus(void);
void GetStatusText(char *buf, int iBufLen);

View File

@ -903,7 +903,6 @@ int ScanCount(pScanData self, int iPoint)
SCWrite(self->pCon, "ERROR: Cannot Count, Scan aborted", eLogError);
return 0;
}
SetStatus(eCounting);
/* wait for finish */
while(DevExecLevelRunning(pServ->pExecutor, RUNDRIVE)){
TaskYield(pServ->pTasker);

View File

@ -175,7 +175,6 @@ tryagain:
/*
first tell the remote server to backup
*/
SetStatusFixed(eBatch);
strcpy(pBueffel, "transact syncbackup");
if (syncFile != NULL) {
strcat(pBueffel, " ");
@ -187,7 +186,6 @@ tryagain:
NETClosePort(connection);
free(connection);
connection = NULL;
ClearFixedStatus(eEager);
if (try > 0)
goto tryagain;
SCWrite(pCon, "ERROR: Failed to contact main SICS server", eError);
@ -207,7 +205,6 @@ tryagain:
NETClosePort(connection);
free(connection);
connection = NULL;
ClearFixedStatus(eEager);
pServ->simMode = 1;
if (try > 0)
goto tryagain;
@ -247,7 +244,6 @@ tryagain:
internalCon = SCCreateDummyConnection(pSics);
if (internalCon == NULL) {
SCWrite(pCon, "ERROR: out of memory in sync", eError);
ClearFixedStatus(eEager);
return 0;
}
@ -258,7 +254,6 @@ tryagain:
}
test = InterpExecute(pSics, internalCon, pBueffel);
SCDeleteConnection(internalCon);
ClearFixedStatus(eEager);
if (test != 1) {
SCWrite(pCon, "ERROR: Failed to read sync information", eError);
return 0;

View File

@ -771,7 +771,6 @@ static int TASUBScanCount(pScanData self, int iPoint)
} else {
status = 1;
}
SetStatus(eOld);
return status;
}

5
velo.c
View File

@ -588,10 +588,7 @@ int VSGetLossCurrent(pVelSel self, SConnection * pCon, float *fLoss)
assert(self);
assert(pCon);
eOld = GetStatus();
SetStatus(eRunning);
iRet = self->pDriv->GetLossCurrent(self->pDriv, fLoss);
SetStatus(eOld);
if (!iRet) {
self->pDriv->GetError(self->pDriv, &iCode, pError, 131);
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: %s while trying to measure loss current",
@ -1161,9 +1158,7 @@ int VelSelAction(SConnection * pCon, SicsInterp * pSics, void *pData,
eError);
return 0;
}
SetStatus(eDriving);
iRet = VSSetTiltRot(self, pCon, fRot, fTilt);
SetStatus(eEager);
if (iRet) {
SCSendOK(pCon);
return 1;