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>
32 /* Definition of ActivitiesQueue class */
38 /** This class handles events in a presentation. Events are
39 time instants where e.g. effects start.
45 std::shared_ptr
< ::canvas::tools::ElapsedTime
>
50 EventQueue(const EventQueue
&) = delete;
51 EventQueue
& operator=(const EventQueue
&) = delete;
53 /** Add the given event to the queue. The event is fired
54 at, or shortly after, its Event::getActivationTime instant.
56 bool addEvent( const EventSharedPtr
& event
);
58 /** Add the given event to the queue. The event is fired
59 at, or shortly after, its Event::getActivationTime instant.
60 The difference to addEvent() is that events added during
61 process() are postponed to next process().
63 bool addEventForNextRound( const EventSharedPtr
& event
);
65 /** Another way to control the order of asynchronous event
66 execution. Use this method to schedule events that are to
67 be executed after all regular events that have no delay,
68 even when they schedule new regular events without delay.
70 bool addEventWhenQueueIsEmpty (const EventSharedPtr
& rpEvent
);
72 /** Process the event queue.
74 This method executes all events whose timeout has
75 expired when calling this method (i.e. all events
76 whose scheduled time is less or equal the current
79 Check for the next available event's timeout via
80 nextTimeout(), or whether the queue is empty
81 altogether via isEmpty().
85 /** Query state of the queue
87 @return false, if queue is empty, true otherwise
91 /** Query timeout for the topmost event in the queue.
93 @return Timeout in seconds, until the next event is
94 ready. The time returned here is relative to the pres
95 timer (i.e. the timer specified at the EventQueue
96 constructor). When the queue is empty (i.e. isEmpty()
97 returns true), the returned value is the highest
98 representable double value
99 (::std::numeric_limits<double>::max()). If the topmost
100 event in the queue is already pending, the timeout
101 returned here will actually be negative.
103 double nextTimeout() const;
105 /** Remove all pending events from the queue.
109 /** Forces an empty queue, firing all events immediately
110 without minding any times.
111 @attention do only call from event loop, this calls process_()!
115 /** Gets the queue's timer object.
117 std::shared_ptr
< ::canvas::tools::ElapsedTime
> const &
118 getTimer() const { return mpTimer
; }
121 mutable ::osl::Mutex maMutex
;
125 EventSharedPtr pEvent
;
128 bool operator<( const EventEntry
& ) const; // to leverage priority_queue's default compare
130 EventEntry( EventSharedPtr
const& p
, double t
)
131 : pEvent(p
), nTime(t
) {}
134 typedef ::std::priority_queue
< EventEntry
> ImplQueueType
;
135 ImplQueueType maEvents
;
136 typedef ::std::vector
<EventEntry
> EventEntryVector
;
137 EventEntryVector maNextEvents
;
138 ImplQueueType maNextNextEvents
;
139 void process_( bool bFireAllEvents
);
141 // perform timing of events via relative time
142 // measurements. The world time starts, when the
143 // EventQueue object is created
144 std::shared_ptr
< ::canvas::tools::ElapsedTime
> mpTimer
;
149 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */