LibreOffice Module salhelper (master) 1
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 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_SALHELPER_TIMER_HXX
25#define INCLUDED_SALHELPER_TIMER_HXX
26
28#include "osl/time.h"
30
31namespace salhelper
32{
33
38struct SAL_WARN_UNUSED TTimeValue : public TimeValue
39{
41 {
42 Seconds = 0;
43 Nanosec = 0;
44 }
45
46 TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
47 {
48 Seconds = Secs;
49 Nanosec = Nano;
50
51 normalize();
52 }
53
54 TTimeValue(sal_uInt32 MilliSecs)
55 {
56 Seconds = MilliSecs / 1000;
57 Nanosec = (MilliSecs % 1000) * 1000000L;
58
59 normalize();
60 }
61
62 TTimeValue( const TimeValue& rTimeValue )
63 {
64 Seconds = rTimeValue.Seconds;
65 Nanosec = rTimeValue.Nanosec;
66
67 normalize();
68 }
69
70 void SAL_CALL normalize()
71 {
72 if ( Nanosec > 1000000000 )
73 {
74 Seconds += Nanosec / 1000000000;
75 Nanosec %= 1000000000;
76 }
77 }
78
79 void SAL_CALL addTime( const TTimeValue& Delta )
80 {
81 Seconds += Delta.Seconds;
82 Nanosec += Delta.Nanosec;
83
84 normalize();
85 }
86
87 bool SAL_CALL isEmpty() const
88 {
89 return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
90 }
91};
92
93inline bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
94{
95 if ( rTimeA.Seconds < rTimeB.Seconds )
96 return true;
97 else if ( rTimeA.Seconds > rTimeB.Seconds )
98 return false;
99 else
100 return ( rTimeA.Nanosec < rTimeB.Nanosec );
101}
102
103inline bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
104{
105 if ( rTimeA.Seconds > rTimeB.Seconds )
106 return true;
107 else if ( rTimeA.Seconds < rTimeB.Seconds )
108 return false;
109 else
110 return ( rTimeA.Nanosec > rTimeB.Nanosec );
111}
112
113inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
114{
115 return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
116 ( rTimeA.Nanosec == rTimeB.Nanosec ) );
117}
118
119class TimerManager;
120
124{
125public:
126
129 Timer();
130
133 Timer( const TTimeValue& Time );
134
137 Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
138
141 void SAL_CALL start();
142
145 void SAL_CALL stop();
146
149 sal_Bool SAL_CALL isTicking() const;
150
153 sal_Bool SAL_CALL isExpired() const;
154
157 sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
158
161 void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
162
165 void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
166
170 void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
171
174 void SAL_CALL addTime( const TTimeValue& Time );
175
178 TTimeValue SAL_CALL getRemainingTime() const;
179
180protected:
181
184 virtual ~Timer() SAL_OVERRIDE;
185
188 virtual void SAL_CALL onShot() = 0;
189
190protected:
191
195
199
203
207
208private:
209
212 Timer( const Timer& rTimer ) SAL_DELETED_FUNCTION;
213
216 void SAL_CALL operator=( const Timer& rTimer ) SAL_DELETED_FUNCTION;
217
218 friend class TimerManager;
219};
220
221}
222
223#endif // INCLUDED_SALHELPER_TIMER_HXX
224
225/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A simple base implementation for reference-counted objects.
Interface for the Timer and handling the event.
Definition: timer.hxx:124
virtual void SAL_CALL onShot()=0
What should be done when the 'timer fires'.
TTimeValue m_aTimeOut
holds (initial) expiration time of this timer.
Definition: timer.hxx:194
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:206
void SAL_CALL operator=(const Timer &rTimer) SAL_DELETED_FUNCTION
Copy assignment operator deleted.
TTimeValue m_aExpired
holds the time of expiration of this timer.
Definition: timer.hxx:198
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:202
Timer(const Timer &rTimer) SAL_DELETED_FUNCTION
Copy constructor deleted.
def stop(arg=None)
bool normalize(sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:103
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:113
Delta
#define SALHELPER_DLLPUBLIC
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:39
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:62
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:54
void SAL_CALL normalize()
Definition: timer.hxx:70
bool SAL_CALL isEmpty() const
Definition: timer.hxx:87
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:46
void SAL_CALL addTime(const TTimeValue &Delta)
Definition: timer.hxx:79
unsigned char sal_Bool
#define SAL_WARN_UNUSED