/* * 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 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 "Net/ThreadManager.h" #include "Common/ConfigManager.h" #include "Common/LogManager.h" #include "Common/Logger.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/Backends/NetworkLogger.h" #include "Daemon/RequestHandlers/CommandRequestHandler.h" #include using namespace Mad; static void requestFinished(const Common::Request&) { Common::Logger::log("Identified."); } int main() { Net::ThreadManager::get()->init(); Common::ModuleManager::get()->loadModule("FileLogger"); Common::ModuleManager::get()->loadModule("SystemBackendPosix"); Common::ModuleManager::get()->loadModule("SystemBackendProc"); Common::ConfigManager::get()->finish(); Common::RequestManager::get()->registerPacketType("Command"); Common::RequestManager::get()->registerPacketType("FSInfo"); Common::RequestManager::get()->registerPacketType("GetStatus"); Common::ClientConnection *connection = new Common::ClientConnection; try { connection->connect(boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::from_string("127.0.0.1"), 6666)); while(connection->isConnecting()) usleep(100000); Common::RequestManager::get()->registerConnection(connection); Common::Logger *networkLogger = new Daemon::Backends::NetworkLogger(connection); Common::LogManager::get()->registerLogger(networkLogger); //char hostname[256]; //gethostname(hostname, sizeof(hostname)); //Common::RequestManager::get()->sendRequest(connection, sigc::ptr_fun(requestFinished), hostname); Common::RequestManager::get()->sendRequest(connection, &requestFinished, "test"); while(connection->isConnected()) usleep(100000); Common::LogManager::get()->unregisterLogger(networkLogger); Common::RequestManager::get()->unregisterConnection(connection); } catch(Net::Exception &e) { Common::Logger::logf(Common::Logger::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"); Common::Initializable::deinit(); return 0; }