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  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 
00030 #ifndef _SALHELPER_TIMER_HXX_
00031 #define _SALHELPER_TIMER_HXX_
00032 
00033 #include <salhelper/simplereferenceobject.hxx>
00034 #include <osl/time.h>
00035 #include "salhelperdllapi.h"
00036 
00037 namespace salhelper
00038 {
00039 
00044 struct TTimeValue : public TimeValue
00045 {
00046     TTimeValue()
00047     {
00048         Seconds = 0;
00049         Nanosec = 0;
00050     }
00051 
00052     TTimeValue( sal_uInt32 Secs, sal_uInt32 Nano )
00053     {
00054         Seconds = Secs;
00055         Nanosec = Nano;
00056 
00057         normalize();
00058     }
00059 
00060     TTimeValue(sal_uInt32 MilliSecs)
00061     {
00062         Seconds = MilliSecs / 1000L;
00063         Nanosec = (MilliSecs % 1000) * 1000000L;
00064 
00065         normalize();
00066     }
00067 
00068     TTimeValue( const TTimeValue& rTimeValue )
00069     {
00070         Seconds = rTimeValue.Seconds;
00071         Nanosec = rTimeValue.Nanosec;
00072 
00073         normalize();
00074     }
00075 
00076     TTimeValue( const TimeValue& rTimeValue )
00077     {
00078         Seconds = rTimeValue.Seconds;
00079         Nanosec = rTimeValue.Nanosec;
00080 
00081         normalize();
00082     }
00083 
00084     void SAL_CALL normalize()
00085     {
00086         if ( Nanosec > 1000000000 )
00087         {
00088             Seconds += Nanosec / 1000000000;
00089             Nanosec %= 1000000000;
00090         }
00091     }
00092 
00093     void SAL_CALL addTime( const TTimeValue& Delta )
00094     {
00095         Seconds += Delta.Seconds;
00096         Nanosec += Delta.Nanosec;
00097 
00098         normalize();
00099     }
00100 
00101     sal_Bool SAL_CALL isEmpty() const
00102     {
00103         return ( ( Seconds == 0 ) && ( Nanosec == 0 ) );
00104     }
00105 };
00106 
00107 inline sal_Bool operator<( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00108 {
00109     if ( rTimeA.Seconds < rTimeB.Seconds )
00110         return sal_True;
00111     else if ( rTimeA.Seconds > rTimeB.Seconds )
00112         return sal_False;
00113     else
00114         return ( rTimeA.Nanosec < rTimeB.Nanosec );
00115 }
00116 
00117 inline sal_Bool operator>( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00118 {
00119     if ( rTimeA.Seconds > rTimeB.Seconds )
00120         return sal_True;
00121     else if ( rTimeA.Seconds < rTimeB.Seconds )
00122         return sal_False;
00123     else
00124         return ( rTimeA.Nanosec > rTimeB.Nanosec );
00125 }
00126 
00127 inline sal_Bool operator==( const TTimeValue& rTimeA, const TTimeValue& rTimeB )
00128 {
00129     return ( ( rTimeA.Seconds == rTimeB.Seconds ) &&
00130              ( rTimeA.Nanosec == rTimeB.Nanosec ) );
00131 }
00132 
00133 class TimerManager;
00134 
00137 class SALHELPER_DLLPUBLIC Timer : public salhelper::SimpleReferenceObject
00138 {
00139 public:
00140 
00143     Timer();
00144 
00147     Timer( const TTimeValue& Time );
00148 
00151     Timer( const TTimeValue& Time, const TTimeValue& RepeatTime );
00152 
00155     void        SAL_CALL start();
00156 
00159     void        SAL_CALL stop();
00160 
00163     sal_Bool    SAL_CALL isTicking() const;
00164 
00167     sal_Bool    SAL_CALL isExpired() const;
00168 
00171     sal_Bool    SAL_CALL expiresBefore( const Timer* pTimer ) const;
00172 
00175     void        SAL_CALL setAbsoluteTime( const TTimeValue& Time );
00176 
00179     void        SAL_CALL setRemainingTime( const TTimeValue& Remaining );
00180 
00184     void        SAL_CALL setRemainingTime( const TTimeValue& Remaining, const TTimeValue& Repeat );
00185 
00188     void        SAL_CALL addTime( const TTimeValue& Time );
00189 
00192     TTimeValue  SAL_CALL getRemainingTime() const;
00193 
00194 protected:
00195 
00198     virtual ~Timer();
00199 
00202     virtual void SAL_CALL onShot() = 0;
00203 
00204 protected:
00205 
00208     TTimeValue  m_aTimeOut;
00209 
00212     TTimeValue  m_aExpired;
00213 
00216     TTimeValue  m_aRepeatDelta;
00217 
00220     Timer*      m_pNext;
00221 
00222 private:
00223 
00226     SALHELPER_DLLPRIVATE Timer( const Timer& rTimer );
00227 
00230     SALHELPER_DLLPRIVATE void SAL_CALL operator=( const Timer& rTimer );
00231 
00232     friend class TimerManager;
00233 };
00234 
00235 }
00236 
00237 #endif  //_SALHELPER_TIMER_HXX_
00238 
00239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines