sigslot_repeater.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef RTC_BASE_SIGSLOT_REPEATER_H__
  11. #define RTC_BASE_SIGSLOT_REPEATER_H__
  12. // repeaters are both signals and slots, which are designed as intermediate
  13. // pass-throughs for signals and slots which don't know about each other (for
  14. // modularity or encapsulation). This eliminates the need to declare a signal
  15. // handler whose sole purpose is to fire another signal. The repeater connects
  16. // to the originating signal using the 'repeat' method. When the repeated
  17. // signal fires, the repeater will also fire.
  18. //
  19. // TODO(deadbeef): Actually use this, after we decide on some style points on
  20. // using signals, so it doesn't get deleted again.
  21. #include "rtc_base/third_party/sigslot/sigslot.h"
  22. namespace sigslot {
  23. template <class mt_policy, typename... Args>
  24. class repeater_with_thread_policy
  25. : public signal_with_thread_policy<mt_policy, Args...>,
  26. public has_slots<mt_policy> {
  27. private:
  28. // These typedefs are just to make the code below more readable. Code using
  29. // repeaters shouldn't need to reference these types directly.
  30. typedef signal_with_thread_policy<mt_policy, Args...> base_type;
  31. typedef repeater_with_thread_policy<mt_policy, Args...> this_type;
  32. public:
  33. repeater_with_thread_policy() {}
  34. repeater_with_thread_policy(const this_type& s) : base_type(s) {}
  35. void reemit(Args... args) { base_type::emit(args...); }
  36. void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
  37. void stop(base_type& s) { s.disconnect(this); }
  38. };
  39. // Alias with default thread policy. Needed because both default arguments
  40. // and variadic template arguments must go at the end of the list, so we
  41. // can't have both at once.
  42. template <typename... Args>
  43. using repeater =
  44. repeater_with_thread_policy<SIGSLOT_DEFAULT_MT_POLICY, Args...>;
  45. } // namespace sigslot
  46. #endif // RTC_BASE_SIGSLOT_REPEATER_H__