1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eventqueue.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_EVENTQUEUE_HXX
32 #define INCLUDED_SLIDESHOW_EVENTQUEUE_HXX
34 #include <canvas/elapsedtime.hxx>
35 #include <osl/mutex.hxx>
39 #include <boost/noncopyable.hpp>
45 /* Definition of ActivitiesQueue class */
51 /** This class handles events in a presentation. Events are
52 time instants where e.g. effects start.
54 class EventQueue
: private ::boost::noncopyable
58 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
>
63 /** Add the given event to the queue. The event is fired
64 at, or shortly after, its Event::getActivationTime instant.
66 bool addEvent( const EventSharedPtr
& event
);
68 /** Add the given event to the queue. The event is fired
69 at, or shortly after, its Event::getActivationTime instant.
70 The difference to addEvent() is that events added during
71 process() are postponed to next process().
73 bool addEventForNextRound( const EventSharedPtr
& event
);
75 /** Another way to control the order of asynchronous event
76 exeqution. Use this method to schedule events that are to
77 be executed after all regular events that have no delay,
78 even when they schedule new regular events without delay.
80 bool addEventWhenQueueIsEmpty (const EventSharedPtr
& rpEvent
);
82 /** Process the event queue.
84 This method executes all events whose timeout has
85 expired when calling this method (i.e. all events
86 whose scheduled time is less or equal the current
89 Check for the next available event's timeout via
90 nextTimeout(), or whether the queue is empty
91 altogether via isEmpty().
95 /** Query state of the queue
97 @return false, if queue is empty, true otherwise
101 /** Query timeout for the topmost event in the queue.
103 @return Timeout in seconds, until the next event is
104 ready. The time returned here is relative to the pres
105 timer (i.e. the timer specified at the EventQueue
106 constructor). When the queue is empty (i.e. isEmpty()
107 returns true), the returned value is the highest
108 representable double value
109 (::std::numeric_limits<double>::max()). If the topmost
110 event in the queue is already pending, the timeout
111 returned here will actually be negative.
113 double nextTimeout() const;
115 /** Remove all pending events from the queue.
119 /** Forces an empty queue, firing all events immediately
120 without minding any times.
121 @attention do only call from event loop, this calls process_()!
125 /** Gets the queue's timer object.
127 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
> const &
128 getTimer() const { return mpTimer
; }
131 mutable ::osl::Mutex maMutex
;
133 struct EventEntry
: public ::std::unary_function
<EventEntry
, bool>
135 EventSharedPtr pEvent
;
138 bool operator<( const EventEntry
& ) const; // to leverage priority_queue's default compare
140 EventEntry( EventSharedPtr
const& p
, double t
)
141 : pEvent(p
), nTime(t
) {}
144 typedef ::std::priority_queue
< EventEntry
> ImplQueueType
;
145 ImplQueueType maEvents
;
146 typedef ::std::vector
<EventEntry
> EventEntryVector
;
147 EventEntryVector maNextEvents
;
148 ImplQueueType maNextNextEvents
;
149 void process_( bool bFireAllEvents
);
151 // perform timing of events via relative time
152 // measurements. The world time starts, when the
153 // EventQueue object is created
154 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
> mpTimer
;
159 #endif /* INCLUDED_SLIDESHOW_EVENTQUEUE_HXX */