1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
23 #include <canvas/elapsedtime.hxx>
24 #include <osl/mutex.hxx>
28 #include <boost/noncopyable.hpp>
34 /* Definition of ActivitiesQueue class */
40 /** This class handles events in a presentation. Events are
41 time instants where e.g. effects start.
43 class EventQueue
: private ::boost::noncopyable
47 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
>
52 /** Add the given event to the queue. The event is fired
53 at, or shortly after, its Event::getActivationTime instant.
55 bool addEvent( const EventSharedPtr
& event
);
57 /** Add the given event to the queue. The event is fired
58 at, or shortly after, its Event::getActivationTime instant.
59 The difference to addEvent() is that events added during
60 process() are postponed to next process().
62 bool addEventForNextRound( const EventSharedPtr
& event
);
64 /** Another way to control the order of asynchronous event
65 exeqution. Use this method to schedule events that are to
66 be executed after all regular events that have no delay,
67 even when they schedule new regular events without delay.
69 bool addEventWhenQueueIsEmpty (const EventSharedPtr
& rpEvent
);
71 /** Process the event queue.
73 This method executes all events whose timeout has
74 expired when calling this method (i.e. all events
75 whose scheduled time is less or equal the current
78 Check for the next available event's timeout via
79 nextTimeout(), or whether the queue is empty
80 altogether via isEmpty().
84 /** Query state of the queue
86 @return false, if queue is empty, true otherwise
90 /** Query timeout for the topmost event in the queue.
92 @return Timeout in seconds, until the next event is
93 ready. The time returned here is relative to the pres
94 timer (i.e. the timer specified at the EventQueue
95 constructor). When the queue is empty (i.e. isEmpty()
96 returns true), the returned value is the highest
97 representable double value
98 (::std::numeric_limits<double>::max()). If the topmost
99 event in the queue is already pending, the timeout
100 returned here will actually be negative.
102 double nextTimeout() const;
104 /** Remove all pending events from the queue.
108 /** Forces an empty queue, firing all events immediately
109 without minding any times.
110 @attention do only call from event loop, this calls process_()!
114 /** Gets the queue's timer object.
116 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
> const &
117 getTimer() const { return mpTimer
; }
120 mutable ::osl::Mutex maMutex
;
122 struct EventEntry
: public ::std::unary_function
<EventEntry
, bool>
124 EventSharedPtr pEvent
;
127 bool operator<( const EventEntry
& ) const; // to leverage priority_queue's default compare
129 EventEntry( EventSharedPtr
const& p
, double t
)
130 : pEvent(p
), nTime(t
) {}
133 typedef ::std::priority_queue
< EventEntry
> ImplQueueType
;
134 ImplQueueType maEvents
;
135 typedef ::std::vector
<EventEntry
> EventEntryVector
;
136 EventEntryVector maNextEvents
;
137 ImplQueueType maNextNextEvents
;
138 void process_( bool bFireAllEvents
);
140 // perform timing of events via relative time
141 // measurements. The world time starts, when the
142 // EventQueue object is created
143 ::boost::shared_ptr
< ::canvas::tools::ElapsedTime
> mpTimer
;
148 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */