diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Client/CommandParser.cpp | 10 | ||||
-rw-r--r-- | src/Client/CommandParser.h | 6 | ||||
-rw-r--r-- | src/Client/Requests/DaemonStatusRequest.cpp | 13 | ||||
-rw-r--r-- | src/Client/Requests/DaemonStatusRequest.h | 8 |
4 files changed, 33 insertions, 4 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index b9368b5..ab1165b 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -21,6 +21,7 @@ #include "Requests/CoreStatusRequest.h" #include "Requests/DaemonListRequest.h" #include "Requests/DaemonStatusRequest.h" +#include <Common/Exception.h> #include <Common/Requests/DisconnectRequest.h> #include <Net/Packets/HostStatusPacket.h> #include <Net/Packets/NameListPacket.h> @@ -150,7 +151,7 @@ void CommandParser::statusCommand(const std::vector<std::string> &args) { if(args.size() == 1) Requests::CoreStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished)); else if(args.size() == 2) - Requests::DaemonStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonStatusRequestFinished), args[1]); + Requests::DaemonStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonStatusRequestFinished), sigc::mem_fun(this, &CommandParser::errorCallback), args[1]); else { std::cerr << args[0] << ": Too many arguments." << std::endl; printUsage("status"); @@ -201,6 +202,13 @@ void CommandParser::daemonStatusRequestFinished(const Net::Packets::HostStatusPa requestFinished(); } +void CommandParser::errorCallback(const Common::Exception &exception) { + std::cerr << "An error occurred during your request." << std::endl; + std::cerr << "Error code: " << exception.getErrorCode() << std::endl << std::endl; + + requestFinished(); +} + bool CommandParser::split(const std::string &str, std::vector<std::string> &ret) { std::string temp; bool quoteSingle = false, quoteDouble = false, escape = false; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index e2b4d58..08b21a1 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -26,6 +26,10 @@ namespace Mad { +namespace Common { +class Exception; +} + namespace Net { class Connection; @@ -74,6 +78,8 @@ class CommandParser { void daemonListRequestFinished(const Net::Packets::NameListPacket &packet); void daemonStatusRequestFinished(const Net::Packets::HostStatusPacket &packet); + void errorCallback(const Common::Exception &exception); + void requestFinished() { activeRequests--; diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp index 7a7b47e..719ae5c 100644 --- a/src/Client/Requests/DaemonStatusRequest.cpp +++ b/src/Client/Requests/DaemonStatusRequest.cpp @@ -19,16 +19,20 @@ #include "DaemonStatusRequest.h" #include <Common/RequestManager.h> +#include <Net/Packets/ErrorPacket.h> #include <Net/Packets/HostStatusPacket.h> namespace Mad { namespace Client { namespace Requests { -bool DaemonStatusRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback, const std::string &daemon0) { +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; @@ -45,7 +49,12 @@ bool DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requ } void DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::OK) { + if(packet.getType() == Net::Packet::ERROR) { + error(Net::Packets::ErrorPacket(packet).getException()); + signalFinished().emit(); + return; + } + else if(packet.getType() != Net::Packet::OK) { signalFinished().emit(); return; // TODO Logging } diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h index 34d3a90..f5c130d 100644 --- a/src/Client/Requests/DaemonStatusRequest.h +++ b/src/Client/Requests/DaemonStatusRequest.h @@ -27,6 +27,10 @@ namespace Mad { +namespace Common { +class Exception; +} + namespace Net { namespace Packets { class HostStatusPacket; @@ -39,13 +43,15 @@ namespace Requests { class DaemonStatusRequest : public Common::Request { 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) {} public: - static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback, const std::string &daemon0); + 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); |