LibreOffice Module vcl (master)  1
timer.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/log.hxx>
21 #include <vcl/timer.hxx>
22 #include <vcl/scheduler.hxx>
23 #include <schedulerimpl.hxx>
24 
26 {
27  // If no AutoTimer, then stop.
28  if ( !mbAuto )
30 }
31 
32 sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64, sal_uInt64 nTimeNow ) const
33 {
34  sal_uInt64 nWakeupTime = GetSchedulerData()->mnUpdateTime + mnTimeout;
35  return ( nWakeupTime <= nTimeNow )
36  ? Scheduler::ImmediateTimeoutMs : nWakeupTime - nTimeNow;
37 }
38 
39 Timer::Timer( bool bAuto, const sal_Char *pDebugName )
40  : Task( pDebugName )
41  , mnTimeout( Scheduler::ImmediateTimeoutMs )
42  , mbAuto( bAuto )
43 {
45 }
46 
47 Timer::Timer( const sal_Char *pDebugName )
48  : Timer( false, pDebugName )
49 {
50 }
51 
52 Timer::Timer( const Timer& rTimer )
53  : Timer( rTimer.mbAuto, rTimer.GetDebugName() )
54 {
56  mnTimeout = rTimer.mnTimeout;
57 }
58 
60 {
61 }
62 
63 Timer& Timer::operator=( const Timer& rTimer )
64 {
65  Task::operator=( rTimer );
67  mnTimeout = rTimer.mnTimeout;
68  SAL_WARN_IF( mbAuto != rTimer.mbAuto, "vcl.schedule",
69  "Copying Timer with different mbAuto value!" );
70  return *this;
71 }
72 
74 {
75  maInvokeHandler.Call( this );
76 }
77 
78 void Timer::Invoke( Timer *arg )
79 {
80  maInvokeHandler.Call( arg );
81 }
82 
84 {
85  Task::Start();
87 }
88 
89 void Timer::SetTimeout( sal_uInt64 nNewTimeout )
90 {
91  mnTimeout = nNewTimeout;
92  // If timer is active, then renew clock.
93  if ( IsActive() )
95 }
96 
97 AutoTimer::AutoTimer( const sal_Char *pDebugName )
98  : Timer( true, pDebugName )
99 {
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetDeletionFlags() override
Definition: timer.cxx:25
AutoTimer(const sal_Char *pDebugName=nullptr)
Definition: timer.cxx:97
Timer(bool bAuto, const sal_Char *pDebugName)
Definition: timer.cxx:39
Link< Timer *, void > maInvokeHandler
Callback Link.
Definition: timer.hxx:28
sal_uInt64 mnUpdateTime
Last Update Time.
bool IsActive() const
Definition: task.hxx:91
Default priority used, e.g. the default timer priority.
char sal_Char
virtual ~Timer() override
Definition: timer.cxx:59
virtual void Start()
Definition: scheduler.cxx:552
sal_uInt64 mnTimeout
Definition: timer.hxx:29
virtual void Start() override
Activates the timer task.
Definition: timer.cxx:83
virtual void Invoke() override
Calls the maInvokeHandler with the parameter this.
Definition: timer.cxx:73
static constexpr sal_uInt64 ImmediateTimeoutMs
Definition: scheduler.hxx:43
void SetTimeout(sal_uInt64 nTimeoutMs)
Definition: timer.cxx:89
Task & operator=(const Task &rTask)
Definition: scheduler.cxx:611
const bool mbAuto
Definition: timer.hxx:30
virtual void SetDeletionFlags()
Definition: scheduler.cxx:547
#define SAL_WARN_IF(condition, area, stream)
static void StartTimer(sal_uInt64 nMS)
Definition: scheduler.cxx:542
virtual sal_uInt64 UpdateMinPeriod(sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow) const override
How long (in MS) until the Task is ready to be dispatched?
Definition: timer.cxx:32
Definition: timer.hxx:26
void SetPriority(TaskPriority ePriority)
Definition: scheduler.cxx:601
Definition: task.hxx:41
const ImplSchedulerData * GetSchedulerData() const
Definition: task.hxx:55
Timer & operator=(const Timer &rTimer)
Definition: timer.cxx:63