20 #include "gatewayconfig.h" 30 if (!append(gwConf)) {
38 m_configMap = gwConf.m_configMap;
39 for (
auto item : m_configMap) {
40 json_incref(item.second);
46 GatewayConfiguration::~GatewayConfiguration()
48 for (
auto &it : m_configMap) {
49 json_decref(it.second);
53 bool GatewayConfiguration::append(
const std::string &
id,
const std::string &jsonConf)
55 json_error_t jsonError;
58 json_t *json = json_loads(jsonConf.c_str(), flags, &jsonError);
59 if (
nullptr == json) {
60 log_error() <<
"Could not parse given string to JSON. Due to: " << jsonError.text <<
" at line: " << jsonError.line;
64 auto ret = append(
id, json);
69 bool GatewayConfiguration::append(
const std::string &
id, json_t *sourceArray)
71 auto search = m_configMap.find(
id);
72 if (search != m_configMap.end()) {
74 json_t *destArray = search->second;
75 json_t *backupArray = json_deep_copy(destArray);
80 json_array_foreach(sourceArray, index, value) {
81 json_t *copy = json_deep_copy(value);
82 if (json_array_append(destArray, copy) < 0) {
83 log_error() <<
"Could not add Gateway Config to json array: " << id;
84 m_configMap[id] = backupArray;
85 json_decref(destArray);
89 json_decref(backupArray);
91 m_configMap[id] = json_deep_copy(sourceArray);
100 for (
auto &conf : source.m_configMap) {
101 if (!append(conf.first, conf.second)) {
108 json_t *GatewayConfiguration::config(
const std::string &gatewayId)
const 110 if (m_configMap.count(gatewayId) == 0) {
114 return json_deep_copy(m_configMap.at(gatewayId));
117 bool GatewayConfiguration::empty()
119 return m_configMap.empty();
122 std::vector<std::string> GatewayConfiguration::ids()
const 124 std::vector<std::string> ids;
125 for (
auto &pair : m_configMap) {
126 ids.push_back(pair.first);
GatewayConfiguration()
Creates a new GatewayConfiguration object.
Developers guide to adding a config item: