xref: /AOO41X/main/slideshow/source/inc/wakeupevent.hxx (revision aaef562f9b4401da6d8a910634bb68eaaacb4ebd)
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
10cdf0e10cSrcweir  *
11*aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
20*aaef562fSAndrew Rist  *************************************************************/
21*aaef562fSAndrew Rist 
22*aaef562fSAndrew Rist 
23cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX
24cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <canvas/elapsedtime.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "event.hxx"
29cdf0e10cSrcweir #include "activitiesqueue.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <boost/bind.hpp>
32cdf0e10cSrcweir #include <boost/noncopyable.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace slideshow {
35cdf0e10cSrcweir namespace internal {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /** Little helper class, used to set Activities active again
38cdf0e10cSrcweir     after some sleep period.
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     Clients can use this class to schedule wakeup events at
41cdf0e10cSrcweir     the EventQueue, to avoid busy-waiting for the next
42cdf0e10cSrcweir     discrete time instant.
43cdf0e10cSrcweir */
44cdf0e10cSrcweir class WakeupEvent : public Event,
45cdf0e10cSrcweir                     private ::boost::noncopyable
46cdf0e10cSrcweir {
47cdf0e10cSrcweir public:
48cdf0e10cSrcweir     WakeupEvent(
49cdf0e10cSrcweir         ::boost::shared_ptr< ::canvas::tools::ElapsedTime > const& pTimeBase,
50cdf0e10cSrcweir         ActivitiesQueue & rActivityQueue );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     virtual void dispose();
53cdf0e10cSrcweir     virtual bool fire();
54cdf0e10cSrcweir     virtual bool isCharged() const;
55cdf0e10cSrcweir     virtual double getActivationTime( double nCurrentTime ) const;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /// Start the internal timer
58cdf0e10cSrcweir     void start();
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /** Set the next timeout this object should generate.
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         @param nextTime
63cdf0e10cSrcweir         Absolute time, measured from the last start() call,
64cdf0e10cSrcweir         when this event should wakeup the Activity again. If
65cdf0e10cSrcweir         your time is relative, simply call start() just before
66cdf0e10cSrcweir         every setNextTimeout() call.
67cdf0e10cSrcweir     */
68cdf0e10cSrcweir     void setNextTimeout( double nextTime );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** Set activity to wakeup.
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         The activity given here will be reinserted into the
73cdf0e10cSrcweir         ActivitiesQueue, once the timeout is reached.
74cdf0e10cSrcweir     */
75cdf0e10cSrcweir     void setActivity( const ActivitySharedPtr& rActivity );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir private:
78cdf0e10cSrcweir     ::canvas::tools::ElapsedTime    maTimer;
79cdf0e10cSrcweir     double                          mnNextTime;
80cdf0e10cSrcweir     ActivitySharedPtr               mpActivity;
81cdf0e10cSrcweir     ActivitiesQueue&                mrActivityQueue;
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir typedef ::boost::shared_ptr< WakeupEvent > WakeupEventSharedPtr;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir } // namespace internal
87cdf0e10cSrcweir } // namespace presentation
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX */
90