From d3a7b7c10b0ef7a3d8c8ea7f1aef2468702dd8f4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 4 Jun 2009 22:32:56 +0200 Subject: Alte Signal-Implementierung entfernt --- src/Common/Connection.h | 6 ++--- src/Common/Request.h | 6 ++--- src/Common/RequestHandler.h | 6 ++--- src/Net/Connection.h | 18 +++++++------- src/Net/Listener.cpp | 8 +++---- src/Net/Listener.h | 8 +++---- src/Net/Signals/Connection.h | 22 +++++++++++------ src/Net/Signals/Connection2.h | 53 ----------------------------------------- src/Net/Signals/GenericSignal.h | 12 +++++----- src/Net/Signals/Signal0.h | 10 +++++--- src/Net/Signals/Signal1.h | 12 ++++++---- src/Net/Signals/Signal2.h | 12 ++++++---- src/Net/Signals/Signal20.h | 46 ----------------------------------- src/Net/Signals/Signal21.h | 47 ------------------------------------ src/Net/Signals/Signal22.h | 47 ------------------------------------ src/Net/Signals/SignalBase.h | 43 +++++++-------------------------- src/Net/Signals/SignalBase2.h | 53 ----------------------------------------- src/Net/Signals/Signals.h | 3 --- 18 files changed, 78 insertions(+), 334 deletions(-) delete mode 100644 src/Net/Signals/Connection2.h delete mode 100644 src/Net/Signals/Signal20.h delete mode 100644 src/Net/Signals/Signal21.h delete mode 100644 src/Net/Signals/Signal22.h delete mode 100644 src/Net/Signals/SignalBase2.h (limited to 'src') diff --git a/src/Common/Connection.h b/src/Common/Connection.h index 6f1cffd..c8ff3e8 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -39,7 +39,7 @@ class Connection : private boost::noncopyable { private: bool authenticated; - Net::Signals::Signal22, uint16_t> signalReceive; + Net::Signals::Signal2, uint16_t> signalReceive; protected: Connection() : authenticated(0) {} @@ -53,10 +53,10 @@ class Connection : private boost::noncopyable { bool sendPacket(const XmlPacket &packet, uint16_t requestId); - Net::Signals::Connection2 connectSignalReceive(const Net::Signals::Signal22, uint16_t>::slot_type &slot) { + Net::Signals::Connection connectSignalReceive(const Net::Signals::Signal2, uint16_t>::slot_type &slot) { return signalReceive.connect(slot); } - void disconnectSignalReceive(const Net::Signals::Connection2 &con) { + void disconnectSignalReceive(const Net::Signals::Connection &con) { signalReceive.disconnect(con); } diff --git a/src/Common/Request.h b/src/Common/Request.h index b8477f7..4698ae5 100644 --- a/src/Common/Request.h +++ b/src/Common/Request.h @@ -44,7 +44,7 @@ class Request : public RequestHandler { boost::shared_ptr packet; Net::Exception exception; - Net::Signals::Signal22, Net::Exception> finished; + Net::Signals::Signal2, Net::Exception> finished; protected: Request() : isFinished(false) {} @@ -80,10 +80,10 @@ class Request : public RequestHandler { virtual void handlePacket(boost::shared_ptr packet); public: - Net::Signals::Connection2 connectSignalFinished(const Net::Signals::Signal22, Net::Exception>::slot_type &slot) { + Net::Signals::Connection connectSignalFinished(const Net::Signals::Signal2, Net::Exception>::slot_type &slot) { return finished.connect(slot); } - void disconnectSignalFinished(const Net::Signals::Connection2 &con) { + void disconnectSignalFinished(const Net::Signals::Connection &con) { finished.disconnect(con); } diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index 87fccba..917649e 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -41,7 +41,7 @@ class RequestHandler : private boost::noncopyable { boost::mutex mutex; - Net::Signals::Signal20 finished; + Net::Signals::Signal0 finished; void callHandlePacket(boost::shared_ptr packet) { boost::lock_guard lock(mutex); @@ -64,10 +64,10 @@ class RequestHandler : private boost::noncopyable { public: virtual ~RequestHandler() {} - Net::Signals::Connection2 connectSignalFinished(const Net::Signals::Signal20::slot_type &slot) { + Net::Signals::Connection connectSignalFinished(const Net::Signals::Signal0::slot_type &slot) { return finished.connect(slot); } - void disconnectSignalFinished(const Net::Signals::Connection2 &con) { + void disconnectSignalFinished(const Net::Signals::Connection &con) { finished.disconnect(con); } }; 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 > receiveSignal; - Signals::Signal20 connectedSignal; - Signals::Signal20 disconnectedSignal; + Signals::Signal1 > 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 >::slot_type &slot) { + Signals::Connection connectSignalReceive(const Signals::Signal1 >::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 con) { { boost::lock_guard lock(mutex); - std::map, std::pair >::iterator it = connections.find(con); + std::map, std::pair >::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,std::pair >::iterator con = connections.begin(); con != connections.end(); ++con) { + for(std::map,std::pair >::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, std::pair > connections; + std::map, std::pair > connections; - Signals::Signal21 > signal; + Signals::Signal1 > signal; void handleAccept(const boost::system::error_code &error, boost::shared_ptr 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 >::slot_type &slot) { + Signals::Connection connectSignalNewConnection(const Signals::Signal1 >::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 - namespace Mad { namespace Net { namespace Signals { -template class SignalBase; +class SignalBase; class Connection { private: - template 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 - * - * 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 . - */ - -#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 #include @@ -30,24 +30,24 @@ namespace Net { namespace Signals { template -class GenericSignal : protected SignalBase2 { +class GenericSignal : protected SignalBase { public: typedef FunctionType slot_type; protected: - std::map handlers; + std::map handlers; public: - Connection2 connect(const slot_type &slot) { + Connection connect(const slot_type &slot) { boost::lock_guard 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 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 + +#include namespace Mad { namespace Net { namespace Signals { -class Signal0 : public SignalBase, boost::function0 > { +class Signal0 : public GenericSignal > { public: void emit() { boost::lock_guard lock(mutex); - signal(); + for(std::map::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 + +#include namespace Mad { namespace Net { namespace Signals { template -class Signal1 : public SignalBase, boost::function1 > { +class Signal1 : public GenericSignal > { public: void emit(T1 arg1) { - boost::lock_guard lock(SignalBase, boost::function1 >::mutex); + boost::lock_guard lock(this->mutex); - SignalBase, boost::function1 >::signal(arg1); + for(typename std::map >::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 + +#include namespace Mad { namespace Net { namespace Signals { template -class Signal2 : public SignalBase, boost::function2 > { +class Signal2 : public GenericSignal > { public: void emit(T1 arg1, T2 arg2) { - boost::lock_guard lock(SignalBase, boost::function2 >::mutex); + boost::lock_guard lock(this->mutex); - SignalBase, boost::function2 >::signal(arg1, arg2); + for(typename std::map >::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 - * - * 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 . - */ - -#ifndef MAD_NET_SIGNALS_SIGNAL20_H_ -#define MAD_NET_SIGNALS_SIGNAL20_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -class Signal20 : public GenericSignal > { - public: - void emit() { - boost::lock_guard lock(mutex); - - for(std::map::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 - * - * 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 . - */ - -#ifndef MAD_NET_SIGNALS_SIGNAL21_H_ -#define MAD_NET_SIGNALS_SIGNAL21_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -template -class Signal21 : public GenericSignal > { - public: - void emit(T1 arg1) { - boost::lock_guard lock(this->mutex); - - for(typename std::map >::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 - * - * 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 . - */ - -#ifndef MAD_NET_SIGNALS_SIGNAL22_H_ -#define MAD_NET_SIGNALS_SIGNAL22_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -template -class Signal22 : public GenericSignal > { - public: - void emit(T1 arg1, T2 arg2) { - boost::lock_guard lock(this->mutex); - - for(typename std::map >::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 -#include -#include #include namespace Mad { namespace Net { namespace Signals { -template class SignalBase : private boost::noncopyable { - public: - typedef boost::slot slot_type; + private: + friend class Connection; - protected: - typedef SignalType signal_type; + unsigned long connectionId; - std::set connections; + protected: boost::mutex mutex; - signal_type signal; - - SignalBase() {} - ~SignalBase() { - // Wait for other threads - boost::lock_guard lock(mutex); + Connection getNewConnection() { + return Connection(this, connectionId++); } - public: - Connection connect(const slot_type &slot) { - boost::lock_guard lock(mutex); - - boost::signals::connection con(signal.connect(slot)); - - connections.insert(con); - return con; - } - - void disconnect(const Connection &connection) { - boost::lock_guard lock(mutex); - - std::set::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 - * - * 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 . - */ - -#ifndef MAD_SIGNALS_SIGNALBASE2_H_ -#define MAD_SIGNALS_SIGNALBASE2_H_ - -#include "Connection2.h" - -#include -#include - -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_ */ -- cgit v1.2.3