1 /*=========================================================================
2  *
3  *  Copyright NumFOCUS
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 /*
19 
20 This file contains the code for the ARTIM timer.
21 
22 Basically, the ARTIM timer will just get the wall time when it's started,
23 and then can be queried for the current time, and then can be stopped (ie,
24 the start time reset).
25 
26 Because we're trying to do this without threading, we should be able to 'start' the
27 ARTIM timer by this mechanism, and then when waiting for a particular response, tight
28 loop that with sleep calls and determinations of when the ARTIM timer has reached its
29 peak.  As such, this isn't a strict 'timer' in the traditional sense of the word,
30 but more of a time keeper.
31 
32 */
33 
34 #include "gdcmARTIMTimer.h"
35 #include "gdcmSystem.h"
36 
37 namespace gdcm
38 {
39 namespace network
40 {
41 
42 //initiates the start and timeout at -1;
ARTIMTimer()43 ARTIMTimer::ARTIMTimer(){
44   mStartTime = 0;
45   mTimeOut = 0;
46 }
GetCurrentTime() const47 double ARTIMTimer::GetCurrentTime() const{
48   return 0; //platform-specific timing functions go here...
49 }
50 
Start()51 void ARTIMTimer::Start(){
52   mStartTime = GetCurrentTime();
53 }
SetTimeout(double inTimeOut)54 void ARTIMTimer::SetTimeout(double inTimeOut){
55   mTimeOut = inTimeOut;
56 }
57 
GetTimeout() const58 double ARTIMTimer::GetTimeout() const{
59   return mTimeOut;
60 }
GetElapsedTime() const61 double ARTIMTimer::GetElapsedTime() const{
62   if (mStartTime > 0){
63     return GetCurrentTime() - mStartTime;
64   } else {
65     return -1; //not started yet
66   }
67 }
68 
GetHasExpired() const69 bool ARTIMTimer::GetHasExpired() const{
70   double theElapsed = GetElapsedTime();
71   if (theElapsed > 0){
72     return theElapsed > mTimeOut;
73   } else {
74     return false; //not started yet
75   }
76 }
77 
Stop()78 void ARTIMTimer::Stop() {
79   mStartTime = -1;//stop the timer by resetting it.
80 }
81 
82 } // end namespace network
83 } // end namespace gdcm
84