LibreOffice LibreOffice 4.3 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 * 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
24 #include <salhelper/simplereferenceobject.hxx>
25 #include <osl/time.h>
26 #include <salhelper/salhelperdllapi.h>
27
28 namespace salhelper
29 {
30
35 struct TTimeValue : public TimeValue
36 {
37 TTimeValue()
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
128 class SALHELPER_DLLPUBLIC Timer : public salhelper::SimpleReferenceObject
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
199 TTimeValue m_aTimeOut;
200
203 TTimeValue m_aExpired;
204
207 TTimeValue m_aRepeatDelta;
208
211 Timer* m_pNext;
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: */
salhelper::Timer::m_aRepeatDelta
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:207
simplereferenceobject.hxx
SALHELPER_DLLPRIVATE
#define SALHELPER_DLLPRIVATE
Definition: salhelperdllapi.h:30
salhelper::TTimeValue::normalize
void normalize()
Definition: timer.hxx:75
salhelper::Timer::m_aExpired
TTimeValue m_aExpired
holds the time of exparation of this timer.
Definition: timer.hxx:203
TimeValue::Seconds
sal_uInt32 Seconds
Definition: time.h:43
salhelper::TTimeValue::addTime
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:84
sal_Bool
unsigned char sal_Bool
Definition: types.h:46
salhelper::operator<
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:98
TimeValue::Nanosec
sal_uInt32 Nanosec
Definition: time.h:44
salhelper::TTimeValue::TTimeValue
TTimeValue()
Definition: timer.hxx:37
salhelperdllapi.h
salhelper::TTimeValue::isEmpty
bool isEmpty() const
Definition: timer.hxx:92
time.h
salhelper::SimpleReferenceObject
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:58
TimeValue
Definition: time.h:42
salhelper
Definition: condition.hxx:29
salhelper::TTimeValue
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:35
salhelper::Timer::m_aTimeOut
TTimeValue m_aTimeOut
holds (initial) exparation time of this timer.
Definition: timer.hxx:199
salhelper::operator==
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:118
salhelper::Timer::m_pNext
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:211
salhelper::TTimeValue::TTimeValue
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:67
salhelper::operator>
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:108
salhelper::Timer
Interface for the Timer and handling the event.
Definition: timer.hxx:128
salhelper::TTimeValue::TTimeValue
TTimeValue(const TTimeValue &rTimeValue)
Definition: timer.hxx:59
salhelper::TTimeValue::TTimeValue
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:43
salhelper::TTimeValue::TTimeValue
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:51
SALHELPER_DLLPUBLIC
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28