Clock.cpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
3 
4  Redistribution of this file, in original or modified form, without
5  prior written consent of Allied Vision Technologies is prohibited.
6 
7 -------------------------------------------------------------------------------
8 
9  File: Clock.cpp
10 
11  Description: Implementation of a platform independent Sleep.
12  (This include file is for internal use only.)
13 
14 -------------------------------------------------------------------------------
15 
16  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
17  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
18  NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 =============================================================================*/
28 
29 #ifdef WIN32
30  #include <sys/timeb.h>
31  #include <windows.h>
32 #else
33  #include <sys/time.h>
34  #include <unistd.h>
35 #endif
36 
37 #include <VimbaCPP/Source/Clock.h>
38 
39 namespace AVT {
40 namespace VmbAPI {
41 
43  : m_dStartTime(0.0)
44 {
45 }
46 
48 {
49 }
50 
52 {
53  m_dStartTime = 0.0;
54 }
55 
57 {
59 }
60 
61 void Clock::SetStartTime( double dStartTime )
62 {
63  m_dStartTime = dStartTime;
64 }
65 
66 double Clock::GetTime() const
67 {
68  double dTime = 0.0;
69 
70 #ifdef WIN32
71  _timeb currSysTime;
72 
73  _ftime_s(&currSysTime);
74 
75  dTime = (currSysTime.time + ((double)currSysTime.millitm) / 1000.0);
76 #else
77  timeval now;
78 
79  if(gettimeofday(&now, (struct timezone *)0)) return 0.0;
80 
81  dTime = ((double)now.tv_sec) + ((double)(now.tv_usec) / 1000000.0);
82 #endif
83 
84  return dTime - m_dStartTime;
85 }
86 
88 {
89  double dAbsTime = 0.0;
90 
91 #ifdef WIN32
92  _timeb currSysTime;
93 
94  _ftime_s(&currSysTime);
95 
96  dAbsTime = (currSysTime.time + ((double)currSysTime.millitm) / 1000.0);
97 #else
98  timeval now;
99 
100  if(gettimeofday(&now, (struct timezone *)0)) return 0.0;
101 
102  dAbsTime = ((double)now.tv_sec) + ((double)(now.tv_usec) / 1000000.0);
103 #endif
104 
105  return dAbsTime;
106 }
107 
108 void Clock::Sleep(double dTime)
109 {
110 #ifdef WIN32
111  ::Sleep((unsigned long)(dTime * 1000.0));
112 #else
113  ::usleep((unsigned long)(dTime * 1000000.0));
114 #endif
115 }
116 
117 void Clock::SleepMS(unsigned long nTimeMS)
118 {
119 #ifdef WIN32
120  ::Sleep(nTimeMS);
121 #else
122  ::usleep(nTimeMS * 1000);
123 #endif
124 }
125 
126 void Clock::SleepAbs(double dAbsTime)
127 {
128  Clock clock;
129  double dTimeDiff = dAbsTime - clock.GetTime();
130 
131 #ifdef WIN32
132  if(dTimeDiff > 4000000.0) dTimeDiff = 4000000.0;
133 #else
134  if(dTimeDiff >= 4000.0) dTimeDiff = 4000.0;
135 #endif
136  while(dTimeDiff > 0.0)
137  {
138  Sleep(dTimeDiff);
139  dTimeDiff = dAbsTime - clock.GetTime();
140 #ifdef WIN32
141  if(dTimeDiff > 4000000.0) dTimeDiff = 4000000.0;
142 #else
143  if(dTimeDiff >= 4000.0) dTimeDiff = 4000.0;
144 #endif
145  }
146 }
147 
148 }} //namespace AVT::VmbAPI
static void SleepMS(unsigned long nTimeMS)
Definition: Clock.cpp:117
double m_dStartTime
Definition: Clock.h:53
static void SleepAbs(double dAbsTime)
Definition: Clock.cpp:126
virtual void Reset()
Definition: Clock.cpp:51
virtual double GetTime() const
Definition: Clock.cpp:66
static double GetAbsTime()
Definition: Clock.cpp:87
virtual ~Clock()
Definition: Clock.cpp:47
static void Sleep(double dTime)
Definition: Clock.cpp:108
virtual void SetStartTime()
Definition: Clock.cpp:56


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Wed Jun 5 2019 22:22:40