- Reworked the connection object and the IO system
- Reworked the support for TRICS - Added a second generation motor
This commit is contained in:
76
statemon.c
76
statemon.c
@ -22,8 +22,7 @@ typedef struct __STATEMON {
|
||||
pICallBack pCall;
|
||||
}StateMon;
|
||||
/*============================ Callbacks =================================*/
|
||||
static int DevexecCallback(int iEvent, void *text, void *pData,
|
||||
commandContext cc){
|
||||
static int DevexecCallback(int iEvent, void *text, void *pData){
|
||||
char pDevice[132];
|
||||
int eventCode;
|
||||
pStateMon self = (pStateMon)pData;
|
||||
@ -47,8 +46,7 @@ typedef struct __STATEMON {
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int StateMonScanInterest(int iEvent, void *pEventData, void *pUser,
|
||||
commandContext cc){
|
||||
static int StateMonScanInterest(int iEvent, void *pEventData, void *pUser){
|
||||
pScanData pScan = NULL;
|
||||
pStateMon self = (pStateMon)pUser;
|
||||
|
||||
@ -69,8 +67,7 @@ static int StateMonScanInterest(int iEvent, void *pEventData, void *pUser,
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int ExeCallback(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc){
|
||||
static int ExeCallback(int iEvent, void *pEvent, void *pUser){
|
||||
pStateMon self = (pStateMon)pUser;
|
||||
char *name = (char *)pEvent;
|
||||
char pBueffel[131];
|
||||
@ -93,23 +90,26 @@ static int ExeCallback(int iEvent, void *pEvent, void *pUser,
|
||||
return 0;
|
||||
}
|
||||
/*=============== user callbacks ============================================*/
|
||||
static int StateInterest(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc){
|
||||
static int StateInterest(int iEvent, void *pEvent, void *pUser){
|
||||
SConnection *pCon = (SConnection *)pUser;
|
||||
char *device = (char *)pEvent;
|
||||
char buffer[256];
|
||||
|
||||
if(pCon == NULL || !SCisConnected(pCon)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(pCon == NULL || device == NULL){
|
||||
printf("Bad StateInterest in statemon\n");
|
||||
return 0;
|
||||
}
|
||||
if(iEvent == STSTART){
|
||||
snprintf(buffer,255,"STARTED = %s", device);
|
||||
SCWriteInContext(pCon,buffer,eWarning,cc);
|
||||
SCWrite(pCon,buffer,eWarning);
|
||||
}
|
||||
if(iEvent == STEND){
|
||||
snprintf(buffer,255,"FINISH = %s", device);
|
||||
SCWriteInContext(pCon,buffer,eWarning,cc);
|
||||
SCWrite(pCon,buffer,eWarning);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -172,14 +172,17 @@ static pHdb locateInterestNode(char *device){
|
||||
return recurseInterestNode(current,pDevice);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int StateHdbInterest(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc){
|
||||
static int StateHdbInterest(int iEvent, void *pEvent, void *pUser){
|
||||
SConnection *pCon = (SConnection *)pUser;
|
||||
char *device = (char *)pEvent, *path = NULL;
|
||||
char buffer[1024];
|
||||
pHdb node = NULL;
|
||||
|
||||
if(pCon == NULL || device == NULL){
|
||||
if(pCon == NULL || !SCisConnected(pCon)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(device == NULL){
|
||||
printf("Bad StateHdbInterest in statemon\n");
|
||||
return 0;
|
||||
}
|
||||
@ -188,11 +191,11 @@ static int StateHdbInterest(int iEvent, void *pEvent, void *pUser,
|
||||
path = GetHipadabaPath(node);
|
||||
if(iEvent == STSTART){
|
||||
snprintf(buffer,1024,"%s STARTED", path);
|
||||
SCWriteInContext(pCon,buffer,eWarning,cc);
|
||||
SCWrite(pCon,buffer,eWarning);
|
||||
}
|
||||
if(iEvent == STEND){
|
||||
snprintf(buffer,1024,"%s FINISH", path);
|
||||
SCWriteInContext(pCon,buffer,eWarning,cc);
|
||||
SCWrite(pCon,buffer,eWarning);
|
||||
}
|
||||
if(path != NULL){
|
||||
free(path);
|
||||
@ -254,11 +257,11 @@ int StateMonFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
*/
|
||||
target = GetCallbackInterface(pDevexec);
|
||||
assert(target != NULL);
|
||||
RegisterCallback(target,cc,DRIVSTAT,DevexecCallback,pNew,NULL);
|
||||
RegisterCallback(target,DRIVSTAT,DevexecCallback,pNew,NULL);
|
||||
target = GetCallbackInterface(exe);
|
||||
assert(target != NULL);
|
||||
RegisterCallback(target,cc,BATCHSTART,ExeCallback,pNew,NULL);
|
||||
RegisterCallback(target,cc,BATCHEND,ExeCallback,pNew,NULL);
|
||||
RegisterCallback(target,BATCHSTART,ExeCallback,pNew,NULL);
|
||||
RegisterCallback(target,BATCHEND,ExeCallback,pNew,NULL);
|
||||
|
||||
if(argc > 1) {
|
||||
pPtr = FindCommandData(pSics,argv[1],"ScanObject");
|
||||
@ -267,13 +270,10 @@ int StateMonFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
} else {
|
||||
target = GetCallbackInterface(pPtr);
|
||||
assert(target != NULL);
|
||||
RegisterCallback(target,cc,SCANSTART,StateMonScanInterest,pNew,NULL);
|
||||
RegisterCallback(target,cc,SCANEND,StateMonScanInterest,pNew,NULL);
|
||||
RegisterCallback(target,SCANSTART,StateMonScanInterest,pNew,NULL);
|
||||
RegisterCallback(target,SCANEND,StateMonScanInterest,pNew,NULL);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* TODO: add kill functions
|
||||
*/
|
||||
AddCommand(pSics,"statemon",StateMonAction,killStateMon,pNew);
|
||||
return 1;
|
||||
}
|
||||
@ -283,6 +283,7 @@ int StateMonAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
long lID;
|
||||
int i;
|
||||
pStateMon self = NULL;
|
||||
SConnection *callCon = NULL;
|
||||
|
||||
self = (pStateMon)pData;
|
||||
assert(self != NULL);
|
||||
@ -293,11 +294,16 @@ int StateMonAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"interest") == 0){
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),STSTART, StateInterest,
|
||||
pCon, NULL);
|
||||
callCon = SCCopyConnection(pCon);
|
||||
if(callCon == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory registering interest",eError);
|
||||
return 0;
|
||||
}
|
||||
lID = RegisterCallback(self->pCall, STSTART, StateInterest,
|
||||
callCon, SCDeleteConnection);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),STEND, StateInterest,
|
||||
pCon, NULL);
|
||||
lID = RegisterCallback(self->pCall, STEND, StateInterest,
|
||||
callCon, NULL);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
@ -306,18 +312,20 @@ int StateMonAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
lID = SCgetCallbackID(pCon,self->pCall);
|
||||
if(lID >= 0){
|
||||
RemoveCallback(self->pCall,lID);
|
||||
SCUnregisterID(pCon,lID);
|
||||
}
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else if(strcmp(argv[1],"hdbinterest") == 0){
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),STSTART, StateHdbInterest,
|
||||
pCon, NULL);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
lID = RegisterCallback(self->pCall, SCGetContext(pCon),STEND, StateHdbInterest,
|
||||
pCon, NULL);
|
||||
SCRegister(pCon,pSics, self->pCall,lID);
|
||||
callCon = SCCopyConnection(pCon);
|
||||
if(callCon == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory registering interest",eError);
|
||||
return 0;
|
||||
}
|
||||
lID = RegisterCallback(self->pCall, STSTART, StateHdbInterest,
|
||||
callCon, SCDeleteConnection);
|
||||
lID = RegisterCallback(self->pCall, STEND, StateHdbInterest,
|
||||
callCon, NULL);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else if(strcmp(argv[1],"start") == 0) {
|
||||
|
Reference in New Issue
Block a user