MQTTSuite
Loading...
Searching...
No Matches
mqtt::mqttcli::SocketContextFactory Class Reference

#include <SocketContextFactory.h>

Inheritance diagram for mqtt::mqttcli::SocketContextFactory:
Collaboration diagram for mqtt::mqttcli::SocketContextFactory:

Public Member Functions

 SocketContextFactory ()=default
core::socket::stream::SocketContext * create (core::socket::stream::SocketConnection *socketConnection) final

Detailed Description

Definition at line 53 of file SocketContextFactory.h.

Constructor & Destructor Documentation

◆ SocketContextFactory()

mqtt::mqttcli::SocketContextFactory::SocketContextFactory ( )
default

Member Function Documentation

◆ create()

core::socket::stream::SocketContext * mqtt::mqttcli::SocketContextFactory::create ( core::socket::stream::SocketConnection * socketConnection)
final

Definition at line 62 of file SocketContextFactory.cpp.

62 {
63 const CLI::App* sessionApp = socketConnection->getConfigInstance()->getSection("session", true, true);
64 const CLI::App* subApp = socketConnection->getConfigInstance()->getSection("sub", true, true);
65 const CLI::App* pubApp = socketConnection->getConfigInstance()->getSection("pub", true, true);
66
67 subApp = (subApp != nullptr && (*subApp)["--topic"]->count() > 0) ? subApp : nullptr;
68 pubApp = (pubApp != nullptr && (*pubApp)["--topic"]->count() > 0 && (*pubApp)["--message"]->count() > 0) ? pubApp : nullptr;
69
70 core::socket::stream::SocketContext* socketContext = nullptr;
71
72 if (subApp != nullptr || pubApp != nullptr) {
73 socketContext = new iot::mqtt::SocketContext(
74 socketConnection,
75 new ::mqtt::mqttcli::lib::Mqtt(socketConnection->getConnectionName(),
76 sessionApp != nullptr ? sessionApp->get_option("--client-id")->as<std::string>() : "",
77 sessionApp != nullptr ? sessionApp->get_option("--qos")->as<uint8_t>() : 0,
78 sessionApp != nullptr ? sessionApp->get_option("--keep-alive")->as<uint16_t>() : 60,
79 sessionApp != nullptr ? !sessionApp->get_option("--retain-session")->as<bool>() : true,
80 sessionApp != nullptr ? sessionApp->get_option("--will-topic")->as<std::string>() : "",
81 sessionApp != nullptr ? sessionApp->get_option("--will-message")->as<std::string>() : "",
82 sessionApp != nullptr ? sessionApp->get_option("--will-qos")->as<uint8_t>() : 0,
83 sessionApp != nullptr ? sessionApp->get_option("--will-retain")->as<bool>() : false,
84 sessionApp != nullptr ? sessionApp->get_option("--username")->as<std::string>() : "",
85 sessionApp != nullptr ? sessionApp->get_option("--password")->as<std::string>() : "",
86 subApp != nullptr ? subApp->get_option("--topic")->as<std::list<std::string>>()
87 : std::list<std::string>(),
88 pubApp != nullptr ? pubApp->get_option("--topic")->as<std::string>() : "",
89 pubApp != nullptr ? pubApp->get_option("--message")->as<std::string>() : "",
90 pubApp != nullptr ? pubApp->get_option("--retain")->as<bool>() : false));
91 } else {
92 VLOG(0) << "[" << Color::Code::FG_RED << "Error" << Color::Code::FG_DEFAULT << "] " << socketConnection->getConnectionName()
93 << ": one of 'sub' or 'pub' is required";
94 }
95
96 return socketContext;
97 }

References mqtt::mqttcli::lib::Mqtt::Mqtt().

Here is the call graph for this function:

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