/* * 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/Connection.h" #include "Net/FdManager.h" #include "Net/IPAddress.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/RequestHandlers/FSInfoRequestHandler.h" #include "Common/RequestHandlers/StatusRequestHandler.h" #include "Daemon/Backends/NetworkLogger.h" #include "Daemon/Requests/IdentifyRequest.h" #include "Daemon/RequestHandlers/CommandRequestHandler.h" #include using namespace Mad; static void requestFinished(const Common::Request&) { Common::Logger::log("Identified."); } int main() { Net::Connection::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(Net::IPAddress("127.0.0.1"), true); while(connection->isConnecting()) Net::FdManager::get()->run(); 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, sigc::ptr_fun(requestFinished), "test"); while(connection->isConnected()) Net::FdManager::get()->run(); Common::LogManager::get()->unregisterLogger(networkLogger); Common::RequestManager::get()->unregisterConnection(connection); } catch(Mad::Common::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(); Net::Connection::deinit(); return 0; }