My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 
30 #ifndef _SALHELPER_TIMER_HXX_
31 #define _SALHELPER_TIMER_HXX_
32 
34 #include <osl/time.h>
35 #include "salhelperdllapi.h"
36 
37 namespace salhelper
38 {
39 
44 struct TTimeValue : public TimeValue
45 {
47  {
48  Seconds = 0;
49  Nanosec = 0;
50  }
51 
52  TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
53  {
54  Seconds = Secs;
55  Nanosec = Nano;
56 
57  normalize();
58  }
59 
60  TTimeValue(sal_uInt32 MilliSecs)
61  {
62  Seconds = MilliSecs / 1000L;
63  Nanosec = (MilliSecs % 1000) * 1000000L;
64 
65  normalize();
66  }
67 
68  TTimeValue( const TTimeValue& rTimeValue )
69  {
70  Seconds = rTimeValue.Seconds;
71  Nanosec = rTimeValue.Nanosec;
72 
73  normalize();
74  }
75 
76  TTimeValue( const TimeValue& rTimeValue )
77  {
78  Seconds = rTimeValue.Seconds;
79  Nanosec = rTimeValue.Nanosec;
80 
81  normalize();
82  }
83 
84  void SAL_CALL normalize()
85  {
86  if ( Nanosec > 1000000000 )
87  {
88  Seconds += Nanosec / 1000000000;
89  Nanosec %= 1000000000;
90  }
91  }
92 
93  void SAL_CALL addTime( const TTimeValue& Delta )
94  {
95  Seconds += Delta.Seconds;
96  Nanosec += Delta.Nanosec;
97 
98  normalize();
99  }
100 
101  sal_Bool SAL_CALL isEmpty() const
102  {
103  return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
104  }
105 };
106 
107 inline sal_Bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
108 {
109  if ( rTimeA.Seconds < rTimeB.Seconds )
110  return sal_True;
111  else if ( rTimeA.Seconds > rTimeB.Seconds )
112  return sal_False;
113  else
114  return ( rTimeA.Nanosec < rTimeB.Nanosec );
115 }
116 
117 inline sal_Bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
118 {
119  if ( rTimeA.Seconds > rTimeB.Seconds )
120  return sal_True;
121  else if ( rTimeA.Seconds < rTimeB.Seconds )
122  return sal_False;
123  else
124  return ( rTimeA.Nanosec > rTimeB.Nanosec );
125 }
126 
127 inline sal_Bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
128 {
129  return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
130  ( rTimeA.Nanosec == rTimeB.Nanosec ) );
131 }
132 
133 class TimerManager;
134 
138 {
139 public:
140 
143  Timer();
144 
147  Timer( const TTimeValue& Time );
148 
151  Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
152 
155  void SAL_CALL start();
156 
159  void SAL_CALL stop();
160 
163  sal_Bool SAL_CALL isTicking() const;
164 
167  sal_Bool SAL_CALL isExpired() const;
168 
171  sal_Bool SAL_CALL expiresBefore( const Timer* pTimer ) const;
172 
175  void SAL_CALL setAbsoluteTime( const TTimeValue& Time );
176 
179  void SAL_CALL setRemainingTime( const TTimeValue& Remaining );
180 
184  void SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
185 
188  void SAL_CALL addTime( const TTimeValue& Time );
189 
192  TTimeValue SAL_CALL getRemainingTime() const;
193 
194 protected:
195 
198  virtual ~Timer();
199 
202  virtual void SAL_CALL onShot() = 0;
203 
204 protected:
205 
209 
213 
217 
221 
222 private:
223 
226  SALHELPER_DLLPRIVATE Timer( const Timer& rTimer );
227 
230  SALHELPER_DLLPRIVATE void SAL_CALL operator=( const Timer& rTimer );
231 
232  friend class TimerManager;
233 };
234 
235 }
236 
237 #endif //_SALHELPER_TIMER_HXX_
238 
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */