From 039c218a7b1f2eae4f8e8305bc8e8bf70a67beab Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 17 Sep 2008 05:33:01 +0200 Subject: Interface der Request-Klassen verbessert; muss noch vereinfacht werden --- src/Client/Requests/CoreStatusRequest.cpp | 27 +++++------------------ src/Client/Requests/CoreStatusRequest.h | 16 +++++--------- src/Client/Requests/DaemonListRequest.cpp | 27 +++++------------------ src/Client/Requests/DaemonListRequest.h | 18 ++++++---------- src/Client/Requests/DaemonStatusRequest.cpp | 33 ++++++----------------------- src/Client/Requests/DaemonStatusRequest.h | 16 +++++--------- 6 files changed, 32 insertions(+), 105 deletions(-) (limited to 'src/Client/Requests') 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 +#include #include namespace Mad { namespace Client { namespace Requests { -bool CoreStatusRequest::send(Net::Connection *connection, const sigc::slot &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 -#include - namespace Mad { namespace Net { @@ -35,17 +33,13 @@ class HostStatusPacket; namespace Client { namespace Requests { -class CoreStatusRequest : public Common::Request { - private: - sigc::signal finished; - - CoreStatusRequest() {} +class CoreStatusRequest : public Common::Request { + 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 &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(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 +#include #include namespace Mad { namespace Client { namespace Requests { -bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot &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 -#include - namespace Mad { namespace Net { @@ -35,17 +33,13 @@ class NameListPacket; namespace Client { namespace Requests { -class DaemonListRequest : public Common::Request { - private: - sigc::signal finished; - - DaemonListRequest() {} - - public: - static bool send(Net::Connection *connection, const sigc::slot &callback); +class DaemonListRequest : public Common::Request { + 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(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 +#include #include #include @@ -26,42 +26,21 @@ namespace Mad { namespace Client { namespace Requests { -bool DaemonStatusRequest::send(Net::Connection *connection, const sigc::slot &callback, - const sigc::slot &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 #include -#include namespace Mad { @@ -40,21 +39,16 @@ class HostStatusPacket; namespace Client { namespace Requests { -class DaemonStatusRequest : public Common::Request { +class DaemonStatusRequest : public Common::Request { private: - sigc::signal finished; - sigc::signal 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 &callback, - const sigc::slot &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(slot), daemon(daemon0) {} }; } -- cgit v1.2.3