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
32sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nTimeNow ) const
33{
34 sal_uInt64 nWakeupTime = GetSchedulerData()->mnUpdateTime + mnTimeout;
35 return ( nWakeupTime <= nTimeNow )
36 ? Scheduler::ImmediateTimeoutMs : nWakeupTime - nTimeNow;
37}
38
39Timer::Timer( bool bAuto, const char *pDebugName )
40 : Task( pDebugName )
41 , mnTimeout( Scheduler::ImmediateTimeoutMs )
42 , mbAuto( bAuto )
43{
45}
46
47Timer::Timer( const char *pDebugName )
48 : Timer( false, pDebugName )
49{
50}
51
52Timer::Timer( const Timer& rTimer )
53 : Timer( rTimer.mbAuto, rTimer.GetDebugName() )
54{
56 mnTimeout = rTimer.mnTimeout;
57}
58
60{
61}
62
63Timer& 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
78void Timer::Invoke( Timer *arg )
79{
80 maInvokeHandler.Call( arg );
81}
82
83void Timer::Start(const bool bStartTimer)
84{
85 Task::Start(false);
86 if (bStartTimer)
88}
89
90void Timer::SetTimeout( sal_uInt64 nNewTimeout )
91{
92 mnTimeout = nNewTimeout;
93 // If timer is active, then renew clock.
94 if ( IsActive() )
96}
97
98AutoTimer::AutoTimer( const char *pDebugName )
99 : Timer( true, pDebugName )
100{
101}
102
103/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AutoTimer(const char *pDebugName)
Definition: timer.cxx:98
static constexpr sal_uInt64 ImmediateTimeoutMs
Definition: scheduler.hxx:43
Definition: task.hxx:43
bool IsActive() const
Definition: task.hxx:101
void SetPriority(TaskPriority ePriority)
Definition: scheduler.cxx:606
const ImplSchedulerData * GetSchedulerData() const
Definition: task.hxx:56
Task & operator=(const Task &rTask)
Definition: scheduler.cxx:616
virtual void Start(bool bStartTimer=true)
Schedules the task for execution.
Definition: scheduler.cxx:554
virtual void SetDeletionFlags()
Definition: scheduler.cxx:549
static void StartTimer(sal_uInt64 nMS)
Definition: scheduler.cxx:544
Definition: timer.hxx:27
Link< Timer *, void > maInvokeHandler
Callback Link.
Definition: timer.hxx:28
sal_uInt64 mnTimeout
Definition: timer.hxx:29
virtual sal_uInt64 UpdateMinPeriod(sal_uInt64 nTimeNow) const override
How long (in MS) until the Task is ready to be dispatched?
Definition: timer.cxx:32
void SetTimeout(sal_uInt64 nTimeoutMs)
Definition: timer.cxx:90
virtual void Start(bool bStartTimer=true) override
Schedules the task for execution.
Definition: timer.cxx:83
virtual void Invoke() override
Calls the maInvokeHandler with the parameter this.
Definition: timer.cxx:73
const bool mbAuto
Definition: timer.hxx:30
Timer(bool bAuto, const char *pDebugName)
Definition: timer.cxx:39
Timer & operator=(const Timer &rTimer)
Definition: timer.cxx:63
virtual ~Timer() override
Definition: timer.cxx:59
virtual void SetDeletionFlags() override
Definition: timer.cxx:25
#define SAL_WARN_IF(condition, area, stream)
sal_uInt64 mnUpdateTime
Last Update Time.
@ DEFAULT
Default priority used, e.g. the default timer priority.