IGSTK
/tmp/buildd/igstk-4.4.0/Source/igstkPulseGenerator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Image Guided Surgery Software Toolkit
00004   Module:    $RCSfile: igstkPulseGenerator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-02-11 01:41:51 $
00007   Version:   $Revision: 1.21 $
00008 
00009   Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
00010   See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __igstkPulseGenerator_h
00019 #define __igstkPulseGenerator_h
00020 
00021 
00022 #include "igstkObject.h"
00023 #include "igstkMacros.h"
00024 #include "igstkStateMachine.h"
00025 
00026 
00027 namespace igstk
00028 {
00049 class PulseGenerator  : public Object
00050 {
00051  
00052 public: 
00053 
00055   igstkStandardClassTraitsMacro( PulseGenerator, Object )
00056 
00057 public:
00058 
00062   void RequestSetFrequency( double frequency );
00063 
00067   void RequestStart();
00068 
00071   void RequestStop();
00072 
00074   igstkGetMacro( Frequency, double );
00075       
00078   static void CheckTimeouts();
00079 
00081   static void Sleep( unsigned int milliseconds );
00082 
00083 protected:
00084 
00087   PulseGenerator(void);
00088 
00089   virtual ~PulseGenerator(void);
00090 
00092   virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
00093 
00094 private:
00095 
00099   double          m_Frequency;
00100   double          m_FrequencyToBeSet;
00101   double          m_Period; // helper varable = 1 / frequency
00102 
00104   igstkDeclareInputMacro( ValidFrequency );
00105   igstkDeclareInputMacro( InvalidLowFrequency );
00106   igstkDeclareInputMacro( InvalidHighFrequency );
00107   igstkDeclareInputMacro( Stop );
00108   igstkDeclareInputMacro( Start );
00109   igstkDeclareInputMacro( Pulse );
00110   igstkDeclareInputMacro( EventReturn );
00111 
00113   igstkDeclareStateMacro( Initial );
00114   igstkDeclareStateMacro( Stopped );
00115   igstkDeclareStateMacro( Pulsing );
00116   igstkDeclareStateMacro( WaitingEventReturn );
00117 
00119   void SetFrequencyProcessing();
00120   
00122   void ReportErrorConditionProcessing();
00123 
00127   void ReportMissedPulseProcessing();
00128 
00131   static double   m_MaximumFrequency;
00132 
00134   static void CallbackTimerGlobal( void * );
00135 
00137   void CallbackTimer();
00138 
00141   void SetTimerProcessing();
00142 
00144   void EmitPulseProcessing();
00145 
00147   void StopPulsesProcessing();
00148 
00150   void NoProcessing();
00151 
00152 
00153 private:
00154 
00157   struct Timeout 
00158     {
00159     double time;
00160     void (*cb)(void*);
00161     void* arg;
00162     Timeout* next;
00163     };
00164 
00165   typedef void (*TimeoutHandler)(void*);
00166 
00167   static void AddTimeout(double time, TimeoutHandler cb, void* data);
00168 
00169   static void RepeatTimeout(double time, TimeoutHandler cb, void *argp);
00170 
00171   static void RemoveTimeout( TimeoutHandler cb, void *argp);
00172 
00173   static void ElapseTimeouts();
00174 
00175   static void InvokeTimeoutActions();
00176 
00177 
00178   static double       m_PreviousClock;
00179 
00180   static Timeout *    m_FirstTimeout;
00181 
00182   static Timeout *    m_FreeTimeout;
00183 
00184   static unsigned int m_FreeTimeoutCount;
00185 
00186   static unsigned int m_NumberOfPulseGenerators;
00187 
00188   mutable itk::SimpleFastMutexLock m_NumberOfPulseGeneratorsLock;
00189 
00190   static char         m_ResetClock;
00191   
00192   static double       m_MissedTimeoutBy;
00193 
00194 };
00195 
00196 } // end of namespace igstk
00197 
00198 #endif //__igstk_PulseGenerator_h_