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 
24 #ifndef INCLUDED_SLIDESHOW_ACTIVITIESQUEUE_HXX
25 #define INCLUDED_SLIDESHOW_ACTIVITIESQUEUE_HXX
26 
27 #include <deque>
28 
29 #include "activity.hxx"
30 #include "unoviewcontainer.hxx"
31 
32 #include <canvas/elapsedtime.hxx>
33 
34 #include <boost/shared_ptr.hpp>
35 #include <boost/utility.hpp> // for boost::noncopyable
36 
37 
38 /* Definition of ActivitiesQueue class */
39 
40 namespace slideshow
41 {
42     namespace internal
43     {
44 		/** This class handles the XSprite updates needed for
45             animations, such as moves, scales etc. You can add
46             activity objects to this class, which are called in a
47             round-robin fashion.
48         */
49         class ActivitiesQueue : private ::boost::noncopyable
50         {
51         public:
52             /** Create an ActivitiesQueue.
53 
54             	@param pPresTimer
55                 Pointer to global presentation timer. Used for
56                 adjusting and holding global presentation time.
57              */
58             ActivitiesQueue(
59                 const ::boost::shared_ptr< ::canvas::tools::ElapsedTime >&	pPresTimer );
60             ~ActivitiesQueue();
61 
62             /** Add the given activity to the queue.
63              */
64             bool addActivity( const ActivitySharedPtr& pActivity );
65 
66             /** Process the activities queue.
67 
68             	This method performs the smallest atomic processing
69             	possible on the queue (typically, this means one
70             	activity get processed).
71              */
72             void process();
73 
74             /** Call all dequeued activities' dequeued() method
75              */
76             void processDequeued();
77 
78 			/** Query state of the queue
79 
80                 @return false, if queue is empty, true otherwise
81              */
82             bool isEmpty() const;
83 
84             /** Remove all pending activities from the queue.
85              */
86             void clear();
87 
88             /** Gets the queue's timer object.
89              */
90             ::boost::shared_ptr< ::canvas::tools::ElapsedTime > const &
getTimer() const91             getTimer() const { return mpTimer; }
92 
93             /** returns number of all activities, waiting, reinserted and dequeued
94              */
size() const95             std::size_t size() const
96             {
97                 return maCurrentActivitiesWaiting.size() + maCurrentActivitiesReinsert.size() + maDequeuedActivities.size();
98             }
99 
100         private:
101             ::boost::shared_ptr< ::canvas::tools::ElapsedTime > mpTimer;
102 
103             typedef ::std::deque< ActivitySharedPtr > ActivityQueue;
104 
105             ActivityQueue 			maCurrentActivitiesWaiting;  // currently running
106                                     				             // activities, that still
107 				                                                 // await processing for this
108                 				                                 // round
109 
110             ActivityQueue 			maCurrentActivitiesReinsert; 	// currently running
111 												                  	// activities, that are
112 										                          	// already processed for
113 										                          	// this round, and wants
114 				            										// to be reinserted next
115 				            										// round
116 
117             ActivityQueue           maDequeuedActivities; // This list collects all activities which did not request
118                                                           // a reinsertion. After the screen update has been
119                                                           // performed, those are notified via dequeued(). This
120                                                           // facilitates cleanup actions taking place _after_ the
121                                                           // current frame has been displayed.
122         };
123 
124     }
125 }
126 #endif /* INCLUDED_SLIDESHOW_ACTIVITIESQUEUE_HXX */
127