- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
538
status.c
538
status.c
@ -55,291 +55,285 @@
|
||||
#undef VALUECHANGE
|
||||
#define VALUECHANGE 2
|
||||
|
||||
|
||||
static char *pText[] = {
|
||||
"Eager to execute commands",
|
||||
"User requested Wait",
|
||||
"Counting",
|
||||
"No Beam",
|
||||
"Paused",
|
||||
"Driving",
|
||||
"Running",
|
||||
"Running a scan",
|
||||
"Writing data",
|
||||
"Processing a batch file",
|
||||
"Halted",
|
||||
"Dead",
|
||||
"Waiting for User Input",
|
||||
"Counting/Driving",
|
||||
"Working",
|
||||
NULL };
|
||||
|
||||
static char *iText[] = {
|
||||
"eager",
|
||||
"userwait",
|
||||
"count",
|
||||
"nobeam",
|
||||
"paused",
|
||||
"driving",
|
||||
"running",
|
||||
"scanning",
|
||||
"writing",
|
||||
"batch",
|
||||
"halt",
|
||||
"dead",
|
||||
"input",
|
||||
"count/drive",
|
||||
"working",
|
||||
NULL };
|
||||
|
||||
static pICallBack pCall = NULL;
|
||||
static int fixed = 0;
|
||||
static Status eCode = eEager;
|
||||
static char *pText[] = {
|
||||
"Eager to execute commands",
|
||||
"User requested Wait",
|
||||
"Counting",
|
||||
"No Beam",
|
||||
"Paused",
|
||||
"Driving",
|
||||
"Running",
|
||||
"Running a scan",
|
||||
"Writing data",
|
||||
"Processing a batch file",
|
||||
"Halted",
|
||||
"Dead",
|
||||
"Waiting for User Input",
|
||||
"Counting/Driving",
|
||||
"Working",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *iText[] = {
|
||||
"eager",
|
||||
"userwait",
|
||||
"count",
|
||||
"nobeam",
|
||||
"paused",
|
||||
"driving",
|
||||
"running",
|
||||
"scanning",
|
||||
"writing",
|
||||
"batch",
|
||||
"halt",
|
||||
"dead",
|
||||
"input",
|
||||
"count/drive",
|
||||
"working",
|
||||
NULL
|
||||
};
|
||||
|
||||
static pICallBack pCall = NULL;
|
||||
static int fixed = 0;
|
||||
static Status eCode = eEager;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void KillStatus(void *pData)
|
||||
{
|
||||
if(pCall != NULL)
|
||||
{
|
||||
DeleteCallBackInterface(pCall);
|
||||
}
|
||||
}
|
||||
void KillStatus(void *pData)
|
||||
{
|
||||
if (pCall != NULL) {
|
||||
DeleteCallBackInterface(pCall);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void SetStatus(Status eNew)
|
||||
{
|
||||
if(!fixed)
|
||||
{
|
||||
if(eCode == eNew)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall,VALUECHANGE,NULL);
|
||||
}
|
||||
}
|
||||
void SetStatus(Status eNew)
|
||||
{
|
||||
if (!fixed) {
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void SetStatusFixed(Status eNew)
|
||||
{
|
||||
if(eCode == eNew)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall,VALUECHANGE,NULL);
|
||||
fixed = 1;
|
||||
}
|
||||
void SetStatusFixed(Status eNew)
|
||||
{
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
fixed = 1;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void ClearFixedStatus(Status eNew)
|
||||
{
|
||||
if(eCode == eNew)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall,VALUECHANGE,NULL);
|
||||
fixed = 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
Status GetStatus(void)
|
||||
{
|
||||
return eCode;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void GetStatusText(char *buf, int iBufLen)
|
||||
{
|
||||
strncpy(buf,pText[(int)eCode],iBufLen-1);
|
||||
}
|
||||
void ClearFixedStatus(Status eNew)
|
||||
{
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
fixed = 0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int SetStatusFromText(char *text)
|
||||
{
|
||||
int i = 0;
|
||||
Status GetStatus(void)
|
||||
{
|
||||
return eCode;
|
||||
}
|
||||
|
||||
/* check for short form */
|
||||
strtolower(text);
|
||||
while(iText[i] != NULL)
|
||||
{
|
||||
if(strcmp(text,iText[i]) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void GetStatusText(char *buf, int iBufLen)
|
||||
{
|
||||
strncpy(buf, pText[(int) eCode], iBufLen - 1);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int SetStatusFromText(char *text)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* check for short form */
|
||||
strtolower(text);
|
||||
while (iText[i] != NULL) {
|
||||
if (strcmp(text, iText[i]) == 0) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i >= 10) {
|
||||
/* check for long form */
|
||||
i = 0;
|
||||
while (pText[i] != NULL) {
|
||||
if (strcmp(text, pText[i]) == 0) {
|
||||
break;
|
||||
}
|
||||
if(i >= 10)
|
||||
{
|
||||
/* check for long form */
|
||||
i = 0;
|
||||
while(pText[i] != NULL)
|
||||
{
|
||||
if(strcmp(text,pText[i]) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(i >= 10)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
SetStatus((Status)i);
|
||||
i++;
|
||||
}
|
||||
if (i >= 10) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
SetStatus((Status) i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int StatusCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
SConnection *pCon;
|
||||
char pBueffel[80];
|
||||
|
||||
assert(pUser);
|
||||
|
||||
pCon = (SConnection *) pUser;
|
||||
if (pCon == NULL || !SCisConnected(pCon)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(pBueffel, "status = %s", pText[(int) eCode]);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int StatusHDBCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
pHdb node = NULL;
|
||||
hdbValue v;
|
||||
|
||||
assert(pUser);
|
||||
|
||||
node = (pHdb) pUser;
|
||||
v = MakeHdbText(pText[eCode]);
|
||||
if (node != NULL && iEvent == VALUECHANGE) {
|
||||
UpdateHipadabaPar(node, v, NULL);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int UserStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pBueffel[512];
|
||||
long lID;
|
||||
pHdb node = NULL;
|
||||
|
||||
assert(pSics);
|
||||
assert(pCon);
|
||||
|
||||
/* create callback if not present */
|
||||
if (pCall == NULL) {
|
||||
pCall = CreateCallBackInterface();
|
||||
}
|
||||
|
||||
/* check for interest */
|
||||
if (argc > 1) {
|
||||
strtolower(argv[1]);
|
||||
if (strcmp(argv[1], "interest") == 0) {
|
||||
lID = RegisterCallback(pCall,
|
||||
VALUECHANGE, StatusCallback,
|
||||
SCCopyConnection(pCon), SCDeleteConnection);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int StatusCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
SConnection *pCon;
|
||||
char pBueffel[80];
|
||||
|
||||
assert(pUser);
|
||||
|
||||
pCon = (SConnection *)pUser;
|
||||
if(pCon == NULL || !SCisConnected(pCon))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(pBueffel,"status = %s", pText[(int)eCode]);
|
||||
SCWrite(pCon,pBueffel,eLog);
|
||||
return 1;
|
||||
}
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int StatusHDBCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
pHdb node = NULL;
|
||||
hdbValue v;
|
||||
|
||||
assert(pUser);
|
||||
|
||||
node = (pHdb)pUser;
|
||||
v = MakeHdbText(pText[eCode]);
|
||||
if(node != NULL && iEvent == VALUECHANGE){
|
||||
UpdateHipadabaPar(node,v,NULL);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int UserStatus(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pBueffel[512];
|
||||
long lID;
|
||||
pHdb node = NULL;
|
||||
|
||||
assert(pSics);
|
||||
assert(pCon);
|
||||
|
||||
/* create callback if not present */
|
||||
if(pCall == NULL)
|
||||
{
|
||||
pCall = CreateCallBackInterface();
|
||||
}
|
||||
|
||||
/* check for interest */
|
||||
if(argc > 1)
|
||||
{
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"interest") == 0)
|
||||
{
|
||||
lID = RegisterCallback(pCall,
|
||||
VALUECHANGE, StatusCallback,
|
||||
SCCopyConnection(pCon), SCDeleteConnection);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(argv[1],"hdbinterest") == 0)
|
||||
{
|
||||
if(argc > 2){
|
||||
node = GetHipadabaNode(GetHipadabaRoot(),argv[2]);
|
||||
if(node != NULL){
|
||||
lID = RegisterCallback(pCall,
|
||||
VALUECHANGE, StatusHDBCallback,
|
||||
node, NULL);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: Hipadaba node not found",eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if (strcmp(argv[1], "hdbinterest") == 0) {
|
||||
if (argc > 2) {
|
||||
node = GetHipadabaNode(GetHipadabaRoot(), argv[2]);
|
||||
if (node != NULL) {
|
||||
lID = RegisterCallback(pCall,
|
||||
VALUECHANGE, StatusHDBCallback,
|
||||
node, NULL);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: require node parameter to register status callback",
|
||||
eError);
|
||||
return 0;
|
||||
SCWrite(pCon, "ERROR: Hipadaba node not found", eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* else just print value */
|
||||
sprintf(pBueffel,"status = %s", pText[(int)eCode]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int ResetStatus(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
} else {
|
||||
SCWrite(pCon,
|
||||
"ERROR: require node parameter to register status callback",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* else just print value */
|
||||
sprintf(pBueffel, "status = %s", pText[(int) eCode]);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int ResetStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
|
||||
if (!SCMatchRights(pCon, usUser)) {
|
||||
SCWrite(pCon, "Insufficient authorisation to reset server", eError);
|
||||
return 0;
|
||||
}
|
||||
SetStatus(eEager);
|
||||
SetInterrupt(eContinue);
|
||||
ClearExecutor(GetExecutor());
|
||||
SCsetMacro(pCon, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ===================== Control Connection Management ====================*/
|
||||
static SConnection *pOwner = NULL;
|
||||
|
||||
void SetControl(SConnection * pCon)
|
||||
{
|
||||
pOwner = pCon;
|
||||
}
|
||||
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
{
|
||||
SCWrite(pCon,"Insufficient authorisation to reset server",eError);
|
||||
return 0;
|
||||
}
|
||||
SetStatus(eEager);
|
||||
SetInterrupt(eContinue);
|
||||
ClearExecutor(GetExecutor());
|
||||
SCsetMacro(pCon,0);
|
||||
return 1;
|
||||
}
|
||||
/* ===================== Control Connection Management ====================*/
|
||||
static SConnection *pOwner = NULL;
|
||||
|
||||
void SetControl(SConnection *pCon)
|
||||
{
|
||||
pOwner = pCon;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int IsControl(SConnection *pCon)
|
||||
{
|
||||
if(pCon == pOwner)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
SConnection *GetControl(void)
|
||||
{
|
||||
return pOwner;
|
||||
}
|
||||
int IsControl(SConnection * pCon)
|
||||
{
|
||||
if (pCon == pOwner) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int RedirectControl(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
|
||||
/* check user Rights */
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"You have NO, I repeat NO, Privilege to grab a control connection",
|
||||
SConnection *GetControl(void)
|
||||
{
|
||||
return pOwner;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int RedirectControl(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
assert(pCon);
|
||||
assert(pSics);
|
||||
|
||||
/* check user Rights */
|
||||
if (!SCMatchRights(pCon, usUser)) {
|
||||
SCWrite(pCon,
|
||||
"You have NO, I repeat NO, Privilege to grab a control connection",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if the connection is dead at all */
|
||||
if(pCon->sockHandle < 0)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"GOTCHA!!! Control still lives! You CANNOT grab it! FUCK OFF",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* now the wizardry */
|
||||
pOwner->sockHandle = pCon->sockHandle;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if the connection is dead at all */
|
||||
if (pCon->sockHandle < 0) {
|
||||
SCWrite(pCon,
|
||||
"GOTCHA!!! Control still lives! You CANNOT grab it! FUCK OFF",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* now the wizardry */
|
||||
pOwner->sockHandle = pCon->sockHandle;
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user