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 <sal/log.hxx>
21 #include <vcl/timer.hxx>
22 #include <vcl/scheduler.hxx>
23 #include <schedulerimpl.hxx>
25 void Timer::SetDeletionFlags()
27 // If no AutoTimer, then stop.
29 Task::SetDeletionFlags();
32 sal_uInt64
Timer::UpdateMinPeriod( sal_uInt64 nTimeNow
) const
34 sal_uInt64 nWakeupTime
= GetSchedulerData()->mnUpdateTime
+ mnTimeout
;
35 return ( nWakeupTime
<= nTimeNow
)
36 ? Scheduler::ImmediateTimeoutMs
: nWakeupTime
- nTimeNow
;
39 Timer::Timer( bool bAuto
, const sal_Char
*pDebugName
)
41 , mnTimeout( Scheduler::ImmediateTimeoutMs
)
44 SetPriority( TaskPriority::DEFAULT
);
47 Timer::Timer( const sal_Char
*pDebugName
)
48 : Timer( false, pDebugName
)
52 Timer::Timer( const Timer
& rTimer
)
53 : Timer( rTimer
.mbAuto
, rTimer
.GetDebugName() )
55 maInvokeHandler
= rTimer
.maInvokeHandler
;
56 mnTimeout
= rTimer
.mnTimeout
;
63 Timer
& Timer::operator=( const Timer
& rTimer
)
65 Task::operator=( rTimer
);
66 maInvokeHandler
= rTimer
.maInvokeHandler
;
67 mnTimeout
= rTimer
.mnTimeout
;
68 SAL_WARN_IF( mbAuto
!= rTimer
.mbAuto
, "vcl.schedule",
69 "Copying Timer with different mbAuto value!" );
75 maInvokeHandler
.Call( this );
78 void Timer::Invoke( Timer
*arg
)
80 maInvokeHandler
.Call( arg
);
86 Task::StartTimer( mnTimeout
);
89 void Timer::SetTimeout( sal_uInt64 nNewTimeout
)
91 mnTimeout
= nNewTimeout
;
92 // If timer is active, then renew clock.
94 StartTimer( mnTimeout
);
97 AutoTimer::AutoTimer( const sal_Char
*pDebugName
)
98 : Timer( true, pDebugName
)
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */