2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
48#include "log/Logger.h"
56#include <nlohmann/json_fwd.hpp>
62 template <
typename ConcretConfigApplication>
64 : utils::SubCommand(parent, concretConfigApplication,
"Applications")
68 "--mqtt-mapping-file",
69 [
this](
const std::string& mappFilename) {
72 }
catch (std::runtime_error& e) {
75 throw CLI::ValidationError(getName(),
76 std::string(
"Activating mapping description in '" + mappFilename +
82 "MQTT mapping file (json format) for integration",
84 !CLI::ExistingDirectory))
87 "--mqtt-session-store",
88 "Path to file for the persistent session store",
90 !CLI::ExistingDirectory)) {
128 bool success =
false;
130 std::ofstream mapFile(
mapFilename, std::ios::trunc);
131 if (mapFile.is_open()) {
137 VLOG(1) <<
"Write mapping file seccess";
138 }
catch (
const std::exception& e) {
139 VLOG(1) <<
"Write mapping file failed: " << e.what();
144 VLOG(1) <<
"Cannot open mapping file for writing: " <<
mapFilename;
151 VLOG(1) <<
"Mapping file: " << mapFilename;
155 bool mustReconnect =
true;
157 if (!mapFilename.empty()) {
158 std::ifstream mapFile(mapFilename);
160 if (mapFile.is_open()) {
162 mustReconnect =
setMapping({std::istreambuf_iterator<
char>(mapFile), std::istreambuf_iterator<
char>()}
);
166 VLOG(1) <<
"Load mapping file success";
167 }
catch (
const std::exception& e) {
170 throw std::runtime_error(
"Loading mapping description from '" + mapFilename +
177 VLOG(1) <<
"Mapping file '" + mapFilename +
178 "' not found. Please provide a valid mapping file with the option --mqtt-mapping-file";
182 return mustReconnect;
190 "HTML root directory",
192 CLI::ExistingDirectory)) {
206 std::string htmlRoot;
std::string getMapping(int indent=2) const
bool loadMapping(const std::string mapFilename)
CLI::Option * sessionStoreOpt
std::string getMappingFilename() const
bool setMapping(const std::string &mapping) const
const std::shared_ptr< MqttMapper > getMqttMapper() const
bool setMappingFile(const std::string &mapFilename)
bool persistMapping() const
ConfigApplication & setSessionStore(const std::string &sessionStore)
ConfigApplication(utils::SubCommand *parent, ConcretConfigApplicationT *concretConfigApplication)
CLI::Option * mappingFileOpt
~ConfigApplication() override
std::shared_ptr< MqttMapper > mqttMapper
std::string getSessionStore() const
ConfigMqttBroker & setHtmlRoot(const std::string &htmlRoot)
std::string getHtmlRoot()
CLI::Option * htmlRootOpt
ConfigMqttBroker(utils::SubCommand *parent)
~ConfigMqttBroker() override
~ConfigMqttIntegrator() override
ConfigMqttIntegrator(utils::SubCommand *parent)
bool setMapping(nlohmann::json mappingJson)
const nlohmann::json & getMapping() const