frequencyGoverner.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLRUTILITIES_FREQUENCYGOVERNER_H_
00016 #define _DLRUTILITIES_FREQUENCYGOVERNER_H_
00017 
00018 #include <dlrUtilities/timeUtilities.h>
00019 
00020 namespace dlr {
00021 
00022   namespace utilities {
00023     
00040     class FrequencyGoverner {
00041     public:
00042 
00055       FrequencyGoverner(double frequency, double duration)
00056         : m_count(0), m_duration(duration), m_period(1.0 / frequency),
00057           m_startTime(getCurrentTime()) {}
00058 
00059 
00064       ~FrequencyGoverner() {}
00065 
00066 
00074       inline bool
00075       isFinished() {return (getCurrentTime() - m_startTime) > m_duration;}
00076 
00077     
00078       inline void
00079       sleepIfNecessary() {
00080         portableSleep(m_startTime + m_count * m_period - getCurrentTime());
00081         ++m_count;
00082       }
00083       
00084     private:
00085 
00086       int m_count;
00087       double m_duration;
00088       double m_period;
00089       double m_startTime;
00090 
00091     }; // class FrequencyGoverner
00092 
00093   } // namespace utilities
00094   
00095 } // namespace dlr
00096 
00097 
00098 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00099 
00100 namespace dlr {
00101 
00102   using utilities::FrequencyGoverner;
00103   
00104 } // namespace dlr
00105 
00106 #endif // #ifndef _DLRUTILITES_FREQUENCYGOVERNER_H_

Generated on Mon Jul 9 20:34:03 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2