MQTTSuite
Loading...
Searching...
No Matches
mqtt::lib::MqttMapper Class Reference

#include <MqttMapper.h>

Collaboration diagram for mqtt::lib::MqttMapper:

Classes

struct  ScheduledPublish

Public Types

using MappedPublishes = std::tuple<std::vector<iot::mqtt::packets::Publish>, std::vector<ScheduledPublish>>
using ConnectParameter = std::tuple<bool, std::string, std::string, uint8_t, bool, std::string, std::string>

Public Member Functions

 MqttMapper ()
 MqttMapper (const MqttMapper &)=delete
MqttMapperoperator= (const MqttMapper &)=delete
virtual ~MqttMapper ()
bool setMapping (nlohmann::json mappingJson)
const nlohmann::json & getMapping () const
std::string getClientId () const
uint16_t getKeepAlive () const
ConnectParameter getConnectPayload () const
std::list< iot::mqtt::Topic > extractSubscriptions () const
MappedPublishes getMappings (const iot::mqtt::packets::Publish &publish)

Static Public Member Functions

static const std::string & getSchema ()
static const nlohmann::json validate (const nlohmann::json &json)
static const nlohmann::json validate (const nlohmann::json &json, nlohmann::json_schema::basic_error_handler &err)

Private Member Functions

nlohmann::json findMatchingTopicLevel (const nlohmann::json &topicLevel, const std::string &topic) const
void getMappedTemplate (const nlohmann::json &templateMapping, nlohmann::json &json, MappedPublishes &mappedPublishes) const
void getTemplateMappings (const nlohmann::json &templateMapping, nlohmann::json &json, const iot::mqtt::packets::Publish &publish, MappedPublishes &mappedPublishes) const

Static Private Member Functions

static void extractSubscription (const nlohmann::json &topicLevelJson, const std::string &topic, std::list< iot::mqtt::Topic > &topicList)
static void extractSubscriptions (const nlohmann::json &mappingJson, const std::string &topic, std::list< iot::mqtt::Topic > &topicList)
static void getStaticMappings (const nlohmann::json &staticMapping, const iot::mqtt::packets::Publish &publish, MappedPublishes &mappedPublishes)
static void getMappedMessage (const std::string &topic, const std::string &message, uint8_t qoS, bool retain, double delay, MappedPublishes &mappedPublishes)
static void getMappedMessage (const nlohmann::json &staticMapping, const iot::mqtt::packets::Publish &publish, MappedPublishes &mappedPublishes)

Private Attributes

nlohmann::json mappingJson
nlohmann::json mappingJsonUnpatched
std::list< void * > pluginHandles
inja::EnvironmentinjaEnvironment

Static Private Attributes

static const nlohmann::json_schema::json_validator validator
static const std::string mappingJsonSchemaString

Detailed Description

Definition at line 76 of file MqttMapper.h.

Member Typedef Documentation

◆ ConnectParameter

using mqtt::lib::MqttMapper::ConnectParameter = std::tuple<bool, std::string, std::string, uint8_t, bool, std::string, std::string>

Definition at line 84 of file MqttMapper.h.

◆ MappedPublishes

using mqtt::lib::MqttMapper::MappedPublishes = std::tuple<std::vector<iot::mqtt::packets::Publish>, std::vector<ScheduledPublish>>

Definition at line 83 of file MqttMapper.h.

Constructor & Destructor Documentation

◆ MqttMapper() [1/2]

mqtt::lib::MqttMapper::MqttMapper ( )

Definition at line 99 of file MqttMapper.cpp.

100 : injaEnvironment(new inja::Environment) {
101 setMapping({});
102 }
bool setMapping(nlohmann::json mappingJson)
inja::Environment * injaEnvironment
Definition MqttMapper.h:134

References injaEnvironment, and setMapping().

Here is the call graph for this function:

◆ MqttMapper() [2/2]

mqtt::lib::MqttMapper::MqttMapper ( const MqttMapper & )
delete

◆ ~MqttMapper()

mqtt::lib::MqttMapper::~MqttMapper ( )
virtual

Definition at line 104 of file MqttMapper.cpp.

104 {
105 delete injaEnvironment;
106
107 for (void* pluginHandle : pluginHandles) {
108 core::DynamicLoader::dlClose(pluginHandle);
109 }
110 }
std::list< void * > pluginHandles
Definition MqttMapper.h:132

References injaEnvironment.

Member Function Documentation

◆ extractSubscription()

void mqtt::lib::MqttMapper::extractSubscription ( const nlohmann::json & topicLevelJson,
const std::string & topic,
std::list< iot::mqtt::Topic > & topicList )
staticprivate

Definition at line 307 of file MqttMapper.cpp.

309 {
310 const std::string name = topicLevelJson["name"];
311
312 if (topicLevelJson.contains("subscription")) {
313 const uint8_t qoS = topicLevelJson["subscription"]["qos"];
314
315 topicList.emplace_back(topic + ((topic.empty() || topic == "/") && !name.empty() ? "" : "/") + name, qoS);
316 }
317
318 if (topicLevelJson.contains("topic_level")) {
319 extractSubscriptions(topicLevelJson, topic + ((topic.empty() || topic == "/") && !name.empty() ? "" : "/") + name, topicList);
320 }
321 }
std::list< iot::mqtt::Topic > extractSubscriptions() const

Referenced by extractSubscriptions().

Here is the caller graph for this function:

◆ extractSubscriptions() [1/2]

std::list< iot::mqtt::Topic > mqtt::lib::MqttMapper::extractSubscriptions ( ) const

Definition at line 232 of file MqttMapper.cpp.

232 {
233 std::list<iot::mqtt::Topic> topicList;
234
235 extractSubscriptions(mappingJson["mapping"], "", topicList);
236
237 return topicList;
238 }
nlohmann::json mappingJson
Definition MqttMapper.h:129

Referenced by mqtt::mqttintegrator::lib::Mqtt::Mqtt(), and mqtt::mqttintegrator::lib::Mqtt::resubscribe().

Here is the caller graph for this function:

◆ extractSubscriptions() [2/2]

void mqtt::lib::MqttMapper::extractSubscriptions ( const nlohmann::json & mappingJson,
const std::string & topic,
std::list< iot::mqtt::Topic > & topicList )
staticprivate

Definition at line 324 of file MqttMapper.cpp.

324 {
325 if (mappingJson.contains("topic_level")) {
326 const nlohmann::json& topicLevels = mappingJson["topic_level"];
327
328 if (topicLevels.is_object()) {
329 extractSubscription(topicLevels, topic, topicList);
330 } else {
331 for (const nlohmann::json& topicLevel : topicLevels) {
332 extractSubscription(topicLevel, topic, topicList);
333 }
334 }
335 }
336 }
static void extractSubscription(const nlohmann::json &topicLevelJson, const std::string &topic, std::list< iot::mqtt::Topic > &topicList)

References extractSubscription().

Here is the call graph for this function:

◆ findMatchingTopicLevel()

nlohmann::json mqtt::lib::MqttMapper::findMatchingTopicLevel ( const nlohmann::json & topicLevel,
const std::string & topic ) const
private

Definition at line 338 of file MqttMapper.cpp.

338 {
339 nlohmann::json foundTopicLevel;
340
341 if (topicLevel.is_object()) {
342 const std::string::size_type slashPosition = topic.find('/');
343 const std::string topicLevelName = topic.substr(0, slashPosition);
344
345 if (topicLevel["name"] == topicLevelName || topicLevel["name"] == "+" || topicLevel["name"] == "#") {
346 if (slashPosition == std::string::npos) {
347 foundTopicLevel = topicLevel;
348 } else if (topicLevel.contains("topic_level")) {
349 foundTopicLevel = findMatchingTopicLevel(topicLevel["topic_level"], topic.substr(slashPosition + 1));
350 }
351 }
352 } else if (topicLevel.is_array()) {
353 for (const nlohmann::json& topicLevelEntry : topicLevel) {
354 foundTopicLevel = findMatchingTopicLevel(topicLevelEntry, topic);
355
356 if (!foundTopicLevel.empty()) {
357 break;
358 }
359 }
360 }
361
362 return foundTopicLevel;
363 }
nlohmann::json findMatchingTopicLevel(const nlohmann::json &topicLevel, const std::string &topic) const

References findMatchingTopicLevel().

Referenced by findMatchingTopicLevel(), and getMappings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getClientId()

std::string mqtt::lib::MqttMapper::getClientId ( ) const

Definition at line 212 of file MqttMapper.cpp.

212 {
213 return mappingJson["connection"]["client_id"];
214 }

Referenced by mqtt::mqttintegrator::lib::Mqtt::Mqtt().

Here is the caller graph for this function:

◆ getConnectPayload()

MqttMapper::ConnectParameter mqtt::lib::MqttMapper::getConnectPayload ( ) const

Definition at line 220 of file MqttMapper.cpp.

220 {
221 const nlohmann::json& connectionJson = mappingJson["connection"];
222
223 return std::make_tuple(connectionJson["clean_session"],
224 connectionJson["will_topic"],
225 connectionJson["will_message"],
226 connectionJson["will_qos"],
227 connectionJson["will_retain"],
228 connectionJson["username"],
229 connectionJson["password"]);
230 }

Referenced by mqtt::mqttintegrator::lib::Mqtt::onConnected().

Here is the caller graph for this function:

◆ getKeepAlive()

uint16_t mqtt::lib::MqttMapper::getKeepAlive ( ) const

Definition at line 216 of file MqttMapper.cpp.

216 {
217 return mappingJson["connection"]["keep_alive"];
218 }

Referenced by mqtt::mqttintegrator::lib::Mqtt::Mqtt().

Here is the caller graph for this function:

◆ getMappedMessage() [1/2]

void mqtt::lib::MqttMapper::getMappedMessage ( const nlohmann::json & staticMapping,
const iot::mqtt::packets::Publish & publish,
MappedPublishes & mappedPublishes )
staticprivate

Definition at line 477 of file MqttMapper.cpp.

479 {
480 const nlohmann::json& messageMapping = staticMapping["message_mapping"];
481
482 VLOG(1) << " Message mapping: " << messageMapping.dump();
483
484 if (messageMapping.is_object()) {
485 if (messageMapping["message"] == publish.getMessage()) {
486 getMappedMessage(staticMapping["mapped_topic"],
487 messageMapping["mapped_message"],
488 staticMapping["qos"],
489 staticMapping["retain"],
490 staticMapping["delay"],
491 mappedPublishes);
492 } else {
493 VLOG(1) << " no matching mapped message found";
494 }
495 } else {
496 const nlohmann::json::const_iterator matchedMessageMappingIterator =
497 std::find_if(messageMapping.begin(), messageMapping.end(), [&publish](const nlohmann::json& messageMappingCandidat) {
498 return messageMappingCandidat["message"] == publish.getMessage();
499 });
500
501 if (matchedMessageMappingIterator != messageMapping.end()) {
502 getMappedMessage(staticMapping["mapped_topic"],
503 (*matchedMessageMappingIterator)["mapped_message"],
504 staticMapping["qos"],
505 staticMapping["retain"],
506 staticMapping["delay"],
507 mappedPublishes);
508 } else {
509 VLOG(1) << " no matching mapped message found";
510 }
511 }
512 }
static void getMappedMessage(const std::string &topic, const std::string &message, uint8_t qoS, bool retain, double delay, MappedPublishes &mappedPublishes)

Referenced by getStaticMappings().

Here is the caller graph for this function:

◆ getMappedMessage() [2/2]

void mqtt::lib::MqttMapper::getMappedMessage ( const std::string & topic,
const std::string & message,
uint8_t qoS,
bool retain,
double delay,
MappedPublishes & mappedPublishes )
staticprivate

Definition at line 457 of file MqttMapper.cpp.

458 {
459 VLOG(1) << " Mapped topic:";
460 VLOG(1) << " -> " << topic;
461 VLOG(1) << " Mapped message:";
462 VLOG(1) << " -> " << message;
463 VLOG(1) << " Send mapping:" << (delay > 0 ? " delayed" : "");
464 VLOG(1) << " Topic: " << topic;
465 VLOG(1) << " Message: " << message;
466 VLOG(1) << " QoS: " << static_cast<int>(qoS);
467 VLOG(1) << " retain: " << retain;
468 VLOG(1) << " Delay: " << delay;
469
470 if (delay < 0.0) {
471 std::get<0>(mappedPublishes).emplace_back(0, topic, message, qoS, false, retain);
472 } else {
473 std::get<1>(mappedPublishes).push_back({delay, iot::mqtt::packets::Publish(0, topic, message, qoS, false, retain)});
474 }
475 }

Referenced by getMappedTemplate().

Here is the caller graph for this function:

◆ getMappedTemplate()

void mqtt::lib::MqttMapper::getMappedTemplate ( const nlohmann::json & templateMapping,
nlohmann::json & json,
MappedPublishes & mappedPublishes ) const
private

Definition at line 366 of file MqttMapper.cpp.

366 {
367 const std::string& mappingTemplate = templateMapping["mapping_template"];
368 const std::string& mappedTopic = templateMapping["mapped_topic"];
369
370 try {
371 // Render topic
372 const std::string renderedTopic = injaEnvironment->render(mappedTopic, json);
373 json["mapped_topic"] = renderedTopic;
374
375 VLOG(1) << " Mapped topic template: " << mappedTopic;
376 VLOG(1) << " -> " << renderedTopic;
377
378 try {
379 // Render message
380 const std::string renderedMessage = injaEnvironment->render(mappingTemplate, json);
381 VLOG(1) << " Mapped message template: " << mappingTemplate;
382 VLOG(1) << " -> " << renderedMessage;
383
384 const nlohmann::json& suppressions = templateMapping["suppressions"];
385 const bool retain = templateMapping["retain"];
386
387 if (suppressions.empty() || std::find(suppressions.begin(), suppressions.end(), renderedMessage) == suppressions.end() ||
388 (retain && renderedMessage.empty())) {
389 const uint8_t qoS = templateMapping["qos"];
390 const double delay = templateMapping["delay"];
391
392 VLOG(1) << " Send mapping:" << (delay > 0 ? " delayed" : "");
393 VLOG(1) << " Topic: " << renderedTopic;
394 VLOG(1) << " Message: " << renderedMessage << "";
395 VLOG(1) << " QoS: " << static_cast<int>(qoS);
396 VLOG(1) << " retain: " << retain;
397 VLOG(1) << " Delay: " << delay;
398
399 getMappedMessage(renderedTopic, renderedMessage, qoS, retain, delay, mappedPublishes);
400 } else {
401 VLOG(1) << " Rendered message: '" << renderedMessage << "' in suppression list:";
402 for (const nlohmann::json& item : suppressions) {
403 VLOG(1) << " '" << item.get<std::string>() << "'";
404 }
405 VLOG(1) << " Send mapping: suppressed";
406 }
407 } catch (const inja::InjaError& e) {
408 VLOG(1) << " Message template rendering failed: " << mappingTemplate << " : " << json.dump();
409 VLOG(1) << " What: " << e.what();
410 VLOG(1) << " INJA: " << e.type << ": " << e.message;
411 VLOG(1) << " INJA (line:column):" << e.location.line << ":" << e.location.column;
412 }
413 } catch (const inja::InjaError& e) {
414 VLOG(1) << " Topic template rendering failed: " << mappingTemplate << " : " << json.dump();
415 VLOG(1) << " What: " << e.what();
416 VLOG(1) << " INJA: " << e.type << ": " << e.message;
417 VLOG(1) << " INJA (line:column):" << e.location.line << ":" << e.location.column;
418 }
419 }
nlohmann::json json
const std::string type
Definition inja.hpp:283
const SourceLocation location
Definition inja.hpp:286
const std::string message
Definition inja.hpp:284

References inja::SourceLocation::column, getMappedMessage(), injaEnvironment, inja::SourceLocation::line, inja::InjaError::location, inja::InjaError::message, inja::Environment::render(), and inja::InjaError::type.

Referenced by getTemplateMappings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMapping()

const nlohmann::json & mqtt::lib::MqttMapper::getMapping ( ) const

Definition at line 208 of file MqttMapper.cpp.

208 {
210 }
nlohmann::json mappingJsonUnpatched
Definition MqttMapper.h:130

References mappingJsonUnpatched.

Referenced by mqtt::lib::ConfigApplication::getMapping(), and mqtt::lib::admin::makeMappingAdminRouter().

Here is the caller graph for this function:

◆ getMappings()

MqttMapper::MappedPublishes mqtt::lib::MqttMapper::getMappings ( const iot::mqtt::packets::Publish & publish)

Definition at line 240 of file MqttMapper.cpp.

240 {
241 MappedPublishes mappedPublishes;
242 if (mappingJson.contains("mapping") && !mappingJson["mapping"].empty()) {
243 nlohmann::json matchingTopicLevel = findMatchingTopicLevel(mappingJson["mapping"]["topic_level"], publish.getTopic());
244
245 if (!matchingTopicLevel.empty()) {
246 const nlohmann::json& subscription = matchingTopicLevel["subscription"];
247
248 if (subscription.contains("static")) {
249 VLOG(1) << "Topic mapping found for:";
250 VLOG(1) << " Type: static";
251 VLOG(1) << " Topic: " << publish.getTopic();
252 VLOG(1) << " Message: " << publish.getMessage();
253 VLOG(1) << " QoS: " << static_cast<uint16_t>(publish.getQoS());
254 VLOG(1) << " Retain: " << publish.getRetain();
255
256 getStaticMappings(subscription["static"], publish, mappedPublishes);
257 }
258
259 if (subscription.contains("value")) {
260 VLOG(1) << "Topic mapping found for:";
261 VLOG(1) << " Type: value";
262 VLOG(1) << " Topic: " << publish.getTopic();
263 VLOG(1) << " Message: " << publish.getMessage();
264 VLOG(1) << " QoS: " << static_cast<uint16_t>(publish.getQoS());
265 VLOG(1) << " Retain: " << publish.getRetain();
266
267 nlohmann::json json;
268 json["message"] = publish.getMessage();
269
270 getTemplateMappings(subscription["value"], json, publish, mappedPublishes);
271 }
272
273 if (subscription.contains("json")) {
274 VLOG(1) << "Topic mapping found for:";
275 VLOG(1) << " Type: json";
276 VLOG(1) << " Topic: " << publish.getTopic();
277 VLOG(1) << " Message: " << publish.getMessage();
278 VLOG(1) << " QoS: " << static_cast<uint16_t>(publish.getQoS());
279 VLOG(1) << " Retain: " << publish.getRetain();
280
281 try {
282 nlohmann::json json;
283 json["message"] = nlohmann::json::parse(publish.getMessage());
284
285 getTemplateMappings(subscription["json"], json, publish, mappedPublishes);
286 } catch (const nlohmann::json::parse_error& e) {
287 VLOG(1) << " Parsing message into json failed: " << publish.getMessage();
288 VLOG(1) << " What: " << e.what() << '\n'
289 << " Exception Id: " << e.id << '\n'
290 << " Byte position of error: " << e.byte;
291 }
292 }
293 }
294 }
295
296 return mappedPublishes;
297 }
void getTemplateMappings(const nlohmann::json &templateMapping, nlohmann::json &json, const iot::mqtt::packets::Publish &publish, MappedPublishes &mappedPublishes) const
std::tuple< std::vector< iot::mqtt::packets::Publish >, std::vector< ScheduledPublish > > MappedPublishes
Definition MqttMapper.h:83
static void getStaticMappings(const nlohmann::json &staticMapping, const iot::mqtt::packets::Publish &publish, MappedPublishes &mappedPublishes)

References findMatchingTopicLevel(), getStaticMappings(), and getTemplateMappings().

Referenced by mqtt::mqttbroker::lib::Mqtt::onPublish(), and mqtt::mqttintegrator::lib::Mqtt::onPublish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSchema()

const std::string & mqtt::lib::MqttMapper::getSchema ( )
static

Definition at line 112 of file MqttMapper.cpp.

112 {
114 }
static const std::string mappingJsonSchemaString
Definition MqttMapper.h:138

References mappingJsonSchemaString.

Referenced by mqtt::lib::admin::makeMappingAdminRouter().

Here is the caller graph for this function:

◆ getStaticMappings()

void mqtt::lib::MqttMapper::getStaticMappings ( const nlohmann::json & staticMapping,
const iot::mqtt::packets::Publish & publish,
MappedPublishes & mappedPublishes )
staticprivate

Definition at line 445 of file MqttMapper.cpp.

447 {
448 if (staticMapping.is_object()) {
449 getMappedMessage(staticMapping, publish, mappedPublishes);
450 } else if (staticMapping.is_array()) {
451 for (const nlohmann::json& concreteStaticMapping : staticMapping) {
452 getMappedMessage(concreteStaticMapping, publish, mappedPublishes);
453 }
454 }
455 }

References getMappedMessage().

Referenced by getMappings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTemplateMappings()

void mqtt::lib::MqttMapper::getTemplateMappings ( const nlohmann::json & templateMapping,
nlohmann::json & json,
const iot::mqtt::packets::Publish & publish,
MappedPublishes & mappedPublishes ) const
private

Definition at line 421 of file MqttMapper.cpp.

424 {
425 json["topic"] = publish.getTopic();
426 json["qos"] = publish.getQoS();
427 json["retain"] = publish.getRetain();
428 json["package_identifier"] = publish.getPacketIdentifier();
429
430 try {
431 VLOG(1) << " Render data: " << json.dump();
432
433 if (templateMapping.is_object()) {
434 getMappedTemplate(templateMapping, json, mappedPublishes);
435 } else {
436 for (const nlohmann::json& concreteTemplateMapping : templateMapping) {
437 getMappedTemplate(concreteTemplateMapping, json, mappedPublishes);
438 }
439 }
440 } catch (const nlohmann::json::exception& e) {
441 VLOG(1) << "JSON Exception during Render data:\n" << e.what();
442 }
443 }
void getMappedTemplate(const nlohmann::json &templateMapping, nlohmann::json &json, MappedPublishes &mappedPublishes) const

References getMappedTemplate().

Referenced by getMappings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

MqttMapper & mqtt::lib::MqttMapper::operator= ( const MqttMapper & )
delete

◆ setMapping()

bool mqtt::lib::MqttMapper::setMapping ( nlohmann::json mappingJson)

Definition at line 116 of file MqttMapper.cpp.

116 { // can throw
117 delete injaEnvironment;
118
119 for (void* handle : pluginHandles) {
120 core::DynamicLoader::dlClose(handle);
121 }
122 pluginHandles.clear();
123
124 injaEnvironment = new inja::Environment;
125
126 nlohmann::json defaultPatch;
127 try {
128 defaultPatch = validator.validate(mappingJson);
129 } catch (const std::exception& e) {
130 throw std::runtime_error("Validating JSON failed: Mapping JSON = " + mappingJson.dump(4) + "\n" + e.what());
131 }
132
133 nlohmann::json oldMappingJson = this->mappingJson;
134 try {
135 this->mappingJson = mappingJson.patch(defaultPatch);
136 if (mappingJson.empty()) {
137 this->mappingJsonUnpatched = this->mappingJson;
138 } else {
140 }
141 } catch (const std::exception& e) {
142 throw std::runtime_error("Patching JSON with default patch failed: Default patch = " + defaultPatch.dump(4) + "\n" + e.what());
143 }
144
145 bool mustReconnect = this->mappingJson["connection"] != oldMappingJson["connection"];
146
147 if (mappingJson["mapping"].contains("plugins")) {
148 VLOG(1) << "Loading plugins ...";
149 for (const nlohmann::json& pluginJson : mappingJson["mapping"]["plugins"]) {
150 const std::string plugin = pluginJson;
151
152 void* handle = core::DynamicLoader::dlOpen(plugin);
153
154 if (handle != nullptr) {
155 pluginHandles.push_back(handle);
156
157 VLOG(1) << " Loading plugin: " << plugin << " ...";
158
159 const std::vector<mqtt::lib::Function>* loadedFunctions =
160 static_cast<std::vector<mqtt::lib::Function>*>(core::DynamicLoader::dlSym(handle, "functions"));
161 if (loadedFunctions != nullptr) {
162 VLOG(1) << " Registering inja 'none void callbacks'";
163 for (const mqtt::lib::Function& function : *loadedFunctions) {
164 VLOG(1) << " " << function.name;
165
166 if (function.numArgs >= 0) {
167 injaEnvironment->add_callback(function.name, function.numArgs, function.function);
168 } else {
169 injaEnvironment->add_callback(function.name, function.function);
170 }
171 }
172 VLOG(1) << " Registering inja 'none void callbacks done'";
173 } else {
174 VLOG(1) << " No inja none 'void callbacks found' in plugin " << plugin;
175 }
176
177 const std::vector<mqtt::lib::VoidFunction>* loadedVoidFunctions =
178 static_cast<std::vector<mqtt::lib::VoidFunction>*>(core::DynamicLoader::dlSym(handle, "voidFunctions"));
179 if (loadedVoidFunctions != nullptr) {
180 VLOG(1) << " Registering inja 'void callbacks'";
181 for (const mqtt::lib::VoidFunction& voidFunction : *loadedVoidFunctions) {
182 VLOG(1) << " " << voidFunction.name;
183
184 if (voidFunction.numArgs >= 0) {
185 injaEnvironment->add_void_callback(voidFunction.name, voidFunction.numArgs, voidFunction.function);
186 } else {
187 injaEnvironment->add_void_callback(voidFunction.name, voidFunction.function);
188 }
189 }
190 VLOG(1) << " Registering inja 'void callbacks' done";
191 } else {
192 VLOG(1) << " No inja 'void callbacks' found in plugin " << plugin;
193 }
194
195 VLOG(1) << " Loading plugin done: " << plugin;
196 } else {
197 VLOG(1) << " Error loading plugin: " << plugin;
198 throw std::runtime_error("Error loading plugin '" + plugin + "': " + core::DynamicLoader::dlError());
199 }
200 }
201
202 VLOG(1) << "Loading plugins done";
203 }
204
205 return mustReconnect;
206 }
static const nlohmann::json_schema::json_validator validator
Definition MqttMapper.h:136

References injaEnvironment, mappingJson, mappingJsonUnpatched, pluginHandles, nlohmann::json_schema::json_validator::validate(), and validator.

Referenced by mqtt::lib::admin::makeMappingAdminRouter(), MqttMapper(), and mqtt::lib::ConfigApplication::setMapping().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate() [1/2]

const nlohmann::json mqtt::lib::MqttMapper::validate ( const nlohmann::json & json)
static

Definition at line 299 of file MqttMapper.cpp.

299 {
300 return validator.validate(json);
301 }

References nlohmann::json_schema::json_validator::validate(), and validator.

Referenced by mqtt::lib::JsonMappingReader::rollbackTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate() [2/2]

const nlohmann::json mqtt::lib::MqttMapper::validate ( const nlohmann::json & json,
nlohmann::json_schema::basic_error_handler & err )
static

Definition at line 303 of file MqttMapper.cpp.

303 {
304 return validator.validate(json, err);
305 }

References nlohmann::json_schema::json_validator::validate(), and validator.

Referenced by mqtt::lib::admin::makeMappingAdminRouter().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ injaEnvironment

inja::Environment* mqtt::lib::MqttMapper::injaEnvironment
private

Definition at line 134 of file MqttMapper.h.

Referenced by getMappedTemplate(), MqttMapper(), setMapping(), and ~MqttMapper().

◆ mappingJson

nlohmann::json mqtt::lib::MqttMapper::mappingJson
private

Definition at line 129 of file MqttMapper.h.

Referenced by setMapping().

◆ mappingJsonSchemaString

const std::string mqtt::lib::MqttMapper::mappingJsonSchemaString
staticprivate

Definition at line 138 of file MqttMapper.h.

Referenced by getSchema().

◆ mappingJsonUnpatched

nlohmann::json mqtt::lib::MqttMapper::mappingJsonUnpatched
private

Definition at line 130 of file MqttMapper.h.

Referenced by getMapping(), and setMapping().

◆ pluginHandles

std::list<void*> mqtt::lib::MqttMapper::pluginHandles
private

Definition at line 132 of file MqttMapper.h.

Referenced by setMapping().

◆ validator

const nlohmann::json_schema::json_validator mqtt::lib::MqttMapper::validator
staticprivate

Definition at line 136 of file MqttMapper.h.

Referenced by setMapping(), validate(), and validate().


The documentation for this class was generated from the following files: