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 #ifndef INCLUDED_SD_SOURCE_UI_INC_TOOLS_TIMERBASEDTASKEXECUTION_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_TOOLS_TIMERBASEDTASKEXECUTION_HXX
23 #include <vcl/timer.hxx>
25 #include <boost/shared_ptr.hpp>
27 namespace sd
{ namespace tools
{
29 class AsynchronousTask
;
31 /** Execute an AsynchronousTask timer based, i.e. every
32 nMillisecondsBetweenSteps milliseconds as much steps are executed as fit
33 into a nMaxTimePerStep millisecond intervall.
35 When a task is executed completely, i.e. HasNextStep() returns <FALSE/>,
36 the TimerBasedTaskExecution destroys itself. This, of course, works
37 only if the creating instance does not hold a shared_ptr to that object.
39 class TimerBasedTaskExecution
42 /** Create a new object of this class.
44 The AsynchronousTask that is to be executed.
45 @param nMillisecondsBetweenSteps
46 Wait at least this long between the execution of steps. Note
47 that more than one step may be executed in succession.
48 @param nMaxTimePerStep
49 The maximal time for executing steps without yielding control.
51 static ::boost::shared_ptr
<TimerBasedTaskExecution
> Create (
52 const ::boost::shared_ptr
<AsynchronousTask
>& rpTask
,
53 sal_uInt32 nMillisecondsBetweenSteps
,
54 sal_uInt32 nMaxTimePerStep
);
56 /** Stop the execution of the task and release the shared pointer to
57 itself so that it will eventually be destroyed.
61 /** Convenience method that calls Release() on the given task. It
62 checks the given weak_ptr for being expired and catches bad_weak_ptr
65 static void ReleaseTask (const ::boost::weak_ptr
<TimerBasedTaskExecution
>& rpTask
);
68 ::boost::shared_ptr
<AsynchronousTask
> mpTask
;
70 /** This shared_ptr to this is used to destroy a TimerBasedTaskExecution
71 object when its task has been executed completely.
73 ::boost::shared_ptr
<TimerBasedTaskExecution
> mpSelf
;
74 sal_uInt32 mnMaxTimePerStep
;
76 TimerBasedTaskExecution (
77 const ::boost::shared_ptr
<AsynchronousTask
>& rpTask
,
78 sal_uInt32 nMillisecondsBetweenSteps
,
79 sal_uInt32 nMaxTimePerStep
);
80 ~TimerBasedTaskExecution();
81 void SetSelf (const ::boost::shared_ptr
<TimerBasedTaskExecution
>& rpSelf
);
86 DECL_LINK_TYPED(TimerCallback
, Timer
*, void);
89 } } // end of namespace ::sd::tools
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */