aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Kinnunen <fluxgen@fluxbox.org>2010-03-18 18:35:19 (GMT)
committerHenrik Kinnunen <fluxgen@fluxbox.org>2010-03-18 18:35:19 (GMT)
commit02bb93590c69b619150735f026f7719df2e5c271 (patch)
treebd1e1d1ca78674ffe57a800fe17aed13f9975b25 /src
parent31a458f3657e53b51849111cf5ddc438c7e612a2 (diff)
downloadfluxbox_paul-02bb93590c69b619150735f026f7719df2e5c271.zip
fluxbox_paul-02bb93590c69b619150735f026f7719df2e5c271.tar.bz2
Added FbTk::relaySignal, which relays new signals to old Subject type signals.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/RelaySignal.hh62
-rw-r--r--src/tests/Makefile4
-rw-r--r--src/tests/testSignals.cc24
3 files changed, 87 insertions, 3 deletions
diff --git a/src/FbTk/RelaySignal.hh b/src/FbTk/RelaySignal.hh
new file mode 100644
index 0000000..e9b7281
--- /dev/null
+++ b/src/FbTk/RelaySignal.hh
@@ -0,0 +1,62 @@
1// RelaySignal.hh
2// Copyright (c) 2010 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#ifndef FBTK_RELAY_SIGNAL_HH
23#define FBTK_RELAY_SIGNAL_HH
24
25#include "Signal.hh"
26#include "MemFun.hh"
27#include "Subject.hh"
28
29namespace FbTk {
30
31/**
32 * Relays a new signal type to the old subject type signal. When the new signal
33 * emits the subject notify() will be called.
34 * This function is temporary and just a helper during transition between old
35 * and new signal system.
36 *
37 * @param from The original source of the signal.
38 * @param to_subject The destination Subject.
39 */
40template < typename Signal >
41void relaySignal(Signal& from, FbTk::Subject& to_subject) {
42 from.connect(MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
43}
44
45/**
46 * Relays a new signal type to the old subject type signal. When the new signal
47 * emits the subject notify() will be called.
48 * This function is temporary and just a helper during transition between old
49 * and new signal system.
50 *
51 * @param tracker Keeps track of signals
52 * @param from The original source of the signal.
53 * @param to_subject The destination Subject
54 */
55template < typename Signal >
56void relaySignal(SignalTracker& tracker, Signal& from, FbTk::Subject& to_subject) {
57 tracker.join(from, MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
58}
59
60} // end namespace FbTk
61
62#endif // FBTK_RELAY_SIGNAL_HH
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 668126e..dd329e6 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,5 +1,5 @@
1CXX=g++ 1CXX=g++
2CXXFLAGS= -I.. -I../FbTk -I../.. -DDEBUG -DUSE_XFT -Wall -g -O2 ../FbTk/libFbTk.a 2CXXFLAGS= -I.. -I../FbTk -I../.. -DDEBUG -DUSE_XFT -Wall -g -O2 -fno-inline
3LIBS= 3LIBS=
4XFLAGS= -I/usr/X11R6/include 4XFLAGS= -I/usr/X11R6/include
5XLIBS= -L/usr/X11R6/lib -lX11 -lXft -lXpm -lImlib2 5XLIBS= -L/usr/X11R6/lib -lX11 -lXft -lXpm -lImlib2
@@ -17,7 +17,7 @@ glxtest: ../FbTk/App.hh glxtest.cc
17 ${CXX} glxtest.cc ${CXXFLAGS} ${XLIBS} -lGL -lGLU -lXpm -o glxtest 17 ${CXX} glxtest.cc ${CXXFLAGS} ${XLIBS} -lGL -lGLU -lXpm -o glxtest
18 18
19testSignals: testSignals.o ../FbTk/Signal.hh ../FbTk/MemFun.hh 19testSignals: testSignals.o ../FbTk/Signal.hh ../FbTk/MemFun.hh
20 $(CXX) $(LIBS) testSignals.o -o testSignals 20 $(CXX) $(LIBS) testSignals.o -o testSignals ../FbTk/libFbTk.a
21 21
22testStringUtil: StringUtiltest.o 22testStringUtil: StringUtiltest.o
23 $(CXX) $(LIBS) StringUtiltest.o ../FbTk/libFbTk.a -o testStringUtil 23 $(CXX) $(LIBS) StringUtiltest.o ../FbTk/libFbTk.a -o testStringUtil
diff --git a/src/tests/testSignals.cc b/src/tests/testSignals.cc
index 6d68d3a..f382289 100644
--- a/src/tests/testSignals.cc
+++ b/src/tests/testSignals.cc
@@ -3,6 +3,9 @@ using namespace std;
3 3
4#include "../FbTk/Signal.hh" 4#include "../FbTk/Signal.hh"
5#include "../FbTk/MemFun.hh" 5#include "../FbTk/MemFun.hh"
6#include "../FbTk/RelaySignal.hh"
7#include "../FbTk/Observer.hh"
8#include "../FbTk/Subject.hh"
6 9
7#include <string> 10#include <string>
8 11
@@ -138,5 +141,24 @@ int main() {
138 2.9); 141 2.9);
139 142
140 } 143 }
141 144 // Test relay new signals to old
145 {
146 cout << "---------- Testing relay of signals" << endl;
147 struct Observer: public FbTk::Observer {
148 void update(FbTk::Subject* subj) {
149 cout << "Observer called." << endl;
150 }
151 };
152 // setup old subject->observer listening
153 FbTk::Subject destination;
154 Observer obs;
155 destination.attach(&obs);
156 // create a new signal and relay it to the
157 // old subject
158 FbTk::Signal<void, string> source;
159 FbTk::relaySignal(source, destination);
160 // the new signal should now make the old
161 // subject notify its observers
162 source.emit("hello world");
163 }
142} 164}