From eebf8d99a204792a0890b60c240de818cd68b470 Mon Sep 17 00:00:00 2001 From: Ethereal Date: Sat, 6 Nov 2010 21:17:35 -0600 Subject: [PATCH] Started implementing Program::Launcher, etc. --- include/monitor/Coordinator.h | 3 +++ include/monitor/config/FileParser.h | 2 +- include/monitor/config/Group.h | 1 + include/monitor/config/Store.h | 2 ++ .../monitor/{config/FileParser.h => module/List.h} | 25 +++++++++-------- .../{config/FileParser.h => module/Module.h} | 24 ++++++++--------- .../{config/FileParser.h => program/Launcher.h} | 25 +++++++++-------- monitor/src/Coordinator.cpp | 31 +++++++++++++++++++++- monitor/src/config/FileParser.cpp | 8 ++++-- monitor/src/config/Group.cpp | 5 ++++ monitor/src/config/Item.cpp | 2 +- monitor/src/config/Store.cpp | 6 +++++ monitor/src/module/List.cpp | 20 ++++++++++++++ monitor/src/module/Module.cpp | 20 ++++++++++++++ monitor/src/program/Launcher.cpp | 30 +++++++++++++++++++++ 15 files changed, 160 insertions(+), 44 deletions(-) copy include/monitor/{config/FileParser.h => module/List.h} (51%) copy include/monitor/{config/FileParser.h => module/Module.h} (53%) copy include/monitor/{config/FileParser.h => program/Launcher.h} (50%) create mode 100644 monitor/src/module/List.cpp create mode 100644 monitor/src/module/Module.cpp create mode 100644 monitor/src/program/Launcher.cpp diff --git a/include/monitor/Coordinator.h b/include/monitor/Coordinator.h index 89092f3..ad6e46b 100644 --- a/include/monitor/Coordinator.h +++ b/include/monitor/Coordinator.h @@ -32,6 +32,9 @@ public: Config::Store *store() const { return m_store; } void run(); +private: + void parseConfigs(); + void usage(); }; } // namespace Monitor diff --git a/include/monitor/config/FileParser.h b/include/monitor/config/FileParser.h index 96e3cc7..fd833a1 100644 --- a/include/monitor/config/FileParser.h +++ b/include/monitor/config/FileParser.h @@ -26,7 +26,7 @@ public: FileParser(Store *store); ~FileParser(); - void parse(const std::string &filename); + void parse(const std::string &filename, bool replace = true); }; } // namespace Config diff --git a/include/monitor/config/Group.h b/include/monitor/config/Group.h index 19c25af..90d2de3 100644 --- a/include/monitor/config/Group.h +++ b/include/monitor/config/Group.h @@ -30,6 +30,7 @@ public: void addItem(Item *item); Item *item(const std::string &name); + Item *getItem(const std::string &name); }; } // namespace Config diff --git a/include/monitor/config/Store.h b/include/monitor/config/Store.h index e60d658..df43c33 100644 --- a/include/monitor/config/Store.h +++ b/include/monitor/config/Store.h @@ -30,7 +30,9 @@ public: ~Store(); Group *group(const std::string &groupName); + Group *findGroup(const std::string &groupName); Item *item(const std::string &groupName, const std::string &itemName); + Item *findItem(const std::string &groupName, const std::string &itemName); Item *item(const std::string &path); }; diff --git a/include/monitor/config/FileParser.h b/include/monitor/module/List.h similarity index 51% copy from include/monitor/config/FileParser.h copy to include/monitor/module/List.h index 96e3cc7..ee5a08a 100644 --- a/include/monitor/config/FileParser.h +++ b/include/monitor/module/List.h @@ -5,31 +5,30 @@ Aesalon is distributed under the terms of the GNU GPLv3. For more licensing information, see the file LICENSE included with the distribution. - @file include/monitor/config/FileParser.h + @file include/monitor/module/List.h */ -#include +#ifndef AesalonMonitor_Module_List_H +#define AesalonMonitor_Module_List_H -#ifndef AesalonMonitor_Config_FileParser_H -#define AesalonMonitor_Config_FileParser_H +#include -#include "Store.h" +#include "Module.h" namespace Monitor { -namespace Config { +namespace Module { -class FileParser { +class List { private: - Store *m_store; + typedef std::vector ModuleList; + ModuleList m_moduleList; public: - FileParser(Store *store); - ~FileParser(); - - void parse(const std::string &filename); + List(); + ~List(); }; -} // namespace Config +} // namespace Module } // namespace Monitor #endif diff --git a/include/monitor/config/FileParser.h b/include/monitor/module/Module.h similarity index 53% copy from include/monitor/config/FileParser.h copy to include/monitor/module/Module.h index 96e3cc7..00d7972 100644 --- a/include/monitor/config/FileParser.h +++ b/include/monitor/module/Module.h @@ -5,31 +5,29 @@ Aesalon is distributed under the terms of the GNU GPLv3. For more licensing information, see the file LICENSE included with the distribution. - @file include/monitor/config/FileParser.h + @file include/monitor/module/Module.h */ -#include +#ifndef AesalonMonitor_Module_Module_H +#define AesalonMonitor_Module_Module_H -#ifndef AesalonMonitor_Config_FileParser_H -#define AesalonMonitor_Config_FileParser_H +#include -#include "Store.h" +#include "config/Store.h" namespace Monitor { -namespace Config { +namespace Module { -class FileParser { +class Module { private: - Store *m_store; + std::string m_moduleName; public: - FileParser(Store *store); - ~FileParser(); - - void parse(const std::string &filename); + Module(Config::Store *store); + ~Module(); }; -} // namespace Config +} // namespace Module } // namespace Monitor #endif diff --git a/include/monitor/config/FileParser.h b/include/monitor/program/Launcher.h similarity index 50% copy from include/monitor/config/FileParser.h copy to include/monitor/program/Launcher.h index 96e3cc7..9dffeb5 100644 --- a/include/monitor/config/FileParser.h +++ b/include/monitor/program/Launcher.h @@ -5,31 +5,30 @@ Aesalon is distributed under the terms of the GNU GPLv3. For more licensing information, see the file LICENSE included with the distribution. - @file include/monitor/config/FileParser.h + @file include/monitor/program/Launcher.h */ -#include +#ifndef AesalonMonitor_Program_Launcher_H +#define AesalonMonitor_Program_Launcher_H -#ifndef AesalonMonitor_Config_FileParser_H -#define AesalonMonitor_Config_FileParser_H - -#include "Store.h" +#include "config/Store.h" namespace Monitor { -namespace Config { +namespace Program { -class FileParser { +class Launcher { private: - Store *m_store; + Config::Store *m_store; + char **m_argv; public: - FileParser(Store *store); - ~FileParser(); + Launcher(Config::Store *store, char **argv); + ~Launcher(); - void parse(const std::string &filename); + void startProcess(); }; -} // namespace Config +} // namespace Program } // namespace Monitor #endif diff --git a/monitor/src/Coordinator.cpp b/monitor/src/Coordinator.cpp index af44e90..3bb3605 100644 --- a/monitor/src/Coordinator.cpp +++ b/monitor/src/Coordinator.cpp @@ -9,14 +9,20 @@ */ +#include + #include "Coordinator.h" #include "config/ArgumentParser.h" +#include "config/FileParser.h" #include "common/Config.h" +#include "program/Launcher.h" namespace Monitor { +Coordinator *Coordinator::m_instance = NULL; + Coordinator::Coordinator(char **argv) : m_argv(argv) { - + m_instance = this; } Coordinator::~Coordinator() { @@ -24,11 +30,34 @@ Coordinator::~Coordinator() { } void Coordinator::run() { + parseConfigs(); + if(m_argv[m_argumentEndpoint] == NULL || m_store->item("help")->boolValue()) { + usage(); + return; + } + + Program::Launcher *launcher = new Program::Launcher(m_store, &m_argv[m_argumentEndpoint]); +} + +void Coordinator::parseConfigs() { m_store = new Config::Store(); + /* Perform first pass through configuration . . . */ + Config::FileParser fp(m_store); + fp.parse(AesalonGlobalConfig); + fp.parse(AesalonUserConfig); + Config::ArgumentParser ap(m_store, m_argv); m_argumentEndpoint = ap.parse(); } +void Coordinator::usage() { + std::cout << "Aesalon version " << AesalonVersion << ". Copyright (C) 2010 Aesalon Development Team." << std::endl; + std::cout << "Aesalon is released under the GNU General Public License, version 3." << std::endl; + std::cout << std::endl; + std::cout << "Usage: " << m_argv[0] << " [options] [--] executable [arguments]" << std::endl; + std::cout << "Options:" << std::endl; +} + } // namespace Monitor diff --git a/monitor/src/config/FileParser.cpp b/monitor/src/config/FileParser.cpp index 3b3fa4d..0741d4c 100644 --- a/monitor/src/config/FileParser.cpp +++ b/monitor/src/config/FileParser.cpp @@ -26,7 +26,7 @@ FileParser::~FileParser() { } -void FileParser::parse(const std::string &filename) { +void FileParser::parse(const std::string &filename, bool replace) { std::ifstream file(filename.c_str(), std::ios_base::in); if(!file.is_open()) return; @@ -54,7 +54,11 @@ void FileParser::parse(const std::string &filename) { if(divider == std::string::npos) throw Common::ParsingException("Configuration file invalid: set command has no argument."); - m_store->item(group, content.substr(0, divider))->setValue(content.substr(divider+1)); + if(replace) m_store->item(group, content.substr(0, divider))->setValue(content.substr(divider+1)); + else { + Item *item = m_store->findItem(group, content.substr(0, divider)); + if(item) item->setValue(content.substr(divider+1)); + } } else { throw Common::ParsingException(Common::StreamAsString() << diff --git a/monitor/src/config/Group.cpp b/monitor/src/config/Group.cpp index 2510117..7b468cd 100644 --- a/monitor/src/config/Group.cpp +++ b/monitor/src/config/Group.cpp @@ -35,5 +35,10 @@ Item *Group::item(const std::string &item) { return i; } +Item *Group::getItem(const std::string &item) { + return m_itemMap[item]; +} + + } // namespace Config } // namespace Monitor diff --git a/monitor/src/config/Item.cpp b/monitor/src/config/Item.cpp index f931278..c7956e1 100644 --- a/monitor/src/config/Item.cpp +++ b/monitor/src/config/Item.cpp @@ -56,7 +56,7 @@ long Item::longValue() const { bool Item::boolValue() const { if(m_value == "true" || m_value == "True") return true; - if(m_value == "false" || m_value == "false") return false; + if(m_value == "false" || m_value == "false" || m_value == "") return false; throw Common::ParsingException(Common::StreamAsString() << "Cannot convert config item " << m_name diff --git a/monitor/src/config/Store.cpp b/monitor/src/config/Store.cpp index 49c352d..2eb42f6 100644 --- a/monitor/src/config/Store.cpp +++ b/monitor/src/config/Store.cpp @@ -35,6 +35,12 @@ Item *Store::item(const std::string &groupName, const std::string &itemName) { return group(groupName)->item(itemName); } +Item *Store::findItem(const std::string &groupName, const std::string &itemName) { + Group *group = m_groupMap[groupName]; + if(group == NULL) return NULL; + return group->getItem(itemName); +} + Item *Store::item(const std::string &path) { std::string::size_type i = path.find('.'); if(i != std::string::npos) return item(path.substr(0, i), path.substr(i+1)); diff --git a/monitor/src/module/List.cpp b/monitor/src/module/List.cpp new file mode 100644 index 0000000..fdf4ba2 --- /dev/null +++ b/monitor/src/module/List.cpp @@ -0,0 +1,20 @@ +/** + Aesalon, a tool to visualize a program's behaviour at run-time. + Copyright (C) 2010, Aesalon Development Team. + + Aesalon is distributed under the terms of the GNU GPLv3. For more + licensing information, see the file LICENSE included with the distribution. + + @file monitor/src/module/List.cpp + +*/ + +#include "module/List.h" + +namespace Monitor { +namespace Module { + + + +} // namespace Module +} // namespace Monitor diff --git a/monitor/src/module/Module.cpp b/monitor/src/module/Module.cpp new file mode 100644 index 0000000..fb22f66 --- /dev/null +++ b/monitor/src/module/Module.cpp @@ -0,0 +1,20 @@ +/** + Aesalon, a tool to visualize a program's behaviour at run-time. + Copyright (C) 2010, Aesalon Development Team. + + Aesalon is distributed under the terms of the GNU GPLv3. For more + licensing information, see the file LICENSE included with the distribution. + + @file monitor/src/module/Module.cpp + +*/ + +#include "module/Module.h" + +namespace Monitor { +namespace Module { + + + +} // namespace Module +} // namespace Monitor diff --git a/monitor/src/program/Launcher.cpp b/monitor/src/program/Launcher.cpp new file mode 100644 index 0000000..cf4d6c2 --- /dev/null +++ b/monitor/src/program/Launcher.cpp @@ -0,0 +1,30 @@ +/** + Aesalon, a tool to visualize a program's behaviour at run-time. + Copyright (C) 2010, Aesalon Development Team. + + Aesalon is distributed under the terms of the GNU GPLv3. For more + licensing information, see the file LICENSE included with the distribution. + + @file monitor/src/program/Launcher.cpp + +*/ + +#include "program/Launcher.h" + +namespace Monitor { +namespace Program { + +Launcher::Launcher(Config::Store *store, char **argv) : m_store(store), m_argv(argv) { + +} + +Launcher::~Launcher() { + +} + +void Launcher::startProcess() { + +} + +} // namespace Program +} // namespace Monitor -- 2.11.4.GIT