-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cpp
More file actions
150 lines (124 loc) · 4.34 KB
/
Config.cpp
File metadata and controls
150 lines (124 loc) · 4.34 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Config.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: Feb 17, 2013
* Author: emo
*/
#include "Config.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <string>
using boost::property_tree::ptree;
using boost::lexical_cast;
namespace blitz {
template<typename T>
inline T getDataIter(ptree::iterator& iter, const char* xml_node)
{
/* (*iter).second.get<std::string>("<tag>"); */
ptree::value_type const& v = *iter;
return v.second.get<T>(xml_node);
}
template<typename T>
inline T getData(ptree& pt, const char* xml_node)
{
return pt.get<T>(xml_node);
}
inline static void dumpPair(ptree::iterator& iter)
{
std::cout << iter->first << "-->" << iter->second.data() << std::endl;
}
template<typename T>
T* createObject()
{
T* object = new T();
return object;
}
void Config::readConfig(const std::string &filename)
{
ptree pt;
try
{
read_xml(filename, pt);
m_logfile = getData<std::string>(pt, "blitz.logfile");
m_pidfile = getData<std::string>(pt, "blitz.pidfile");
m_threads = getData<unsigned int>(pt, "blitz.threads");
m_webservice_port = getData<unsigned int>(pt, "blitz.webservice_port");
for (ptree::iterator iter = pt.get_child("blitz").begin(); iter != pt.get_child("blitz").end(); iter++)
{
if (iter->first == "pipeline")
{
std::string type = getDataIter<std::string>(iter, "<xmlattr>.type");
if (0 == type.compare("http"))
{
HttpPipelineConfig conf;
conf.id = getDataIter<unsigned int>(iter, "<xmlattr>.id");
conf.name = getDataIter<std::string>(iter, "<xmlattr>.name");
conf.source_url = getDataIter<std::string>(iter, "source");
ptree pt_sink = (*iter).second.get_child("sink");
conf.sink_ip = getData<std::string>(pt_sink, "ip");
conf.sink_port = getData<unsigned short>(pt_sink, "port");
conf.sink_sessions = getData<unsigned short>(pt_sink, "sessions");
m_pipeline_configs.push_back(conf);
}
}
if (iter->first == "vod_service")
{
std::string service_state = getDataIter<std::string>(iter, "<xmlattr>.state");
if (0 == service_state.compare("enable"))
{
m_vod_config.state = true;
m_vod_config.service_ip = getDataIter<std::string>(iter, "ip");
m_vod_config.service_port = getDataIter<unsigned short>(iter, "port");
m_vod_config.filepath = getDataIter<std::string>(iter, "filepath");
}
else
m_vod_config.state = false;
}
}
}
catch(std::exception& ex)
{
std::cout << "Exception from boost::property_tree " << ex.what() << std::endl;
}
}
unsigned short Config::getPipelineID(unsigned id)
{
return m_pipeline_configs.at(id).id;
}
unsigned short Config::getPipelineSinkPort(unsigned id)
{
return m_pipeline_configs.at(id).sink_port;
}
unsigned short Config::getPipelineSinkMaxSesssions(unsigned id)
{
return m_pipeline_configs.at(id).sink_sessions;
}
std::string& Config::getPipelineName(unsigned id)
{
return m_pipeline_configs.at(id).name;
}
std::string& Config::getPipelineSourceURL(unsigned id)
{
return m_pipeline_configs.at(id).source_url;
}
std::string& Config::getPipelineSinkIP(unsigned id)
{
return m_pipeline_configs.at(id).sink_ip;
}
} // blitz