Home | History | Annotate | Download | only in base
      1 /*
      2  *  Copyright 2006 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 WEBRTC_BASE_SIGSLOTREPEATER_H__
     12 #define WEBRTC_BASE_SIGSLOTREPEATER_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 #include "webrtc/base/sigslot.h"
     22 
     23 namespace sigslot {
     24 
     25   template<class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     26   class repeater0 : public signal0<mt_policy>,
     27                     public has_slots<mt_policy>
     28   {
     29   public:
     30     typedef signal0<mt_policy> base_type;
     31     typedef repeater0<mt_policy> this_type;
     32 
     33     repeater0() { }
     34     repeater0(const this_type& s) : base_type(s) { }
     35 
     36     void reemit() { signal0<mt_policy>::emit(); }
     37     void repeat(base_type &s) { s.connect(this, &this_type::reemit); }
     38     void stop(base_type &s) { s.disconnect(this); }
     39   };
     40 
     41   template<class arg1_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     42   class repeater1 : public signal1<arg1_type, mt_policy>,
     43                     public has_slots<mt_policy>
     44   {
     45   public:
     46     typedef signal1<arg1_type, mt_policy> base_type;
     47     typedef repeater1<arg1_type, mt_policy> this_type;
     48 
     49     repeater1() { }
     50     repeater1(const this_type& s) : base_type(s) { }
     51 
     52     void reemit(arg1_type a1) { signal1<arg1_type, mt_policy>::emit(a1); }
     53     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
     54     void stop(base_type &s) { s.disconnect(this); }
     55   };
     56 
     57   template<class arg1_type, class arg2_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     58   class repeater2 : public signal2<arg1_type, arg2_type, mt_policy>,
     59                     public has_slots<mt_policy>
     60   {
     61   public:
     62     typedef signal2<arg1_type, arg2_type, mt_policy> base_type;
     63     typedef repeater2<arg1_type, arg2_type, mt_policy> this_type;
     64 
     65     repeater2() { }
     66     repeater2(const this_type& s) : base_type(s) { }
     67 
     68     void reemit(arg1_type a1, arg2_type a2) { signal2<arg1_type, arg2_type, mt_policy>::emit(a1,a2); }
     69     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
     70     void stop(base_type &s) { s.disconnect(this); }
     71   };
     72 
     73   template<class arg1_type, class arg2_type, class arg3_type,
     74            class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     75   class repeater3 : public signal3<arg1_type, arg2_type, arg3_type, mt_policy>,
     76                     public has_slots<mt_policy>
     77   {
     78   public:
     79     typedef signal3<arg1_type, arg2_type, arg3_type, mt_policy> base_type;
     80     typedef repeater3<arg1_type, arg2_type, arg3_type, mt_policy> this_type;
     81 
     82     repeater3() { }
     83     repeater3(const this_type& s) : base_type(s) { }
     84 
     85     void reemit(arg1_type a1, arg2_type a2, arg3_type a3) {
     86             signal3<arg1_type, arg2_type, arg3_type, mt_policy>::emit(a1,a2,a3);
     87     }
     88     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
     89     void stop(base_type &s) { s.disconnect(this); }
     90   };
     91 
     92 }  // namespace sigslot
     93 
     94 #endif  // WEBRTC_BASE_SIGSLOTREPEATER_H__
     95