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);
67 subApp = (subApp !=
nullptr && (*subApp)[
"--topic"]->count() > 0) ? subApp :
nullptr;
68 pubApp = (pubApp !=
nullptr && (*pubApp)[
"--topic"]->count() > 0 && (*pubApp)[
"--message"]->count() > 0) ? pubApp :
nullptr;
70 core::socket::stream::SocketContext* socketContext =
nullptr;
72 if (subApp !=
nullptr || pubApp !=
nullptr) {
73 socketContext =
new iot::
mqtt::SocketContext(
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));
92 VLOG(0) <<
"[" << Color::Code::FG_RED <<
"Error" << Color::Code::FG_DEFAULT <<
"] " << socketConnection->getConnectionName()
93 <<
": one of 'sub' or 'pub' is required";
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
Mqtt(const std::string &connectionName, const std::string &clientId, uint8_t qoSDefault, uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, const std::list< std::string > &subTopics, const std::string &pubTopic, const std::string &pubMessage, bool pubRetain=false, const std::string &sessionStoreFileName="")