1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* 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 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 <http://www.gnu.org/licenses/>.
*/
#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 <unistd.h>
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<Daemon::RequestHandlers::CommandRequestHandler>("Command");
Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo");
Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("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<Daemon::Requests::IdentifyRequest>(connection, sigc::ptr_fun(requestFinished), hostname);
Common::RequestManager::get()->sendRequest<Common::Requests::IdentifyRequest>(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;
}
|