Leosac  0.8.0
Open Source Access Control
MqttExternalServer.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 
24 #include "tools/log.hpp"
25 #include <chrono>
26 #include <zmqpp/zmqpp.hpp>
27 #include <mqtt/async_client.h>
28 
29 namespace Leosac
30 {
31 namespace Module
32 {
33 namespace Mqtt
34 {
39 {
40  public:
45  MqttExternalServer(zmqpp::context &ctx, std::shared_ptr<const MqttServerConfig> config,
46  const std::vector<std::shared_ptr<const MqttExternalMessage>> &topics);
47 
48  void register_sockets(zmqpp::reactor *reactor);
49 
50  void connect();
51 
52  void disconnect();
53 
57  void handle_topic_request(const std::string& topic_name);
58 
62  void handle_mqtt_msg(mqtt::const_message_ptr msg);
63 
67  void handle_request();
68 
69  std::shared_ptr<const MqttServerConfig> config() const;
70 
71  const std::vector<std::shared_ptr<const MqttExternalMessage>>& topics() const;
72 
73  const std::string& name() const;
74 
75  private:
76 
80  zmqpp::socket sock_;
81 
85  zmqpp::socket bus_push_;
86 
90  std::map<std::string, zmqpp::socket> topic_socks_;
91 
95  std::shared_ptr<mqtt::async_client> client_;
96 
97  std::shared_ptr<const MqttServerConfig> config_;
98 
99  std::vector<std::shared_ptr<const MqttExternalMessage>> topics_;
100 };
101 }
102 }
103 }
FGPIO.hpp
Leosac::Module::Mqtt::MqttExternalServer::topics_
std::vector< std::shared_ptr< const MqttExternalMessage > > topics_
Definition: MqttExternalServer.hpp:99
Leosac::Module::Mqtt::MqttExternalServer::handle_mqtt_msg
void handle_mqtt_msg(mqtt::const_message_ptr msg)
Message received from mqtt.
Definition: MqttExternalServer.cpp:253
Leosac::Module::Mqtt::MqttExternalServer::register_sockets
void register_sockets(zmqpp::reactor *reactor)
Definition: MqttExternalServer.cpp:147
Leosac::Module::Mqtt::MqttExternalServer::handle_request
void handle_request()
Someone sent a request.
Definition: MqttExternalServer.cpp:306
MqttConfig.hpp
Leosac::Module::Mqtt::MqttExternalServer::bus_push_
zmqpp::socket bus_push_
Socket to write to the message bus.
Definition: MqttExternalServer.hpp:85
Leosac::Module::Mqtt::MqttExternalServer::config_
std::shared_ptr< const MqttServerConfig > config_
Definition: MqttExternalServer.hpp:97
Leosac::Module::Mqtt::MqttExternalServer::client_
std::shared_ptr< mqtt::async_client > client_
The MQTT client.
Definition: MqttExternalServer.hpp:95
Leosac::Module::Mqtt::MqttExternalServer
Implementation class, for use by the Mqtt module only.
Definition: MqttExternalServer.hpp:38
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Mqtt::MqttExternalServer::name
const std::string & name() const
Definition: MqttExternalServer.cpp:344
Leosac::Module::Mqtt::MqttExternalServer::topics
const std::vector< std::shared_ptr< const MqttExternalMessage > > & topics() const
Definition: MqttExternalServer.cpp:349
Leosac::Module::Mqtt::MqttExternalServer::handle_topic_request
void handle_topic_request(const std::string &topic_name)
Request received on the topic specific socket.
Definition: MqttExternalServer.cpp:192
Leosac::Module::Mqtt::MqttExternalServer::topic_socks_
std::map< std::string, zmqpp::socket > topic_socks_
REP socket to receive command on for topics.
Definition: MqttExternalServer.hpp:90
Leosac::Module::Mqtt::MqttExternalServer::connect
void connect()
Definition: MqttExternalServer.cpp:158
Leosac::Module::Mqtt::MqttExternalServer::config
std::shared_ptr< const MqttServerConfig > config() const
Definition: MqttExternalServer.cpp:354
log.hpp
Leosac::Module::Mqtt::MqttExternalServer::MqttExternalServer
MqttExternalServer(zmqpp::context &ctx, std::shared_ptr< const MqttServerConfig > config, const std::vector< std::shared_ptr< const MqttExternalMessage >> &topics)
Definition: MqttExternalServer.cpp:118
Leosac::Module::Mqtt::MqttExternalServer::sock_
zmqpp::socket sock_
REP socket to receive command on.
Definition: MqttExternalServer.hpp:80
Leosac::Module::Mqtt::MqttExternalServer::disconnect
void disconnect()
Definition: MqttExternalServer.cpp:187