summaryrefslogtreecommitdiffstats
path: root/src/Net/Signals
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-04 22:32:56 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-04 22:32:56 +0200
commitd3a7b7c10b0ef7a3d8c8ea7f1aef2468702dd8f4 (patch)
tree5bc2a48eb2a03ae03e321d7d576658eeabad688d /src/Net/Signals
parent0b27c37fe95c6aced613d51a3624f8930a96ad3f (diff)
downloadmad-d3a7b7c10b0ef7a3d8c8ea7f1aef2468702dd8f4.tar
mad-d3a7b7c10b0ef7a3d8c8ea7f1aef2468702dd8f4.zip
Alte Signal-Implementierung entfernt
Diffstat (limited to 'src/Net/Signals')
-rw-r--r--src/Net/Signals/Connection.h22
-rw-r--r--src/Net/Signals/Connection2.h53
-rw-r--r--src/Net/Signals/GenericSignal.h12
-rw-r--r--src/Net/Signals/Signal0.h10
-rw-r--r--src/Net/Signals/Signal1.h12
-rw-r--r--src/Net/Signals/Signal2.h12
-rw-r--r--src/Net/Signals/Signal20.h46
-rw-r--r--src/Net/Signals/Signal21.h47
-rw-r--r--src/Net/Signals/Signal22.h47
-rw-r--r--src/Net/Signals/SignalBase.h43
-rw-r--r--src/Net/Signals/SignalBase2.h53
-rw-r--r--src/Net/Signals/Signals.h3
12 files changed, 52 insertions, 308 deletions
diff --git a/src/Net/Signals/Connection.h b/src/Net/Signals/Connection.h
index 0e66611..7730e13 100644
--- a/src/Net/Signals/Connection.h
+++ b/src/Net/Signals/Connection.h
@@ -20,22 +20,30 @@
#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 SignalBase;
class Connection {
private:
- template <typename SignalType, typename FunctionType> friend class SignalBase;
+ friend class SignalBase;
+
+ SignalBase *signal;
+ unsigned long id;
+
+ Connection(SignalBase *signal0, unsigned long id0)
+ : signal(signal0), id(id0) {}
- boost::signals::connection connection;
+ public:
+ bool operator==(const Connection &o) const {
+ return (signal == o.signal && id == o.id);
+ }
- Connection(const boost::signals::connection &connection0)
- : connection(connection0) {}
+ bool operator<(const Connection &o) const {
+ return (signal != o.signal) ? (signal < o.signal) : (id < o.id);
+ }
};
}
diff --git a/src/Net/Signals/Connection2.h b/src/Net/Signals/Connection2.h
deleted file mode 100644
index ab80a61..0000000
--- a/src/Net/Signals/Connection2.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Connection2.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_CONNECTION2_H_
-#define MAD_NET_SIGNALS_CONNECTION2_H_
-
-namespace Mad {
-namespace Net {
-namespace Signals {
-
-class SignalBase2;
-
-class Connection2 {
- private:
- friend class SignalBase2;
-
- SignalBase2 *signal;
- unsigned long id;
-
- Connection2(SignalBase2 *signal0, unsigned long id0)
- : signal(signal0), id(id0) {}
-
- public:
- bool operator==(const Connection2 &o) const {
- return (signal == o.signal && id == o.id);
- }
-
- bool operator<(const Connection2 &o) const {
- return (signal != o.signal) ? (signal < o.signal) : (id < o.id);
- }
-};
-
-}
-}
-}
-
-#endif /* MAD_NET_SIGNALS_CONNECTION2_H_ */
diff --git a/src/Net/Signals/GenericSignal.h b/src/Net/Signals/GenericSignal.h
index d4fa8df..aa6cfa1 100644
--- a/src/Net/Signals/GenericSignal.h
+++ b/src/Net/Signals/GenericSignal.h
@@ -20,7 +20,7 @@
#ifndef MAD_NET_SIGNALS_GENERICSIGNAL_H_
#define MAD_NET_SIGNALS_GENERICSIGNAL_H_
-#include "SignalBase2.h"
+#include "SignalBase.h"
#include <map>
#include <boost/thread/locks.hpp>
@@ -30,24 +30,24 @@ namespace Net {
namespace Signals {
template <typename FunctionType>
-class GenericSignal : protected SignalBase2 {
+class GenericSignal : protected SignalBase {
public:
typedef FunctionType slot_type;
protected:
- std::map<Connection2, slot_type> handlers;
+ std::map<Connection, slot_type> handlers;
public:
- Connection2 connect(const slot_type &slot) {
+ Connection connect(const slot_type &slot) {
boost::lock_guard<boost::mutex> lock(mutex);
- Connection2 con = getNewConnection();
+ Connection con = getNewConnection();
handlers.insert(std::make_pair(con, slot));
return con;
}
- bool disconnect(const Connection2 &connection) {
+ bool disconnect(const Connection &connection) {
boost::lock_guard<boost::mutex> lock(mutex);
return handlers.erase(connection);
diff --git a/src/Net/Signals/Signal0.h b/src/Net/Signals/Signal0.h
index c468135..5c0a691 100644
--- a/src/Net/Signals/Signal0.h
+++ b/src/Net/Signals/Signal0.h
@@ -20,18 +20,22 @@
#ifndef MAD_NET_SIGNALS_SIGNAL0_H_
#define MAD_NET_SIGNALS_SIGNAL0_H_
-#include "SignalBase.h"
+#include "GenericSignal.h"
+#include <Net/ThreadManager.h>
+
+#include <boost/function.hpp>
namespace Mad {
namespace Net {
namespace Signals {
-class Signal0 : public SignalBase<boost::signal0<void>, boost::function0<void> > {
+class Signal0 : public GenericSignal<boost::function0<void> > {
public:
void emit() {
boost::lock_guard<boost::mutex> lock(mutex);
- signal();
+ for(std::map<Connection, slot_type>::iterator handler = handlers.begin(); handler != handlers.end(); ++handler)
+ Net::ThreadManager::get()->pushWork(handler->second);
}
};
diff --git a/src/Net/Signals/Signal1.h b/src/Net/Signals/Signal1.h
index b9649be..331c5cb 100644
--- a/src/Net/Signals/Signal1.h
+++ b/src/Net/Signals/Signal1.h
@@ -20,19 +20,23 @@
#ifndef MAD_NET_SIGNALS_SIGNAL1_H_
#define MAD_NET_SIGNALS_SIGNAL1_H_
-#include "SignalBase.h"
+#include "GenericSignal.h"
+#include <Net/ThreadManager.h>
+
+#include <boost/function.hpp>
namespace Mad {
namespace Net {
namespace Signals {
template <typename T1>
-class Signal1 : public SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> > {
+class Signal1 : public GenericSignal<boost::function1<void, T1> > {
public:
void emit(T1 arg1) {
- boost::lock_guard<boost::mutex> lock(SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> >::mutex);
+ boost::lock_guard<boost::mutex> lock(this->mutex);
- SignalBase<boost::signal1<void, T1>, boost::function1<void, T1> >::signal(arg1);
+ for(typename std::map<Connection, typename GenericSignal<boost::function1<void, T1> >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler)
+ Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1));
}
};
diff --git a/src/Net/Signals/Signal2.h b/src/Net/Signals/Signal2.h
index 374a239..3fb9315 100644
--- a/src/Net/Signals/Signal2.h
+++ b/src/Net/Signals/Signal2.h
@@ -20,19 +20,23 @@
#ifndef MAD_NET_SIGNALS_SIGNAL2_H_
#define MAD_NET_SIGNALS_SIGNAL2_H_
-#include "SignalBase.h"
+#include "GenericSignal.h"
+#include <Net/ThreadManager.h>
+
+#include <boost/function.hpp>
namespace Mad {
namespace Net {
namespace Signals {
template <typename T1, typename T2>
-class Signal2 : public SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> > {
+class Signal2 : public GenericSignal<boost::function2<void, T1, T2> > {
public:
void emit(T1 arg1, T2 arg2) {
- boost::lock_guard<boost::mutex> lock(SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> >::mutex);
+ boost::lock_guard<boost::mutex> lock(this->mutex);
- SignalBase<boost::signal2<void, T1, T2>, boost::function2<void, T1, T2> >::signal(arg1, arg2);
+ for(typename std::map<Connection, typename GenericSignal<boost::function2<void, T1, T2> >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler)
+ Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1, arg2));
}
};
diff --git a/src/Net/Signals/Signal20.h b/src/Net/Signals/Signal20.h
deleted file mode 100644
index 0a12640..0000000
--- a/src/Net/Signals/Signal20.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Signal20.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_SIGNAL20_H_
-#define MAD_NET_SIGNALS_SIGNAL20_H_
-
-#include "GenericSignal.h"
-#include <Net/ThreadManager.h>
-
-#include <boost/function.hpp>
-
-namespace Mad {
-namespace Net {
-namespace Signals {
-
-class Signal20 : public GenericSignal<boost::function0<void> > {
- public:
- void emit() {
- boost::lock_guard<boost::mutex> lock(mutex);
-
- for(std::map<Connection2, slot_type>::iterator handler = handlers.begin(); handler != handlers.end(); ++handler)
- Net::ThreadManager::get()->pushWork(handler->second);
- }
-};
-
-}
-}
-}
-
-#endif /* MAD_NET_SIGNALS_SIGNAL20_H_ */
diff --git a/src/Net/Signals/Signal21.h b/src/Net/Signals/Signal21.h
deleted file mode 100644
index 799296f..0000000
--- a/src/Net/Signals/Signal21.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Signal21.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_SIGNAL21_H_
-#define MAD_NET_SIGNALS_SIGNAL21_H_
-
-#include "GenericSignal.h"
-#include <Net/ThreadManager.h>
-
-#include <boost/function.hpp>
-
-namespace Mad {
-namespace Net {
-namespace Signals {
-
-template <typename T1>
-class Signal21 : public GenericSignal<boost::function1<void, T1> > {
- public:
- void emit(T1 arg1) {
- boost::lock_guard<boost::mutex> lock(this->mutex);
-
- for(typename std::map<Connection2, typename GenericSignal<boost::function1<void, T1> >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler)
- Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1));
- }
-};
-
-}
-}
-}
-
-#endif /* MAD_NET_SIGNALS_SIGNAL21_H_ */
diff --git a/src/Net/Signals/Signal22.h b/src/Net/Signals/Signal22.h
deleted file mode 100644
index a3b2ac4..0000000
--- a/src/Net/Signals/Signal22.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Signal22.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_SIGNAL22_H_
-#define MAD_NET_SIGNALS_SIGNAL22_H_
-
-#include "GenericSignal.h"
-#include <Net/ThreadManager.h>
-
-#include <boost/function.hpp>
-
-namespace Mad {
-namespace Net {
-namespace Signals {
-
-template <typename T1, typename T2>
-class Signal22 : public GenericSignal<boost::function2<void, T1, T2> > {
- public:
- void emit(T1 arg1, T2 arg2) {
- boost::lock_guard<boost::mutex> lock(this->mutex);
-
- for(typename std::map<Connection2, typename GenericSignal<boost::function2<void, T1, T2> >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler)
- Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1, arg2));
- }
-};
-
-}
-}
-}
-
-#endif /* MAD_NET_SIGNALS_SIGNAL22_H_ */
diff --git a/src/Net/Signals/SignalBase.h b/src/Net/Signals/SignalBase.h
index 9e2de62..ea1b1e9 100644
--- a/src/Net/Signals/SignalBase.h
+++ b/src/Net/Signals/SignalBase.h
@@ -23,54 +23,27 @@
#include "Connection.h"
#include <set>
-#include <boost/signals.hpp>
-#include <boost/thread/locks.hpp>
#include <boost/thread/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;
+ private:
+ friend class Connection;
- protected:
- typedef SignalType signal_type;
+ unsigned long connectionId;
- std::set<boost::signals::connection> connections;
+ protected:
boost::mutex mutex;
- signal_type signal;
-
- SignalBase() {}
- ~SignalBase() {
- // Wait for other threads
- boost::lock_guard<boost::mutex> lock(mutex);
+ Connection getNewConnection() {
+ return Connection(this, connectionId++);
}
- public:
- Connection connect(const slot_type &slot) {
- boost::lock_guard<boost::mutex> lock(mutex);
-
- boost::signals::connection con(signal.connect(slot));
-
- connections.insert(con);
- return con;
- }
-
- void disconnect(const Connection &connection) {
- boost::lock_guard<boost::mutex> lock(mutex);
-
- std::set<boost::signals::connection>::iterator it = connections.find(connection.connection);
-
- if(it == connections.end())
- return;
-
- it->disconnect();
- connections.erase(it);
- }
+ SignalBase() : connectionId(0) {}
+ virtual ~SignalBase() {}
};
}
diff --git a/src/Net/Signals/SignalBase2.h b/src/Net/Signals/SignalBase2.h
deleted file mode 100644
index d5cb0a7..0000000
--- a/src/Net/Signals/SignalBase2.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SignalBase2.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_SIGNALBASE2_H_
-#define MAD_SIGNALS_SIGNALBASE2_H_
-
-#include "Connection2.h"
-
-#include <set>
-#include <boost/thread/mutex.hpp>
-
-namespace Mad {
-namespace Net {
-namespace Signals {
-
-class SignalBase2 : private boost::noncopyable {
- private:
- friend class Connection2;
-
- unsigned long connectionId;
-
- protected:
- boost::mutex mutex;
-
- Connection2 getNewConnection() {
- return Connection2(this, connectionId++);
- }
-
- SignalBase2() : connectionId(0) {}
- virtual ~SignalBase2() {}
-};
-
-}
-}
-}
-
-#endif /* MAD_SIGNALS_SIGNALBASE2_H_ */
diff --git a/src/Net/Signals/Signals.h b/src/Net/Signals/Signals.h
index b4c9bac..4ee4f95 100644
--- a/src/Net/Signals/Signals.h
+++ b/src/Net/Signals/Signals.h
@@ -23,8 +23,5 @@
#include "Signal0.h"
#include "Signal1.h"
#include "Signal2.h"
-#include "Signal20.h"
-#include "Signal21.h"
-#include "Signal22.h"
#endif /* MAD_SIGNALS_SIGNALS_H_ */