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/mad.cpp | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'src/mad.cpp') diff --git a/src/mad.cpp b/src/mad.cpp index b1dbb8f..e0266f8 100644 --- a/src/mad.cpp +++ b/src/mad.cpp @@ -17,15 +17,17 @@ * with this program. If not, see . */ -#include "Core/ThreadManager.h" #include "Core/ConfigManager.h" #include "Core/LogManager.h" + #include "Common/ModuleManager.h" #include "Common/RequestManager.h" #include "Common/ClientConnection.h" #include "Common/Requests/IdentifyRequest.h" #include "Common/RequestHandlers/FSInfoRequestHandler.h" #include "Common/RequestHandlers/StatusRequestHandler.h" + +#include "Daemon/Application.h" #include "Daemon/Backends/NetworkLogger.h" #include "Daemon/RequestHandlers/CommandRequestHandler.h" @@ -35,19 +37,19 @@ using namespace Mad; int main() { - Core::ThreadManager::get()->init(); + Daemon::Application application; - Common::ModuleManager::get()->loadModule("FileLogger"); - Common::ModuleManager::get()->loadModule("SystemBackendPosix"); - Common::ModuleManager::get()->loadModule("SystemBackendProc"); + application.getModuleManager()->loadModule("FileLogger"); + application.getModuleManager()->loadModule("SystemBackendPosix"); + application.getModuleManager()->loadModule("SystemBackendProc"); - Core::ConfigManager::get()->finish(); + application.getConfigManager()->finish(); - Common::RequestManager::get()->registerPacketType("Command"); - Common::RequestManager::get()->registerPacketType("FSInfo"); - Common::RequestManager::get()->registerPacketType("GetStatus"); + application.getRequestManager()->registerPacketType("Command"); + application.getRequestManager()->registerPacketType("FSInfo"); + application.getRequestManager()->registerPacketType("GetStatus"); - Common::ClientConnection *connection = new Common::ClientConnection; + Common::ClientConnection *connection = new Common::ClientConnection(&application); try { connection->connect(boost::asio::ip::tcp::endpoint( @@ -55,40 +57,33 @@ int main() { connection->waitWhileConnecting(); - Common::RequestManager::get()->registerConnection(connection); + application.getRequestManager()->registerConnection(connection); - boost::shared_ptr networkLogger(new Daemon::Backends::NetworkLogger(connection)); - Core::LogManager::get()->registerLogger(networkLogger); + boost::shared_ptr networkLogger(new Daemon::Backends::NetworkLogger(&application, connection)); + application.getLogManager()->registerLogger(networkLogger); - - //char hostname[256]; - //gethostname(hostname, sizeof(hostname)); - //Common::RequestManager::get()->sendRequest(connection, sigc::ptr_fun(requestFinished), hostname); - //Common::RequestManager::get()->sendRequest1(connection, "test")->wait(); { - boost::shared_ptr request(new Common::Requests::IdentifyRequest("test")); - Common::RequestManager::get()->sendRequest(connection, request); + boost::shared_ptr request(new Common::Requests::IdentifyRequest(&application, "test")); + application.getRequestManager()->sendRequest(connection, request); request->wait(); } - Core::Logger::log("Identified."); + application.log("Identified."); connection->waitWhileConnected(); - Core::LogManager::get()->unregisterLogger(networkLogger); + application.getLogManager()->unregisterLogger(networkLogger); - Common::RequestManager::get()->unregisterConnection(connection); + application.getRequestManager()->unregisterConnection(connection); } catch(Core::Exception &e) { - Core::Logger::logf(Core::Logger::CRITICAL, "Connection error: %s", e.strerror().c_str()); + application.logf(Core::LoggerBase::CRITICAL, "Connection error: %s", e.strerror().c_str()); } delete connection; - Common::RequestManager::get()->unregisterPacketType("Command"); - Common::RequestManager::get()->unregisterPacketType("FSInfo"); - Common::RequestManager::get()->unregisterPacketType("GetStatus"); - - Core::Initializable::deinit(); + application.getRequestManager()->unregisterPacketType("Command"); + application.getRequestManager()->unregisterPacketType("FSInfo"); + application.getRequestManager()->unregisterPacketType("GetStatus"); return 0; } -- cgit v1.2.3