Leosac  0.8.0
Open Source Access Control
MqttConfig.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2022 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #define ODB_NO_BASE_VERSION
25 #include "hardware/HardwareFwd.hpp"
26 #include "modules/mqtt/MqttFwd.hpp"
27 #include "tools/db/database.hpp"
28 #include <chrono>
29 
30 #pragma db model version(1, 1, open)
31 
32 namespace Leosac
33 {
34 namespace Module
35 {
36 namespace Mqtt
37 {
38 
43 #pragma db object callback(validation_callback) table("HARDWARE_ExternalServer_Mqtt")
45 {
47  : Hardware::ExternalServer("localhost", 1883)
48  , client_id_("leosac")
49  , subscribe_prefix_("homeassistant/")
50  , publish_prefix_("leosac/")
51  , ssl_(false)
52  {
53  }
54 
55  MqttServerConfig(const MqttServerConfig &) = default;
56 
57  std::string client_id() const
58  {
59  return client_id_;
60  }
61 
62  std::string subscribe_prefix() const
63  {
64  return subscribe_prefix_;
65  }
66 
67  std::string publish_prefix() const
68  {
69  return publish_prefix_;
70  }
71 
72  std::string username() const
73  {
74  return username_;
75  }
76 
77  std::string password() const
78  {
79  return password_;
80  }
81 
82  bool ssl() const
83  {
84  return ssl_;
85  }
86 
87  std::string ssl_ca_certs() const
88  {
89  return ssl_ca_certs_;
90  }
91 
92  std::string ssl_client_certfile() const
93  {
94  return ssl_client_certfile_;
95  }
96 
97  std::string ssl_client_keyfile() const
98  {
99  return ssl_client_keyfile_;
100  }
101 
102  bool ssl_insecure() const
103  {
104  return ssl_insecure_;
105  }
106 
110  void validation_callback(odb::callback_event, odb::database &) const;
111 
112  std::string client_id_;
113  std::string subscribe_prefix_;
114  std::string publish_prefix_;
115  std::string username_;
116  std::string password_;
117  bool ssl_;
118  std::string ssl_ca_certs_;
119  std::string ssl_client_certfile_;
120  std::string ssl_client_keyfile_;
122 };
123 
124 #pragma db object callback(validation_callback) table("HARDWARE_ExternalMessage_Mqtt")
126 {
128  {
129  }
130 
131  MqttExternalMessage(const MqttExternalMessage &) = default;
132 };
133 
142 {
143  public:
144  MqttConfig() = default;
145 
146  void add_server(std::shared_ptr<const MqttServerConfig>);
147  void add_topic(std::shared_ptr<const MqttExternalMessage>);
148  const std::vector<std::shared_ptr<const MqttServerConfig>> &servers() const;
149  const std::vector<std::shared_ptr<const MqttExternalMessage>> &topics() const;
150 
151  private:
152  std::vector<std::shared_ptr<const MqttServerConfig>> servers_;
153  std::vector<std::shared_ptr<const MqttExternalMessage>> topics_;
154 };
155 }
156 }
157 }
Leosac::Module::Mqtt::MqttServerConfig::client_id
std::string client_id() const
Definition: MqttConfig.hpp:57
Leosac::Module::Mqtt::MqttExternalMessage::MqttExternalMessage
MqttExternalMessage()
Definition: MqttConfig.hpp:127
Leosac::Module::Mqtt::MqttServerConfig
An instance of this class represents the configuration of one Mqtt server.
Definition: MqttConfig.hpp:44
ExternalMessage.hpp
Leosac::Module::Mqtt::MqttServerConfig::ssl_client_keyfile_
std::string ssl_client_keyfile_
Definition: MqttConfig.hpp:120
Leosac::Module::Mqtt::MqttServerConfig::password
std::string password() const
Definition: MqttConfig.hpp:77
database.hpp
Leosac::Module::Mqtt::MqttConfig::add_server
void add_server(std::shared_ptr< const MqttServerConfig >)
Definition: MqttConfig.cpp:31
Leosac::Module::Mqtt::MqttServerConfig::subscribe_prefix
std::string subscribe_prefix() const
Definition: MqttConfig.hpp:62
Leosac::Module::Mqtt::MqttServerConfig::ssl_insecure
bool ssl_insecure() const
Definition: MqttConfig.hpp:102
Leosac::Module::Mqtt::MqttConfig
Transient configuration object that stores the list of mqtt servers use/configure.
Definition: MqttConfig.hpp:141
Leosac::Module::Mqtt::MqttConfig::add_topic
void add_topic(std::shared_ptr< const MqttExternalMessage >)
Definition: MqttConfig.cpp:41
Leosac::Module::Mqtt::MqttServerConfig::password_
std::string password_
Definition: MqttConfig.hpp:116
ExternalServer.hpp
Leosac::Module::Mqtt::MqttConfig::servers
const std::vector< std::shared_ptr< const MqttServerConfig > > & servers() const
Definition: MqttConfig.cpp:36
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Mqtt::MqttServerConfig::ssl_client_certfile
std::string ssl_client_certfile() const
Definition: MqttConfig.hpp:92
Leosac::Module::Mqtt::MqttServerConfig::subscribe_prefix_
std::string subscribe_prefix_
Definition: MqttConfig.hpp:113
Leosac::Module::Mqtt::MqttServerConfig::MqttServerConfig
MqttServerConfig()
Definition: MqttConfig.hpp:46
Leosac::Module::Mqtt::MqttServerConfig::username
std::string username() const
Definition: MqttConfig.hpp:72
Leosac::Module::Mqtt::MqttConfig::topics_
std::vector< std::shared_ptr< const MqttExternalMessage > > topics_
Definition: MqttConfig.hpp:153
Leosac::Module::Mqtt::MqttConfig::MqttConfig
MqttConfig()=default
Leosac::Module::Mqtt::MqttServerConfig::publish_prefix
std::string publish_prefix() const
Definition: MqttConfig.hpp:67
Leosac::Module::Mqtt::MqttExternalMessage
Definition: MqttConfig.hpp:125
Leosac::Module::Mqtt::MqttServerConfig::ssl
bool ssl() const
Definition: MqttConfig.hpp:82
Leosac::Module::Mqtt::MqttConfig::topics
const std::vector< std::shared_ptr< const MqttExternalMessage > > & topics() const
Definition: MqttConfig.cpp:46
HardwareFwd.hpp
Leosac::Module::Mqtt::MqttServerConfig::ssl_client_certfile_
std::string ssl_client_certfile_
Definition: MqttConfig.hpp:119
Leosac::Hardware::ExternalMessage
Abstraction of an External Messaging device.
Definition: ExternalMessage.hpp:41
Leosac::Module::Mqtt::MqttServerConfig::username_
std::string username_
Definition: MqttConfig.hpp:115
Leosac::Module::Mqtt::MqttServerConfig::client_id_
std::string client_id_
Definition: MqttConfig.hpp:112
Leosac::Module::Mqtt::MqttServerConfig::ssl_
bool ssl_
Definition: MqttConfig.hpp:117
Leosac::Module::Mqtt::MqttConfig::servers_
std::vector< std::shared_ptr< const MqttServerConfig > > servers_
Definition: MqttConfig.hpp:152
Leosac::Module::Mqtt::MqttServerConfig::ssl_insecure_
bool ssl_insecure_
Definition: MqttConfig.hpp:121
Leosac::Hardware::ExternalServer
Abstraction of an External Server device.
Definition: ExternalServer.hpp:38
Leosac::Module::Mqtt::MqttServerConfig::ssl_client_keyfile
std::string ssl_client_keyfile() const
Definition: MqttConfig.hpp:97
Leosac::Module::Mqtt::MqttServerConfig::validation_callback
void validation_callback(odb::callback_event, odb::database &) const
ODB callback wrt database operation.
Definition: MqttConfig.cpp:51
MqttFwd.hpp
Leosac::Module::Mqtt::MqttServerConfig::ssl_ca_certs
std::string ssl_ca_certs() const
Definition: MqttConfig.hpp:87
Leosac::Module::Mqtt::MqttServerConfig::publish_prefix_
std::string publish_prefix_
Definition: MqttConfig.hpp:114
Leosac::Hardware::ExternalServer::ExternalServer
ExternalServer()
Definition: ExternalServer.cpp:27
Leosac::Module::Mqtt::MqttServerConfig::ssl_ca_certs_
std::string ssl_ca_certs_
Definition: MqttConfig.hpp:118