summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-12-29 23:27:06 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-12-29 23:27:06 +0100
commit757edd54cca1d3bc19617284bba5d008a976f704 (patch)
tree53b1c4b0293e3fa91e642b5e4d6d404f9d05827b
parent5d94fe647e59aaec7775f1e1bd4a4982b677af01 (diff)
Read music root and httpd port from audist.conf.
-rw-r--r--SConstruct3
-rw-r--r--config.cpp22
-rw-r--r--config.h13
-rw-r--r--main.cpp6
4 files changed, 41 insertions, 3 deletions
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 <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
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<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++) {