LibreOffice
LibreOffice 4.3 SDK C/C++ API Reference
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  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #ifndef INCLUDED_SALHELPER_TIMER_HXX
22 #define INCLUDED_SALHELPER_TIMER_HXX
23 
25 #include <osl/time.h>
27 
28 namespace salhelper
29 {
30 
35 struct TTimeValue : public TimeValue
36 {
38  {
39  Seconds = 0;
40  Nanosec = 0;
41  }
42 
43  TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
44  {
45  Seconds = Secs;
46  Nanosec = Nano;
47 
48  normalize();
49  }
50 
51  TTimeValue(sal_uInt32 MilliSecs)
52  {
53  Seconds = MilliSecs / 1000L;
54  Nanosec = (MilliSecs % 1000) * 1000000L;
55 
56  normalize();
57  }
58 
59  TTimeValue( const TTimeValue& rTimeValue )
60  {
61  Seconds = rTimeValue.Seconds;
62  Nanosec = rTimeValue.Nanosec;
63 
64  normalize();
65  }
66 
67  TTimeValue( const TimeValue& rTimeValue )
68  {
69  Seconds = rTimeValue.Seconds;
70  Nanosec = rTimeValue.Nanosec;
71 
72  normalize();
73  }
74 
75  void SAL_CALL normalize()
76  {
77  if ( Nanosec > 1000000000 )
78  {
79  Seconds += Nanosec / 1000000000;
80  Nanosec %= 1000000000;
81  }
82  }
83 
84  void SAL_CALL addTime( const TTimeValue& Delta )
85  {
86  Seconds += Delta.Seconds;
87  Nanosec += Delta.Nanosec;
88 
89  normalize();
90  }
91 
92  bool SAL_CALL isEmpty() const
93  {
94  return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
95  }
96 };
97 
98 inline bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
99 {
100  if ( rTimeA.Seconds < rTimeB.Seconds )
101  return true;
102  else if ( rTimeA.Seconds > rTimeB.Seconds )
103  return false;
104  else
105  return ( rTimeA.Nanosec < rTimeB.Nanosec );
106 }
107 
108 inline bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
109 {
110  if ( rTimeA.Seconds > rTimeB.Seconds )
111  return true;
112  else if ( rTimeA.Seconds < rTimeB.Seconds )
113  return false;
114  else
115  return ( rTimeA.Nanosec > rTimeB.Nanosec );
116 }
117 
118 inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
119 {
120  return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
121  ( rTimeA.Nanosec == rTimeB.Nanosec ) );
122 }
123 
124 class TimerManager;
125 
129 {
130 public:
131 
134  Timer();
135 
138  Timer( const TTimeValue& Time );
139 
142  Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
143 
146  void SAL_CALL start();
147 
150  void SAL_CALL stop();
151 
154  sal_Bool SAL_CALL isTicking() const;
155 
158  sal_Bool SAL_CALL isExpired() const;
159 
162  sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
163 
166  void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
167 
170  void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
171 
175  void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
176 
179  void SAL_CALL addTime( const TTimeValue& Time );
180 
183  TTimeValue SAL_CALL getRemainingTime() const;
184 
185 protected:
186 
189  virtual ~Timer();
190 
193  virtual void SAL_CALL onShot() = 0;
194 
195 protected:
196 
200 
204 
208 
212 
213 private:
214 
217  SALHELPER_DLLPRIVATE Timer( const Timer& rTimer );
218 
221  SALHELPER_DLLPRIVATE void SAL_CALL operator=( const Timer& rTimer );
222 
223  friend class TimerManager;
224 };
225 
226 }
227 
228 #endif // INCLUDED_SALHELPER_TIMER_HXX
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:207
#define SALHELPER_DLLPRIVATE
Definition: salhelperdllapi.h:30
void normalize()
Definition: timer.hxx:75
TTimeValue m_aExpired
holds the time of exparation of this timer.
Definition: timer.hxx:203
sal_uInt32 Seconds
Definition: time.h:43
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:84
unsigned char sal_Bool
Definition: types.h:46
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:98
sal_uInt32 Nanosec
Definition: time.h:44
TTimeValue()
Definition: timer.hxx:37
bool isEmpty() const
Definition: timer.hxx:92
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:58
Definition: time.h:42
Definition: condition.hxx:29
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:35
TTimeValue m_aTimeOut
holds (initial) exparation time of this timer.
Definition: timer.hxx:199
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:118
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:211
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:67
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:108
Interface for the Timer and handling the event.
Definition: timer.hxx:128
TTimeValue(const TTimeValue &rTimeValue)
Definition: timer.hxx:59
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:43
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:51
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28