# HG changeset patch # User František Kučera # Date 1651871396 -7200 # Node ID 4993a084b8ba0bb6fc32f753a2bf87f285571b3f # Parent 7fdf75648c0a95954045e06a16b41353b5665e48 link to mosquittopp library diff -r 7fdf75648c0a -r 4993a084b8ba src/CMakeLists.txt --- a/src/CMakeLists.txt Fri May 06 21:54:09 2022 +0200 +++ b/src/CMakeLists.txt Fri May 06 23:09:56 2022 +0200 @@ -34,7 +34,7 @@ ) # Link libraries: -target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES} rt) +target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES} mosquittopp) set_property(TARGET ${EXECUTABLE_FILE} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) install(TARGETS ${EXECUTABLE_FILE} DESTINATION bin) diff -r 7fdf75648c0a -r 4993a084b8ba src/MQTT.h --- a/src/MQTT.h Fri May 06 21:54:09 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/** - * Relational pipes - * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include -#include -#include -#include - -namespace relpipe { -namespace in { -namespace mqtt { - -class MQTT { -private: - const static size_t MSG_SIZE = 8192; // TODO: configurable/dynamic - std::string queueName; - mqd_t handle = -2; - bool unlinkOnClose = false; - - MQTT(std::string queueName, mqd_t handle, bool unlinkOnClose) : queueName(queueName), handle(handle), unlinkOnClose(unlinkOnClose) { - } - -public: - - virtual ~MQTT() { - if (handle >= 0) mq_close(handle); - if (unlinkOnClose) mq_unlink(queueName.c_str()); - } - - static MQTT* open(std::string queueName, bool unlinkOnClose = false) { - mqd_t handle = mq_open(queueName.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); - if (handle >= 0) return new MQTT(queueName, handle, unlinkOnClose); - else throw std::logic_error("Unable to open MQTT: " + queueName + " error: " + strerror(errno)); - } - - void send(std::string message) { - int result = mq_send(handle, message.c_str(), message.size(), 0); - if (result) throw std::logic_error("Unable to send message to" + queueName + " error: " + strerror(errno)); - } - - std::string receive() { - char buffer[MSG_SIZE + 1]; - memset(buffer, 0, MSG_SIZE + 1); - ssize_t msgSize = mq_receive(handle, buffer, MSG_SIZE, nullptr); - - if (msgSize > sizeof (buffer))throw std::logic_error("Invalid MQTT message size."); - else if (msgSize >= 0) return std::string(buffer, msgSize); - else throw std::logic_error("Unable to receive MQTT message from " + queueName + " error: " + strerror(errno)); - } - -}; - -} -} -} diff -r 7fdf75648c0a -r 4993a084b8ba src/MQTTCommand.cpp --- a/src/MQTTCommand.cpp Fri May 06 21:54:09 2022 +0200 +++ b/src/MQTTCommand.cpp Fri May 06 23:09:56 2022 +0200 @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -33,7 +35,6 @@ #include #include "MQTTCommand.h" -#include "MQTT.h" #include "Hex.h" using namespace std; @@ -47,7 +48,12 @@ void MQTTCommand::process(std::shared_ptr writer, Configuration& configuration) { vector metadata; - std::shared_ptr mq(MQTT::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose)); + { + // TODO: remove + int major, minor, patch; + mosqpp::lib_version(&major, &minor, &patch); + std::cerr << "mosquitto version: " << major << "." << minor << "." << patch << std::endl; + } writer->startRelation(configuration.relation,{ {L"queue", TypeId::STRING}, @@ -57,7 +63,7 @@ for (int i = configuration.messageCount; continueProcessing && i > 0; i--) { // TODO: maybe rather call mq_timedreceive() inside and check continueProcessing (to be able to stop even when no messages are comming) - std::string message = mq->receive(); + std::string message = "TODO"; // FIXME: receive message writer->writeAttribute(configuration.queue); writer->writeAttribute(Hex::toTxt(message));