blob: 6fa75040695d6be785b656deacc470c9ee595c34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "config.h"
#include "music.h"
#include "decoder.h"
#include "encoder.h"
#include "httpd.h"
#include "telnetd.h"
#include "http_static.h"
#include <iostream>
#include <vector>
#include <boost/thread.hpp>
void foo_handler(HTTP::Connection::p connection) {
std::cout << "Handling!" << std::endl;
MusicListing::p ml = music::get(connection->path);
if(ml) {
ml->render(connection);
} else {
connection->send_error(404);
}
}
int main(int argc, char **argv) {
try {
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(), config::vm["audist.httpd_port"].as<int>()));
httpd.add_handler("files", &foo_handler);
HTTP::Static static_files("static");
httpd.add_handler("static", static_files);
httpd.add_handler("", static_files);
telnet::Server telnetd(io_service, tcp::endpoint(tcp::v6(), config::vm["audist.telnetd_port"].as<int>()));
std::size_t num_threads = config::vm["audist.threads"].as<std::size_t>();
std::vector<boost::shared_ptr<boost::thread> > threads;
for(std::size_t i = 0; i < num_threads; i++) {
boost::shared_ptr<boost::thread> thread(new boost::thread(boost::bind(&boost::asio::io_service::run, &io_service)));
threads.push_back(thread);
}
for(std::size_t i = 0; i < num_threads; i++) {
threads[i]->join();
}
} catch(std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
|