Line data Source code
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 <tools/time.hxx>
21 : #include <vcl/timer.hxx>
22 : #include <saltimer.hxx>
23 : #include <svdata.hxx>
24 : #include <salinst.hxx>
25 :
26 : #define MAX_TIMER_PERIOD SAL_MAX_UINT64
27 :
28 53765362 : void Timer::ImplStartTimer( ImplSVData* pSVData, sal_uInt64 nMS )
29 : {
30 53765362 : InitSystemTimer();
31 :
32 53765362 : if ( !nMS )
33 26900595 : nMS = 1;
34 :
35 : // Assume underlying timers are recurring timers, if same period - just wait.
36 53765362 : if ( nMS != pSVData->mnTimerPeriod )
37 : {
38 44628 : pSVData->mnTimerPeriod = nMS;
39 44628 : pSVData->mpSalTimer->Start( nMS );
40 : }
41 53765362 : }
42 :
43 22951 : void Timer::SetDeletionFlags()
44 : {
45 : // if no AutoTimer than stop
46 22951 : if ( !mbAuto )
47 : {
48 10978 : mpSchedulerData->mbDelete = true;
49 10978 : mbActive = false;
50 : }
51 22951 : }
52 :
53 54398144 : bool Timer::ReadyForSchedule( bool bTimer )
54 : {
55 : (void)bTimer;
56 54398144 : return (mpSchedulerData->mnUpdateTime + mnTimeout) <= tools::Time::GetSystemTicks();
57 : }
58 :
59 54391186 : sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTime )
60 : {
61 54391186 : sal_uInt64 nNewTime = tools::Time::GetSystemTicks();
62 : sal_uInt64 nDeltaTime;
63 : //determine smallest time slot
64 54391186 : if( mpSchedulerData->mnUpdateTime == nTime )
65 : {
66 35907 : nDeltaTime = mnTimeout;
67 35907 : if( nDeltaTime < nMinPeriod )
68 25155 : nMinPeriod = nDeltaTime;
69 : }
70 : else
71 : {
72 54355279 : nDeltaTime = mpSchedulerData->mnUpdateTime + mnTimeout;
73 54355279 : if( nDeltaTime < nNewTime )
74 13457 : nMinPeriod = 1;
75 : else
76 : {
77 54341822 : nDeltaTime -= nNewTime;
78 54341822 : if( nDeltaTime < nMinPeriod )
79 40587235 : nMinPeriod = nDeltaTime;
80 : }
81 : }
82 :
83 54391186 : return nMinPeriod;
84 : }
85 :
86 : /**
87 : * Initialize the platform specific timer on which all the
88 : * platform independent timers are built
89 : */
90 53765362 : void Timer::InitSystemTimer()
91 : {
92 53765362 : ImplSVData* pSVData = ImplGetSVData();
93 53765362 : if( ! pSVData->mpSalTimer )
94 : {
95 333 : pSVData->mnTimerPeriod = MAX_TIMER_PERIOD;
96 333 : pSVData->mpSalTimer = pSVData->mpDefInst->CreateSalTimer();
97 333 : pSVData->mpSalTimer->SetCallback( CallbackTaskScheduling );
98 : }
99 53765362 : }
100 :
101 294648 : Timer::Timer(const sal_Char *pDebugName) : Scheduler(pDebugName)
102 : {
103 294648 : mnTimeout = 1;
104 294648 : mbAuto = false;
105 294648 : mePriority = SchedulerPriority::HIGHEST;
106 294648 : }
107 :
108 421 : Timer::Timer( const Timer& rTimer ) : Scheduler(rTimer)
109 : {
110 421 : mnTimeout = rTimer.mnTimeout;
111 421 : mbAuto = rTimer.mbAuto;
112 421 : maTimeoutHdl = rTimer.maTimeoutHdl;
113 421 : }
114 :
115 22561 : void Timer::Invoke()
116 : {
117 22561 : maTimeoutHdl.Call( this );
118 22561 : }
119 :
120 250946 : void Timer::Start()
121 : {
122 250946 : Scheduler::Start();
123 :
124 250946 : ImplSVData* pSVData = ImplGetSVData();
125 250946 : if ( mnTimeout < pSVData->mnTimerPeriod )
126 575 : Timer::ImplStartTimer( pSVData, mnTimeout );
127 250946 : }
128 :
129 365084 : void Timer::SetTimeout( sal_uInt64 nNewTimeout )
130 : {
131 365084 : mnTimeout = nNewTimeout;
132 : // if timer is active then renew clock
133 365084 : if ( mbActive )
134 : {
135 3486 : ImplSVData* pSVData = ImplGetSVData();
136 3486 : if ( !pSVData->mnUpdateStack && (mnTimeout < pSVData->mnTimerPeriod) )
137 0 : Timer::ImplStartTimer( pSVData, mnTimeout );
138 : }
139 365084 : }
140 :
141 51 : Timer& Timer::operator=( const Timer& rTimer )
142 : {
143 51 : Scheduler::operator=(rTimer);
144 51 : maTimeoutHdl = rTimer.maTimeoutHdl;
145 51 : mnTimeout = rTimer.mnTimeout;
146 51 : mbAuto = rTimer.mbAuto;
147 51 : return *this;
148 : }
149 :
150 32716 : AutoTimer::AutoTimer()
151 : {
152 32716 : mbAuto = true;
153 32716 : }
154 :
155 421 : AutoTimer::AutoTimer( const AutoTimer& rTimer ) : Timer( rTimer )
156 : {
157 421 : mbAuto = true;
158 421 : }
159 :
160 51 : AutoTimer& AutoTimer::operator=( const AutoTimer& rTimer )
161 : {
162 51 : Timer::operator=( rTimer );
163 51 : return *this;
164 : }
165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|