1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <wakeupevent.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace slideshow
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     namespace internal
37cdf0e10cSrcweir     {
38cdf0e10cSrcweir         WakeupEvent::WakeupEvent(
39cdf0e10cSrcweir             boost::shared_ptr<canvas::tools::ElapsedTime> const & pTimeBase,
40cdf0e10cSrcweir             ActivitiesQueue& rActivityQueue ) :
41cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
42cdf0e10cSrcweir             Event(::rtl::OUString::createFromAscii("WakeupEvent")),
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir             maTimer(pTimeBase),
45cdf0e10cSrcweir             mnNextTime(0.0),
46cdf0e10cSrcweir             mpActivity(),
47cdf0e10cSrcweir             mrActivityQueue( rActivityQueue )
48cdf0e10cSrcweir         {
49cdf0e10cSrcweir         }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         void WakeupEvent::dispose()
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir             mpActivity.reset();
54cdf0e10cSrcweir         }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         bool WakeupEvent::fire()
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             if( !mpActivity )
59cdf0e10cSrcweir                 return false;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir             return mrActivityQueue.addActivity( mpActivity );
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         bool WakeupEvent::isCharged() const
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             // this event won't expire, we fire everytime we're
67cdf0e10cSrcweir             // re-inserted into the event queue.
68cdf0e10cSrcweir             return true;
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         double WakeupEvent::getActivationTime( double nCurrentTime ) const
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             const double nElapsedTime( maTimer.getElapsedTime() );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             return ::std::max( nCurrentTime,
76cdf0e10cSrcweir                                nCurrentTime - nElapsedTime + mnNextTime );
77cdf0e10cSrcweir         }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         void WakeupEvent::start()
80cdf0e10cSrcweir         {
81cdf0e10cSrcweir             // start timer
82cdf0e10cSrcweir             maTimer.reset();
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         void WakeupEvent::setNextTimeout( double rNextTime )
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             mnNextTime = rNextTime;
88cdf0e10cSrcweir         }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         void WakeupEvent::setActivity( const ActivitySharedPtr& rActivity )
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             mpActivity = rActivity;
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir }
96