1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX
24 #define INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX
25 
26 #include <canvas/elapsedtime.hxx>
27 
28 #include "event.hxx"
29 #include "activitiesqueue.hxx"
30 
31 #include <boost/bind.hpp>
32 #include <boost/noncopyable.hpp>
33 
34 namespace slideshow {
35 namespace internal {
36 
37 /** Little helper class, used to set Activities active again
38     after some sleep period.
39 
40     Clients can use this class to schedule wakeup events at
41     the EventQueue, to avoid busy-waiting for the next
42     discrete time instant.
43 */
44 class WakeupEvent : public Event,
45                     private ::boost::noncopyable
46 {
47 public:
48     WakeupEvent(
49         ::boost::shared_ptr< ::canvas::tools::ElapsedTime > const& pTimeBase,
50         ActivitiesQueue & rActivityQueue );
51 
52     virtual void dispose();
53     virtual bool fire();
54     virtual bool isCharged() const;
55     virtual double getActivationTime( double nCurrentTime ) const;
56 
57     /// Start the internal timer
58     void start();
59 
60     /** Set the next timeout this object should generate.
61 
62         @param nextTime
63         Absolute time, measured from the last start() call,
64         when this event should wakeup the Activity again. If
65         your time is relative, simply call start() just before
66         every setNextTimeout() call.
67     */
68     void setNextTimeout( double nextTime );
69 
70     /** Set activity to wakeup.
71 
72         The activity given here will be reinserted into the
73         ActivitiesQueue, once the timeout is reached.
74     */
75     void setActivity( const ActivitySharedPtr& rActivity );
76 
77 private:
78     ::canvas::tools::ElapsedTime    maTimer;
79     double                          mnNextTime;
80     ActivitySharedPtr               mpActivity;
81     ActivitiesQueue&                mrActivityQueue;
82 };
83 
84 typedef ::boost::shared_ptr< WakeupEvent > WakeupEventSharedPtr;
85 
86 } // namespace internal
87 } // namespace presentation
88 
89 #endif /* INCLUDED_SLIDESHOW_WAKEUPEVENT_HXX */
90