/* * mad.cpp * * Copyright (C) 2008 Matthias Schiffer * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program. If not, see . */ #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" using namespace Mad; int main() { Daemon::Application application; application.getConfigManager()->loadFile("madd.conf"); application.getConfigManager()->configure(); application.getRequestManager()->registerPacketType("Command"); application.getRequestManager()->registerPacketType("FSInfo"); application.getRequestManager()->registerPacketType("GetStatus"); Common::ClientConnection *connection = new Common::ClientConnection(&application); try { application.getRequestManager()->registerConnection(connection); connection->connect(boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::from_string("127.0.0.1"), 6666)); connection->waitWhileConnecting(); boost::shared_ptr networkLogger(new Daemon::Backends::NetworkLogger(&application, connection)); application.getLogManager()->registerLogger(networkLogger); { boost::shared_ptr request(new Common::Requests::IdentifyRequest(&application, "test")); application.getRequestManager()->sendRequest(connection, request); request->wait(); } application.log("Identified."); connection->waitWhileConnected(); application.getLogManager()->unregisterLogger(networkLogger); application.getRequestManager()->unregisterConnection(connection); } catch(Core::Exception &e) { application.log(Core::Logger::LOG_CRITICAL, Core::Format("Error: %1%") % e); } delete connection; application.getRequestManager()->unregisterPacketType("Command"); application.getRequestManager()->unregisterPacketType("FSInfo"); application.getRequestManager()->unregisterPacketType("GetStatus"); return 0; }