I am beginning to question the need for a marshaller.
[aesalon.git] / src / monitor / Coordinator.cpp
blob41018fa58506ed0d50f73a9dde7aa8f85da420fe
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/monitor/Coordinator.cpp
8 */
10 #include <iostream>
12 #include "Config.h"
14 #include "monitor/Coordinator.h"
15 #include "monitor/ArgumentParser.h"
16 #include "monitor/Launcher.h"
17 #include "config/Parser.h"
18 #include "util/PathSanitizer.h"
19 #include "util/MessageSystem.h"
21 namespace Monitor {
23 Coordinator *Coordinator::m_instance = NULL;
25 Coordinator::Coordinator(char **argv) : m_argv(argv) {
26 m_instance = this;
29 Coordinator::~Coordinator() {
33 void Coordinator::run() {
34 parseConfigs();
36 if(m_vault->get("::list-attributes") == "true") {
37 Message(Log, "Listing all configuration keys and values.");
38 Message(Log, "Some auto-generated values may have non-canonical values.");
39 std::vector<Config::Vault::KeyPair> list;
40 m_vault->match("*", list);
41 for(std::vector<Config::Vault::KeyPair>::iterator i = list.begin(); i != list.end(); ++i) {
42 if(i->first[0] == ':' && i->first[1] == ':') continue;
44 Message(Log, " * \"" << i->first << "\" ==> \"" << i->second << "\"");
47 else if(m_vault->get("::version") == "true") {
48 usage(false);
50 else if(m_argv[m_argcOffset] == NULL || m_vault->get("::help") == "true") {
51 usage(true);
53 else {
54 DataOutputController doc;
55 m_dataOutputController = &doc;
56 Launcher launcher(m_argv + m_argcOffset);
58 launcher.launch();
62 void Coordinator::parseConfigs() {
63 Config::Parser parser;
64 m_vault = new Config::Vault();
66 parser.parse(m_vault, Util::PathSanitizer::sanitize(AesalonMonitorGlobalConfig));
67 parser.parse(m_vault, Util::PathSanitizer::sanitize(AesalonMonitorUserConfig));
68 parser.parse(m_vault, Util::PathSanitizer::sanitize(AesalonMonitorLocalConfig));
70 m_argcOffset = ArgumentParser::parse(m_vault, m_argv);
73 void Coordinator::usage(bool displayHelp) {
74 std::cout << "Aesalon version " << AesalonVersion << ". Copyright (C) 2009-2011 Aesalon Development Team."
75 << std::endl;
76 std::cout << "Aesalon is released under the GNU General Public License, version 3." << std::endl;
77 std::cout << "See the file LICENSE included with the distribution for more details." << std::endl;
79 if(!displayHelp) return;
80 std::cout << std::endl;
81 std::cout << "Usage: " << m_argv[0] << " [options] [--] executable [arguments]" << std::endl;
82 std::cout << "Options:" << std::endl;
83 std::cout << "\t--help/--usage\n\t\tDisplays this usage message." << std::endl;
84 std::cout << "\t--version\n\t\tDisplays version information." << std::endl;
85 std::cout << "\t--search <path>\n\t\tSearches <path> for modules." << std::endl;
86 std::cout << "\t--use-module <module>\n\t\tPrepares <module> for loading." << std::endl;
87 std::cout << "\t--set <attribute>[=value]\n\t\tSets a module attribute." << std::endl;
88 std::cout << "\t--list-attributes\n\t\tLists all the available attributes." << std::endl;
91 } // namespace Monitor