UDK 3.2.7 C/C++ API Reference

salhelper/timer.hxx

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 
00021 #ifndef _SALHELPER_TIMER_HXX_
00022 #define _SALHELPER_TIMER_HXX_
00023 
00024 #include <salhelper/simplereferenceobject.hxx>
00025 #include <osl/time.h>
00026 #include "salhelperdllapi.h"
00027 
00028 namespace salhelper
00029 {
00030 
00035 struct TTimeValue : public TimeValue
00036 {
00037     TTimeValue()
00038     {
00039         Seconds = 0;
00040         Nanosec = 0;
00041     }
00042 
00043     TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
00044     {
00045         Seconds = Secs;
00046         Nanosec = Nano;
00047 
00048         normalize();
00049     }
00050 
00051     TTimeValue(sal_uInt32 MilliSecs)
00052     {
00053         Seconds = MilliSecs / 1000L;
00054         Nanosec = (MilliSecs % 1000) * 1000000L;
00055 
00056         normalize();
00057     }
00058 
00059     TTimeValue( const TTimeValue& rTimeValue )
00060     {
00061         Seconds = rTimeValue.Seconds;
00062         Nanosec = rTimeValue.Nanosec;
00063 
00064         normalize();
00065     }
00066 
00067     TTimeValue( const TimeValue& rTimeValue )
00068     {
00069         Seconds = rTimeValue.Seconds;
00070         Nanosec = rTimeValue.Nanosec;
00071 
00072         normalize();
00073     }
00074 
00075     void SAL_CALL normalize()
00076     {
00077         if ( Nanosec > 1000000000 )
00078         {
00079             Seconds += Nanosec / 1000000000;
00080             Nanosec %= 1000000000;
00081         }
00082     }
00083 
00084     void SAL_CALL addTime( const TTimeValue& Delta )
00085     {
00086         Seconds += Delta.Seconds;
00087         Nanosec += Delta.Nanosec;
00088 
00089         normalize();
00090     }
00091 
00092     sal_Bool SAL_CALL isEmpty() const
00093     {
00094         return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
00095     }
00096 };
00097 
00098 inline sal_Bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00099 {
00100     if ( rTimeA.Seconds < rTimeB.Seconds )
00101         return sal_True;
00102     else if ( rTimeA.Seconds > rTimeB.Seconds )
00103         return sal_False;
00104     else
00105         return ( rTimeA.Nanosec < rTimeB.Nanosec );
00106 }
00107 
00108 inline sal_Bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00109 {
00110     if ( rTimeA.Seconds > rTimeB.Seconds )
00111         return sal_True;
00112     else if ( rTimeA.Seconds < rTimeB.Seconds )
00113         return sal_False;
00114     else
00115         return ( rTimeA.Nanosec > rTimeB.Nanosec );
00116 }
00117 
00118 inline sal_Bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00119 {
00120     return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
00121              ( rTimeA.Nanosec == rTimeB.Nanosec ) );
00122 }
00123 
00124 class TimerManager;
00125 
00128 class SALHELPER_DLLPUBLIC Timer : public salhelper::SimpleReferenceObject
00129 {
00130 public:
00131 
00134     Timer();
00135 
00138     Timer( const TTimeValue& Time );
00139 
00142     Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
00143 
00146     void        SAL_CALL start();
00147 
00150     void        SAL_CALL stop();
00151 
00154     sal_Bool    SAL_CALL isTicking() const;
00155 
00158     sal_Bool    SAL_CALL isExpired() const;
00159 
00162     sal_Bool    SAL_CALL expiresBefore( const Timer* pTimer ) const;
00163 
00166     void        SAL_CALL setAbsoluteTime( const TTimeValue& Time );
00167 
00170     void        SAL_CALL setRemainingTime( const TTimeValue& Remaining );
00171 
00175     void        SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
00176 
00179     void        SAL_CALL addTime( const TTimeValue& Time );
00180 
00183     TTimeValue  SAL_CALL getRemainingTime() const;
00184 
00185 protected:
00186 
00189     virtual ~Timer();
00190 
00193     virtual void SAL_CALL onShot() = 0;
00194 
00195 protected:
00196 
00199     TTimeValue  m_aTimeOut;
00200 
00203     TTimeValue  m_aExpired;
00204 
00207     TTimeValue  m_aRepeatDelta;
00208 
00211     Timer*      m_pNext;
00212 
00213 private:
00214 
00217     SALHELPER_DLLPRIVATE Timer( const Timer& rTimer );
00218 
00221     SALHELPER_DLLPRIVATE void SAL_CALL operator=( const Timer& rTimer );
00222 
00223     friend class TimerManager;
00224 };
00225 
00226 }
00227 
00228 #endif  //_SALHELPER_TIMER_HXX_
00229 
00230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines