Successfully converted to using two threads rather than two processes.
[aesalon.git] / monitor / src / Coordinator.cpp
bloba3ce5433559fb9053b88b6eea011be2e2264fc86
1 /**
2 Aesalon, a tool to visualize a program's behaviour at run-time.
3 Copyright (C) 2010, Aesalon Development Team.
5 Aesalon is distributed under the terms of the GNU GPLv3. For more
6 licensing information, see the file LICENSE included with the distribution.
8 @file monitor/src/Coordinator.cpp
12 #include <iostream>
13 #include <limits.h>
14 #include <stdlib.h>
16 #include "Coordinator.h"
17 #include "config/ArgumentParser.h"
18 #include "config/Parser.h"
19 #include "common/Config.h"
20 #include "program/Launcher.h"
21 #include "module/Module.h"
22 #include "config/ConcreteVault.h"
23 #include "common/PathSanitizer.h"
24 #include "program/Conductor.h"
26 namespace Monitor {
28 Coordinator *Coordinator::m_instance = NULL;
30 Coordinator::Coordinator(char **argv) : m_argv(argv) {
31 m_instance = this;
34 Coordinator::~Coordinator() {
38 void Coordinator::run() {
39 parseConfigs();
41 if(m_vault->get("::list-attributes") == "true") {
42 std::cout << "Listing all configuration keys and values." << std::endl;
43 std::cout << "Please note that many of these are auto-generated." << std::endl;
44 std::cout << "================" << std::endl;
45 std::vector<Config::Vault::KeyPair> list;
46 m_vault->match("*", list);
47 for(std::vector<Config::Vault::KeyPair>::iterator i = list.begin(); i != list.end(); ++i) {
48 if(i->first[0] == ':' && i->first[1] == ':') continue;
50 std::cout << " * \"" << i->first << "\" ==> \"" << i->second << "\"\n";
53 else if(m_argv[m_argcOffset] == NULL || m_vault->get("::help") == "true") {
54 usage(true);
55 return;
58 Program::Launcher launcher(&m_argv[m_argcOffset]);
60 launcher.forkTarget();
62 std::cout << "In monitor process . . ." << std::endl;
63 Program::Conductor conductor(launcher.readFd());
64 conductor.monitor();
66 launcher.waitForChild();
67 conductor.join();
70 void Coordinator::parseConfigs() {
71 Config::Parser parser;
73 Config::ConcreteVault *vault = new Config::ConcreteVault();
75 parser.parse(vault, Common::PathSanitizer::sanitize(AesalonGlobalConfig));
76 parser.parse(vault, Common::PathSanitizer::sanitize(AesalonUserConfig));
77 parser.parse(vault, Common::PathSanitizer::sanitize(AesalonLocalConfig));
79 Config::ArgumentParser argParser;
80 m_argcOffset = argParser.parse(vault, m_argv);
82 m_vault = vault;
85 void Coordinator::usage(bool displayHelp) {
86 std::cout << "Aesalon version " << AesalonVersion << ". Copyright (C) 2010 Aesalon Development Team." << std::endl;
87 std::cout << "Aesalon is released under the GNU General Public License, version 3." << std::endl;
89 if(!displayHelp) return;
90 std::cout << std::endl;
91 std::cout << "Usage: " << m_argv[0] << " [options] [--] executable [arguments]" << std::endl;
92 std::cout << "Options:" << std::endl;
93 std::cout << "\t--help\n\t\tDisplays this usage message." << std::endl;
94 std::cout << "\t--version\n\t\tDisplays version information." << std::endl;
95 std::cout << "\t--search <path>\n\t\tSearches <path> for modules." << std::endl;
96 std::cout << "\t--use-module <module>\n\t\tPrepares <module> for loading." << std::endl;
97 std::cout << "\t--set <attribute>[=value]\n\t\tSets a module attribute." << std::endl;
98 std::cout << "\t--list-attributes\n\t\tLists all the available attributes." << std::endl;
101 } // namespace Monitor