summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-17 05:33:01 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-17 05:33:01 +0200
commit039c218a7b1f2eae4f8e8305bc8e8bf70a67beab (patch)
tree362a59253abd77b5e41800d73a7c5dacf18617f7 /src/Client
parenta0cffb5475d35f0a19b95af2ce56bf6c90c82256 (diff)
downloadmad-039c218a7b1f2eae4f8e8305bc8e8bf70a67beab.tar
mad-039c218a7b1f2eae4f8e8305bc8e8bf70a67beab.zip
Interface der Request-Klassen verbessert; muss noch vereinfacht werden
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp71
-rw-r--r--src/Client/CommandParser.h12
-rw-r--r--src/Client/Requests/CoreStatusRequest.cpp27
-rw-r--r--src/Client/Requests/CoreStatusRequest.h16
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp27
-rw-r--r--src/Client/Requests/DaemonListRequest.h18
-rw-r--r--src/Client/Requests/DaemonStatusRequest.cpp33
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h16
8 files changed, 84 insertions, 136 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 3cb5749..407b9c8 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -22,6 +22,7 @@
#include "Requests/DaemonListRequest.h"
#include "Requests/DaemonStatusRequest.h"
#include <Common/Exception.h>
+#include <Common/RequestManager.h>
#include <Common/Requests/DisconnectRequest.h>
#include <Net/Packets/HostStatusPacket.h>
#include <Net/Packets/NameListPacket.h>
@@ -144,14 +145,14 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) {
void CommandParser::listHostsCommand(const std::vector<std::string>&) {
activeRequests++;
- Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonListRequest(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished))));
}
void CommandParser::statusCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Requests::CoreStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::CoreStatusRequest(sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished))));
else if(args.size() == 2)
- Requests::DaemonStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonStatusRequestFinished), sigc::mem_fun(this, &CommandParser::errorCallback), args[1]);
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(args[1], sigc::mem_fun(this, &CommandParser::daemonStatusRequestFinished))));
else {
std::cerr << args[0] << ": Too many arguments." << std::endl;
printUsage("status");
@@ -163,47 +164,67 @@ void CommandParser::statusCommand(const std::vector<std::string> &args) {
void CommandParser::exitCommand(const std::vector<std::string>&) {
activeRequests++;
- disconnect = true;
- Common::Requests::DisconnectRequest::send(connection, sigc::mem_fun(this, &CommandParser::requestFinished));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::DisconnectRequest(sigc::mem_fun(this, &CommandParser::disconnectRequestFinished))));
}
-void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) {
- std::cout << "Server status:" << std::endl;
-
- printHostStatus(packet);
+void CommandParser::coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) {
+ try {
+ const Net::Packets::HostStatusPacket &packet = request.getResult();
+ std::cout << "Server status:" << std::endl;
+ printHostStatus(packet);
+ }
+ catch(Common::Exception &exception) {
+ std::cerr << "An error occurred during your request: " << exception.strerror() << "." << std::endl << std::endl;
+ }
requestFinished();
}
-void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket &packet) {
- const std::vector<std::string>& hosts = packet.getNameList();
+void CommandParser::daemonListRequestFinished(const Common::Request<Net::Packets::NameListPacket> &request) {
+ try {
+ const std::vector<std::string>& hosts = request.getResult().getNameList();
- if(hosts.empty()) {
- std::cout << "There aren't any active hosts." << std::endl << std::endl;
- }
- else {
- std::cout << "Active hosts:" << std::endl;
+ if(hosts.empty()) {
+ std::cout << "There aren't any active hosts." << std::endl << std::endl;
+ }
+ else {
+ std::cout << "Active hosts:" << std::endl;
- for(std::vector<std::string>::const_iterator host = hosts.begin(); host != hosts.end(); ++host)
- std::cout << "\t" << *host << std::endl;
+ for(std::vector<std::string>::const_iterator host = hosts.begin(); host != hosts.end(); ++host)
+ std::cout << "\t" << *host << std::endl;
- std::cout << std::endl;
+ std::cout << std::endl;
+ }
+ }
+ catch(Common::Exception &exception) {
+ std::cerr << "An error occurred during your request: " << exception.strerror() << "." << std::endl << std::endl;
}
requestFinished();
}
-void CommandParser::daemonStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) {
- std::cout << "Host status:" << std::endl;
-
- printHostStatus(packet);
+void CommandParser::daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) {
+ try {
+ const Net::Packets::HostStatusPacket &packet = request.getResult();
+ std::cout << "Host status:" << std::endl;
+ printHostStatus(packet);
+ }
+ catch(Common::Exception &exception) {
+ std::cerr << "An error occurred during your request: " << exception.strerror() << "." << std::endl << std::endl;
+ }
requestFinished();
}
-void CommandParser::errorCallback(const Common::Exception &exception) {
- std::cerr << "An error occurred during your request: " << exception.strerror() << "." << std::endl << std::endl;
+void CommandParser::disconnectRequestFinished(const Common::Request<> &request) {
+ try {
+ request.getResult();
+ disconnect = true;
+ }
+ catch(Common::Exception &exception) {
+ std::cerr << "An error occurred during your request: " << exception.strerror() << "." << std::endl << std::endl;
+ }
requestFinished();
}
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 08b21a1..4137cb3 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -20,7 +20,8 @@
#ifndef MAD_CLIENT_COMMANDPARSER_H_
#define MAD_CLIENT_COMMANDPARSER_H_
-#include <sigc++/signal.h>
+#include <Common/Request.h>
+
#include <string>
#include <vector>
@@ -74,11 +75,10 @@ class CommandParser {
void statusCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
- void coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet);
- void daemonListRequestFinished(const Net::Packets::NameListPacket &packet);
- void daemonStatusRequestFinished(const Net::Packets::HostStatusPacket &packet);
-
- void errorCallback(const Common::Exception &exception);
+ void coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
+ void daemonListRequestFinished(const Common::Request<Net::Packets::NameListPacket> &request);
+ void daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
+ void disconnectRequestFinished(const Common::Request<> &request);
void requestFinished() {
activeRequests--;
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) {}
};
}