diff options
Diffstat (limited to 'src/madd.cpp')
-rw-r--r-- | src/madd.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/madd.cpp b/src/madd.cpp new file mode 100644 index 0000000..0062d01 --- /dev/null +++ b/src/madd.cpp @@ -0,0 +1,84 @@ +/* + * mad.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#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()->finish(); + + application.getRequestManager()->registerPacketType<Daemon::RequestHandlers::CommandRequestHandler>("Command"); + application.getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); + application.getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("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<Core::Logger> networkLogger(new Daemon::Backends::NetworkLogger(&application, connection)); + application.getLogManager()->registerLogger(networkLogger); + + { + boost::shared_ptr<Common::Requests::IdentifyRequest> 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.logf(Core::Logger::LOG_CRITICAL, "Connection error: %s", e.what()); + } + + delete connection; + + application.getRequestManager()->unregisterPacketType("Command"); + application.getRequestManager()->unregisterPacketType("FSInfo"); + application.getRequestManager()->unregisterPacketType("GetStatus"); + + return 0; +} |