OpenShot Library | libopenshot-audio  0.2.0
juce_AsyncUpdater.h
1 
2 /** @weakgroup juce_events-broadcasters
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Has a callback method that is triggered asynchronously.
33 
34  This object allows an asynchronous callback function to be triggered, for
35  tasks such as coalescing multiple updates into a single callback later on.
36 
37  Basically, one or more calls to the triggerAsyncUpdate() will result in the
38  message thread calling handleAsyncUpdate() as soon as it can.
39 
40  @tags{Events}
41 */
43 {
44 public:
45  //==============================================================================
46  /** Creates an AsyncUpdater object. */
47  AsyncUpdater();
48 
49  /** Destructor.
50  If there are any pending callbacks when the object is deleted, these are lost.
51  */
52  virtual ~AsyncUpdater();
53 
54  //==============================================================================
55  /** Causes the callback to be triggered at a later time.
56 
57  This method returns immediately, after which a callback to the
58  handleAsyncUpdate() method will be made by the message thread as
59  soon as possible.
60 
61  If an update callback is already pending but hasn't happened yet, calling
62  this method will have no effect.
63 
64  It's thread-safe to call this method from any thread, BUT beware of calling
65  it from a real-time (e.g. audio) thread, because it involves posting a message
66  to the system queue, which means it may block (and in general will do on
67  most OSes).
68  */
69  void triggerAsyncUpdate();
70 
71  /** This will stop any pending updates from happening.
72 
73  If called after triggerAsyncUpdate() and before the handleAsyncUpdate()
74  callback happens, this will cancel the handleAsyncUpdate() callback.
75 
76  Note that this method simply cancels the next callback - if a callback is already
77  in progress on a different thread, this won't block until the callback finishes, so
78  there's no guarantee that the callback isn't still running when the method returns.
79  */
80  void cancelPendingUpdate() noexcept;
81 
82  /** If an update has been triggered and is pending, this will invoke it
83  synchronously.
84 
85  Use this as a kind of "flush" operation - if an update is pending, the
86  handleAsyncUpdate() method will be called immediately; if no update is
87  pending, then nothing will be done.
88 
89  Because this may invoke the callback, this method must only be called on
90  the main event thread.
91  */
92  void handleUpdateNowIfNeeded();
93 
94  /** Returns true if there's an update callback in the pipeline. */
95  bool isUpdatePending() const noexcept;
96 
97  //==============================================================================
98  /** Called back to do whatever your class needs to do.
99 
100  This method is called by the message thread at the next convenient time
101  after the triggerAsyncUpdate() method has been called.
102  */
103  virtual void handleAsyncUpdate() = 0;
104 
105 private:
106  //==============================================================================
107  class AsyncUpdaterMessage;
110 
111  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AsyncUpdater)
112 };
113 
114 } // namespace juce
115 
116 /** @}*/
JUCE_API
#define JUCE_API
This macro is added to all JUCE public class declarations.
Definition: juce_StandardHeader.h:143
juce::AsyncUpdater
Has a callback method that is triggered asynchronously.
Definition: juce_AsyncUpdater.h:42
juce::ReferenceCountedObjectPtr
A smart-pointer class which points to a reference-counted object.
Definition: juce_ReferenceCountedObject.h:245
juce::AsyncUpdater::AsyncUpdaterMessage
Definition: juce_AsyncUpdater.cpp:26