build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / app / timer.cxx
blobaccd9273474606769d4443c687a0bde56a647a8a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/time.hxx>
21 #include <vcl/timer.hxx>
22 #include "saltimer.hxx"
24 void Timer::SetDeletionFlags()
26 // If no AutoTimer, then stop.
27 if ( !mbAuto )
29 mpSchedulerData->mbDelete = true;
30 mbActive = false;
34 bool Timer::ReadyForSchedule( bool /* bTimerOnly */, sal_uInt64 nTimeNow ) const
36 return (mpSchedulerData->mnUpdateTime + mnTimeout) <= nTimeNow;
39 bool Timer::IsIdle() const
41 return false;
44 sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime ) const
46 sal_uInt64 nDeltaTime;
47 //determine smallest time slot
48 if( mpSchedulerData->mnUpdateTime == nTime )
50 nDeltaTime = mnTimeout;
51 if( nDeltaTime < nMinPeriod )
52 nMinPeriod = nDeltaTime;
54 else
56 nDeltaTime = mpSchedulerData->mnUpdateTime + mnTimeout;
57 if( nDeltaTime < nTime )
58 nMinPeriod = ImmediateTimeoutMs;
59 else
61 nDeltaTime -= nTime;
62 if( nDeltaTime < nMinPeriod )
63 nMinPeriod = nDeltaTime;
67 return nMinPeriod;
70 Timer::Timer(const sal_Char *pDebugName) :
71 Scheduler(pDebugName),
72 mnTimeout(ImmediateTimeoutMs),
73 mbAuto(false)
75 mePriority = SchedulerPriority::HIGHEST;
78 Timer::Timer( const Timer& rTimer ) :
79 Scheduler(rTimer),
80 mnTimeout(rTimer.mnTimeout),
81 mbAuto(rTimer.mbAuto)
83 maTimeoutHdl = rTimer.maTimeoutHdl;
86 void Timer::Invoke()
88 maTimeoutHdl.Call( this );
91 void Timer::Start()
93 Scheduler::Start();
94 Scheduler::ImplStartTimer(mnTimeout);
97 void Timer::SetTimeout( sal_uInt64 nNewTimeout )
99 mnTimeout = nNewTimeout;
100 // If timer is active, then renew clock.
101 if ( mbActive )
103 Scheduler::ImplStartTimer(mnTimeout);
107 Timer& Timer::operator=( const Timer& rTimer )
109 Scheduler::operator=(rTimer);
110 maTimeoutHdl = rTimer.maTimeoutHdl;
111 mnTimeout = rTimer.mnTimeout;
112 mbAuto = rTimer.mbAuto;
113 return *this;
116 AutoTimer::AutoTimer( const sal_Char *pDebugName )
117 : Timer( pDebugName )
119 mbAuto = true;
122 AutoTimer::AutoTimer( const AutoTimer& rTimer ) : Timer( rTimer )
124 mbAuto = true;
127 AutoTimer& AutoTimer::operator=( const AutoTimer& rTimer )
129 Timer::operator=( rTimer );
130 return *this;
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */