From 9ca70bbfa460fe1c6c31b8e685be6df24935ab73 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 15 Sep 2008 06:26:15 +0200 Subject: Kann jetzt Status von Daemons abfragen --- .../RequestHandlers/DisconnectRequestHandler.cpp | 5 +-- src/Common/RequestHandlers/Makefile.am | 4 +- src/Common/RequestHandlers/Makefile.in | 8 ++-- .../RequestHandlers/StatusRequestHandler.cpp | 49 ++++++++++++++++++++++ src/Common/RequestHandlers/StatusRequestHandler.h | 40 ++++++++++++++++++ 5 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/Common/RequestHandlers/StatusRequestHandler.cpp create mode 100644 src/Common/RequestHandlers/StatusRequestHandler.h (limited to 'src/Common/RequestHandlers') diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index 967649e..aa98c04 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -25,9 +25,6 @@ namespace Common { namespace RequestHandlers { bool DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(isFinished()) - return false; - if(packet.getType() != Net::Packet::DISCONNECT) return false; // TODO Logging @@ -36,7 +33,7 @@ bool DisconnectRequestHandler::handlePacket(Net::Connection *connection, const N connection->disconnect(); - setFinished(); + signalFinished().emit(); return true; } diff --git a/src/Common/RequestHandlers/Makefile.am b/src/Common/RequestHandlers/Makefile.am index 9133148..4a266e8 100644 --- a/src/Common/RequestHandlers/Makefile.am +++ b/src/Common/RequestHandlers/Makefile.am @@ -1,5 +1,5 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp +librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp StatusRequestHandler.cpp -noinst_HEADERS = DisconnectRequestHandler.h +noinst_HEADERS = DisconnectRequestHandler.h StatusRequestHandler.h diff --git a/src/Common/RequestHandlers/Makefile.in b/src/Common/RequestHandlers/Makefile.in index c55394a..c933082 100644 --- a/src/Common/RequestHandlers/Makefile.in +++ b/src/Common/RequestHandlers/Makefile.in @@ -45,7 +45,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = -am_librequesthandlers_la_OBJECTS = DisconnectRequestHandler.lo +am_librequesthandlers_la_OBJECTS = DisconnectRequestHandler.lo \ + StatusRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_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 = librequesthandlers.la -librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp -noinst_HEADERS = DisconnectRequestHandler.h +librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp StatusRequestHandler.cpp +noinst_HEADERS = DisconnectRequestHandler.h StatusRequestHandler.h all: all-am .SUFFIXES: @@ -238,6 +239,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DisconnectRequestHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StatusRequestHandler.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp new file mode 100644 index 0000000..0a437fa --- /dev/null +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -0,0 +1,49 @@ +/* + * StatusRequestHandler.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#include "StatusRequestHandler.h" +#include "../SystemBackend.h" +#include +#include + +namespace Mad { +namespace Common { +namespace RequestHandlers { + +bool StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::STATUS) + return false; // TODO Logging + + // TODO Require authentication + + SystemBackend::UptimeInfo uptimeInfo = SystemBackend::getBackend()->getUptimeInfo(); + SystemBackend::MemoryInfo memInfo = SystemBackend::getBackend()->getMemoryInfo(); + + if(!connection->send(Net::Packets::HostStatusPacket(Net::Packet::OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime, + memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap))) + return false; + + signalFinished().emit(); + + return true; +} + +} +} +} diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h new file mode 100644 index 0000000..db2176a --- /dev/null +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -0,0 +1,40 @@ +/* + * StatusRequestHandler.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_ +#define MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_ + +#include "../RequestHandler.h" + +namespace Mad { +namespace Common { +namespace RequestHandlers { + +class StatusRequestHandler : public RequestHandler { + public: + StatusRequestHandler() {} + + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_ */ -- cgit v1.2.3