[dasher] DynamicFilter: HandleEvent to keep state in sync with BP_DASHER_PAUSED



commit ea510f3d6a7de99708295269d28563070240f629
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Sat Nov 20 19:00:48 2010 +0000

    DynamicFilter: HandleEvent to keep state in sync with BP_DASHER_PAUSED
    
    (otherwise, external changes could cause crash)
    Add CDasherInterfaceBase::GetActiveInput{Device,Method}.

 Src/DasherCore/DasherInterfaceBase.h      |    2 ++
 Src/DasherCore/DynamicFilter.cpp          |   25 ++++++++++++++++---------
 Src/DasherCore/DynamicFilter.h            |    2 ++
 Src/DasherCore/TwoButtonDynamicFilter.cpp |    1 +
 Src/DasherCore/TwoPushDynamicFilter.cpp   |    1 +
 5 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index b486c41..aaad70b 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -359,6 +359,8 @@ public:
   CDasherModule *RegisterModule(CDasherModule *pModule);
   CDasherModule *GetModule(ModuleID_t iID);
   CDasherModule *GetModuleByName(const std::string &strName);
+  CDasherInput *GetActiveInputDevice() {return m_pInput;}
+  CInputFilter *GetActiveInputMethod() {return m_pInputFilter;}
   void SetDefaultInputDevice(CDasherInput *);
   void SetDefaultInputMethod(CInputFilter *);
 
diff --git a/Src/DasherCore/DynamicFilter.cpp b/Src/DasherCore/DynamicFilter.cpp
index 0e44f98..95a0315 100644
--- a/Src/DasherCore/DynamicFilter.cpp
+++ b/Src/DasherCore/DynamicFilter.cpp
@@ -85,27 +85,23 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
   // 0 = ordinary click
   // 1 = long click
   
-  // First sanity check - if Dasher is paused then jump to the
-  // appropriate state
-  if(GetBoolParameter(BP_DASHER_PAUSED) && !isPaused())
-    pause();
-
   // TODO: Check that state diagram implemented here is what we
   // decided upon
 
   // What happens next depends on the state:
   if (isPaused()) {
-  //Any button causes a restart
+    //Any button causes a restart
     if(pUserLog)
       pUserLog->KeyDown(iButton, iType, 1);
-    m_pInterface->Unpause(iTime);
     run();
+    m_pInterface->Unpause(iTime);
   } else if (isReversing()) {
+    //Any button pauses
     if(pUserLog)
       pUserLog->KeyDown(iButton, iType, 2);
     
-    pause();
     m_pInterface->Stop();
+    //change in BP_DASHER_PAUSED calls pause().
   } else {
     //running; examine event/button-press type
     switch(iType) {
@@ -114,7 +110,6 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
         //dedicated pause button
         if(pUserLog)
           pUserLog->KeyDown(iButton, iType, 2);
-        pause();
         m_pInterface->Stop();
         break;
       }
@@ -132,6 +127,18 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
   }
 }
 
+void CDynamicFilter::HandleEvent(CEvent *pEvent) {
+  if (pEvent->m_iEventType==EV_PARAM_NOTIFY) {
+    if (static_cast<CParameterNotificationEvent *>(pEvent)->m_iParameter==BP_DASHER_PAUSED) {
+      if (GetBoolParameter(BP_DASHER_PAUSED))
+        pause(); //make sure we're in sync
+      else if (m_pInterface->GetActiveInputMethod()==this && isPaused())
+        //if we're active: can't unpause, as we don't know which way to go, run or reverse?
+        SetBoolParameter(BP_DASHER_PAUSED, true);
+    }
+  }
+}
+
 void CDynamicFilter::reverse()
 {
   m_iState = 1;
diff --git a/Src/DasherCore/DynamicFilter.h b/Src/DasherCore/DynamicFilter.h
index 509226c..ae54ffa 100644
--- a/Src/DasherCore/DynamicFilter.h
+++ b/Src/DasherCore/DynamicFilter.h
@@ -39,6 +39,8 @@ class CDynamicFilter : public CInputFilter {
   virtual void KeyDown(int iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel, CUserLogBase *pUserLog);
   virtual void KeyUp(int iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel);
 
+  //respond to changes to BP_DASHER_PAUSED to keep m_iState in sync
+  virtual void HandleEvent(CEvent *pEvent);
  protected:
   virtual void ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog) = 0;
   virtual void Event(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog);
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.cpp b/Src/DasherCore/TwoButtonDynamicFilter.cpp
index d85a14e..a792db9 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.cpp
+++ b/Src/DasherCore/TwoButtonDynamicFilter.cpp
@@ -211,4 +211,5 @@ void CTwoButtonDynamicFilter::HandleEvent(Dasher::CEvent *pEvent)
         m_bDecorationChanged = true;
     }
   }
+  CDynamicFilter::HandleEvent(pEvent);
 }
diff --git a/Src/DasherCore/TwoPushDynamicFilter.cpp b/Src/DasherCore/TwoPushDynamicFilter.cpp
index 89e3139..4ef4028 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.cpp
+++ b/Src/DasherCore/TwoPushDynamicFilter.cpp
@@ -102,6 +102,7 @@ bool CTwoPushDynamicFilter::DecorateView(CDasherView *pView, CDasherInput *pInpu
 
 void CTwoPushDynamicFilter::HandleEvent(Dasher::CEvent * pEvent)
 {
+  CDynamicFilter::HandleEvent(pEvent);
   if(pEvent->m_iEventType == EV_PARAM_NOTIFY)
   {
     Dasher::CParameterNotificationEvent * pEvt(static_cast < Dasher::CParameterNotificationEvent * >(pEvent));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]