LibreOffice
LibreOffice 24.2 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  * 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 
31 namespace 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 
93 inline 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 
103 inline 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 
113 inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
114 {
115  return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
116  ( rTimeA.Nanosec == rTimeB.Nanosec ) );
117 }
118 
119 class TimerManager;
120 
124 {
125 public:
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 
180 protected:
181 
184  virtual ~Timer() SAL_OVERRIDE;
185 
188  virtual void SAL_CALL onShot() = 0;
189 
190 protected:
191 
195 
199 
203 
207 
208 private:
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_OVERRIDE
C++11 "override" feature.
Definition: types.h:391
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:62
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:46
TTimeValue m_aExpired
holds the time of expiration of this timer.
Definition: timer.hxx:198
TTimeValue()
Definition: timer.hxx:40
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:93
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:378
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:103
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:113
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
Interface for the Timer and handling the event.
Definition: timer.hxx:123
bool isEmpty() const
Definition: timer.hxx:87
sal_uInt32 Nanosec
Definition: time.h:78
unsigned char sal_Bool
Definition: types.h:38
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:79
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:202
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:54
TTimeValue m_aTimeOut
holds (initial) expiration time of this timer.
Definition: timer.hxx:194
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:32
Time since Jan-01-1970.
Definition: time.h:76
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:61
sal_uInt32 Seconds
Definition: time.h:77
Definition: condition.hxx:33
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:206
void normalize()
Definition: timer.hxx:70
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:38