MQTTSuite
Loading...
Searching...
No Matches
StoragePlan.h
Go to the documentation of this file.
1/*
2 * MQTTSuite - A lightweight MQTT Integration System
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2022, 2023, 2024, 2025, 2026
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 */
11
12#ifndef MQTTSTORE_LIB_STORAGEPLAN_H
13#define MQTTSTORE_LIB_STORAGEPLAN_H
14
15#include <nlohmann/json_fwd.hpp>
16
17#ifndef DOXYGEN_SHOULD_SKIP_THIS
18
19#include <cstddef>
20#include <optional>
21#include <string>
22#include <vector>
23
24#endif
25
26namespace mqtt::mqttstore::lib {
27
29 public:
31 std::string column;
32 std::string jsonPointer;
33 std::optional<std::size_t> topicLevel;
34 std::optional<std::string> literal;
35 bool required = false;
36 };
37
38 struct Projection {
39 std::string name;
40 std::string topic;
41 std::string table;
42 std::vector<ColumnMapping> columns;
43 };
44
45 [[nodiscard]] static StoragePlan fromFile(const std::string& fileName);
46 [[nodiscard]] static StoragePlan fromJson(const nlohmann::json& json);
47
48 [[nodiscard]] const std::vector<Projection>& getProjections() const;
49 [[nodiscard]] std::vector<const Projection*> match(const std::string& topic) const;
50
51 private:
52 static bool topicMatches(const std::string& filter, const std::string& topic);
53 std::vector<Projection> projections;
54 };
55
56} // namespace mqtt::mqttstore::lib
57
58#endif // MQTTSTORE_LIB_STORAGEPLAN_H
static std::string quoteIdentifier(const std::string &identifier)
static std::string buildRawInsertSql(const std::string &rawTable, const MqttMessage &message, const std::optional< nlohmann::json > &payloadJson)
static std::string jsonValueForColumn(const StoragePlan::ColumnMapping &mapping, const MqttMessage &message, const nlohmann::json &payloadJson)
static std::string sqlValue(const nlohmann::json &value)
static bool hasBinaryContent(const std::string &payload)
MariaDbStorage(const std::string &connectionName, const ConnectionConfig &connectionConfig, std::string rawTable, bool autoCreateRawTable, StoragePlan storagePlan)
static bool isSafeIdentifier(const std::string &identifier)
void storeProjections(const MqttMessage &message, const std::optional< nlohmann::json > &payloadJson)
static std::string buildProjectionInsertSql(const StoragePlan::Projection &projection, const MqttMessage &message, const nlohmann::json &payloadJson)
database::mariadb::MariaDBClient mariaDB
static std::optional< nlohmann::json > parsePayload(const std::string &payload)
void store(const MqttMessage &message)
static void execLogFailure(const std::string &connectionName, const std::string &operation, const std::string &errorString, unsigned int errorNumber)
static std::string sqlQuote(const std::string &value)
void onConnected() final
Definition Mqtt.cpp:74
const std::string willTopic
Definition Mqtt.h:68
Mqtt(const std::string &connectionName, const std::string &clientId, std::uint8_t qoSDefault, std::uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, std::uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, const std::list< std::string > &subTopics, MariaDbStorage::ConnectionConfig connectionConfig, const std::string &rawTable, bool autoCreateRawTable, StoragePlan storagePlan, const std::string &sessionStoreFileName="")
Definition Mqtt.cpp:37
const std::uint8_t qoSDefault
Definition Mqtt.h:66
MariaDbStorage storage
Definition Mqtt.h:65
void onConnack(const iot::mqtt::packets::Connack &connack) final
Definition Mqtt.cpp:97
const bool cleanSession
Definition Mqtt.h:67
const bool willRetain
Definition Mqtt.h:71
const std::string willMessage
Definition Mqtt.h:69
iot::mqtt::client::Mqtt Super
Definition Mqtt.h:54
const std::uint8_t willQoS
Definition Mqtt.h:70
bool onSignal(int signum) final
Definition Mqtt.cpp:79
const std::list< std::string > subTopics
Definition Mqtt.h:74
void onPublish(const iot::mqtt::packets::Publish &publish) final
Definition Mqtt.cpp:136
const std::string username
Definition Mqtt.h:72
const std::string password
Definition Mqtt.h:73
static std::uint8_t getQos(const std::string &qoSString)
Definition Mqtt.cpp:87
void onSuback(const iot::mqtt::packets::Suback &suback) final
Definition Mqtt.cpp:150
const std::vector< Projection > & getProjections() const
std::vector< const Projection * > match(const std::string &topic) const
static StoragePlan fromJson(const nlohmann::json &json)
static StoragePlan fromFile(const std::string &fileName)
static bool topicMatches(const std::string &filter, const std::string &topic)
std::vector< Projection > projections
Definition StoragePlan.h:53
std::vector< ColumnMapping > columns
Definition StoragePlan.h:42