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
40namespace 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  };
56
57  template<class arg1_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
58  class repeater1 : public signal1<arg1_type, mt_policy>,
59                    public has_slots<mt_policy>
60  {
61  public:
62    typedef signal1<arg1_type, mt_policy> base_type;
63    typedef repeater1<arg1_type, mt_policy> this_type;
64
65    repeater1() { }
66    repeater1(const this_type& s) : base_type(s) { }
67
68    void reemit(arg1_type a1) { signal1<arg1_type, mt_policy>::emit(a1); }
69    void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
70  };
71
72  template<class arg1_type, class arg2_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
73  class repeater2 : public signal2<arg1_type, arg2_type, mt_policy>,
74                    public has_slots<mt_policy>
75  {
76  public:
77    typedef signal2<arg1_type, arg2_type, mt_policy> base_type;
78    typedef repeater2<arg1_type, arg2_type, mt_policy> this_type;
79
80    repeater2() { }
81    repeater2(const this_type& s) : base_type(s) { }
82
83    void reemit(arg1_type a1, arg2_type a2) { signal2<arg1_type, arg2_type, mt_policy>::emit(a1,a2); }
84    void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
85  };
86
87  template<class arg1_type, class arg2_type, class arg3_type,
88           class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
89  class repeater3 : public signal3<arg1_type, arg2_type, arg3_type, mt_policy>,
90                    public has_slots<mt_policy>
91  {
92  public:
93    typedef signal3<arg1_type, arg2_type, arg3_type, mt_policy> base_type;
94    typedef repeater3<arg1_type, arg2_type, arg3_type, mt_policy> this_type;
95
96    repeater3() { }
97    repeater3(const this_type& s) : base_type(s) { }
98
99    void reemit(arg1_type a1, arg2_type a2, arg3_type a3) {
100            signal3<arg1_type, arg2_type, arg3_type, mt_policy>::emit(a1,a2,a3);
101    }
102    void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
103  };
104
105}  // namespace sigslot
106
107#endif  // TALK_BASE_SIGSLOTREPEATER_H__
108