summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp120
-rw-r--r--src/Client/CommandParser.h5
-rw-r--r--src/Client/Requests/CoreStatusRequest.cpp15
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp9
-rw-r--r--src/Client/Requests/DaemonStatusRequest.cpp59
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h58
-rw-r--r--src/Client/Requests/Makefile.am4
-rw-r--r--src/Client/Requests/Makefile.in8
8 files changed, 202 insertions, 76 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index badbef7..30a0c16 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -20,6 +20,7 @@
#include "CommandParser.h"
#include "Requests/CoreStatusRequest.h"
#include "Requests/DaemonListRequest.h"
+#include "Requests/DaemonStatusRequest.h"
#include <Common/Requests/DisconnectRequest.h>
#include <Net/Packets/HostStatusPacket.h>
#include <Net/Packets/NameListPacket.h>
@@ -57,57 +58,7 @@ void CommandParser::printUsage(const std::string& command) {
std::cerr << "Usage: " << cmd->cmdline << std::endl;
}
-void CommandParser::helpCommand(const std::vector<std::string> &args) {
- if(args.size() == 1) {
- std::cout << "Available commands:" << std::endl << std::endl;
-
- for(int i = 0; commands[i].commands[0] != 0; ++i) {
- std::cout << commands[i].commands[0];
-
- for(int j = 1; commands[i].commands[j] != 0; ++j)
- std::cout << ", " << commands[i].commands[j];
-
- std::cout << std::endl << "\t" << commands[i].desc << std::endl;
- }
- }
- else if(args.size() == 2) {
- const Command* command = findCommand(args[1]);
-
- if(command) {
- std::cout << "Usage: " << command->cmdline << std::endl << std::endl;
- std::cout << command->longdesc << std::endl;
- }
- else
- std::cerr << args[0] << ": Command '" << args[1] << "' doesn't exist." << std::endl;
- }
- else {
- std::cerr << args[0] << ": Too many arguments." << std::endl;
- printUsage("help");
- }
-}
-
-void CommandParser::listHostsCommand(const std::vector<std::string>&) {
- activeRequests++;
-
- Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished));
-}
-
-void CommandParser::statusCommand(const std::vector<std::string>&) {
- activeRequests++;
-
- Requests::CoreStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished));
-}
-
-void CommandParser::exitCommand(const std::vector<std::string>&) {
- activeRequests++;
- disconnect = true;
-
- Common::Requests::DisconnectRequest::send(connection, sigc::mem_fun(this, &CommandParser::requestFinished));
-}
-
-void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) {
- std::cout << "Server status:" << std::endl;
-
+void CommandParser::printHostStatus(const Net::Packets::HostStatusPacket &packet) {
if(packet.getUptime()) {
unsigned long days = packet.getUptime()/86400;
unsigned long hours = (packet.getUptime()%86400)/3600;
@@ -158,6 +109,65 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPack
std::printf("\n");
}
+}
+
+void CommandParser::helpCommand(const std::vector<std::string> &args) {
+ if(args.size() == 1) {
+ std::cout << "Available commands:" << std::endl << std::endl;
+
+ for(int i = 0; commands[i].commands[0] != 0; ++i) {
+ std::cout << commands[i].commands[0];
+
+ for(int j = 1; commands[i].commands[j] != 0; ++j)
+ std::cout << ", " << commands[i].commands[j];
+
+ std::cout << std::endl << "\t" << commands[i].desc << std::endl;
+ }
+ }
+ else if(args.size() == 2) {
+ const Command* command = findCommand(args[1]);
+
+ if(command) {
+ std::cout << "Usage: " << command->cmdline << std::endl << std::endl;
+ std::cout << command->longdesc << std::endl;
+ }
+ else
+ std::cerr << args[0] << ": Command '" << args[1] << "' doesn't exist." << std::endl;
+ }
+ else {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ printUsage("help");
+ }
+}
+
+void CommandParser::listHostsCommand(const std::vector<std::string>&) {
+ activeRequests++;
+
+ Requests::DaemonListRequest::send(connection, 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));
+ else if(args.size() == 2)
+ Requests::DaemonStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonStatusRequestFinished), args[1]);
+ else
+ return;
+
+ activeRequests++;
+}
+
+void CommandParser::exitCommand(const std::vector<std::string>&) {
+ activeRequests++;
+ disconnect = true;
+
+ Common::Requests::DisconnectRequest::send(connection, sigc::mem_fun(this, &CommandParser::requestFinished));
+}
+
+void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) {
+ std::cout << "Server status:" << std::endl;
+
+ printHostStatus(packet);
requestFinished();
}
@@ -180,6 +190,14 @@ void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket
requestFinished();
}
+void CommandParser::daemonStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) {
+ std::cout << "Host status:" << std::endl;
+
+ printHostStatus(packet);
+
+ 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 40d36a7..e2b4d58 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -63,13 +63,16 @@ class CommandParser {
const Command* findCommand(const std::string& command);
void printUsage(const std::string& command);
+ void printHostStatus(const Net::Packets::HostStatusPacket &packet);
+
void helpCommand(const std::vector<std::string> &args);
void listHostsCommand(const std::vector<std::string>&);
- void statusCommand(const std::vector<std::string>&);
+ 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 requestFinished() {
activeRequests--;
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp
index af34752..1c477b8 100644
--- a/src/Client/Requests/CoreStatusRequest.cpp
+++ b/src/Client/Requests/CoreStatusRequest.cpp
@@ -38,27 +38,20 @@ bool CoreStatusRequest::send(Net::Connection *connection, const sigc::slot<void,
}
bool CoreStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- if(isSent())
+ if(!connection->send(Net::Packet(Net::Packet::STATUS, requestId)))
return false;
- if(!connection->send(Net::Packet(Net::Packet::CORE_STATUS, requestId)))
- return false;
-
- setSent();
return true;
}
bool CoreStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(isFinished())
- return false;
-
if(packet.getType() != Net::Packet::OK)
return false; // TODO Logging
- finished(Net::Packets::HostStatusPacket(packet));
+ finished(Net::Packets::HostStatusPacket(packet));
- setFinished();
- return true;
+ signalFinished().emit();
+ return true;
}
}
diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp
index a0e4cf1..97ee335 100644
--- a/src/Client/Requests/DaemonListRequest.cpp
+++ b/src/Client/Requests/DaemonListRequest.cpp
@@ -38,26 +38,19 @@ bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot<void,
}
bool DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- if(isSent())
- return false;
-
if(!connection->send(Net::Packet(Net::Packet::LIST_DAEMONS, requestId)))
return false;
- setSent();
return true;
}
bool DaemonListRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(isFinished())
- return false;
-
if(packet.getType() != Net::Packet::OK)
return false; // TODO Logging
finished(Net::Packets::NameListPacket(packet));
- setFinished();
+ signalFinished().emit();
return true;
}
diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp
new file mode 100644
index 0000000..8308e96
--- /dev/null
+++ b/src/Client/Requests/DaemonStatusRequest.cpp
@@ -0,0 +1,59 @@
+/*
+ * DaemonStatusRequest.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DaemonStatusRequest.h"
+#include <Common/RequestManager.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) {
+ DaemonStatusRequest *request = new DaemonStatusRequest(daemon0);
+
+ request->finished.connect(callback);
+
+ 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;
+}
+
+bool DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::OK)
+ return false; // TODO Logging
+
+ finished(Net::Packets::HostStatusPacket(packet));
+
+ signalFinished().emit();
+ return true;
+}
+
+}
+}
+}
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
new file mode 100644
index 0000000..0aff41b
--- /dev/null
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -0,0 +1,58 @@
+/*
+ * DaemonStatusRequest.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
+#define MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
+
+#include <Common/Request.h>
+
+#include <string>
+#include <sigc++/signal.h>
+
+namespace Mad {
+
+namespace Net {
+namespace Packets {
+class HostStatusPacket;
+}
+}
+
+namespace Client {
+namespace Requests {
+
+class DaemonStatusRequest : public Common::Request {
+ private:
+ sigc::signal<void,const Net::Packets::HostStatusPacket&> finished;
+
+ 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);
+
+ virtual bool sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual bool handlePacket(Net::Connection*, const Net::Packet &packet);
+};
+
+}
+}
+}
+
+#endif /* MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_ */
diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am
index bf15a08..e8e72d4 100644
--- a/src/Client/Requests/Makefile.am
+++ b/src/Client/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp
+librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h
+noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h DaemonStatusRequest.h
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index 81f6cec..7ebd73d 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -45,7 +45,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = CoreStatusRequest.lo DaemonListRequest.lo
+am_librequests_la_OBJECTS = CoreStatusRequest.lo DaemonListRequest.lo \
+ DaemonStatusRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -184,8 +185,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h
+librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp
+noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h DaemonStatusRequest.h
all: all-am
.SUFFIXES:
@@ -239,6 +240,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<