1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AsynchronousCall.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_ASYNCHRONOUS_CALL_HXX
32 #define SD_ASYNCHRONOUS_CALL_HXX
34 #include <vcl/timer.hxx>
36 #include <boost/function.hpp>
38 namespace sd
{ namespace tools
{
41 /** Store a function object and execute it asynchronous.
43 The features of this class are:
44 a) It provides a wrapper around a VCL Timer so that generic function
46 b) When more than one function objects are posted to be executed later
47 then the pending ones are erased and only the last one will actually be
50 Use this class like this:
51 aInstanceOfAsynchronousCall.Post(
53 ::std::mem_fun(&DrawViewShell::SwitchPage),
57 class AsynchronousCall
60 /** Create a new asynchronous call. Each object of this class processes
61 one (semantical) type of call.
63 AsynchronousCall (void);
65 ~AsynchronousCall (void);
67 /** Post a function object that is to be executed asynchronously. When
68 this method is called while the current function object has not bee
69 executed then the later is destroyed and only the given function
70 object will be executed.
72 The function object that may be called asynchronously in the
74 @param nTimeoutInMilliseconds
75 The timeout in milliseconds until the function object is
78 typedef ::boost::function0
<void> AsynchronousFunction
;
80 const AsynchronousFunction
& rFunction
,
81 sal_uInt32 nTimeoutInMilliseconds
=10);
85 /** The function object that will be executed when the TimerCallback
86 function is called the next time. This pointer may be NULL.
88 ::std::auto_ptr
<AsynchronousFunction
> mpFunction
;
89 DECL_LINK(TimerCallback
,Timer
*);
93 } } // end of namespace ::sd::tools