IGSTK
igstkPulseGenerator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkPulseGenerator.h,v $
5  Language: C++
6  Date: $Date: 2008-02-11 01:41:51 $
7  Version: $Revision: 1.21 $
8 
9  Copyright (c) ISC Insight Software Consortium. All rights reserved.
10  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __igstkPulseGenerator_h
19 #define __igstkPulseGenerator_h
20 
21 
22 #include "igstkObject.h"
23 #include "igstkMacros.h"
24 #include "igstkStateMachine.h"
25 
26 
27 namespace igstk
28 {
49 class PulseGenerator : public Object
50 {
51 
52 public:
53 
56 
57 public:
58 
62  void RequestSetFrequency( double frequency );
63 
67  void RequestStart();
68 
71  void RequestStop();
72 
74  igstkGetMacro( Frequency, double );
75 
78  static void CheckTimeouts();
79 
81  static void Sleep( unsigned int milliseconds );
82 
83 protected:
84 
87  PulseGenerator(void);
88 
89  virtual ~PulseGenerator(void);
90 
92  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
93 
94 private:
95 
99  double m_Frequency;
100  double m_FrequencyToBeSet;
101  double m_Period; // helper varable = 1 / frequency
102 
104  igstkDeclareInputMacro( ValidFrequency );
105  igstkDeclareInputMacro( InvalidLowFrequency );
106  igstkDeclareInputMacro( InvalidHighFrequency );
107  igstkDeclareInputMacro( Stop );
108  igstkDeclareInputMacro( Start );
109  igstkDeclareInputMacro( Pulse );
110  igstkDeclareInputMacro( EventReturn );
111 
113  igstkDeclareStateMacro( Initial );
114  igstkDeclareStateMacro( Stopped );
115  igstkDeclareStateMacro( Pulsing );
116  igstkDeclareStateMacro( WaitingEventReturn );
117 
119  void SetFrequencyProcessing();
120 
122  void ReportErrorConditionProcessing();
123 
127  void ReportMissedPulseProcessing();
128 
131  static double m_MaximumFrequency;
132 
134  static void CallbackTimerGlobal( void * );
135 
137  void CallbackTimer();
138 
141  void SetTimerProcessing();
142 
144  void EmitPulseProcessing();
145 
147  void StopPulsesProcessing();
148 
150  void NoProcessing();
151 
152 
153 private:
154 
157  struct Timeout
158  {
159  double time;
160  void (*cb)(void*);
161  void* arg;
162  Timeout* next;
163  };
164 
165  typedef void (*TimeoutHandler)(void*);
166 
167  static void AddTimeout(double time, TimeoutHandler cb, void* data);
168 
169  static void RepeatTimeout(double time, TimeoutHandler cb, void *argp);
170 
171  static void RemoveTimeout( TimeoutHandler cb, void *argp);
172 
173  static void ElapseTimeouts();
174 
175  static void InvokeTimeoutActions();
176 
177 
178  static double m_PreviousClock;
179 
180  static Timeout * m_FirstTimeout;
181 
182  static Timeout * m_FreeTimeout;
183 
184  static unsigned int m_FreeTimeoutCount;
185 
186  static unsigned int m_NumberOfPulseGenerators;
187 
188  mutable itk::SimpleFastMutexLock m_NumberOfPulseGeneratorsLock;
189 
190  static char m_ResetClock;
191 
192  static double m_MissedTimeoutBy;
193 
194 };
195 
196 } // end of namespace igstk
197 
198 #endif //__igstk_PulseGenerator_h_
This class produces ClockTickEvents at a user-defined frequency.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print the object information.
#define igstkGetMacro(name, type)
Get built-in type.
Definition: igstkMacros.h:105
void RequestStop()
Request to stop generating pulses.
Base class for all the IGSTK classes.
Definition: igstkObject.h:40
virtual ~PulseGenerator(void)
#define igstkStandardClassTraitsMacro(classname, superclassname)
Convenience macro for traits of a non-templated class.
Definition: igstkMacros.h:275
defines standard system-wide macros, constants, and other common parameters in the IGSTK Library...
static void CheckTimeouts()
Method to be called from the main event loop in order to keep the timers counting.
static void Sleep(unsigned int milliseconds)
Sleep for a number of milliseconds.
PulseGenerator(void)
Constructor is protected in order to enforce the use of the New() operator.