LibreOffice
LibreOffice 6.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 #ifndef INCLUDED_SALHELPER_TIMER_HXX
22 #define INCLUDED_SALHELPER_TIMER_HXX
23 
25 #include "osl/time.h"
27 
28 namespace salhelper
29 {
30 
36 {
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 TimeValue& rTimeValue )
60  {
61  Seconds = rTimeValue.Seconds;
62  Nanosec = rTimeValue.Nanosec;
63 
64  normalize();
65  }
66 
67  void SAL_CALL normalize()
68  {
69  if ( Nanosec > 1000000000 )
70  {
71  Seconds += Nanosec / 1000000000;
72  Nanosec %= 1000000000;
73  }
74  }
75 
76  void SAL_CALL addTime( const TTimeValue& Delta )
77  {
78  Seconds += Delta.Seconds;
79  Nanosec += Delta.Nanosec;
80 
81  normalize();
82  }
83 
84  bool SAL_CALL isEmpty() const
85  {
86  return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
87  }
88 };
89 
90 inline bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
91 {
92  if ( rTimeA.Seconds < rTimeB.Seconds )
93  return true;
94  else if ( rTimeA.Seconds > rTimeB.Seconds )
95  return false;
96  else
97  return ( rTimeA.Nanosec < rTimeB.Nanosec );
98 }
99 
100 inline bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
101 {
102  if ( rTimeA.Seconds > rTimeB.Seconds )
103  return true;
104  else if ( rTimeA.Seconds < rTimeB.Seconds )
105  return false;
106  else
107  return ( rTimeA.Nanosec > rTimeB.Nanosec );
108 }
109 
110 inline bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
111 {
112  return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
113  ( rTimeA.Nanosec == rTimeB.Nanosec ) );
114 }
115 
116 class TimerManager;
117 
121 {
122 public:
123 
126  Timer();
127 
130  Timer( const TTimeValue& Time );
131 
134  Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
135 
138  void SAL_CALL start();
139 
142  void SAL_CALL stop();
143 
146  sal_Bool SAL_CALL isTicking() const;
147 
150  sal_Bool SAL_CALL isExpired() const;
151 
154  sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
155 
158  void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
159 
162  void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
163 
167  void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
168 
171  void SAL_CALL addTime( const TTimeValue& Time );
172 
175  TTimeValue SAL_CALL getRemainingTime() const;
176 
177 protected:
178 
181  virtual ~Timer() SAL_OVERRIDE;
182 
185  virtual void SAL_CALL onShot() = 0;
186 
187 protected:
188 
192 
196 
200 
204 
205 private:
206 
209  Timer( const Timer& rTimer ) SAL_DELETED_FUNCTION;
210 
213  void SAL_CALL operator=( const Timer& rTimer ) SAL_DELETED_FUNCTION;
214 
215  friend class TimerManager;
216 };
217 
218 }
219 
220 #endif // INCLUDED_SALHELPER_TIMER_HXX
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Timer * m_pNext
Pointer to the next timer (to fire).
Definition: timer.hxx:203
sal_uInt32 Seconds
Definition: time.h:67
TTimeValue(const TimeValue &rTimeValue)
Definition: timer.hxx:59
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:602
sal_uInt32 Nanosec
Definition: time.h:68
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:409
Helper class for easier manipulation with TimeValue.
Definition: timer.hxx:35
unsigned char sal_Bool
Definition: types.h:38
TTimeValue(sal_uInt32 MilliSecs)
Definition: timer.hxx:51
TTimeValue m_aExpired
holds the time of exparation of this timer.
Definition: timer.hxx:195
Definition: condition.hxx:30
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:57
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:90
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:110
TTimeValue m_aTimeOut
holds (initial) exparation time of this timer.
Definition: timer.hxx:191
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:100
Definition: time.h:66
void addTime(const TTimeValue &Delta)
Definition: timer.hxx:76
bool isEmpty() const
Definition: timer.hxx:84
TTimeValue()
Definition: timer.hxx:37
TTimeValue m_aRepeatDelta
holds the time interveal of successive expirations.
Definition: timer.hxx:199
TTimeValue(sal_uInt32 Secs, sal_uInt32 Nano)
Definition: timer.hxx:43
void normalize()
Definition: timer.hxx:67
Interface for the Timer and handling the event.
Definition: timer.hxx:120