diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-25 13:36:02 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-25 13:36:02 +0200 |
commit | af0f84058d322d68cbbff98ef272dd2bcd0f692c (patch) | |
tree | 23b1fb83790f2100ae2d16eb0af71122e88cba0a /src/Common | |
parent | 3a8e13c8ef66a4fdb06b2051bd7ab95ca24cc81c (diff) | |
download | mad-af0f84058d322d68cbbff98ef272dd2bcd0f692c.tar mad-af0f84058d322d68cbbff98ef272dd2bcd0f692c.zip |
Daemon-Host kann jetzt heruntergefahren und neu gestartet werden
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Backends/SystemBackendPosix.h | 14 | ||||
-rw-r--r-- | src/Common/Exception.cpp | 2 | ||||
-rw-r--r-- | src/Common/Exception.h | 2 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.cpp | 2 | ||||
-rw-r--r-- | src/Common/SystemBackend.cpp | 18 | ||||
-rw-r--r-- | src/Common/SystemBackend.h | 6 |
6 files changed, 41 insertions, 3 deletions
diff --git a/src/Common/Backends/SystemBackendPosix.h b/src/Common/Backends/SystemBackendPosix.h index aa2b9be..9efd59f 100644 --- a/src/Common/Backends/SystemBackendPosix.h +++ b/src/Common/Backends/SystemBackendPosix.h @@ -33,7 +33,7 @@ namespace Mad { namespace Common { namespace Backends { -class SystemBackendPosix { +class SystemBackendPosix : public SystemBackend { private: static SystemBackendPosix backend; static std::map<pid_t, sigc::slot<void, int> > processes; @@ -46,9 +46,21 @@ class SystemBackendPosix { setChildHandler(); } + protected: + virtual bool doShutdown() {return exec(sigc::slot<void, int>(), "/sbin/halt");} + virtual bool doReboot() {return exec(sigc::slot<void, int>(), "/sbin/reboot");} + public: ~SystemBackendPosix(); + static void registerBackend() { + SystemBackend::registerBackend(&backend); + } + + static void unregisterBackend() { + SystemBackend::unregisterBackend(&backend); + } + static bool exec(sigc::slot<void, int> resultHandler, const std::string &filename, const std::vector<std::string> &argv = std::vector<std::string>(), const std::vector<std::string> &env = std::vector<std::string>()); }; diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp index 9366fe7..67eb1d9 100644 --- a/src/Common/Exception.cpp +++ b/src/Common/Exception.cpp @@ -42,6 +42,8 @@ std::string Exception::strerror() const { return ret + "Not available"; case NOT_FINISHED: return ret + "Not finished"; + case NOT_IMPLEMENTED: + return ret + "Not implemented"; case INTERNAL_ERRNO: return ret + std::strerror(subCode); case INTERNAL_GNUTLS: diff --git a/src/Common/Exception.h b/src/Common/Exception.h index 9862f9b..7b86fbd 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -28,7 +28,7 @@ namespace Common { class Exception { public: enum ErrorCode { - SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, + SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, NOT_IMPLEMENTED = 0x0005, INTERNAL_ERRNO = 0x0010, INTERNAL_GNUTLS = 0x0011, INVALID_ADDRESS = 0x0020, ALREADY_IDENTIFIED = 0x0030, UNKNOWN_DAEMON = 0x0031 diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index ad37964..dbdf9e1 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -31,7 +31,7 @@ namespace RequestHandlers { void StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { if(packet.getType() != Net::Packet::STATUS) { Logger::log(Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET))); signalFinished().emit(); return; diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemBackend.cpp index 0d4b2b7..c017356 100644 --- a/src/Common/SystemBackend.cpp +++ b/src/Common/SystemBackend.cpp @@ -52,5 +52,23 @@ SystemBackend::LoadInfo SystemBackend::getLoadInfo() { return ret; } +bool SystemBackend::shutdown() { + bool ret = false; + + for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end() && !ret; ++backend) + ret = (*backend)->doShutdown(); + + return ret; +} + +bool SystemBackend::reboot() { + bool ret = false; + + for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end() && !ret; ++backend) + ret = (*backend)->doReboot(); + + return ret; +} + } } diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h index c531224..d9506a9 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -85,6 +85,9 @@ class SystemBackend { return ret; } + virtual bool doShutdown() {return false;} + virtual bool doReboot() {return false;} + virtual int getPriority() const { return 0; } @@ -95,6 +98,9 @@ class SystemBackend { static UptimeInfo getUptimeInfo(); static MemoryInfo getMemoryInfo(); static LoadInfo getLoadInfo(); + + static bool shutdown(); + static bool reboot(); }; } |