diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-17 05:33:01 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-17 05:33:01 +0200 |
commit | 039c218a7b1f2eae4f8e8305bc8e8bf70a67beab (patch) | |
tree | 362a59253abd77b5e41800d73a7c5dacf18617f7 /src/Client/Requests | |
parent | a0cffb5475d35f0a19b95af2ce56bf6c90c82256 (diff) | |
download | mad-039c218a7b1f2eae4f8e8305bc8e8bf70a67beab.tar mad-039c218a7b1f2eae4f8e8305bc8e8bf70a67beab.zip |
Interface der Request-Klassen verbessert; muss noch vereinfacht werden
Diffstat (limited to 'src/Client/Requests')
-rw-r--r-- | src/Client/Requests/CoreStatusRequest.cpp | 27 | ||||
-rw-r--r-- | src/Client/Requests/CoreStatusRequest.h | 16 | ||||
-rw-r--r-- | src/Client/Requests/DaemonListRequest.cpp | 27 | ||||
-rw-r--r-- | src/Client/Requests/DaemonListRequest.h | 18 | ||||
-rw-r--r-- | src/Client/Requests/DaemonStatusRequest.cpp | 33 | ||||
-rw-r--r-- | src/Client/Requests/DaemonStatusRequest.h | 16 |
6 files changed, 32 insertions, 105 deletions
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp index 93552f6..35a63e2 100644 --- a/src/Client/Requests/CoreStatusRequest.cpp +++ b/src/Client/Requests/CoreStatusRequest.cpp @@ -18,41 +18,24 @@ */ #include "CoreStatusRequest.h" -#include <Common/RequestManager.h> +#include <Net/Connection.h> #include <Net/Packets/HostStatusPacket.h> namespace Mad { namespace Client { namespace Requests { -bool CoreStatusRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback) { - CoreStatusRequest *request = new CoreStatusRequest(); - - request->finished.connect(callback); - - if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) - return true; - - delete request; - return false; -} - -bool CoreStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - if(!connection->send(Net::Packet(Net::Packet::STATUS, requestId))) - return false; - - return true; +void CoreStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::STATUS, requestId)); } void CoreStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { if(packet.getType() != Net::Packet::OK) { - signalFinished().emit(); + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } - finished(Net::Packets::HostStatusPacket(packet)); - - signalFinished().emit(); + finish(Net::Packets::HostStatusPacket(packet)); } } diff --git a/src/Client/Requests/CoreStatusRequest.h b/src/Client/Requests/CoreStatusRequest.h index ff9bdc1..94aff9c 100644 --- a/src/Client/Requests/CoreStatusRequest.h +++ b/src/Client/Requests/CoreStatusRequest.h @@ -22,8 +22,6 @@ #include <Common/Request.h> -#include <sigc++/signal.h> - namespace Mad { namespace Net { @@ -35,17 +33,13 @@ class HostStatusPacket; namespace Client { namespace Requests { -class CoreStatusRequest : public Common::Request { - private: - sigc::signal<void,const Net::Packets::HostStatusPacket&> finished; - - CoreStatusRequest() {} +class CoreStatusRequest : public Common::Request<Net::Packets::HostStatusPacket> { + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); public: - static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback); - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection*, const Net::Packet &packet); + CoreStatusRequest(slot_type slot) : Common::Request<Net::Packets::HostStatusPacket>(slot) {} }; } diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp index cc6d353..2c2e195 100644 --- a/src/Client/Requests/DaemonListRequest.cpp +++ b/src/Client/Requests/DaemonListRequest.cpp @@ -18,41 +18,24 @@ */ #include "DaemonListRequest.h" -#include <Common/RequestManager.h> +#include <Net/Connection.h> #include <Net/Packets/NameListPacket.h> namespace Mad { namespace Client { namespace Requests { -bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback) { - DaemonListRequest *request = new DaemonListRequest(); - - request->finished.connect(callback); - - if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) - return true; - - delete request; - return false; -} - -bool DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - if(!connection->send(Net::Packet(Net::Packet::LIST_DAEMONS, requestId))) - return false; - - return true; +void DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::LIST_DAEMONS, requestId)); } void DaemonListRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { if(packet.getType() != Net::Packet::OK) { - signalFinished().emit(); + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } - finished(Net::Packets::NameListPacket(packet)); - - signalFinished().emit(); + finish(Net::Packets::NameListPacket(packet)); } } diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h index 9a11d19..5c57502 100644 --- a/src/Client/Requests/DaemonListRequest.h +++ b/src/Client/Requests/DaemonListRequest.h @@ -22,8 +22,6 @@ #include <Common/Request.h> -#include <sigc++/signal.h> - namespace Mad { namespace Net { @@ -35,17 +33,13 @@ class NameListPacket; namespace Client { namespace Requests { -class DaemonListRequest : public Common::Request { - private: - sigc::signal<void,const Net::Packets::NameListPacket&> finished; - - DaemonListRequest() {} - - public: - static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback); +class DaemonListRequest : public Common::Request<Net::Packets::NameListPacket> { + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection*, const Net::Packet &packet); + public: + DaemonListRequest(slot_type slot) : Common::Request<Net::Packets::NameListPacket>(slot) {} }; } diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp index 719ae5c..9238ed6 100644 --- a/src/Client/Requests/DaemonStatusRequest.cpp +++ b/src/Client/Requests/DaemonStatusRequest.cpp @@ -18,7 +18,7 @@ */ #include "DaemonStatusRequest.h" -#include <Common/RequestManager.h> +#include <Net/Connection.h> #include <Net/Packets/ErrorPacket.h> #include <Net/Packets/HostStatusPacket.h> @@ -26,42 +26,21 @@ namespace Mad { namespace Client { namespace Requests { -bool DaemonStatusRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback, - const sigc::slot<void,const Common::Exception&> &errorCallback, const std::string &daemon0) -{ - DaemonStatusRequest *request = new DaemonStatusRequest(daemon0); - - request->finished.connect(callback); - request->error.connect(errorCallback); - - if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) - return true; - - delete request; - return false; -} - -bool DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - if(!connection->send(Net::Packet(Net::Packet::DAEMON_STATUS, requestId, daemon.c_str(), daemon.length()))) - return false; - - return true; +void DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::DAEMON_STATUS, requestId, daemon.c_str(), daemon.length())); } void DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { if(packet.getType() == Net::Packet::ERROR) { - error(Net::Packets::ErrorPacket(packet).getException()); - signalFinished().emit(); + finishWithError(Net::Packets::ErrorPacket(packet).getException()); return; } else if(packet.getType() != Net::Packet::OK) { - signalFinished().emit(); + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } - finished(Net::Packets::HostStatusPacket(packet)); - - signalFinished().emit(); + finish(Net::Packets::HostStatusPacket(packet)); } } diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h index f5c130d..8f74ca4 100644 --- a/src/Client/Requests/DaemonStatusRequest.h +++ b/src/Client/Requests/DaemonStatusRequest.h @@ -23,7 +23,6 @@ #include <Common/Request.h> #include <string> -#include <sigc++/signal.h> namespace Mad { @@ -40,21 +39,16 @@ class HostStatusPacket; namespace Client { namespace Requests { -class DaemonStatusRequest : public Common::Request { +class DaemonStatusRequest : public Common::Request<Net::Packets::HostStatusPacket> { private: - sigc::signal<void,const Net::Packets::HostStatusPacket&> finished; - sigc::signal<void,const Common::Exception&> error; - std::string daemon; - DaemonStatusRequest(const std::string &daemon0) : daemon(daemon0) {} + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); public: - static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback, - const sigc::slot<void,const Common::Exception&> &errorCallback, const std::string &daemon0); - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection*, const Net::Packet &packet); + DaemonStatusRequest(const std::string &daemon0, slot_type slot) : Common::Request<Net::Packets::HostStatusPacket>(slot), daemon(daemon0) {} }; } |