From 757edd54cca1d3bc19617284bba5d008a976f704 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 29 Dec 2010 23:27:06 +0100 Subject: Read music root and httpd port from audist.conf. --- SConstruct | 3 ++- config.cpp | 22 ++++++++++++++++++++++ config.h | 13 +++++++++++++ main.cpp | 6 ++++-- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 config.cpp create mode 100644 config.h diff --git a/SConstruct b/SConstruct index 6874336..bb8f8bd 100644 --- a/SConstruct +++ b/SConstruct @@ -3,13 +3,14 @@ AddOption('--release', action = 'store_true') env = Environment(CPPPATH = ['.'], CCFLAGS = ['-pthread'], LINKFLAGS = ['-pthread']) if env['PLATFORM'] == 'darwin': - env.Append(LIBS = ['boost_system', 'boost_filesystem', 'boost_regex', 'boost_thread', 'mp3lame']) + env.Append(LIBS = ['boost_system', 'boost_filesystem', 'boost_regex', 'boost_thread', 'boost_program_options', 'mp3lame']) else: conf = Configure(env) conf.CheckLib('boost_system-mt') conf.CheckLib('boost_filesystem-mt') conf.CheckLib('boost_regex-mt') conf.CheckLib('boost_thread-mt') + conf.CheckLib('boost_program_options-mt') conf.CheckLib('mp3lame') env = conf.Finish() diff --git a/config.cpp b/config.cpp new file mode 100644 index 0000000..1fbcde5 --- /dev/null +++ b/config.cpp @@ -0,0 +1,22 @@ +#include "config.h" + +#include +#include +#include + +po::variables_map config::vm; + +void config::init() { + po::options_description desc("foo"); + desc.add_options() + ("audist.music_root", po::value(), "music root") + ("audist.httpd_port", po::value()->default_value(8000), "httpd port") + ; + std::ifstream is("audist.conf", std::ios::in); + po::store(po::parse_config_file(is, desc, true), vm); + po::notify(vm); + + if(!vm.count("audist.music_root")) { + throw std::runtime_error("audist.music_root music be specified in audist.conf"); + } +} diff --git a/config.h b/config.h new file mode 100644 index 0000000..2969b2c --- /dev/null +++ b/config.h @@ -0,0 +1,13 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include + +namespace po = boost::program_options; + +namespace config { + extern po::variables_map vm; + void init(); +}; + +#endif diff --git a/main.cpp b/main.cpp index 19695cf..dc96f5a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include "config.h" #include "music.h" #include "decoder.h" #include "encoder.h" @@ -10,13 +11,14 @@ int main(int argc, char **argv) { try { - music::init(argv[1]); + config::init(); + music::init(config::vm["audist.music_root"].as()); decoder::init(); encoder::init(); boost::asio::io_service io_service; - HTTP::Server httpd(io_service, tcp::endpoint(tcp::v6(), 8000)); + HTTP::Server httpd(io_service, tcp::endpoint(tcp::v6(), config::vm["audist.httpd_port"].as())); std::vector > threads; for(std::size_t i = 0; i < 10; i++) { -- cgit v1.2.3