Home | History | Annotate | Download | only in base
      1 /*
      2  * libjingle
      3  * Copyright 2006, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef TALK_BASE_SIGSLOTREPEATER_H__
     29 #define TALK_BASE_SIGSLOTREPEATER_H__
     30 
     31 // repeaters are both signals and slots, which are designed as intermediate
     32 // pass-throughs for signals and slots which don't know about each other (for
     33 // modularity or encapsulation).  This eliminates the need to declare a signal
     34 // handler whose sole purpose is to fire another signal.  The repeater connects
     35 // to the originating signal using the 'repeat' method.  When the repeated
     36 // signal fires, the repeater will also fire.
     37 
     38 #include "talk/base/sigslot.h"
     39 
     40 namespace sigslot {
     41 
     42   template<class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     43   class repeater0 : public signal0<mt_policy>,
     44                     public has_slots<mt_policy>
     45   {
     46   public:
     47     typedef signal0<mt_policy> base_type;
     48     typedef repeater0<mt_policy> this_type;
     49 
     50     repeater0() { }
     51     repeater0(const this_type& s) : base_type(s) { }
     52 
     53     void reemit() { signal0<mt_policy>::emit(); }
     54     void repeat(base_type &s) { s.connect(this, &this_type::reemit); }
     55     void stop(base_type &s) { s.disconnect(this); }
     56   };
     57 
     58   template<class arg1_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     59   class repeater1 : public signal1<arg1_type, mt_policy>,
     60                     public has_slots<mt_policy>
     61   {
     62   public:
     63     typedef signal1<arg1_type, mt_policy> base_type;
     64     typedef repeater1<arg1_type, mt_policy> this_type;
     65 
     66     repeater1() { }
     67     repeater1(const this_type& s) : base_type(s) { }
     68 
     69     void reemit(arg1_type a1) { signal1<arg1_type, mt_policy>::emit(a1); }
     70     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
     71     void stop(base_type &s) { s.disconnect(this); }
     72   };
     73 
     74   template<class arg1_type, class arg2_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     75   class repeater2 : public signal2<arg1_type, arg2_type, mt_policy>,
     76                     public has_slots<mt_policy>
     77   {
     78   public:
     79     typedef signal2<arg1_type, arg2_type, mt_policy> base_type;
     80     typedef repeater2<arg1_type, arg2_type, mt_policy> this_type;
     81 
     82     repeater2() { }
     83     repeater2(const this_type& s) : base_type(s) { }
     84 
     85     void reemit(arg1_type a1, arg2_type a2) { signal2<arg1_type, arg2_type, mt_policy>::emit(a1,a2); }
     86     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
     87     void stop(base_type &s) { s.disconnect(this); }
     88   };
     89 
     90   template<class arg1_type, class arg2_type, class arg3_type,
     91            class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
     92   class repeater3 : public signal3<arg1_type, arg2_type, arg3_type, mt_policy>,
     93                     public has_slots<mt_policy>
     94   {
     95   public:
     96     typedef signal3<arg1_type, arg2_type, arg3_type, mt_policy> base_type;
     97     typedef repeater3<arg1_type, arg2_type, arg3_type, mt_policy> this_type;
     98 
     99     repeater3() { }
    100     repeater3(const this_type& s) : base_type(s) { }
    101 
    102     void reemit(arg1_type a1, arg2_type a2, arg3_type a3) {
    103             signal3<arg1_type, arg2_type, arg3_type, mt_policy>::emit(a1,a2,a3);
    104     }
    105     void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
    106     void stop(base_type &s) { s.disconnect(this); }
    107   };
    108 
    109 }  // namespace sigslot
    110 
    111 #endif  // TALK_BASE_SIGSLOTREPEATER_H__
    112