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>
33 /* Definition of ActivitiesQueue class */
39 /** This class handles events in a presentation. Events are
40 time instants where e.g. effects start.
46 std::shared_ptr
< ::canvas::tools::ElapsedTime
>
51 EventQueue(const EventQueue
&) = delete;
52 EventQueue
& operator=(const EventQueue
&) = delete;
54 /** Add the given event to the queue. The event is fired
55 at, or shortly after, its Event::getActivationTime instant.
57 bool addEvent( const EventSharedPtr
& event
);
59 /** Add the given event to the queue. The event is fired
60 at, or shortly after, its Event::getActivationTime instant.
61 The difference to addEvent() is that events added during
62 process() are postponed to next process().
64 bool addEventForNextRound( const EventSharedPtr
& event
);
66 /** Another way to control the order of asynchronous event
67 execution. Use this method to schedule events that are to
68 be executed after all regular events that have no delay,
69 even when they schedule new regular events without delay.
71 bool addEventWhenQueueIsEmpty (const EventSharedPtr
& rpEvent
);
73 /** Process the event queue.
75 This method executes all events whose timeout has
76 expired when calling this method (i.e. all events
77 whose scheduled time is less or equal the current
80 Check for the next available event's timeout via
81 nextTimeout(), or whether the queue is empty
82 altogether via isEmpty().
86 /** Query state of the queue
88 @return false, if queue is empty, true otherwise
92 /** Query timeout for the topmost event in the queue.
94 @return Timeout in seconds, until the next event is
95 ready. The time returned here is relative to the pres
96 timer (i.e. the timer specified at the EventQueue
97 constructor). When the queue is empty (i.e. isEmpty()
98 returns true), the returned value is the highest
99 representable double value
100 (::std::numeric_limits<double>::max()). If the topmost
101 event in the queue is already pending, the timeout
102 returned here will actually be negative.
104 double nextTimeout() const;
106 /** Remove all pending events from the queue.
110 /** Forces an empty queue, firing all events immediately
111 without minding any times.
112 @attention do only call from event loop, this calls process_()!
116 /** Gets the queue's timer object.
118 std::shared_ptr
< ::canvas::tools::ElapsedTime
> const &
119 getTimer() const { return mpTimer
; }
122 mutable ::osl::Mutex maMutex
;
124 struct EventEntry
: public ::std::unary_function
<EventEntry
, bool>
126 EventSharedPtr pEvent
;
129 bool operator<( const EventEntry
& ) const; // to leverage priority_queue's default compare
131 EventEntry( EventSharedPtr
const& p
, double t
)
132 : pEvent(p
), nTime(t
) {}
135 typedef ::std::priority_queue
< EventEntry
> ImplQueueType
;
136 ImplQueueType maEvents
;
137 typedef ::std::vector
<EventEntry
> EventEntryVector
;
138 EventEntryVector maNextEvents
;
139 ImplQueueType maNextNextEvents
;
140 void process_( bool bFireAllEvents
);
142 // perform timing of events via relative time
143 // measurements. The world time starts, when the
144 // EventQueue object is created
145 std::shared_ptr
< ::canvas::tools::ElapsedTime
> mpTimer
;
150 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */