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 .
22 #include <vcl/timer.hxx>
28 class AsynchronousTask
;
30 /** Execute an AsynchronousTask timer based, i.e. every
31 nMillisecondsBetweenSteps milliseconds as much steps are executed as fit
32 into a nMaxTimePerStep millisecond interval.
34 When a task is executed completely, i.e. HasNextStep() returns <FALSE/>,
35 the TimerBasedTaskExecution destroys itself. This, of course, works
36 only if the creating instance does not hold a shared_ptr to that object.
38 class TimerBasedTaskExecution
41 /** Create a new object of this class.
43 The AsynchronousTask that is to be executed.
44 @param nMillisecondsBetweenSteps
45 Wait at least this long between the execution of steps. Note
46 that more than one step may be executed in succession.
47 @param nMaxTimePerStep
48 The maximal time for executing steps without yielding control.
50 static std::shared_ptr
<TimerBasedTaskExecution
> Create (
51 const std::shared_ptr
<AsynchronousTask
>& rpTask
,
52 sal_uInt32 nMillisecondsBetweenSteps
,
53 sal_uInt32 nMaxTimePerStep
);
55 /** Stop the execution of the task and release the shared pointer to
56 itself so that it will eventually be destroyed.
60 /** Convenience method that calls Release() on the given task. It
61 checks the given weak_ptr for being expired and catches bad_weak_ptr
64 static void ReleaseTask (const std::weak_ptr
<TimerBasedTaskExecution
>& rpTask
);
67 std::shared_ptr
<AsynchronousTask
> mpTask
;
69 /** This shared_ptr to this is used to destroy a TimerBasedTaskExecution
70 object when its task has been executed completely.
72 std::shared_ptr
<TimerBasedTaskExecution
> mpSelf
;
73 sal_uInt32 mnMaxTimePerStep
;
75 TimerBasedTaskExecution (
76 std::shared_ptr
<AsynchronousTask
> pTask
,
77 sal_uInt32 nMillisecondsBetweenSteps
,
78 sal_uInt32 nMaxTimePerStep
);
79 ~TimerBasedTaskExecution();
84 DECL_LINK(TimerCallback
, Timer
*, void);
87 } // end of namespace ::sd::tools
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */