1 /*
2  *  Copyright 2017 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef RTC_BASE_SIGSLOT_REPEATER_H__
12 #define RTC_BASE_SIGSLOT_REPEATER_H__
13 
14 // repeaters are both signals and slots, which are designed as intermediate
15 // pass-throughs for signals and slots which don't know about each other (for
16 // modularity or encapsulation).  This eliminates the need to declare a signal
17 // handler whose sole purpose is to fire another signal.  The repeater connects
18 // to the originating signal using the 'repeat' method.  When the repeated
19 // signal fires, the repeater will also fire.
20 //
21 // TODO(deadbeef): Actually use this, after we decide on some style points on
22 // using signals, so it doesn't get deleted again.
23 
24 #include "rtc_base/third_party/sigslot/sigslot.h"
25 
26 namespace sigslot {
27 
28 template <class mt_policy, typename... Args>
29 class repeater_with_thread_policy
30     : public signal_with_thread_policy<mt_policy, Args...>,
31       public has_slots<mt_policy> {
32  private:
33   // These typedefs are just to make the code below more readable. Code using
34   // repeaters shouldn't need to reference these types directly.
35   typedef signal_with_thread_policy<mt_policy, Args...> base_type;
36   typedef repeater_with_thread_policy<mt_policy, Args...> this_type;
37 
38  public:
repeater_with_thread_policy()39   repeater_with_thread_policy() {}
repeater_with_thread_policy(const this_type & s)40   repeater_with_thread_policy(const this_type& s) : base_type(s) {}
41 
reemit(Args...args)42   void reemit(Args... args) { base_type::emit(args...); }
repeat(base_type & s)43   void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
stop(base_type & s)44   void stop(base_type& s) { s.disconnect(this); }
45 };
46 
47 // Alias with default thread policy. Needed because both default arguments
48 // and variadic template arguments must go at the end of the list, so we
49 // can't have both at once.
50 template <typename... Args>
51 using repeater =
52     repeater_with_thread_policy<SIGSLOT_DEFAULT_MT_POLICY, Args...>;
53 
54 }  // namespace sigslot
55 
56 #endif  // RTC_BASE_SIGSLOT_REPEATER_H__
57