-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlitz.cpp
106 lines (91 loc) · 3.28 KB
/
Blitz.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Blitz.cpp
* Copyright (C) 2013 Emil Penchev, Bulgaria
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* Created on: Jan 6, 2013
* Author: emo
*/
#include <boost/asio/io_service.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include "DataPacket.h"
#include "HttpSource.h"
#include "HttpSink.h"
#include "Log.h"
#include "Daemon.h"
#include "Config.h"
#include "IOServicePool.h"
#include "VODService.h"
#include "ControlChannel.h"
#include "WebService.h"
int main(int argc, char* argv[])
{
std::string config_filename;
std::vector<std::string> args(argv, argv+argc);
if (args.size() == 3)
{
if (args[1] == "-c")
{
config_filename = args[2];
}
else
{
printf("Usage: %s -c conf.xml \n", argv[0]);
return 1;
}
}
else
{
printf("Usage: %s -c conf.xml \n", argv[0]);
return 1;
}
BLITZ_LOG_INFO("Starting blitz daemon");
try
{
blitz::Config conf;
conf.readConfig(config_filename);
blitz::IOServicePool thread_pool(conf.getNumThreads());
blitz::Daemon::daemonize(conf.getPidfile().c_str(), conf.getLogfile().c_str());
blitz::WebService web_service(thread_pool.getIOService(), conf.getWebServicePort());
for (unsigned i = 0; i < conf.getNumPipeline(); i++)
{
boost::asio::io_service& io_service = thread_pool.getIOService();
blitz::DataSource* source = new blitz::HttpSource(io_service, conf.getPipelineSourceURL(i));
blitz::DataSink* sink = new blitz::HttpSink(io_service, conf.getPipelineSinkPort(i), conf.getPipelineSinkIP(i),
conf.getPipelineName(i), conf.getPipelineID(i));
source->addSink(sink);
source->start();
blitz::Controler* controler = dynamic_cast<blitz::Controler*>(sink);
web_service.registerControler(controler);
}
if (conf.isVodServiceEnable())
{
boost::asio::io_service& io_service = thread_pool.getIOService();
blitz::VODService* vservice = new blitz::VODService(io_service, conf.getVodServicePort(), conf.getVodServiceIP(), conf.getVodServiceFilePath());
blitz::Controler* vservice_controler = dynamic_cast<blitz::Controler*>(vservice);
web_service.registerControler(vservice_controler);
vservice->start();
}
web_service.start();
thread_pool.run();
}
catch (std::exception& e)
{
// this is in log file
BLITZ_LOG_ERROR("Exception: %s", e.what());
exit(1);
}
return 0;
}