78 const nlohmann::json bridgeJsonSchema =
nlohmann::json::parse(bridgeJsonSchemaString);
81 if (!fileName.empty()) {
82 std::ifstream bridgeConfigJsonFile(fileName);
84 if (bridgeConfigJsonFile.is_open()) {
85 VLOG(1) <<
"Bridge config JSON: " << fileName;
100 }
catch (
const std::exception& e) {
101 VLOG(1) <<
" Patching JSON with default patch failed:\n" << defaultPatch.dump(4);
102 VLOG(1) <<
" " << e.what();
104 }
catch (
const std::exception& e) {
106 VLOG(1) <<
" " << e.what();
108 }
catch (
const std::exception& e) {
109 VLOG(1) <<
" Setting root json mapping schema failed:\n" << bridgeJsonSchema.dump(4);
110 VLOG(1) <<
" " << e.what();
112 }
catch (
const std::exception& e) {
113 VLOG(1) <<
" JSON map file parsing failed:" << e.what() <<
" at " << bridgeConfigJsonFile.tellg();
116 bridgeConfigJsonFile.close();
118 VLOG(1) <<
"BridgeJsonConfig: " << fileName <<
" not found";
123 }
catch (
const std::exception& e) {
124 VLOG(1) <<
"Parsing schema failed: " << e.what();
125 VLOG(1) << bridgeJsonSchemaString;
128 VLOG(1) <<
"MappingFile already loaded and validated";
166 for (
auto& [fullInstanceName, bridge] : bridgeMap) {
174 std::ofstream ofs(
fileName, std::ios::binary);
180 for (
const nlohmann::json& bridgeConfigJson : bridgesConfigJsonActive[
"bridges"]) {
181 bridgeMap.emplace(bridgeConfigJson[
"name"],
182 Bridge{bridgeConfigJson[
"name"], bridgeConfigJson[
"prefix"], bridgeConfigJson[
"disabled"]});
184 for (
const nlohmann::json& brokerConfigJson : bridgeConfigJson[
"brokers"]) {
185 std::list<iot::mqtt::Topic> topics;
186 for (
const nlohmann::json& topicJson : brokerConfigJson[
"topics"]) {
187 if (!topicJson[
"topic"].get<std::string>().empty()) {
188 topics.emplace_back(topicJson[
"topic"],
193 const nlohmann::json& mqtt = brokerConfigJson[
"mqtt"];
194 const nlohmann::json& network = brokerConfigJson[
"network"];
196 const std::string fullInstanceName =
197 bridgeMap.find(bridgeConfigJson[
"name"])->second.getName() +
"+" + network[
"instance_name"].get<std::string>();
199 bridgeMap.find(bridgeConfigJson[
"name"])
200 ->second.addBroker(fullInstanceName,
201 Broker(bridgeMap.find(bridgeConfigJson[
"name"])->second,
202 brokerConfigJson[
"session_store"],
205 network[
"encryption"],
206 network[
"transport"],
207 network[network[
"protocol"]],
210 mqtt[
"clean_session"],
212 mqtt[
"will_message"],
217 mqtt[
"loop_prevention"],
218 brokerConfigJson[
"prefix"],
219 brokerConfigJson[
"disabled"],