From 7234fe326d16d6bf9f4374a09ddc6ef790e6723f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Jun 2009 22:03:02 +0200 Subject: Globale Variablen durch Application-Klasse ersetzt --- src/Daemon/Application.cpp | 28 +++++++++++++++++ src/Daemon/Application.h | 36 ++++++++++++++++++++++ src/Daemon/Backends/NetworkLogger.h | 8 ++--- src/Daemon/CMakeLists.txt | 2 +- src/Daemon/Daemon.cpp | 21 ------------- .../RequestHandlers/CommandRequestHandler.cpp | 4 +-- src/Daemon/RequestHandlers/CommandRequestHandler.h | 5 +-- src/Daemon/Requests/LogRequest.h | 9 +++--- 8 files changed, 78 insertions(+), 35 deletions(-) create mode 100644 src/Daemon/Application.cpp create mode 100644 src/Daemon/Application.h delete mode 100644 src/Daemon/Daemon.cpp (limited to 'src/Daemon') diff --git a/src/Daemon/Application.cpp b/src/Daemon/Application.cpp new file mode 100644 index 0000000..d31cbf5 --- /dev/null +++ b/src/Daemon/Application.cpp @@ -0,0 +1,28 @@ +/* + * Application.cpp + * + * Copyright (C) 2009 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 "Application.h" + +namespace Mad { +namespace Daemon { + +Application::Application() : Common::Application(false) {} + +} +} diff --git a/src/Daemon/Application.h b/src/Daemon/Application.h new file mode 100644 index 0000000..4be7f22 --- /dev/null +++ b/src/Daemon/Application.h @@ -0,0 +1,36 @@ +/* + * Application.h + * + * Copyright (C) 2009 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_DAEMON_APPLICATION_H_ +#define MAD_DAEMON_APPLICATION_H_ + +#include + +namespace Mad { +namespace Daemon { + +class Application : public Common::Application { + public: + Application(); +}; + +} +} + +#endif /* MAD_DAEMON_APPLICATION_H_ */ diff --git a/src/Daemon/Backends/NetworkLogger.h b/src/Daemon/Backends/NetworkLogger.h index c0b123a..557cc14 100644 --- a/src/Daemon/Backends/NetworkLogger.h +++ b/src/Daemon/Backends/NetworkLogger.h @@ -20,7 +20,6 @@ #ifndef MAD_DAEMON_BACKENDS_NETWORKLOGGER_H_ #define MAD_DAEMON_BACKENDS_NETWORKLOGGER_H_ -#include #include #include @@ -30,16 +29,17 @@ namespace Backends { class NetworkLogger : public Core::Logger { private: + Common::Application *application; Common::Connection *connection; protected: virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, time_t messageTimestamp, const std::string &message) { - boost::shared_ptr request(new Requests::LogRequest(category, level, messageTimestamp, message)); - Common::RequestManager::get()->sendRequest(connection, request); + boost::shared_ptr request(new Requests::LogRequest(application, category, level, messageTimestamp, message)); + application->getRequestManager()->sendRequest(connection, request); } public: - NetworkLogger(Common::Connection *connection0) : connection(connection0) {} + NetworkLogger(Common::Application *application0, Common::Connection *connection0) : application(application0), connection(connection0) {} }; } diff --git a/src/Daemon/CMakeLists.txt b/src/Daemon/CMakeLists.txt index 68c5f5d..151c229 100644 --- a/src/Daemon/CMakeLists.txt +++ b/src/Daemon/CMakeLists.txt @@ -6,6 +6,6 @@ include_directories(${INCLUDES}) add_library(Daemon Backends/NetworkLogger.h - Daemon.cpp + Application.cpp Application.h ) target_link_libraries(Daemon DaemonRequestHandlers DaemonRequests Common) diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp deleted file mode 100644 index 3725498..0000000 --- a/src/Daemon/Daemon.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Daemon.cpp - * - * Copyright (C) 2009 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 . - */ - - -// Empty... diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp index d00c415..ae11de5 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -31,9 +31,9 @@ void CommandRequestHandler::handleRequest(boost::shared_ptrreboot(); + getApplication()->getSystemManager()->reboot(); else - Common::SystemManager::get()->shutdown(); + getApplication()->getSystemManager()->shutdown(); ret->setType("OK"); } diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h index 22c7a4b..db7b3d4 100644 --- a/src/Daemon/RequestHandlers/CommandRequestHandler.h +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h @@ -28,10 +28,11 @@ namespace RequestHandlers { class CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { private: - static void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); + void handleRequest(boost::shared_ptr packet, Common::XmlPacket *ret); public: - CommandRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("Command", &CommandRequestHandler::handleRequest) {} + CommandRequestHandler(Common::Application *application) + : Common::RequestHandlers::SimpleRequestHandler(application, "Command", boost::bind(&CommandRequestHandler::handleRequest, this, _1, _2)) {} }; } diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h index 6ee3b3d..a3cda41 100644 --- a/src/Daemon/Requests/LogRequest.h +++ b/src/Daemon/Requests/LogRequest.h @@ -21,7 +21,6 @@ #define MAD_DAEMON_REQUESTS_LOGREQUEST_H_ #include -#include #include namespace Mad { @@ -30,8 +29,8 @@ namespace Requests { class LogRequest : public Common::Request { private: - Core::Logger::MessageCategory category; - Core::Logger::MessageLevel level; + Core::LoggerBase::MessageCategory category; + Core::LoggerBase::MessageLevel level; time_t messageTimestamp; std::string message; @@ -39,8 +38,8 @@ class LogRequest : public Common::Request { virtual void sendRequest(); public: - LogRequest(Core::Logger::MessageCategory category0, Core::Logger::MessageLevel level0, time_t messageTimestamp0, const std::string &message0) - : category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {} + LogRequest(Common::Application *application, Core::LoggerBase::MessageCategory category0, Core::LoggerBase::MessageLevel level0, time_t messageTimestamp0, const std::string &message0) + : Common::Request(application), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {} }; } -- cgit v1.2.3