LibreOffice: salhelper/timer.hxx Source File

LibreOffice LibreOffice 5.1 SDK C/C++ API Reference

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

- File List
- File Members

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 TimeValue(rTimeValue)
61 {
62 normalize();
63 }
64
65 TTimeValue( const TimeValue& rTimeValue )
66 {
67 Seconds = rTimeValue.Seconds;
68 Nanosec = rTimeValue.Nanosec;
69
70 normalize();
71 }
72
73 void SAL_CALL normalize()
74 {
75 if ( Nanosec > 1000000000 )
76 {
77 Seconds += Nanosec / 1000000000;
78 Nanosec %= 1000000000;
79 }
80 }
81
82 void SAL_CALL addTime( const TTimeValue& Delta )
83 {
84 Seconds += Delta.Seconds;
85 Nanosec += Delta.Nanosec;
86
87 normalize();
88 }
89
90 bool SAL_CALL isEmpty() const
91 {
92 return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
93 }
94 };
95
96 inline bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
97 {
98 if ( rTimeA.Seconds < rTimeB.Seconds )
99 return true;
100 else if ( rTimeA.Seconds > rTimeB.Seconds )
101 return false;
102 else
103 return ( rTimeA.Nanosec < rTimeB.Nanosec );
104 }
105
106 inline bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
107 {
108 if ( rTimeA.Seconds > rTimeB.Seconds )
109 return true;
110 else if ( rTimeA.Seconds < rTimeB.Seconds )
111 return false;
112 else
113 return ( rTimeA.Nanosec > rTimeB.Nanosec );
114 }
115
116 inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
117 {
118 return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
119 ( rTimeA.Nanosec == rTimeB.Nanosec ) );
120 }
121
122 class TimerManager;
123
126 class SALHELPER_DLLPUBLIC Timer : public salhelper::SimpleReferenceObject
127 {
128 public:
129
132 Timer();
133
136 Timer( const TTimeValue& Time );
137
140 Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
141
144 void SAL_CALL start();
145
148 void SAL_CALL stop();
149
152 sal_Bool SAL_CALL isTicking() const;
153
156 sal_Bool SAL_CALL isExpired() const;
157
160 sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
161
164 void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
165
168 void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
169
173 void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
174
177 void SAL_CALL addTime( const TTimeValue& Time );
178
181 TTimeValue SAL_CALL getRemainingTime() const;
182
183 protected:
184
187 virtual ~Timer();
188
191 virtual void SAL_CALL onShot() = 0;
192
193 protected:
194
197 TTimeValue m_aTimeOut;
198
201 TTimeValue m_aExpired;
202
205 TTimeValue m_aRepeatDelta;
206
209 Timer* m_pNext;
210
211 private:
212
215 Timer( const Timer& rTimer ) SAL_DELETED_FUNCTION;
216
219 void SAL_CALL operator=( const Timer& rTimer ) SAL_DELETED_FUNCTION;
220
221 friend class TimerManager;
222 };
223
224 }
225
226 #endif // INCLUDED_SALHELPER_TIMER_HXX
227
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
salhelper::Timer::m_pNext
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:209
TimeValue::Seconds
sal_uInt32 Seconds
Definition: time.h:71
salhelper::TTimeValue::TTimeValue
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:65
salhelper::TTimeValue::TTimeValue
TTimeValue(const TTimeValue &rTimeValue)
Definition: timer.hxx:59
salhelper
Definition: condition.hxx:29
simplereferenceobject.hxx
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:408
TimeValue::Nanosec
sal_uInt32 Nanosec
Definition: time.h:72
salhelper::TTimeValue
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:35
sal_Bool
unsigned char sal_Bool
Definition: types.h:48
salhelper::operator<
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:96
time.h
salhelper::TTimeValue::TTimeValue
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:51
salhelper::operator>
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:106
salhelperdllapi.h
salhelper::Timer::m_aExpired
TTimeValue m_aExpired
holds the time of exparation of this timer.
Definition: timer.hxx:201
salhelper::SimpleReferenceObject
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:57
SALHELPER_DLLPUBLIC
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28
salhelper::Timer::m_aTimeOut
TTimeValue m_aTimeOut
holds (initial) exparation time of this timer.
Definition: timer.hxx:197
TimeValue
Definition: time.h:70
salhelper::operator==
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:116
salhelper::TTimeValue::addTime
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:82
salhelper::TTimeValue::isEmpty
bool isEmpty() const
Definition: timer.hxx:90
salhelper::TTimeValue::TTimeValue
TTimeValue()
Definition: timer.hxx:37
salhelper::Timer::m_aRepeatDelta
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:205
salhelper::TTimeValue::TTimeValue
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:43
salhelper::TTimeValue::normalize
void normalize()
Definition: timer.hxx:73
salhelper::Timer
Interface for the Timer and handling the event.
Definition: timer.hxx:126