From 5fdfe023c698c6649ec1ac287f1b9d517ccb51dc Mon Sep 17 00:00:00 2001 From: strange Date: Tue, 16 Feb 2010 12:24:09 -0700 Subject: [PATCH] Added a configuration system for the monitor. The monitor now parses /etc/aesalon.conf (system-wide configuration) and ~/.config/aesalon/aesalon.conf (user configuration) for information. The entries are of the form 'variable=value', where variable is the same as an argument that is passed to the monitor. Just makes things a little easier . . . --- build.config | 5 ++++ gui/src/session/ActiveBlocksEngine.h | 2 +- monitor/src/CMakeLists.txt | 2 ++ monitor/src/Initializer.cpp | 29 ++++++++++++++++------- monitor/src/Initializer.h | 3 +++ monitor/src/misc/ConfigParser.cpp | 46 ++++++++++++++++++++++++++++++++++++ monitor/src/misc/ConfigParser.h | 24 +++++++++++++++++++ 7 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 monitor/src/misc/ConfigParser.cpp create mode 100644 monitor/src/misc/ConfigParser.h diff --git a/build.config b/build.config index 71528ea..0e052ab 100644 --- a/build.config +++ b/build.config @@ -5,6 +5,11 @@ set(LIBC_PATH "/lib/libc.so.6") # The default TCP port to use set(DEFAULT_PORT 6321) +# The default user-specific config file path +set(USER_CONFIG_PATH "~/.config/aesalon/aesalon.conf") +# The default system-wide config file path +set(SYS_CONFIG_PATH "/etc/aesalon.conf") + # Build configuration # If DEVELOPMENT_BUILD is true, then aesalon will output a lot of debugging diff --git a/gui/src/session/ActiveBlocksEngine.h b/gui/src/session/ActiveBlocksEngine.h index 25ab39d..0abd689 100644 --- a/gui/src/session/ActiveBlocksEngine.h +++ b/gui/src/session/ActiveBlocksEngine.h @@ -7,7 +7,7 @@ class ActiveBlocksEngine : public GraphDataEngine { Q_OBJECT protected: DataRequest *spawn_new_request(const Timestamp ×tamp) const - { return new ActiveBlocksRequest(this, timestamp); } + { return NULL; /*new ActiveBlocksRequest(this, timestamp);*/ } public: ActiveBlocksEngine(QObject *parent, DataThread *data_thread); virtual ~ActiveBlocksEngine(); diff --git a/monitor/src/CMakeLists.txt b/monitor/src/CMakeLists.txt index 0df4d5a..776b0aa 100644 --- a/monitor/src/CMakeLists.txt +++ b/monitor/src/CMakeLists.txt @@ -2,6 +2,8 @@ add_definitions(-std=c++0x -W -Wall -ansi -pedantic -Wno-unused-parameter -Wno-l add_definitions(-DAESALON_MAJOR_VERSION="${AESALON_MAJOR_VERSION}" -DAESALON_MINOR_VERSION="${AESALON_MINOR_VERSION}" -DAESALON_PATCHLEVEL="${AESALON_PATCHLEVEL}" -DAESALON_PLATFORM=${AESALON_PLATFORM}) add_definitions(-DAESALON_PLATFORM_x86=0 -DAESALON_PLATFORM_x86_64=1) +add_definitions(-DSYS_CONFIG_PATH="${SYS_CONFIG_PATH}" -DUSER_CONFIG_PATH="${USER_CONFIG_PATH}") + if(PROFILE_BUILD) add_definitions(-pg) endif(PROFILE_BUILD) diff --git a/monitor/src/Initializer.cpp b/monitor/src/Initializer.cpp index bba6800..caa4a19 100644 --- a/monitor/src/Initializer.cpp +++ b/monitor/src/Initializer.cpp @@ -34,13 +34,22 @@ void Initializer::initialize() { return_value = 0; storage_manager = NULL; + config_parser = new Misc::ConfigParser(); + argument_parser = new Misc::ArgumentParser(argv); argument_parser->add_argument(new Misc::Argument("help", 'h', Misc::Argument::NO_ARGUMENT, "")); - argument_parser->add_argument(new Misc::Argument("tcp-port", 'p', Misc::Argument::REQUIRED_ARGUMENT, "6321")); - argument_parser->add_argument(new Misc::Argument("wait", 'w', Misc::Argument::OPTIONAL_ARGUMENT, "1")); - argument_parser->add_argument(new Misc::Argument("libc-path", 0, Misc::Argument::REQUIRED_ARGUMENT, LIBC_PATH)); - argument_parser->add_argument(new Misc::Argument("overload-path", 'o', Misc::Argument::REQUIRED_ARGUMENT, "./aesalon_overload.so")); + std::string port = config_parser->get_config_item("tcp-port"); + if(port == "") port = Misc::StreamAsString() << DEFAULT_PORT; + argument_parser->add_argument(new Misc::Argument("tcp-port", 'p', Misc::Argument::REQUIRED_ARGUMENT, port)); + std::string wait = config_parser->get_config_item("wait"); + if(wait == "") wait = "1"; + argument_parser->add_argument(new Misc::Argument("wait", 'w', Misc::Argument::OPTIONAL_ARGUMENT, wait)); + std::string libc_path = config_parser->get_config_item("libc-path"); + if(libc_path == "") libc_path = LIBC_PATH; + argument_parser->add_argument(new Misc::Argument("libc-path", 0, Misc::Argument::REQUIRED_ARGUMENT, libc_path)); + std::string overload_path = config_parser->get_config_item("overload-path"); + argument_parser->add_argument(new Misc::Argument("overload-path", 'o', Misc::Argument::REQUIRED_ARGUMENT, overload_path)); argument_parser->parse(); @@ -49,6 +58,9 @@ void Initializer::initialize() { return; } + if(argument_parser->get_argument("overload-path")->get_data() == "") + throw Exception::BasicException("No overload-path specified."); + storage_manager = new StorageManager(); if(argument_parser->get_postargs()) { @@ -98,10 +110,11 @@ void Initializer::usage() { std::cout << ", copyright (C) 2009-2010 strange " << std::endl; std::cout << "usage: " << argv[0] << " [arguments] executable [executable arguments]" << std::endl; std::cout << "\t--help, -h\t\tPrint this usage message." << std::endl; - std::cout << "\t--tcp-port, -p\t\tSet the port to listen on for connections. Defaults to " << DEFAULT_PORT << "." << std::endl; - std::cout << "\t--wait, -w\t\tWait for a TCP connection before executing. Defaults to false." << std::endl; - std::cout << "\t--libc-path\t\tThe path to the current version of libc being used. Defaults to " << LIBC_PATH << "." << std::endl; - std::cout << "\t--\t\t\tDenotes the end of the argument list." << std::endl; + std::cout << "\t--tcp-port, -p\t\tSet the port to listen on for connections. Currently is " << argument_parser->get_argument("tcp-port")->get_data() << "." << std::endl; + std::cout << "\t--wait, -w\t\tNumber of TCP connections to accept before executing. Defaults to 0." << std::endl; + std::cout << "\t--libc-path\t\tThe path to the current version of libc being used. Currently is " << LIBC_PATH << "." << std::endl; + std::cout << "\t--overload-path\t\tThe path to the aesalon overload library. Currently is " << argument_parser->get_argument("overload-path")->get_data() << "." << std::endl; + std::cout << "\t--\t\t\tOptional, denotes the end of the argument list." << std::endl; } void Initializer::run() { diff --git a/monitor/src/Initializer.h b/monitor/src/Initializer.h index 2d3b662..ac964d5 100644 --- a/monitor/src/Initializer.h +++ b/monitor/src/Initializer.h @@ -7,6 +7,7 @@ #include "ProgramManager.h" #include "misc/ArgumentParser.h" #include "StorageManager.h" +#include "misc/ConfigParser.h" /** Initializer class. Basically, handles initialization of the Monitor. */ class Initializer : public Misc::Singleton { @@ -22,6 +23,8 @@ private: Misc::ArgumentParser *argument_parser; + Misc::ConfigParser *config_parser; + StorageManager *storage_manager; /** Initialize the aesalon monitor. */ diff --git a/monitor/src/misc/ConfigParser.cpp b/monitor/src/misc/ConfigParser.cpp new file mode 100644 index 0000000..b2bc426 --- /dev/null +++ b/monitor/src/misc/ConfigParser.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include "ConfigParser.h" +#include "Message.h" +#include "StreamAsString.h" + +namespace Misc { + +ConfigParser::ConfigParser() { + parse_config_file(SYS_CONFIG_PATH); + parse_config_file(USER_CONFIG_PATH); +} + +ConfigParser::~ConfigParser() { + +} + +void ConfigParser::parse_config_file(std::string filename) { + if(filename.find("~") != std::string::npos) { + filename.replace(filename.find("~"), 1, std::string(getenv("HOME"))); + } + std::ifstream stream(filename.c_str()); + + if(!stream.is_open()) { + Message::Message(Message::WARNING_MESSAGE, Misc::StreamAsString() << "Couldn't open configuration file \"" << filename << "\""); + return; + } + + char *buffer = new char[1024]; + + while(!stream.eof()) { + stream.getline(buffer, 1024, '\n'); + std::string buf_string = buffer; + if(buf_string.find("=") == std::string::npos) continue; + std::string config_name = buf_string.substr(0, buf_string.find("=")); + buf_string = buf_string.substr(buf_string.find("=")+1); + config_map[config_name] = buf_string; + } + + delete[] buffer; + + stream.close(); +} + +} // namespace Misc diff --git a/monitor/src/misc/ConfigParser.h b/monitor/src/misc/ConfigParser.h new file mode 100644 index 0000000..5ace058 --- /dev/null +++ b/monitor/src/misc/ConfigParser.h @@ -0,0 +1,24 @@ +#ifndef AESALON_CONFIG_PARSER_H +#define AESALON_CONFIG_PARSER_H + +#include +#include + +namespace Misc { + +class ConfigParser { +private: + std::map config_map; + void parse_config_file(std::string filename); +public: + ConfigParser(); + virtual ~ConfigParser(); + + std::string get_config_item(std::string reference_name) { + return config_map[reference_name]; + } +}; + +} // namespace Misc + +#endif -- 2.11.4.GIT