diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-05-30 13:37:06 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-05-30 13:37:06 +0200 |
commit | a77d2d1e08e4e2e8dfb5e4fc326f6c8fe315a898 (patch) | |
tree | 36a4c899af336c7e9dc326da7231d4d9e17e8a1b /src/Common | |
parent | cb8e66c1b1f1c8076053d71347d0b1f96ca0bca1 (diff) | |
download | mad-a77d2d1e08e4e2e8dfb5e4fc326f6c8fe315a898.tar mad-a77d2d1e08e4e2e8dfb5e4fc326f6c8fe315a898.zip |
Thread-sichere Signale implementiert
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/ClientConnection.cpp | 2 | ||||
-rw-r--r-- | src/Common/Connection.cpp | 2 | ||||
-rw-r--r-- | src/Common/Connection.h | 16 | ||||
-rw-r--r-- | src/Common/Request.h | 12 | ||||
-rw-r--r-- | src/Common/RequestHandler.h | 9 | ||||
-rw-r--r-- | src/Common/RequestHandlers/DisconnectRequestHandler.cpp | 4 | ||||
-rw-r--r-- | src/Common/RequestHandlers/FSInfoRequestHandler.cpp | 4 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.cpp | 4 | ||||
-rw-r--r-- | src/Common/RequestManager.cpp | 4 |
9 files changed, 29 insertions, 28 deletions
diff --git a/src/Common/ClientConnection.cpp b/src/Common/ClientConnection.cpp index ee9f5cf..b9a6721 100644 --- a/src/Common/ClientConnection.cpp +++ b/src/Common/ClientConnection.cpp @@ -26,7 +26,7 @@ namespace Mad { namespace Common { ClientConnection::ClientConnection() : connection(new Net::ClientConnection) { - connection->signalReceive().connect(boost::bind(&ClientConnection::receive, this, _1)); + connection->connectSignalReceive(boost::bind(&ClientConnection::receive, this, _1)); } bool ClientConnection::send(const Net::Packet &packet) { diff --git a/src/Common/Connection.cpp b/src/Common/Connection.cpp index f476a68..5b2eee9 100644 --- a/src/Common/Connection.cpp +++ b/src/Common/Connection.cpp @@ -24,7 +24,7 @@ namespace Mad { namespace Common { void Connection::receive(const Net::Packet &packet) { - signal(XmlPacket(packet), packet.getRequestId()); + signalReceive.emit(XmlPacket(packet), packet.getRequestId()); } bool Connection::sendPacket(const XmlPacket &packet, uint16_t requestId) { diff --git a/src/Common/Connection.h b/src/Common/Connection.h index 5ac46a2..2d74548 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -20,11 +20,11 @@ #ifndef MAD_COMMON_CONNECTION_H_ #define MAD_COMMON_CONNECTION_H_ +#include <Net/Signals/Signals.h> + #include <stdint.h> #include <sys/types.h> -#include <boost/signal.hpp> - namespace Mad { namespace Net { @@ -35,15 +35,11 @@ namespace Common { class XmlPacket; -class Connection { +class Connection : private boost::noncopyable { private: bool authenticated; - boost::signal2<void, const XmlPacket&, uint16_t> signal; - - // Prevent shallow copy - Connection(const Connection &o); - Connection& operator=(const Connection &o); + Net::Signals::Signal2<void, const XmlPacket&, uint16_t> signalReceive; protected: Connection() : authenticated(0) {} @@ -57,8 +53,8 @@ class Connection { bool sendPacket(const XmlPacket &packet, uint16_t requestId); - boost::signal2<void, const XmlPacket&, uint16_t>& signalReceive() { - return signal; + Net::Signals::Connection connectSignalReceive(const Net::Signals::Signal2<void, const XmlPacket&, uint16_t>::slot_type &slot) { + return signalReceive.connect(slot); } virtual bool disconnect() = 0; diff --git a/src/Common/Request.h b/src/Common/Request.h index 3979e0c..6f72667 100644 --- a/src/Common/Request.h +++ b/src/Common/Request.h @@ -34,24 +34,24 @@ class Request : public RequestHandler { private: friend class RequestManager; - boost::signal1<void, const Request&> finished; + Net::Signals::Signal1<void, const Request&> finished; std::auto_ptr<XmlPacket> res; Net::Exception exp; public: - typedef boost::function1<void, const Request&> slot_type; + typedef Net::Signals::Signal1<void, const Request&>::slot_type slot_type; protected: Request(Connection *connection, uint16_t requestId, slot_type slot) : RequestHandler(connection, requestId), exp(Net::Exception::NOT_FINISHED) { finished.connect(slot); - finished.connect(boost::bind((void(boost::signal0<void>::*)())&boost::signal0<void>::operator(), &signalFinished())); + finished.connect(boost::bind(&Request::signalFinished, this)); } - void finish(std::auto_ptr<XmlPacket> result) {res = result; finished(*this);} - void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished(*this);} - void finishWithError(const Net::Exception &e) {exp = e; finished(*this);} + void finish(std::auto_ptr<XmlPacket> result) {res = result; finished.emit(*this);} + void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished.emit(*this);} + void finishWithError(const Net::Exception &e) {exp = e; finished.emit(*this);} virtual void sendRequest() = 0; virtual void handlePacket(const XmlPacket &packet); diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index d4a591a..58ffeb7 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -23,6 +23,8 @@ #include "Connection.h" #include "XmlPacket.h" +#include <Net/Signals/Signals.h> + #include <boost/cstdint.hpp> namespace Mad { @@ -33,7 +35,7 @@ class RequestManager; class RequestHandler { private: - boost::signal0<void> finished; + Net::Signals::Signal0<void> finished; Connection *connection; boost::uint16_t requestId; @@ -45,7 +47,10 @@ class RequestHandler { protected: RequestHandler(Connection *connection0, boost::uint16_t requestId0) : connection(connection0), requestId(requestId0) {} - boost::signal0<void>& signalFinished() {return finished;} + void signalFinished() {finished.emit();} + Net::Signals::Connection connectSignalFinished(const Net::Signals::Signal0<void>::slot_type &slot) { + return finished.connect(slot); + } Connection* getConnection() const { return connection; diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index 163aa75..ac8e7dc 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -35,7 +35,7 @@ void DisconnectRequestHandler::handlePacket(const XmlPacket &packet) { sendPacket(ret); - signalFinished()(); + signalFinished(); return; } @@ -47,7 +47,7 @@ void DisconnectRequestHandler::handlePacket(const XmlPacket &packet) { getConnection()->disconnect(); - signalFinished()(); + signalFinished(); } } diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp index 94756b5..9044c68 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp @@ -37,7 +37,7 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) { sendPacket(ret); - signalFinished()(); + signalFinished(); return; } @@ -73,7 +73,7 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) { } sendPacket(ret); - signalFinished()(); + signalFinished(); } } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index c564680..e766670 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -38,7 +38,7 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) { sendPacket(ret); - signalFinished()(); + signalFinished(); return; } @@ -74,7 +74,7 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) { ret.add("loadAvg15", loadAvg15); sendPacket(ret); - signalFinished()(); + signalFinished(); } } diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 8940339..f328bf7 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -33,7 +33,7 @@ bool RequestManager::RequestMap::addRequest(boost::uint16_t id, boost::shared_pt if(!insert(std::make_pair(id, info)).second) return false; - info->signalFinished().connect(boost::bind(&RequestManager::RequestMap::deleteRequest, this, id)); + info->connectSignalFinished(boost::bind(&RequestManager::RequestMap::deleteRequest, this, id)); return true; } @@ -120,7 +120,7 @@ void RequestManager::registerConnection(Connection *connection) { requestMaps.insert(std::make_pair(connection, new RequestMap())); - connection->signalReceive().connect(boost::bind(&RequestManager::receiveHandler, this, connection, _1, _2)); + connection->connectSignalReceive(boost::bind(&RequestManager::receiveHandler, this, connection, _1, _2)); } RequestManager::RequestManager() : server(false), lastRequestId(-1) { |