summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Client/CommandParser.cpp2
-rw-r--r--src/Client/InformationManager.cpp56
-rw-r--r--src/Client/InformationManager.h78
-rw-r--r--src/Client/Makefile.am4
-rw-r--r--src/Client/Makefile.in8
-rw-r--r--src/Client/Requests/CoreStatusRequest.cpp1
-rw-r--r--src/Client/Requests/CoreStatusRequest.h8
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp1
-rw-r--r--src/Client/Requests/DaemonListRequest.h8
-rw-r--r--src/Client/Requests/DaemonStatusRequest.cpp1
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h8
-rw-r--r--src/Common/RequestManager.cpp4
-rw-r--r--src/Core/ConnectionManager.h2
-rw-r--r--src/Core/Requests/DaemonStatusRequest.cpp1
-rw-r--r--src/Core/Requests/DaemonStatusRequest.h8
-rw-r--r--src/madc.cpp16
16 files changed, 165 insertions, 41 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 1a5a96c..663c214 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -40,7 +40,7 @@ const CommandParser::Command CommandParser::commands[] = {
{{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand},
{{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
{{"reboot", 0}, "reboot host", "Reboots a host", "Reboots a host.", &CommandParser::rebootCommand},
- {{"shutdown", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand},
+ {{"shutdown", "halt", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand},
{{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand},
{{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
new file mode 100644
index 0000000..3a8caab
--- /dev/null
+++ b/src/Client/InformationManager.cpp
@@ -0,0 +1,56 @@
+/*
+ * InformationManager.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 "InformationManager.h"
+#include "Requests/DaemonListRequest.h"
+#include <Common/Logger.h>
+#include <Common/RequestManager.h>
+
+
+namespace Mad {
+namespace Client {
+
+std::auto_ptr<InformationManager> InformationManager::informationManager;
+
+InformationManager::InformationManager(Net::Connection *connection) : initFinished(false) {
+ Common::RequestManager::getRequestManager()->sendRequest(connection,
+ std::auto_ptr<Common::RequestBase>(
+ new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished))
+ )
+ );
+}
+
+void InformationManager::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request) {
+ try {
+ const std::vector<Common::HostInfo> &hostInfo = request.getResult().getHostInfo();
+
+ for(std::vector<Common::HostInfo>::const_iterator daemon = hostInfo.begin(); daemon != hostInfo.end(); ++daemon) {
+ daemons.clear();
+ daemons.insert(std::make_pair(daemon->getName(), *daemon));
+ }
+
+ initFinished = true;
+ }
+ catch(Common::Exception &e) {
+ Common::Logger::logf(Common::Logger::CRITICAL, "Host list request failed: %s", e.strerror().c_str());
+ }
+}
+
+}
+}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
new file mode 100644
index 0000000..5670f8f
--- /dev/null
+++ b/src/Client/InformationManager.h
@@ -0,0 +1,78 @@
+/*
+ * InformationManager.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_INFORMATIONMANAGER_H_
+#define MAD_CLIENT_INFORMATIONMANAGER_H_
+
+#include <map>
+#include <memory>
+
+#include <Common/HostInfo.h>
+#include <Common/Request.h>
+
+namespace Mad {
+
+namespace Net {
+class Connection;
+
+namespace Packets {
+class HostListPacket;
+}
+
+}
+
+namespace Client {
+
+class InformationManager {
+ private:
+ static std::auto_ptr<InformationManager> informationManager;
+
+ std::map<std::string, Common::HostInfo> daemons;
+ bool initFinished;
+
+ // Prevent shallow copy
+ InformationManager(const InformationManager &o);
+ InformationManager& operator=(const InformationManager &o);
+
+ InformationManager(Net::Connection *connection);
+
+ void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request);
+
+ public:
+ static InformationManager* getInformationManager() {
+ return informationManager.get();
+ }
+
+ static void init(Net::Connection *connection) {
+ informationManager = std::auto_ptr<InformationManager>(new InformationManager(connection));
+ }
+
+ bool isInitialised() const {
+ return initFinished;
+ }
+
+ const std::map<std::string, Common::HostInfo>& getDaemons() const {
+ return daemons;
+ }
+};
+
+}
+}
+
+#endif /* MAD_CLIENT_INFORMATIONMANAGER_H_ */
diff --git a/src/Client/Makefile.am b/src/Client/Makefile.am
index cfbabd4..5de3bc6 100644
--- a/src/Client/Makefile.am
+++ b/src/Client/Makefile.am
@@ -1,7 +1,7 @@
SUBDIRS = Requests
noinst_LTLIBRARIES = libclient.la
-libclient_la_SOURCES = CommandManager.cpp CommandParser.cpp
+libclient_la_SOURCES = CommandManager.cpp CommandParser.cpp InformationManager.cpp
libclient_la_LIBADD = Requests/librequests.la
-noinst_HEADERS = CommandManager.h CommandParser.h
+noinst_HEADERS = CommandManager.h CommandParser.h InformationManager.h
diff --git a/src/Client/Makefile.in b/src/Client/Makefile.in
index b9e2d98..8d6b09e 100644
--- a/src/Client/Makefile.in
+++ b/src/Client/Makefile.in
@@ -48,7 +48,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libclient_la_DEPENDENCIES = Requests/librequests.la
-am_libclient_la_OBJECTS = CommandManager.lo CommandParser.lo
+am_libclient_la_OBJECTS = CommandManager.lo CommandParser.lo \
+ InformationManager.lo
libclient_la_OBJECTS = $(am_libclient_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -198,9 +199,9 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests
noinst_LTLIBRARIES = libclient.la
-libclient_la_SOURCES = CommandManager.cpp CommandParser.cpp
+libclient_la_SOURCES = CommandManager.cpp CommandParser.cpp InformationManager.cpp
libclient_la_LIBADD = Requests/librequests.la
-noinst_HEADERS = CommandManager.h CommandParser.h
+noinst_HEADERS = CommandManager.h CommandParser.h InformationManager.h
all: all-recursive
.SUFFIXES:
@@ -254,6 +255,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandParser.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InformationManager.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp
index 35a63e2..69e3ecf 100644
--- a/src/Client/Requests/CoreStatusRequest.cpp
+++ b/src/Client/Requests/CoreStatusRequest.cpp
@@ -19,7 +19,6 @@
#include "CoreStatusRequest.h"
#include <Net/Connection.h>
-#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
namespace Client {
diff --git a/src/Client/Requests/CoreStatusRequest.h b/src/Client/Requests/CoreStatusRequest.h
index 94aff9c..f57f4bf 100644
--- a/src/Client/Requests/CoreStatusRequest.h
+++ b/src/Client/Requests/CoreStatusRequest.h
@@ -21,15 +21,9 @@
#define MAD_CLIENT_REQUESTS_CORESTATUSREQUEST_H_
#include <Common/Request.h>
+#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostStatusPacket;
-}
-}
-
namespace Client {
namespace Requests {
diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp
index 279d19c..690aaea 100644
--- a/src/Client/Requests/DaemonListRequest.cpp
+++ b/src/Client/Requests/DaemonListRequest.cpp
@@ -19,7 +19,6 @@
#include "DaemonListRequest.h"
#include <Net/Connection.h>
-#include <Net/Packets/HostListPacket.h>
namespace Mad {
namespace Client {
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 625e430..fbf0e70 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -21,15 +21,9 @@
#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
#include <Common/Request.h>
+#include <Net/Packets/HostListPacket.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostListPacket;
-}
-}
-
namespace Client {
namespace Requests {
diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp
index 9238ed6..94407b4 100644
--- a/src/Client/Requests/DaemonStatusRequest.cpp
+++ b/src/Client/Requests/DaemonStatusRequest.cpp
@@ -20,7 +20,6 @@
#include "DaemonStatusRequest.h"
#include <Net/Connection.h>
#include <Net/Packets/ErrorPacket.h>
-#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
namespace Client {
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
index cd71dfb..3190ca1 100644
--- a/src/Client/Requests/DaemonStatusRequest.h
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -21,17 +21,11 @@
#define MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
#include <Common/Request.h>
+#include <Net/Packets/HostStatusPacket.h>
#include <string>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostStatusPacket;
-}
-}
-
namespace Client {
namespace Requests {
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index afe72b0..8d0c73c 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -102,8 +102,10 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<RequestBase> request) {
std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
- if(it == requestMaps.end())
+ if(it == requestMaps.end()) {
+ Logger::log(Logger::CRITICAL, "Trying to send a request over an unregistered connecion.");
return false;
+ }
RequestMap *requestMap = it->second;
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index 0832b5a..9b8615c 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -75,7 +75,7 @@ class ConnectionManager {
connectionManager = std::auto_ptr<ConnectionManager>(new ConnectionManager());
}
- virtual ~ConnectionManager();
+ ~ConnectionManager();
bool wait(int timeout) {
return (poll(pollfds.data(), pollfds.size(), timeout) > 0);
diff --git a/src/Core/Requests/DaemonStatusRequest.cpp b/src/Core/Requests/DaemonStatusRequest.cpp
index 1741731..3b028c9 100644
--- a/src/Core/Requests/DaemonStatusRequest.cpp
+++ b/src/Core/Requests/DaemonStatusRequest.cpp
@@ -19,7 +19,6 @@
#include "DaemonStatusRequest.h"
#include <Common/RequestManager.h>
-#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
namespace Core {
diff --git a/src/Core/Requests/DaemonStatusRequest.h b/src/Core/Requests/DaemonStatusRequest.h
index baeb847..09cbc2b 100644
--- a/src/Core/Requests/DaemonStatusRequest.h
+++ b/src/Core/Requests/DaemonStatusRequest.h
@@ -21,15 +21,9 @@
#define MAD_CORE_REQUESTS_DAEMONSTATUSREQUEST_H_
#include <Common/Request.h>
+#include <Net/Packets/HostStatusPacket.h>
namespace Mad {
-
-namespace Net {
-namespace Packets {
-class HostStatusPacket;
-}
-}
-
namespace Core {
namespace Requests {
diff --git a/src/madc.cpp b/src/madc.cpp
index b109448..a2c7fda 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -24,6 +24,7 @@
#include "Common/RequestManager.h"
#include "Common/Util.h"
#include "Client/CommandParser.h"
+#include "Client/InformationManager.h"
#include <iostream>
#include <cstring>
@@ -94,10 +95,23 @@ int main(int argc, char *argv[]) {
connection->sendReceive(fd.revents);
}
- std::cerr << " connected." << std::endl << std::endl;
+ std::cerr << " connected." << std::endl;
Common::RequestManager::getRequestManager()->registerConnection(connection);
+ std::cerr << "Receiving host list..." << std::flush;
+
+ Client::InformationManager::init(connection);
+
+ while(!Client::InformationManager::getInformationManager()->isInitialised()) {
+ struct pollfd fd = connection->getPollfd();
+
+ if(poll(&fd, 1, 10000) > 0)
+ connection->sendReceive(fd.revents);
+ }
+
+ std::cerr << " done." << std::endl << std::endl;
+
parser = new Mad::Client::CommandParser(connection);
parser->signalFinished().connect(sigc::ptr_fun(activateReadline));