summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Connection.h18
-rw-r--r--src/Net/Listener.cpp8
-rw-r--r--src/Net/Listener.h8
-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
15 files changed, 69 insertions, 325 deletions
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index 505dcea..e1ca63b 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -70,9 +70,9 @@ class Connection : boost::noncopyable {
Packet::Data header;
- Signals::Signal21<boost::shared_ptr<Packet> > receiveSignal;
- Signals::Signal20 connectedSignal;
- Signals::Signal20 disconnectedSignal;
+ Signals::Signal1<boost::shared_ptr<Packet> > receiveSignal;
+ Signals::Signal0 connectedSignal;
+ Signals::Signal0 disconnectedSignal;
bool receiving;
unsigned long sending;
@@ -171,24 +171,24 @@ class Connection : boost::noncopyable {
bool send(const Packet &packet);
- Signals::Connection2 connectSignalReceive(const Signals::Signal21<boost::shared_ptr<Packet> >::slot_type &slot) {
+ Signals::Connection connectSignalReceive(const Signals::Signal1<boost::shared_ptr<Packet> >::slot_type &slot) {
return receiveSignal.connect(slot);
}
- void disconnectSignalReceive(const Signals::Connection2 &connection) {
+ void disconnectSignalReceive(const Signals::Connection &connection) {
receiveSignal.disconnect(connection);
}
- Signals::Connection2 connectSignalConnected(const Signals::Signal20::slot_type &slot) {
+ Signals::Connection connectSignalConnected(const Signals::Signal0::slot_type &slot) {
return connectedSignal.connect(slot);
}
- void disconnectSignalConnected(const Signals::Connection2 &connection) {
+ void disconnectSignalConnected(const Signals::Connection &connection) {
connectedSignal.disconnect(connection);
}
- Signals::Connection2 connectSignalDisconnected(const Signals::Signal20::slot_type &slot) {
+ Signals::Connection connectSignalDisconnected(const Signals::Signal0::slot_type &slot) {
return disconnectedSignal.connect(slot);
}
- void disconnectSignalDisconnected(const Signals::Connection2 &connection) {
+ void disconnectSignalDisconnected(const Signals::Connection &connection) {
disconnectedSignal.disconnect(connection);
}
};
diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp
index b9779ec..6da2762 100644
--- a/src/Net/Listener.cpp
+++ b/src/Net/Listener.cpp
@@ -39,8 +39,8 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share
con->_setState(Connection::CONNECT);
- Signals::Connection2 con1 = con->connectSignalConnected(boost::bind(&Listener::handleConnect, this, con));
- Signals::Connection2 con2 = con->connectSignalDisconnected(boost::bind(&Listener::handleDisconnect, this, con));
+ Signals::Connection con1 = con->connectSignalConnected(boost::bind(&Listener::handleConnect, this, con));
+ Signals::Connection con2 = con->connectSignalDisconnected(boost::bind(&Listener::handleDisconnect, this, con));
connections.insert(std::make_pair(con, std::make_pair(con1, con2)));
@@ -54,7 +54,7 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share
void Listener::handleConnect(boost::shared_ptr<Connection> con) {
{
boost::lock_guard<boost::mutex> lock(mutex);
- std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection2, Signals::Connection2> >::iterator it = connections.find(con);
+ std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection, Signals::Connection> >::iterator it = connections.find(con);
if(it == connections.end())
return;
@@ -93,7 +93,7 @@ sslContext(Connection::ioService, boost::asio::ssl::context::sslv23)
}
Listener::~Listener() {
- for(std::map<boost::shared_ptr<Connection>,std::pair<Signals::Connection2, Signals::Connection2> >::iterator con = connections.begin(); con != connections.end(); ++con) {
+ for(std::map<boost::shared_ptr<Connection>,std::pair<Signals::Connection, Signals::Connection> >::iterator con = connections.begin(); con != connections.end(); ++con) {
con->first->disconnect();
// TODO wait...
}
diff --git a/src/Net/Listener.h b/src/Net/Listener.h
index 600fcf9..2e25051 100644
--- a/src/Net/Listener.h
+++ b/src/Net/Listener.h
@@ -38,9 +38,9 @@ class Listener : boost::noncopyable {
boost::asio::ip::tcp::acceptor acceptor;
boost::asio::ssl::context sslContext;
- std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection2, Signals::Connection2> > connections;
+ std::map<boost::shared_ptr<Connection>, std::pair<Signals::Connection, Signals::Connection> > connections;
- Signals::Signal21<boost::shared_ptr<Connection> > signal;
+ Signals::Signal1<boost::shared_ptr<Connection> > signal;
void handleAccept(const boost::system::error_code &error, boost::shared_ptr<Connection> con);
@@ -52,10 +52,10 @@ class Listener : boost::noncopyable {
const boost::asio::ip::tcp::endpoint &address0 = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 6666)) throw(Exception);
virtual ~Listener();
- Signals::Connection2 connectSignalNewConnection(const Signals::Signal21<boost::shared_ptr<Connection> >::slot_type &slot) {
+ Signals::Connection connectSignalNewConnection(const Signals::Signal1<boost::shared_ptr<Connection> >::slot_type &slot) {
return signal.connect(slot);
}
- void disconnectSignalNewConnection(const Signals::Connection2 &connection) {
+ void disconnectSignalNewConnection(const Signals::Connection &connection) {
signal.disconnect(connection);
}
};
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_ */