AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timer.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 
4 #ifndef INCLUDED_SALHELPER_TIMER_HXX
5 #define INCLUDED_SALHELPER_TIMER_HXX
6 
8 #include "osl/time.h"
10 
11 namespace salhelper
12 {
13 
19 {
21  {
22  Seconds = 0;
23  Nanosec = 0;
24  }
25 
26  TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
27  {
28  Seconds = Secs;
29  Nanosec = Nano;
30 
31  normalize();
32  }
33 
34  TTimeValue(sal_uInt32 MilliSecs)
35  {
36  Seconds = MilliSecs / 1000;
37  Nanosec = (MilliSecs % 1000) * 1000000L;
38 
39  normalize();
40  }
41 
42  TTimeValue( const TimeValue& rTimeValue )
43  {
44  Seconds = rTimeValue.Seconds;
45  Nanosec = rTimeValue.Nanosec;
46 
47  normalize();
48  }
49 
50  void SAL_CALL normalize()
51  {
52  if ( Nanosec > 1000000000 )
53  {
54  Seconds += Nanosec / 1000000000;
55  Nanosec %= 1000000000;
56  }
57  }
58 
59  void SAL_CALL addTime( const TTimeValue& Delta )
60  {
61  Seconds += Delta.Seconds;
62  Nanosec += Delta.Nanosec;
63 
64  normalize();
65  }
66 
67  bool SAL_CALL isEmpty() const
68  {
69  return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
70  }
71 };
72 
73 inline bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
74 {
75  if ( rTimeA.Seconds < rTimeB.Seconds )
76  return true;
77  else if ( rTimeA.Seconds > rTimeB.Seconds )
78  return false;
79  else
80  return ( rTimeA.Nanosec < rTimeB.Nanosec );
81 }
82 
83 inline bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
84 {
85  if ( rTimeA.Seconds > rTimeB.Seconds )
86  return true;
87  else if ( rTimeA.Seconds < rTimeB.Seconds )
88  return false;
89  else
90  return ( rTimeA.Nanosec > rTimeB.Nanosec );
91 }
92 
93 inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
94 {
95  return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
96  ( rTimeA.Nanosec == rTimeB.Nanosec ) );
97 }
98 
99 class TimerManager;
100 
104 {
105 public:
106 
109  Timer();
110 
113  Timer( const TTimeValue& Time );
114 
117  Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
118 
121  void SAL_CALL start();
122 
125  void SAL_CALL stop();
126 
129  sal_Bool SAL_CALL isTicking() const;
130 
133  sal_Bool SAL_CALL isExpired() const;
134 
137  sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
138 
141  void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
142 
145  void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
146 
150  void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
151 
154  void SAL_CALL addTime( const TTimeValue& Time );
155 
158  TTimeValue SAL_CALL getRemainingTime() const;
159 
160 protected:
161 
164  virtual ~Timer() SAL_OVERRIDE;
165 
168  virtual void SAL_CALL onShot() = 0;
169 
170 protected:
171 
175 
179 
183 
187 
188 private:
189 
192  Timer( const Timer& rTimer ) SAL_DELETED_FUNCTION;
193 
196  void SAL_CALL operator=( const Timer& rTimer ) SAL_DELETED_FUNCTION;
197 
198  friend class TimerManager;
199 };
200 
201 }
202 
203 #endif // INCLUDED_SALHELPER_TIMER_HXX
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isEmpty() const
Definition: timer.hxx:67
Time since Jan-01-1970.
Definition: time.h:56
unsigned char sal_Bool
Definition: types.h:18
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:34
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
TTimeValue m_aExpired
holds the time of expiration of this timer.
Definition: timer.hxx:178
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:182
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:26
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:59
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:73
sal_uInt32 Seconds
Definition: time.h:57
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:83
TTimeValue()
Definition: timer.hxx:20
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:567
sal_uInt32 Nanosec
Definition: time.h:58
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:41
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:186
TTimeValue m_aTimeOut
holds (initial) expiration time of this timer.
Definition: timer.hxx:174
#define SAL_OVERRIDE
C++11 &quot;override&quot; feature.
Definition: types.h:371
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:18
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:42
Interface for the Timer and handling the event.
Definition: timer.hxx:103
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:12
void normalize()
Definition: timer.hxx:50
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:358