summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-15 06:26:15 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-15 06:26:15 +0200
commit9ca70bbfa460fe1c6c31b8e685be6df24935ab73 (patch)
tree8fe0a6e164d7d2f4e5f23e073c0a80a0b29daf94 /src/Common
parent30bec92571ba23f1f2aa6b12149f6545a4ef0d7e (diff)
downloadmad-9ca70bbfa460fe1c6c31b8e685be6df24935ab73.tar
mad-9ca70bbfa460fe1c6c31b8e685be6df24935ab73.zip
Kann jetzt Status von Daemons abfragen
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Request.h10
-rw-r--r--src/Common/RequestHandler.h10
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp5
-rw-r--r--src/Common/RequestHandlers/Makefile.am4
-rw-r--r--src/Common/RequestHandlers/Makefile.in8
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp49
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.h40
-rw-r--r--src/Common/RequestManager.cpp20
-rw-r--r--src/Common/RequestManager.h5
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp9
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.cpp9
-rw-r--r--src/Common/Requests/IdentifyRequest.cpp9
12 files changed, 118 insertions, 60 deletions
diff --git a/src/Common/Request.h b/src/Common/Request.h
index 17e5eab..3d4be63 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -27,17 +27,7 @@ namespace Mad {
namespace Common {
class Request : public RequestHandler {
- private:
- bool sent;
-
- protected:
- Request() : sent(false) {}
-
- void setSent() {sent = true;}
-
public:
- bool isSent() const {return sent;}
-
virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) = 0;
};
diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h
index 4a72bd5..305836c 100644
--- a/src/Common/RequestHandler.h
+++ b/src/Common/RequestHandler.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLER_H_
+#include <sigc++/signal.h>
+
namespace Mad {
namespace Net {
@@ -33,17 +35,15 @@ class RequestManager;
class RequestHandler {
private:
- bool finished;
+ sigc::signal<void> finished;
protected:
- RequestHandler() : finished(false) {}
-
- void setFinished() {finished = true;}
+ RequestHandler() {}
public:
virtual ~RequestHandler() {}
- bool isFinished() const {return finished;}
+ sigc::signal<void> signalFinished() {return finished;}
virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) = 0;
};
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 <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 "StatusRequestHandler.h"
+#include "../SystemBackend.h"
+#include <Net/Connection.h>
+#include <Net/Packets/HostStatusPacket.h>
+
+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 <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_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_ */
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 8ebfce0..e2864b1 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -21,6 +21,8 @@
#include "Request.h"
#include "RequestHandlers/DisconnectRequestHandler.h"
+#include <sigc++/bind.h>
+#include <sigc++/retype_return.h>
#include <iostream>
namespace Mad {
@@ -29,6 +31,15 @@ namespace Common {
std::auto_ptr<RequestManager> RequestManager::requestManager;
+bool RequestManager::RequestMap::addRequest(uint16_t id, RequestHandler *info) {
+ if(!insert(std::make_pair(id, info)).second)
+ return false;
+
+ info->signalFinished().connect(sigc::hide_return(sigc::bind(sigc::mem_fun(this, &RequestManager::RequestMap::deleteRequest), id)));
+
+ return true;
+}
+
RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) {
iterator it = find(id);
if(it == end())
@@ -65,22 +76,15 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
if(request) {
request->handlePacket(connection, packet);
- if(request->isFinished())
- requestMap->deleteRequest(packet.getRequestId());
-
return;
}
std::map<Net::Packet::Type,RequestHandlerFactory*>::iterator factoryIt = requestHandlerFactories.find(packet.getType());
if(factoryIt != requestHandlerFactories.end()) {
request = factoryIt->second->createRequestHandler();
+ requestMap->addRequest(packet.getRequestId(), request);
request->handlePacket(connection, packet);
- if(!request->isFinished())
- requestMap->addRequest(packet.getRequestId(), request);
- else
- delete request;
-
return;
}
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index 795f277..c050d1d 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -47,10 +47,7 @@ class RequestManager {
delete it->second;
}
- bool addRequest(uint16_t id, RequestHandler *info) {
- return insert(std::make_pair(id, info)).second;
- }
-
+ bool addRequest(uint16_t id, RequestHandler *info);
RequestHandler* findRequest(uint16_t id);
bool deleteRequest(uint16_t id);
};
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp
index 0b6e3bc..090b840 100644
--- a/src/Common/Requests/DisconnectRequest.cpp
+++ b/src/Common/Requests/DisconnectRequest.cpp
@@ -37,20 +37,13 @@ bool DisconnectRequest::send(Net::Connection *connection, const sigc::slot<void>
}
bool DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- if(isSent())
- return false;
-
if(!connection->send(Net::Packet(Net::Packet::DISCONNECT, requestId)))
return false;
- setSent();
return true;
}
bool DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(isFinished())
- return false;
-
if(packet.getType() != Net::Packet::OK)
return false; // TODO Logging
@@ -58,7 +51,7 @@ bool DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Pac
finished();
- setFinished();
+ signalFinished().emit();
return true;
}
diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp
index 705db41..a4a1b17 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.cpp
+++ b/src/Common/Requests/GSSAPIAuthRequest.cpp
@@ -48,9 +48,6 @@ bool GSSAPIAuthRequest::send(Net::Connection *connection, const std::string &ser
}
bool GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- if(isSent())
- return false;
-
OM_uint32 majStat, minStat;
gss_buffer_desc buffer;
@@ -86,14 +83,10 @@ bool GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques
gss_release_buffer(&minStat, &buffer);
- setSent();
return true;
}
bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(isFinished())
- return false;
-
if(packet.getType() != Net::Packet::GSSAPI_AUTH)
return false; // TODO Logging
@@ -160,7 +153,7 @@ bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac
gss_release_buffer(&minStat, &sendBuffer);
- setFinished();
+ signalFinished().emit();
}
return true;
diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp
index 54d49e2..9214baf 100644
--- a/src/Common/Requests/IdentifyRequest.cpp
+++ b/src/Common/Requests/IdentifyRequest.cpp
@@ -36,24 +36,17 @@ bool IdentifyRequest::send(Net::Connection *connection, const std::string &hostn
}
bool IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- if(isSent())
- return false;
-
if(!connection->send(Net::Packet(Net::Packet::IDENTIFY, requestId, hostname.c_str(), hostname.length())))
return false;
- setSent();
return true;
}
bool IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(isFinished())
- return false;
-
if(packet.getType() != Net::Packet::OK)
return false; // TODO Logging
- setFinished();
+ signalFinished().emit();
return true;
}