1*aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*aaef562fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*aaef562fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*aaef562fSAndrew Rist * distributed with this work for additional information
6*aaef562fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*aaef562fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*aaef562fSAndrew Rist * "License"); you may not use this file except in compliance
9*aaef562fSAndrew Rist * with the License. You may obtain a copy of the License at
10*aaef562fSAndrew Rist *
11*aaef562fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*aaef562fSAndrew Rist *
13*aaef562fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*aaef562fSAndrew Rist * software distributed under the License is distributed on an
15*aaef562fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*aaef562fSAndrew Rist * KIND, either express or implied. See the License for the
17*aaef562fSAndrew Rist * specific language governing permissions and limitations
18*aaef562fSAndrew Rist * under the License.
19*aaef562fSAndrew Rist *
20*aaef562fSAndrew Rist *************************************************************/
21*aaef562fSAndrew Rist
22*aaef562fSAndrew Rist
23cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_DELAYEVENT_HXX
24cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_DELAYEVENT_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <boost/function.hpp>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "event.hxx"
29cdf0e10cSrcweir #include "debug.hxx"
30cdf0e10cSrcweir #include <boost/noncopyable.hpp>
31cdf0e10cSrcweir
32cdf0e10cSrcweir namespace slideshow {
33cdf0e10cSrcweir namespace internal {
34cdf0e10cSrcweir
35cdf0e10cSrcweir /** Event, which delays the functor call the given amount of time
36cdf0e10cSrcweir */
37cdf0e10cSrcweir class Delay : public Event, private ::boost::noncopyable
38cdf0e10cSrcweir {
39cdf0e10cSrcweir public:
40cdf0e10cSrcweir typedef ::boost::function0<void> FunctorT;
41cdf0e10cSrcweir
42cdf0e10cSrcweir template <typename FuncT>
Delay(FuncT const & func,double nTimeout,const::rtl::OUString & rsDescription)43cdf0e10cSrcweir Delay( FuncT const& func,
44cdf0e10cSrcweir double nTimeout
45cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
46cdf0e10cSrcweir , const ::rtl::OUString& rsDescription
47cdf0e10cSrcweir ) : Event(rsDescription),
48cdf0e10cSrcweir #else
49cdf0e10cSrcweir ) :
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir mnTimeout(nTimeout), maFunc(func), mbWasFired(false) {}
52cdf0e10cSrcweir
Delay(const boost::function0<void> & func,double nTimeout,const::rtl::OUString & rsDescription)53cdf0e10cSrcweir Delay( const boost::function0<void>& func,
54cdf0e10cSrcweir double nTimeout
55cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
56cdf0e10cSrcweir , const ::rtl::OUString& rsDescription
57cdf0e10cSrcweir ) : Event(rsDescription),
58cdf0e10cSrcweir #else
59cdf0e10cSrcweir ) :
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir mnTimeout(nTimeout),
62cdf0e10cSrcweir maFunc(func),
63cdf0e10cSrcweir mbWasFired(false) {}
64cdf0e10cSrcweir
65cdf0e10cSrcweir // Event:
66cdf0e10cSrcweir virtual bool fire();
67cdf0e10cSrcweir virtual bool isCharged() const;
68cdf0e10cSrcweir virtual double getActivationTime( double nCurrentTime ) const;
69cdf0e10cSrcweir // Disposable:
70cdf0e10cSrcweir virtual void dispose();
71cdf0e10cSrcweir
72cdf0e10cSrcweir private:
73cdf0e10cSrcweir double const mnTimeout;
74cdf0e10cSrcweir FunctorT maFunc;
75cdf0e10cSrcweir bool mbWasFired;
76cdf0e10cSrcweir };
77cdf0e10cSrcweir
78cdf0e10cSrcweir #if OSL_DEBUG_LEVEL <= 1
79cdf0e10cSrcweir
80cdf0e10cSrcweir /** Generate delay event
81cdf0e10cSrcweir
82cdf0e10cSrcweir @param func
83cdf0e10cSrcweir Functor to call when the event fires.
84cdf0e10cSrcweir
85cdf0e10cSrcweir @param nTimeout
86cdf0e10cSrcweir Timeout in seconds, to wait until functor is called.
87cdf0e10cSrcweir
88cdf0e10cSrcweir @return generated delay event
89cdf0e10cSrcweir */
90cdf0e10cSrcweir template <typename FuncT>
makeDelay_(FuncT const & func,double nTimeout)91cdf0e10cSrcweir inline EventSharedPtr makeDelay_( FuncT const& func, double nTimeout )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir return EventSharedPtr( new Delay( func, nTimeout ) );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir /** Generate immediate event
97cdf0e10cSrcweir
98cdf0e10cSrcweir @param func
99cdf0e10cSrcweir Functor to call when the event fires.
100cdf0e10cSrcweir
101cdf0e10cSrcweir @return generated immediate event.
102cdf0e10cSrcweir */
103cdf0e10cSrcweir template <typename FuncT>
makeEvent_(FuncT const & func)104cdf0e10cSrcweir inline EventSharedPtr makeEvent_( FuncT const& func )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir return EventSharedPtr( new Delay( func, 0.0 ) );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir
110cdf0e10cSrcweir // Strip away description.
111cdf0e10cSrcweir #define makeDelay(f, t, d) makeDelay_(f, t)
112cdf0e10cSrcweir #define makeEvent(f, d) makeEvent_(f)
113cdf0e10cSrcweir
114cdf0e10cSrcweir #else // OSL_DEBUG_LEVEL > 1
115cdf0e10cSrcweir
116cdf0e10cSrcweir class Delay_ : public Delay {
117cdf0e10cSrcweir public:
118cdf0e10cSrcweir template <typename FuncT>
Delay_(FuncT const & func,double nTimeout,char const * from_function,char const * from_file,int from_line,const::rtl::OUString & rsDescription)119cdf0e10cSrcweir Delay_( FuncT const& func, double nTimeout,
120cdf0e10cSrcweir char const* from_function, char const* from_file, int from_line,
121cdf0e10cSrcweir const ::rtl::OUString& rsDescription)
122cdf0e10cSrcweir : Delay(func, nTimeout, rsDescription),
123cdf0e10cSrcweir FROM_FUNCTION(from_function),
124cdf0e10cSrcweir FROM_FILE(from_file), FROM_LINE(from_line) {}
125cdf0e10cSrcweir
126cdf0e10cSrcweir char const* const FROM_FUNCTION;
127cdf0e10cSrcweir char const* const FROM_FILE;
128cdf0e10cSrcweir int const FROM_LINE;
129cdf0e10cSrcweir };
130cdf0e10cSrcweir
131cdf0e10cSrcweir template <typename FuncT>
makeDelay_(FuncT const & func,double nTimeout,char const * from_function,char const * from_file,int from_line,const::rtl::OUString & rsDescription)132cdf0e10cSrcweir inline EventSharedPtr makeDelay_(
133cdf0e10cSrcweir FuncT const& func, double nTimeout,
134cdf0e10cSrcweir char const* from_function, char const* from_file, int from_line,
135cdf0e10cSrcweir const ::rtl::OUString& rsDescription)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir return EventSharedPtr( new Delay_( func, nTimeout,
138cdf0e10cSrcweir from_function, from_file, from_line, rsDescription) );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir #define makeDelay(f, t, d) makeDelay_(f, t, \
142cdf0e10cSrcweir BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
143cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(d)))
144cdf0e10cSrcweir #define makeEvent(f, d) makeDelay_(f, 0.0, \
145cdf0e10cSrcweir BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
146cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(d)))
147cdf0e10cSrcweir
148cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL <= 1
149cdf0e10cSrcweir
150cdf0e10cSrcweir } // namespace internal
151cdf0e10cSrcweir } // namespace presentation
152cdf0e10cSrcweir
153cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_DELAYEVENT_HXX */
154