Various code cleanups.
[aesalon.git] / monitor / src / Initializer.cpp
blobcc4718f00d60ba6a04fc2a5d7e8bb84000e06d62
1 #include <iostream>
3 #include "Initializer.h"
4 #include "LogSystem.h"
5 #include "program/ElfAnalyzer.h"
6 #include "network/TcpManager.h"
8 Initializer *Initializer::m_singleton = 0;
10 Initializer::Initializer(char *argv[]) : m_argv(argv) {
11 m_singleton = this;
12 m_configuration = new Misc::Configuration(m_argv);
13 m_moduleMapper = new Module::ModuleMapper();
14 m_socketManager = NULL;
15 m_launcher = NULL;
16 m_socketManager = NULL;
19 Initializer::~Initializer() {
20 if(m_launcher) delete m_launcher;
21 if(m_socketManager) delete m_socketManager;
22 if(m_moduleMapper) delete m_moduleMapper;
23 if(m_configuration) delete m_configuration;
26 int Initializer::run() {
27 if(m_configuration->traverse("help")->asBool()) {
28 usage();
29 return 0;
31 else if(m_configuration->launchArguments().size() == 0) {
32 LogSystem::logConfigurationMessage("No filename specified. Displaying usage information.");
33 usage();
34 return 0;
37 m_socketManager = new Network::TcpManager(m_configuration->traverse("tcpPort")->asInt());
38 m_socketManager->waitForConnections(m_configuration->traverse("networkWait")->asInt());
40 m_launcher = new Program::Launcher();
42 m_launcher->start();
44 return m_launcher->returnCode();
47 void Initializer::usage() {
48 std::cout << "Aesalon version " << AesalonVersion << ". Copyright (C) 2009-2010, strange." << std::endl;
49 std::cout << "This program is released under the GNU GPLv3. " << std::endl;
50 std::cout << "\tFor more legal information, see the included file LICENSE." << std::endl;
51 std::cout << "usage: " << m_argv[0] << " [options] [--] filename [arguments]" << std::endl;
53 std::cout << "\nOptions:" << std::endl;
54 std::cout << "\t--help: displays this help message." << std::endl;
55 std::cout << "\t--networkWait: amount of network clients to wait for before executing." << std::endl;
56 std::cout << "\t--tcpPort: TCP port to listen on." << std::endl;
57 std::cout << "\t--logFile: optional log file to write collected data to." << std::endl;
58 std::cout << "\t--shmSize: size of the SHM used to communicate." << std::endl;
60 std::cout << "\nEnvironment variables:" << std::endl;
61 std::cout << "\tAesalonSearchPath: a colon-separated path to search for modules." << std::endl;