1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.
28 Task::SetDeletionFlags();
31 bool Timer::ReadyForSchedule( bool /* bIdle */, sal_uInt64 nTimeNow
) const
33 return (GetSchedulerData()->mnUpdateTime
+ mnTimeout
) <= nTimeNow
;
36 bool Timer::IsIdle() const
41 sal_uInt64
Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod
, sal_uInt64 nTimeNow
) const
43 sal_uInt64 nWakeupTime
= GetSchedulerData()->mnUpdateTime
+ mnTimeout
;
44 if( nWakeupTime
<= nTimeNow
)
45 return Scheduler::ImmediateTimeoutMs
;
48 sal_uInt64 nSleepTime
= nWakeupTime
- nTimeNow
;
49 return ( nSleepTime
< nMinPeriod
) ? nSleepTime
: nMinPeriod
;
53 Timer::Timer( bool bAuto
, const sal_Char
*pDebugName
)
55 , mnTimeout( Scheduler::ImmediateTimeoutMs
)
58 SetPriority( TaskPriority::HIGHEST
);
61 Timer::Timer( const sal_Char
*pDebugName
)
62 : Timer( false, pDebugName
)
66 Timer::Timer( const Timer
& rTimer
)
67 : Timer( rTimer
.mbAuto
, rTimer
.GetDebugName() )
69 maInvokeHandler
= rTimer
.maInvokeHandler
;
70 mnTimeout
= rTimer
.mnTimeout
;
77 Timer
& Timer::operator=( const Timer
& rTimer
)
79 Task::operator=( rTimer
);
80 maInvokeHandler
= rTimer
.maInvokeHandler
;
81 mnTimeout
= rTimer
.mnTimeout
;
82 SAL_WARN_IF( mbAuto
!= rTimer
.mbAuto
, "vcl.schedule",
83 "Copying Timer with different mbAuto value!" );
89 maInvokeHandler
.Call( this );
92 void Timer::Invoke( Timer
*arg
)
94 maInvokeHandler
.Call( arg
);
100 Task::StartTimer( mnTimeout
);
103 void Timer::SetTimeout( sal_uInt64 nNewTimeout
)
105 mnTimeout
= nNewTimeout
;
106 // If timer is active, then renew clock.
108 StartTimer( mnTimeout
);
111 AutoTimer::AutoTimer( const sal_Char
*pDebugName
)
112 : Timer( true, pDebugName
)
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */