From 6ed6e5e6cbcba6a2c2fe6544dae75872c326c870 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 25 May 2007 16:17:44 +1000 Subject: [PATCH] Make motor uninterest work by using RemoveCallback3 and a custom function to check that the pCon is the correct one. Remove any prior interest for this motor and pCon before installing the new one. Limits the interest callback message count to one. r1987 | dcl | 2007-05-25 16:17:44 +1000 (Fri, 25 May 2007) | 3 lines --- motor.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/motor.c b/motor.c index 78eae618..c136d758 100644 --- a/motor.c +++ b/motor.c @@ -1180,6 +1180,16 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray); iRet = Tcl_Eval(pServ->pSics->pTcl,pCommand); return iRet; } + +static int CheckMotiMatch(const void* context, const void* pUserData) +{ + pMotInfo pMoti = (pMotInfo) pUserData; + SConnection *pCon = (SConnection*) context; + if (pMoti->pCon == pCon) + return 0; + return 1; +} + /*---------------------------------------------------------------------------- The wrapper function for a motor. Commands currently supported are: @@ -1280,6 +1290,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray); } pMoti->lastValue = fValue; + RemoveCallback3(self->pCall, InterestCallback, CheckMotiMatch, pCon); /* only this one */ lID = RegisterCallback(self->pCall, SCGetContext(pCon),MOTDRIVE, InterestCallback, pMoti, KillInfo); SCRegister(pCon,pSics, self->pCall,lID); @@ -1289,7 +1300,7 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray); } else if(strcmp(pCurrent->text,"uninterest") == 0) { - RemoveCallback2(self->pCall,pCon); + RemoveCallback3(self->pCall, InterestCallback, CheckMotiMatch, pCon); SCSendOK(pCon); DeleteTokenList(pList); return 1;