diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConnectionManager.cpp | 4 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp | 71 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h (renamed from src/Core/Requests/DaemonStatusRequest.h) | 31 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp | 4 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.h | 3 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.am | 6 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.in | 15 | ||||
-rw-r--r-- | src/Core/Requests/DaemonStatusRequest.cpp | 42 | ||||
-rw-r--r-- | src/Core/Requests/Makefile.am | 4 | ||||
-rw-r--r-- | src/Core/Requests/Makefile.in | 7 |
10 files changed, 118 insertions, 69 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 93d6d3f..a41b024 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -20,9 +20,11 @@ #include "ConnectionManager.h" #include "ConfigManager.h" #include <Common/Logger.h> +#include <Common/RequestHandlers/FSInfoRequestHandler.h> #include <Common/RequestHandlers/StatusRequestHandler.h> #include "Requests/DaemonStateUpdateRequest.h" #include "RequestHandlers/DaemonCommandRequestHandler.h" +#include "RequestHandlers/DaemonFSInfoRequestHandler.h" #include "RequestHandlers/DaemonListRequestHandler.h" #include "RequestHandlers/DaemonStatusRequestHandler.h" #include "RequestHandlers/GSSAPIAuthRequestHandler.h" @@ -78,9 +80,11 @@ void ConnectionManager::updateState(const std::string &name, Common::HostInfo::S ConnectionManager::ConnectionManager() { Common::RequestManager::init(true); + Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>(Net::Packet::FS_INFO); Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>(Net::Packet::DAEMON_FS_INFO); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); diff --git a/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp new file mode 100644 index 0000000..1267520 --- /dev/null +++ b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.cpp @@ -0,0 +1,71 @@ +/* + * DaemonFSInfoRequestHandler.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 "DaemonFSInfoRequestHandler.h" +#include "../ConnectionManager.h" +#include <Common/Logger.h> +#include <Common/Requests/FSInfoRequest.h> +#include <Net/Packets/ErrorPacket.h> +#include <Net/Packets/FSInfoPacket.h> + + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +void DaemonFSInfoRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::DAEMON_FS_INFO) { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + con = connection; + requestId = packet.getRequestId(); + + std::string daemonName((char*)packet.getData(), packet.getLength()); + + try { + Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName); + Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(this, &DaemonFSInfoRequestHandler::requestFinished)))); + } + catch(Common::Exception &e) { + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); + } +} + +void DaemonFSInfoRequestHandler::requestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request) { + try { + const Net::Packet &packet = request.getResult(); + con->send(Net::Packet(Net::Packet::OK, requestId, packet.getData(), packet.getLength())); + } + catch(Common::Exception &e) { + con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e)); + } + + signalFinished().emit(); +} + +} +} +} diff --git a/src/Core/Requests/DaemonStatusRequest.h b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h index 09cbc2b..2f6c69c 100644 --- a/src/Core/Requests/DaemonStatusRequest.h +++ b/src/Core/RequestHandlers/DaemonFSInfoRequestHandler.h @@ -1,5 +1,5 @@ /* - * DaemonStatusRequest.h + * DaemonFSInfoRequestHandler.h * * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> * @@ -17,27 +17,40 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_CORE_REQUESTS_DAEMONSTATUSREQUEST_H_ -#define MAD_CORE_REQUESTS_DAEMONSTATUSREQUEST_H_ +#ifndef MAD_CORE_REQUESTHANDLERS_DAEMONFSINFOREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_DAEMONFSINFOREQUESTHANDLER_H_ +#include <Common/RequestHandler.h> #include <Common/Request.h> -#include <Net/Packets/HostStatusPacket.h> +#include <stdint.h> namespace Mad { + +namespace Net { +namespace Packets { +class FSInfoPacket; +} +} + namespace Core { -namespace Requests { +namespace RequestHandlers { + +class DaemonFSInfoRequestHandler : public Common::RequestHandler { + private: + Net::Connection *con; + uint16_t requestId; + + void requestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request); -class DaemonStatusRequest : 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: - DaemonStatusRequest(slot_type slot) : Common::Request<Net::Packets::HostStatusPacket>(slot) {} + DaemonFSInfoRequestHandler() {} }; } } } -#endif /* MAD_CORE_REQUESTS_DAEMONSTATUSREQUEST_H_ */ +#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONFSINFOREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp index 7fcf9fe..4add098 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp @@ -20,7 +20,7 @@ #include "DaemonStatusRequestHandler.h" #include "../ConnectionManager.h" #include <Common/Logger.h> -#include <Core/Requests/DaemonStatusRequest.h> +#include <Common/Requests/StatusRequest.h> #include <Net/Packets/ErrorPacket.h> #include <Net/Packets/HostStatusPacket.h> @@ -47,7 +47,7 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const try { Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName); - Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)))); + Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)))); } catch(Common::Exception &e) { connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h index d8edc41..36fabc0 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h @@ -33,9 +33,6 @@ class HostStatusPacket; } namespace Core { - -class ConnectionManager; - namespace RequestHandlers { class DaemonStatusRequestHandler : public Common::RequestHandler { diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am index 484df59..79aef5e 100644 --- a/src/Core/RequestHandlers/Makefile.am +++ b/src/Core/RequestHandlers/Makefile.am @@ -1,4 +1,6 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp +librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \ + IdentifyRequestHandler.cpp LogRequestHandler.cpp -noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h +noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \ + IdentifyRequestHandler.h LogRequestHandler.h diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in index e0dc6f2..46c1381 100644 --- a/src/Core/RequestHandlers/Makefile.in +++ b/src/Core/RequestHandlers/Makefile.in @@ -49,9 +49,9 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = am_librequesthandlers_la_OBJECTS = DaemonCommandRequestHandler.lo \ - DaemonListRequestHandler.lo DaemonStatusRequestHandler.lo \ - GSSAPIAuthRequestHandler.lo IdentifyRequestHandler.lo \ - LogRequestHandler.lo + DaemonFSInfoRequestHandler.lo DaemonListRequestHandler.lo \ + DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \ + IdentifyRequestHandler.lo LogRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -190,8 +190,12 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp -noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h +librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \ + IdentifyRequestHandler.cpp LogRequestHandler.cpp + +noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \ + IdentifyRequestHandler.h LogRequestHandler.h + all: all-am .SUFFIXES: @@ -244,6 +248,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequestHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonFSInfoRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@ diff --git a/src/Core/Requests/DaemonStatusRequest.cpp b/src/Core/Requests/DaemonStatusRequest.cpp deleted file mode 100644 index 3b028c9..0000000 --- a/src/Core/Requests/DaemonStatusRequest.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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> - -namespace Mad { -namespace Core { -namespace Requests { - -void DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - connection->send(Net::Packet(Net::Packet::STATUS, requestId)); -} - -void DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::OK) { - finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); - return; // TODO Logging - } - - finish(Net::Packets::HostStatusPacket(packet)); -} - -} -} -} diff --git a/src/Core/Requests/Makefile.am b/src/Core/Requests/Makefile.am index e69088b..f101b84 100644 --- a/src/Core/Requests/Makefile.am +++ b/src/Core/Requests/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp DaemonStatusRequest.cpp +librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp -noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h DaemonStatusRequest.h +noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in index e6367a2..26aa0fe 100644 --- a/src/Core/Requests/Makefile.in +++ b/src/Core/Requests/Makefile.in @@ -49,7 +49,7 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequests_la_LIBADD = am_librequests_la_OBJECTS = CommandRequest.lo \ - DaemonStateUpdateRequest.lo DaemonStatusRequest.lo + DaemonStateUpdateRequest.lo librequests_la_OBJECTS = $(am_librequests_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -188,8 +188,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp DaemonStatusRequest.cpp -noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h DaemonStatusRequest.h +librequests_la_SOURCES = CommandRequest.cpp DaemonStateUpdateRequest.cpp +noinst_HEADERS = CommandRequest.h DaemonStateUpdateRequest.h all: all-am .SUFFIXES: @@ -243,7 +243,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStateUpdateRequest.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 $@ $< |