LibreOffice
LibreOffice 25.8 SDK C/C++ API Reference
Loading...
Searching...
No Matches
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
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
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
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: */
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition types.h:396
unsigned char sal_Bool
Definition types.h:38
#define SAL_OVERRIDE
C++11 "override" feature.
Definition types.h:409
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
#define SALHELPER_DLLPUBLIC
Definition salhelperdllapi.h:32
Definition condition.hxx:34
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
A simple base implementation for reference-counted objects.
Definition simplereferenceobject.hxx:62
Helper class for easier manipulation with TimeValue.
Definition timer.hxx:39
void addTime(const TTimeValue &Delta)
Definition timer.hxx:79
TTimeValue(const TimeValue &rTimeValue)
Definition timer.hxx:62
TTimeValue(sal_uInt32 MilliSecs)
Definition timer.hxx:54
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition timer.hxx:46
bool isEmpty() const
Definition timer.hxx:87
void normalize()
Definition timer.hxx:70
TTimeValue()
Definition timer.hxx:40
void start()
Start timer.
TTimeValue getRemainingTime() const
Returns the remaining time before timer expiration relative to now.
Timer(const TTimeValue &Time)
Constructor.
virtual void onShot()=0
What should be done when the 'timer fires'.
void setRemainingTime(const TTimeValue &Remaining, const TTimeValue &Repeat)
Set the time to fire to 'now' + Remaining with repeat interveal Repeat.
void stop()
Abort timer prematurely.
virtual ~Timer() SAL_OVERRIDE
Destructor.
Timer(const TTimeValue &Time, const TTimeValue &RepeatTime)
Constructor.
TTimeValue m_aTimeOut
holds (initial) expiration time of this timer.
Definition timer.hxx:194
sal_Bool isExpired() const
Is the timer expired?
Timer * m_pNext
Pointer to the next timer (to fire).
Definition timer.hxx:206
TTimeValue m_aExpired
holds the time of expiration of this timer.
Definition timer.hxx:198
friend class TimerManager
Definition timer.hxx:218
void addTime(const TTimeValue &Time)
Adds Time to the 'fire time'.
sal_Bool expiresBefore(const Timer *pTimer) const
Does pTimer expires before us?
void setAbsoluteTime(const TTimeValue &Time)
Set the absolute time when the timer should fire.
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition timer.hxx:202
Timer()
Constructor.
sal_Bool isTicking() const
Returns sal_True if timer is running.
void setRemainingTime(const TTimeValue &Remaining)
Set the time to fire to 'now' + Remaining.
Time since Jan-01-1970.
Definition time.h:76
sal_uInt32 Seconds
Definition time.h:77
sal_uInt32 Nanosec
Definition time.h:78