webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
signal_utils.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // signal_utils:
7 // Helper classes for tracking dependent state changes between objects.
8 // These changes are signaled to the dependent class via channels.
9 
10 #ifndef LIBANGLE_SIGNAL_UTILS_H_
11 #define LIBANGLE_SIGNAL_UTILS_H_
12 
13 #include <set>
14 
15 #include "common/angleutils.h"
16 
17 namespace angle
18 {
19 
20 // Message token passed to the receiver;
22 
23 // Interface that the depending class inherits from.
25 {
26  public:
27  virtual ~SignalReceiver() = default;
28  virtual void signal(SignalToken token) = 0;
29 };
30 
31 class ChannelBinding;
32 
33 // The host class owns the channel. It uses the channel to fire signals to the receiver.
35 {
36  public:
39 
40  void signal() const;
41  void reset();
42 
43  private:
44  // Only the ChannelBinding class should add or remove receivers.
45  friend class ChannelBinding;
46  void addReceiver(ChannelBinding *receiver);
47  void removeReceiver(ChannelBinding *receiver);
48 
49  std::vector<ChannelBinding *> mReceivers;
50 };
51 
52 // The dependent class keeps bindings to the host's BroadcastChannel.
54 {
55  public:
57  ~ChannelBinding();
58  ChannelBinding(const ChannelBinding &other) = default;
59  ChannelBinding &operator=(const ChannelBinding &other) = default;
60 
61  void bind(BroadcastChannel *channel);
62  void reset();
63  void signal() const;
64  void onChannelClosed();
65 
66  private:
67  BroadcastChannel *mChannel;
68  SignalReceiver *mReceiver;
69  SignalToken mToken;
70 };
71 
72 } // namespace angle
73 
74 #endif // LIBANGLE_SIGNAL_UTILS_H_
virtual void signal(SignalToken token)=0
Definition: signal_utils.h:24
Definition: rtcweb.c:78
std::integral_constant< std::uint32_t, V > uint32_t
Definition: Brigand.h:441
uint32_t SignalToken
Definition: signal_utils.h:21
Definition: Platform.h:33
Definition: signal_utils.h:34
Definition: signal_utils.h:53
Definition: rtpw.c:144
Definition: ApplePayLineItem.idl:30
Definition: angleutils.h:26
virtual ~SignalReceiver()=default
const AtomicString & reset()
Definition: InputTypeNames.cpp:124