LibreOffice Module slideshow (master) 1
interruptabledelayevent.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SLIDESHOW_SOURCE_INC_INTERRUPTABLEDELAYEVENT_HXX
21#define INCLUDED_SLIDESHOW_SOURCE_INC_INTERRUPTABLEDELAYEVENT_HXX
22
23#include "delayevent.hxx"
24
25#include <utility>
26
27namespace slideshow::internal
28 {
36 class DelayFacade : public Event
37 {
38 public:
40 double nTimeout ) :
41 Event("DelayFacade"),
42 mpEvent(std::move( xEvent )),
43 mnTimeout( nTimeout )
44 {
45 }
46
47 virtual bool fire() override
48 {
49 if( mpEvent && isCharged() )
50 {
51 // pass on directly - we're supposed to be called
52 // from EventQueue here, anyway - and if not,
53 // we're only keeping that incorrect transitively.
54 return mpEvent->fire();
55 }
56
57 return false;
58 }
59
60 virtual bool isCharged() const override
61 {
62 // pass on to wrappee - this ensures that we return
63 // false on isCharged(), even if the other event has
64 // been fired outside our own fire() method
65 return mpEvent && mpEvent->isCharged();
66 }
67
68 virtual double getActivationTime( double nCurrentTime ) const override
69 {
70 // enforce _our_ timeout to our clients (this
71 // overrides any timeout possibly set at the wrappee!)
72 return nCurrentTime + mnTimeout;
73 }
74
75 virtual void dispose() override
76 {
77 mpEvent.reset();
78 }
79
80 private:
82 double mnTimeout;
83 };
84
87 {
93
100 };
101
126 template< typename Functor > InterruptableEventPair makeInterruptableDelay( const Functor& rFunctor,
127 double nTimeout )
128 {
130
131 aRes.mpImmediateEvent = makeEvent( rFunctor, "makeInterruptableDelay");
132 aRes.mpTimeoutEvent = std::make_shared<DelayFacade>( aRes.mpImmediateEvent,
133 nTimeout );
134
135 return aRes;
136 }
137
138}
139
140#endif // INCLUDED_SLIDESHOW_SOURCE_INC_INTERRUPTABLEDELAYEVENT_HXX
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Event, which delays calling passed Event's fire() method the given amount of time.
virtual bool isCharged() const override
Query whether this event is still charged, i.e.
virtual bool fire() override
Execute the event.
DelayFacade(EventSharedPtr xEvent, double nTimeout)
virtual double getActivationTime(double nCurrentTime) const override
Query the activation time instant this event shall be fired, if it was inserted at instant nCurrentTi...
virtual void dispose() override
Dispose all object references.
Definition of Event interface.
Definition: event.hxx:33
#define makeEvent(f, d)
Definition: delayevent.hxx:131
::std::shared_ptr< Event > EventSharedPtr
Definition: event.hxx:76
InterruptableEventPair makeInterruptableDelay(const Functor &rFunctor, double nTimeout)
Generate an interruptable delay event.
Return value for makeInterruptableDelay()
EventSharedPtr mpImmediateEvent
This member contains a pointer to the interruption event.
EventSharedPtr mpTimeoutEvent
This member contains a pointer to the timeout event.