summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/SystemBackendPosix.cpp31
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp57
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h50
-rw-r--r--src/Common/RequestHandlers/Makefile.am4
-rw-r--r--src/Common/RequestHandlers/Makefile.in7
-rw-r--r--src/Common/Requests/FSInfoRequest.cpp45
-rw-r--r--src/Common/Requests/FSInfoRequest.h43
-rw-r--r--src/Common/Requests/Makefile.am4
-rw-r--r--src/Common/Requests/Makefile.in9
-rw-r--r--src/Common/Requests/StatusRequest.cpp42
-rw-r--r--src/Common/Requests/StatusRequest.h43
11 files changed, 322 insertions, 13 deletions
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 <cstdio>
#include <cstdlib>
#include <cstring>
+#include <sstream>
#include <fcntl.h>
#include <signal.h>
@@ -62,9 +64,32 @@ SystemBackendPosix::~SystemBackendPosix() {
void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
- // TODO Process df output
+ std::vector<FSInfo> ret;
+ std::istringstream stream(output);
+ std::string str;
- callback(std::vector<FSInfo>());
+ 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<void, const std::vector<FSInfo>& > &callback) {
@@ -200,7 +225,7 @@ bool SystemBackendPosix::execWithOutput(const sigc::slot<void, int, const std::s
dup2(pipeHandles[1], STDOUT_FILENO); // set the new pipe as stdout
close(pipeHandles[1]);
- bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0);
+ bool ret (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0);
if(ret)
processesWithOutput.insert(std::make_pair(pid, std::make_pair(resultHandler, pipeHandles[0])));
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
new file mode 100644
index 0000000..5d71277
--- /dev/null
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -0,0 +1,57 @@
+/*
+ * FSInfoRequestHandler.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 "FSInfoRequestHandler.h"
+#include "../Logger.h"
+#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+#include <Net/Packets/FSInfoPacket.h>
+
+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<SystemBackend::FSInfo> &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 <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_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
+#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
+
+#include "../RequestHandler.h"
+#include "../SystemBackend.h"
+
+#include <stdint.h>
+
+namespace Mad {
+namespace Common {
+namespace RequestHandlers {
+
+class FSInfoRequestHandler : public RequestHandler {
+ private:
+ Net::Connection *connection;
+ uint16_t requestId;
+
+ void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &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 <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 "FSInfoRequest.h"
+#include <Net/Connection.h>
+
+#include <iostream>
+
+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 <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_COMMON_REQUESTS_FSINFOREQUEST_H_
+#define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
+
+#include "../Request.h"
+#include <Net/Packets/FSInfoPacket.h>
+
+namespace Mad {
+namespace Common {
+namespace Requests {
+
+class FSInfoRequest : public Request<Net::Packets::FSInfoPacket> {
+ 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<Net::Packets::FSInfoPacket>(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 <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 "StatusRequest.h"
+#include <Net/Connection.h>
+
+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 <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_COMMON_REQUESTS_STATUSREQUEST_H_
+#define MAD_COMMON_REQUESTS_STATUSREQUEST_H_
+
+#include "../Request.h"
+#include <Net/Packets/HostStatusPacket.h>
+
+namespace Mad {
+namespace Common {
+namespace Requests {
+
+class StatusRequest : public 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:
+ StatusRequest(slot_type slot) : Request<Net::Packets::HostStatusPacket>(slot) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_REQUESTS_STATUSREQUEST_H_ */