sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / slideshow / source / inc / eventqueue.hxx
blob41c6201b60a256689de8d3b657ce9637793581de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "event.hxx"
27 #include <mutex>
28 #include <queue>
29 #include <utility>
30 #include <vector>
33 /* Definition of ActivitiesQueue class */
35 namespace slideshow::internal
37 /** This class handles events in a presentation. Events are
38 time instants where e.g. effects start.
40 class EventQueue
42 public:
43 EventQueue(
44 std::shared_ptr< ::canvas::tools::ElapsedTime > pPresTimer );
46 ~EventQueue();
48 EventQueue(const EventQueue&) = delete;
49 EventQueue& operator=(const EventQueue&) = delete;
51 /** Add the given event to the queue. The event is fired
52 at, or shortly after, its Event::getActivationTime instant.
54 bool addEvent( const EventSharedPtr& event );
56 /** Add the given event to the queue. The event is fired
57 at, or shortly after, its Event::getActivationTime instant.
58 The difference to addEvent() is that events added during
59 process() are postponed to next process().
61 bool addEventForNextRound( const EventSharedPtr& event );
63 /** Another way to control the order of asynchronous event
64 execution. Use this method to schedule events that are to
65 be executed after all regular events that have no delay,
66 even when they schedule new regular events without delay.
68 bool addEventWhenQueueIsEmpty (const EventSharedPtr& rpEvent);
70 /** Process the event queue.
72 This method executes all events whose timeout has
73 expired when calling this method (i.e. all events
74 whose scheduled time is less or equal the current
75 time).
77 Check for the next available event's timeout via
78 nextTimeout(), or whether the queue is empty
79 altogether via isEmpty().
81 void process();
83 /** Query state of the queue
85 @return false, if queue is empty, true otherwise
87 bool isEmpty() const;
89 /** Query timeout for the topmost event in the queue.
91 @return Timeout in seconds, until the next event is
92 ready. The time returned here is relative to the pres
93 timer (i.e. the timer specified at the EventQueue
94 constructor). When the queue is empty (i.e. isEmpty()
95 returns true), the returned value is the highest
96 representable double value
97 (::std::numeric_limits<double>::max()). If the topmost
98 event in the queue is already pending, the timeout
99 returned here will actually be negative.
101 double nextTimeout() const;
103 /** Remove all pending events from the queue.
105 void clear();
107 /** Forces an empty queue, firing all events immediately
108 without minding any times.
109 @attention do only call from event loop, this calls process_()!
111 void forceEmpty();
113 /** Gets the queue's timer object.
115 std::shared_ptr< ::canvas::tools::ElapsedTime > const &
116 getTimer() const { return mpTimer; }
118 private:
119 mutable std::mutex maMutex;
121 struct EventEntry
123 EventSharedPtr pEvent;
124 double nTime;
126 bool operator<( const EventEntry& ) const; // to leverage priority_queue's default compare
128 EventEntry( EventSharedPtr p, double t )
129 : pEvent(std::move(p)), nTime(t) {}
132 typedef ::std::priority_queue< EventEntry > ImplQueueType;
133 ImplQueueType maEvents;
134 typedef ::std::vector<EventEntry> EventEntryVector;
135 EventEntryVector maNextEvents;
136 ImplQueueType maNextNextEvents;
137 void process_( bool bFireAllEvents );
139 // perform timing of events via relative time
140 // measurements. The world time starts, when the
141 // EventQueue object is created
142 std::shared_ptr< ::canvas::tools::ElapsedTime > mpTimer;
146 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTQUEUE_HXX
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */