diff options
-rw-r--r-- | SConstruct | 3 | ||||
-rw-r--r-- | config.cpp | 22 | ||||
-rw-r--r-- | config.h | 13 | ||||
-rw-r--r-- | main.cpp | 6 |
4 files changed, 41 insertions, 3 deletions
@@ -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 <string> +#include <fstream> +#include <stdexcept> + +po::variables_map config::vm; + +void config::init() { + po::options_description desc("foo"); + desc.add_options() + ("audist.music_root", po::value<std::string>(), "music root") + ("audist.httpd_port", po::value<int>()->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 <boost/program_options.hpp> + +namespace po = boost::program_options; + +namespace config { + extern po::variables_map vm; + void init(); +}; + +#endif @@ -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<std::string>()); 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<int>())); std::vector<boost::shared_ptr<boost::thread> > threads; for(std::size_t i = 0; i < 10; i++) { |