This is the first version of the newly refactored status code handling.
Status codes are now determined by a special task which inspects SICS for what is going on. Before this was a global variable which caused conflicts when multiple instances in the code tried to set it.
This commit is contained in:
167
status.c
167
status.c
@ -52,6 +52,9 @@
|
||||
#include "status.h"
|
||||
#include "interrupt.h"
|
||||
#include "sicshipadaba.h"
|
||||
#include "messagepipe.h"
|
||||
#include "scan.h"
|
||||
#include "exeman.h"
|
||||
#undef VALUECHANGE
|
||||
#define VALUECHANGE 2
|
||||
|
||||
@ -97,6 +100,8 @@ static char *iText[] = {
|
||||
static pICallBack pCall = NULL;
|
||||
static int fixed = 0;
|
||||
static Status eCode = eEager;
|
||||
static int userWait = 0;
|
||||
static double lastStatus = .0;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void KillStatus(void *pData)
|
||||
{
|
||||
@ -108,24 +113,35 @@ void KillStatus(void *pData)
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void SetStatus(Status eNew)
|
||||
{
|
||||
if (!fixed) {
|
||||
/* if (!fixed) {
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
This now only manages the userWait status
|
||||
*/
|
||||
if(eNew == eUserWait){
|
||||
userWait = 1;
|
||||
} else {
|
||||
if(userWait == 1){
|
||||
userWait = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void SetStatusFixed(Status eNew)
|
||||
{
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
fixed = 1;
|
||||
// if (eCode == eNew) {
|
||||
// return;
|
||||
// }
|
||||
// eCode = eNew;
|
||||
// InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
// fixed = 1;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -279,7 +295,9 @@ int ResetStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, "Insufficient authorisation to reset server", eError);
|
||||
return 0;
|
||||
}
|
||||
SetStatus(eEager);
|
||||
// SetStatus(eEager);
|
||||
eCode = eEager;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
SetInterrupt(eContinue);
|
||||
ClearExecutor(GetExecutor());
|
||||
SCsetMacro(pCon, 0);
|
||||
@ -337,3 +355,136 @@ int RedirectControl(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pOwner->sockHandle = pCon->sockHandle;
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------
|
||||
Message pipe based new status calculation code
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
static int DevexecStatusFunc(void *message, void *userData)
|
||||
{
|
||||
|
||||
int *status = (int *)message;
|
||||
|
||||
*status = GetDevExecInstStatus(pServ->pExecutor);
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------
|
||||
This must be identical to the definition in interface.c As this structure is only
|
||||
required in interface.c and here, I choose not to put it into an header file.
|
||||
-------------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int id;
|
||||
void *obj;
|
||||
pICountable pCount;
|
||||
SConnection *pCon;
|
||||
char *name;
|
||||
}CountTaskData;
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
static int CheckCountStatus(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
int testStatus;
|
||||
pTaskHead it;
|
||||
CountTaskData *countTask = NULL;
|
||||
|
||||
if(*status == eCounting){
|
||||
for(it = TaskIteratorStart(pServ->pTasker); it != NULL; it = TaskIteratorNext(it)){
|
||||
countTask = (CountTaskData *)GetTaskData(it);
|
||||
if(countTask != NULL && countTask->id == COUNTID){
|
||||
testStatus = countTask->pCount->CheckCountStatus(countTask->obj,pServ->dummyCon);
|
||||
if(testStatus == HWNoBeam){
|
||||
*status = eOutOfBeam;
|
||||
}
|
||||
if(testStatus == HWPause){
|
||||
*status = ePaused;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MPSTOP;
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static pScanData scan = NULL;
|
||||
static int CheckScan(void *message, void *userData)
|
||||
{
|
||||
char *scannames[] = {"xxxscan","iscan", NULL};
|
||||
unsigned int count = 0;
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(scan == NULL){
|
||||
while(scannames[count] != NULL){
|
||||
scan = FindCommandData(pServ->pSics, scannames[count],NULL);
|
||||
if(scan != NULL){
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(scan != NULL){
|
||||
if(isScanRunning(scan)){
|
||||
*status = eScanning;
|
||||
return MPCONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static int CheckExe(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(isBatchRunning()){
|
||||
*status = eBatch;
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*------------------------------------------------------------------------------*/
|
||||
static int CheckUserWait(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(isTaskRunning(pServ->pTasker,"wait")){
|
||||
*status = eUserWait;
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
static pMP statusPipe = NULL;
|
||||
|
||||
static void BuildStatusChain(void)
|
||||
{
|
||||
statusPipe = MakeMP();
|
||||
AppendMPFilter(statusPipe,DevexecStatusFunc,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckCountStatus,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckScan,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckExe,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckUserWait,NULL,NULL);
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
static int StatusTask(void *data)
|
||||
{
|
||||
int status = eEager;
|
||||
|
||||
MPprocess(statusPipe,&status);
|
||||
if(status != eCode && DoubleTime() > lastStatus + .1){
|
||||
eCode = status;
|
||||
lastStatus = DoubleTime();
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void InitStatus(void)
|
||||
{
|
||||
BuildStatusChain();
|
||||
TaskRegisterN(pServ->pTasker,"statustask",StatusTask, NULL, NULL, NULL,1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user