summaryrefslogtreecommitdiffstats
path: root/src/Net/Signals
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net/Signals')
-rw-r--r--src/Net/Signals/Connection.h45
-rw-r--r--src/Net/Signals/Signal0.h43
-rw-r--r--src/Net/Signals/Signal1.h41
-rw-r--r--src/Net/Signals/Signal2.h41
-rw-r--r--src/Net/Signals/SignalBase.h80
-rw-r--r--src/Net/Signals/Signals.h27
6 files changed, 277 insertions, 0 deletions
diff --git a/src/Net/Signals/Connection.h b/src/Net/Signals/Connection.h
new file mode 100644
index 0000000..0e66611
--- /dev/null
+++ b/src/Net/Signals/Connection.h
@@ -0,0 +1,45 @@
+/*
+ * Connection.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_SIGNALS_CONNECTION_H_
+#define MAD_NET_SIGNALS_CONNECTION_H_
+
+#include <boost/signals/connection.hpp>
+
+namespace Mad {
+namespace Net {
+namespace Signals {
+
+template <typename SignalType, typename FunctionType> class SignalBase;
+
+class Connection {
+ private:
+ template <typename SignalType, typename FunctionType> friend class SignalBase;
+
+ boost::signals::connection connection;
+
+ Connection(const boost::signals::connection &connection0)
+ : connection(connection0) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_SIGNALS_CONNECTION_H_ */
diff --git a/src/Net/Signals/Signal0.h b/src/Net/Signals/Signal0.h
new file mode 100644
index 0000000..32859ab
--- /dev/null
+++ b/src/Net/Signals/Signal0.h
@@ -0,0 +1,43 @@
+/*
+ * Signal0.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_SIGNALS_SIGNAL0_H_
+#define MAD_NET_SIGNALS_SIGNAL0_H_
+
+#include "SignalBase.h"
+
+namespace Mad {
+namespace Net {
+namespace Signals {
+
+template <typename R>
+class Signal0 : public SignalBase<boost::signal0<R>, boost::function0<R> > {
+ public:
+ R emit() {
+ boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal0<R>, boost::function0<R> >::mutex);
+
+ return SignalBase<boost::signal0<R>, boost::function0<R> >::signal();
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_SIGNALS_SIGNAL0_H_ */
diff --git a/src/Net/Signals/Signal1.h b/src/Net/Signals/Signal1.h
new file mode 100644
index 0000000..78eaa47
--- /dev/null
+++ b/src/Net/Signals/Signal1.h
@@ -0,0 +1,41 @@
+/*
+ * Signal1.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_SIGNALS_SIGNAL1_H_
+#define MAD_NET_SIGNALS_SIGNAL1_H_
+
+namespace Mad {
+namespace Net {
+namespace Signals {
+
+template <typename R, typename T1>
+class Signal1 : public SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> > {
+ public:
+ R emit(T1 arg1) {
+ boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> >::mutex);
+
+ return SignalBase<boost::signal1<R, T1>, boost::function1<R, T1> >::signal(arg1);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_SIGNALS_SIGNAL1_H_ */
diff --git a/src/Net/Signals/Signal2.h b/src/Net/Signals/Signal2.h
new file mode 100644
index 0000000..afa528e
--- /dev/null
+++ b/src/Net/Signals/Signal2.h
@@ -0,0 +1,41 @@
+/*
+ * Signal2.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_SIGNALS_SIGNAL2_H_
+#define MAD_NET_SIGNALS_SIGNAL2_H_
+
+namespace Mad {
+namespace Net {
+namespace Signals {
+
+template <typename R, typename T1, typename T2>
+class Signal2 : public SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> > {
+ public:
+ R emit(T1 arg1, T2 arg2) {
+ boost::lock_guard<boost::recursive_mutex> lock(SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> >::mutex);
+
+ return SignalBase<boost::signal2<R, T1, T2>, boost::function2<R, T1, T2> >::signal(arg1, arg2);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_SIGNALS_SIGNAL2_H_ */
diff --git a/src/Net/Signals/SignalBase.h b/src/Net/Signals/SignalBase.h
new file mode 100644
index 0000000..fc5f2c6
--- /dev/null
+++ b/src/Net/Signals/SignalBase.h
@@ -0,0 +1,80 @@
+/*
+ * SignalBase.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_SIGNALS_SIGNALBASE_H_
+#define MAD_SIGNALS_SIGNALBASE_H_
+
+#include "Connection.h"
+
+#include <set>
+#include <boost/signals.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+
+namespace Mad {
+namespace Net {
+namespace Signals {
+
+template <typename SignalType, typename FunctionType>
+class SignalBase : private boost::noncopyable {
+ public:
+ typedef boost::slot<FunctionType> slot_type;
+
+ protected:
+ typedef SignalType signal_type;
+
+ std::set<boost::signals::connection> connections;
+ boost::recursive_mutex mutex;
+
+ signal_type signal;
+
+ SignalBase() {}
+ ~SignalBase() {
+ // Wait for other threads
+ boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ }
+
+ public:
+ Connection connect(const slot_type &slot) {
+ boost::lock_guard<boost::recursive_mutex> lock(mutex);
+
+ boost::signals::connection con(signal.connect(slot));
+
+ connections.insert(con);
+ return con;
+ }
+
+ void disconnect(const Connection &connection) {
+ boost::lock_guard<boost::recursive_mutex> lock(mutex);
+
+ std::set<boost::signals::connection>::iterator it = connections.find(connection.connection);
+
+ if(it == connections.end())
+ return;
+
+ it->disconnect();
+ connections.erase(it);
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_SIGNALS_SIGNALBASE_H_ */
diff --git a/src/Net/Signals/Signals.h b/src/Net/Signals/Signals.h
new file mode 100644
index 0000000..4ee4f95
--- /dev/null
+++ b/src/Net/Signals/Signals.h
@@ -0,0 +1,27 @@
+/*
+ * Signals.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_SIGNALS_SIGNALS_H_
+#define MAD_SIGNALS_SIGNALS_H_
+
+#include "Signal0.h"
+#include "Signal1.h"
+#include "Signal2.h"
+
+#endif /* MAD_SIGNALS_SIGNALS_H_ */