From 58c5d4eefdf1cdee0651f7c74ffd1501adbdc9c3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 8 Oct 2008 23:08:21 +0200 Subject: fsinfo-Befehl implementiert --- src/Common/Backends/SystemBackendPosix.cpp | 31 ++++++++++-- .../RequestHandlers/FSInfoRequestHandler.cpp | 57 ++++++++++++++++++++++ src/Common/RequestHandlers/FSInfoRequestHandler.h | 50 +++++++++++++++++++ src/Common/RequestHandlers/Makefile.am | 4 +- src/Common/RequestHandlers/Makefile.in | 7 +-- src/Common/Requests/FSInfoRequest.cpp | 45 +++++++++++++++++ src/Common/Requests/FSInfoRequest.h | 43 ++++++++++++++++ src/Common/Requests/Makefile.am | 4 +- src/Common/Requests/Makefile.in | 9 ++-- src/Common/Requests/StatusRequest.cpp | 42 ++++++++++++++++ src/Common/Requests/StatusRequest.h | 43 ++++++++++++++++ 11 files changed, 322 insertions(+), 13 deletions(-) create mode 100644 src/Common/RequestHandlers/FSInfoRequestHandler.cpp create mode 100644 src/Common/RequestHandlers/FSInfoRequestHandler.h create mode 100644 src/Common/Requests/FSInfoRequest.cpp create mode 100644 src/Common/Requests/FSInfoRequest.h create mode 100644 src/Common/Requests/StatusRequest.cpp create mode 100644 src/Common/Requests/StatusRequest.h (limited to 'src/Common') diff --git a/src/Common/Backends/SystemBackendPosix.cpp b/src/Common/Backends/SystemBackendPosix.cpp index ca8b440..acb6bb6 100644 --- a/src/Common/Backends/SystemBackendPosix.cpp +++ b/src/Common/Backends/SystemBackendPosix.cpp @@ -19,8 +19,10 @@ #include "SystemBackendPosix.h" +#include #include #include +#include #include #include @@ -62,9 +64,32 @@ SystemBackendPosix::~SystemBackendPosix() { void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot& > &callback) { - // TODO Process df output + std::vector ret; + std::istringstream stream(output); + std::string str; - callback(std::vector()); + std::getline(stream, str); // ignore first line + + while(!stream.eof()) { + std::getline(stream, str); + + char *fsName = new char[str.length()+1]; + char *mountedOn = new char[str.length()+1]; + + FSInfo info; + + if(std::sscanf(str.c_str(), "%s %lld %lld %lld %*d%% %s", fsName, &info.total, &info.used, &info.available, mountedOn) == 5) { + info.fsName = fsName; + info.mountedOn = mountedOn; + + ret.push_back(info); + } + + delete [] fsName; + delete [] mountedOn; + } + + callback(ret); } bool SystemBackendPosix::fsInfo(const sigc::slot& > &callback) { @@ -200,7 +225,7 @@ bool SystemBackendPosix::execWithOutput(const sigc::slot + * + * 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 "FSInfoRequestHandler.h" +#include "../Logger.h" +#include +#include +#include + +namespace Mad { +namespace Common { +namespace RequestHandlers { + +void FSInfoRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::FS_INFO) { + Logger::log(Logger::ERROR, "Received an unexpected packet."); + con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + connection = con; + requestId = packet.getRequestId(); + + if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) { + con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::NOT_IMPLEMENTED))); + signalFinished().emit(); + } +} + +void FSInfoRequestHandler::fsInfoHandler(const std::vector &info) { + connection->send(Net::Packets::FSInfoPacket(Net::Packet::OK, requestId, info)); + signalFinished().emit(); +} + +} +} +} diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h new file mode 100644 index 0000000..8de89ce --- /dev/null +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h @@ -0,0 +1,50 @@ +/* + * FSInfoRequestHandler.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_FSINFOREQUESTHANDLER_H_ +#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_ + +#include "../RequestHandler.h" +#include "../SystemBackend.h" + +#include + +namespace Mad { +namespace Common { +namespace RequestHandlers { + +class FSInfoRequestHandler : public RequestHandler { + private: + Net::Connection *connection; + uint16_t requestId; + + void fsInfoHandler(const std::vector &info); + + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + FSInfoRequestHandler() {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_ */ diff --git a/src/Common/RequestHandlers/Makefile.am b/src/Common/RequestHandlers/Makefile.am index 4a266e8..0572641 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 StatusRequestHandler.cpp +librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp FSInfoRequestHandler.cpp StatusRequestHandler.cpp -noinst_HEADERS = DisconnectRequestHandler.h StatusRequestHandler.h +noinst_HEADERS = DisconnectRequestHandler.h FSInfoRequestHandler.h StatusRequestHandler.h diff --git a/src/Common/RequestHandlers/Makefile.in b/src/Common/RequestHandlers/Makefile.in index 8139c28..a332620 100644 --- a/src/Common/RequestHandlers/Makefile.in +++ b/src/Common/RequestHandlers/Makefile.in @@ -49,7 +49,7 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = am_librequesthandlers_la_OBJECTS = DisconnectRequestHandler.lo \ - StatusRequestHandler.lo + FSInfoRequestHandler.lo StatusRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_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 = librequesthandlers.la -librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp StatusRequestHandler.cpp -noinst_HEADERS = DisconnectRequestHandler.h StatusRequestHandler.h +librequesthandlers_la_SOURCES = DisconnectRequestHandler.cpp FSInfoRequestHandler.cpp StatusRequestHandler.cpp +noinst_HEADERS = DisconnectRequestHandler.h FSInfoRequestHandler.h StatusRequestHandler.h all: all-am .SUFFIXES: @@ -242,6 +242,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)/FSInfoRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StatusRequestHandler.Plo@am__quote@ .cpp.o: diff --git a/src/Common/Requests/FSInfoRequest.cpp b/src/Common/Requests/FSInfoRequest.cpp new file mode 100644 index 0000000..c8492ff --- /dev/null +++ b/src/Common/Requests/FSInfoRequest.cpp @@ -0,0 +1,45 @@ +/* + * FSInfoRequest.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 "FSInfoRequest.h" +#include + +#include + +namespace Mad { +namespace Common { +namespace Requests { + +void FSInfoRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::FS_INFO, requestId)); +} + +void FSInfoRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::OK) { + finishWithError(Exception(Exception::UNEXPECTED_PACKET)); + return; // TODO Logging + } + + finish(Net::Packets::FSInfoPacket(packet)); +} + +} +} +} + diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h new file mode 100644 index 0000000..9ae7673 --- /dev/null +++ b/src/Common/Requests/FSInfoRequest.h @@ -0,0 +1,43 @@ +/* + * FSInfoRequest.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_REQUESTS_FSINFOREQUEST_H_ +#define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ + +#include "../Request.h" +#include + +namespace Mad { +namespace Common { +namespace Requests { + +class FSInfoRequest : public Request { + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + FSInfoRequest(slot_type slot) : Request(slot) {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ */ diff --git a/src/Common/Requests/Makefile.am b/src/Common/Requests/Makefile.am index d455da6..ff116fc 100644 --- a/src/Common/Requests/Makefile.am +++ b/src/Common/Requests/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp +librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp -noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h +noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h diff --git a/src/Common/Requests/Makefile.in b/src/Common/Requests/Makefile.in index 6de55d0..5b5e2fe 100644 --- a/src/Common/Requests/Makefile.in +++ b/src/Common/Requests/Makefile.in @@ -48,7 +48,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequests_la_LIBADD = -am_librequests_la_OBJECTS = DisconnectRequest.lo GSSAPIAuthRequest.lo +am_librequests_la_OBJECTS = DisconnectRequest.lo FSInfoRequest.lo \ + GSSAPIAuthRequest.lo StatusRequest.lo librequests_la_OBJECTS = $(am_librequests_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -187,8 +188,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp -noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h +librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp +noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h all: all-am .SUFFIXES: @@ -241,7 +242,9 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DisconnectRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FSInfoRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StatusRequest.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Common/Requests/StatusRequest.cpp b/src/Common/Requests/StatusRequest.cpp new file mode 100644 index 0000000..dbaba23 --- /dev/null +++ b/src/Common/Requests/StatusRequest.cpp @@ -0,0 +1,42 @@ +/* + * CoreStatusRequest.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 "StatusRequest.h" +#include + +namespace Mad { +namespace Common { +namespace Requests { + +void StatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::STATUS, requestId)); +} + +void StatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::OK) { + finishWithError(Exception(Exception::UNEXPECTED_PACKET)); + return; // TODO Logging + } + + finish(Net::Packets::HostStatusPacket(packet)); +} + +} +} +} diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h new file mode 100644 index 0000000..5712404 --- /dev/null +++ b/src/Common/Requests/StatusRequest.h @@ -0,0 +1,43 @@ +/* + * StatusRequest.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_REQUESTS_STATUSREQUEST_H_ +#define MAD_COMMON_REQUESTS_STATUSREQUEST_H_ + +#include "../Request.h" +#include + +namespace Mad { +namespace Common { +namespace Requests { + +class StatusRequest : public Request { + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + StatusRequest(slot_type slot) : Request(slot) {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTS_STATUSREQUEST_H_ */ -- cgit v1.2.3