# HG changeset patch # User František Kučera # Date 1646354450 -3600 # Node ID fc9911b1d29518ec931c2cefbd130560d35c8818 # Parent 67898f122f53545bcda47d4a771e0877b49ffab1 send messages to PosixMQ: currently each attribute in one message diff -r 67898f122f53 -r fc9911b1d295 src/CMakeLists.txt --- a/src/CMakeLists.txt Fri Mar 04 01:11:27 2022 +0100 +++ b/src/CMakeLists.txt Fri Mar 04 01:40:50 2022 +0100 @@ -34,7 +34,7 @@ ) # Link libraries: -target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES}) +target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES} rt) set_property(TARGET ${EXECUTABLE_FILE} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) install(TARGETS ${EXECUTABLE_FILE} DESTINATION bin) diff -r 67898f122f53 -r fc9911b1d295 src/PosixMQ.h --- a/src/PosixMQ.h Fri Mar 04 01:11:27 2022 +0100 +++ b/src/PosixMQ.h Fri Mar 04 01:40:50 2022 +0100 @@ -22,7 +22,7 @@ #include namespace relpipe { -namespace in { +namespace out { namespace posixmq { class PosixMQ { @@ -41,11 +41,16 @@ } static PosixMQ* open(std::string queueName) { - mqd_t handle = mq_open(queueName.c_str(), O_RDONLY | O_CREAT); + mqd_t handle = mq_open(queueName.c_str(), O_RDWR | O_CREAT); if (handle >= 0) return new PosixMQ(queueName, handle); else throw std::logic_error("Unable to open PosixMQ: " + 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("mq_send() = " + std::to_string(result) + " error: " + strerror(errno)); + } + std::string receive() { char buffer[MSG_SIZE + 1]; memset(buffer, 0, MSG_SIZE + 1); diff -r 67898f122f53 -r fc9911b1d295 src/PosixMQHandler.h --- a/src/PosixMQHandler.h Fri Mar 04 01:11:27 2022 +0100 +++ b/src/PosixMQHandler.h Fri Mar 04 01:40:50 2022 +0100 @@ -29,28 +29,36 @@ #include #include +#include "PosixMQ.h" + namespace relpipe { namespace out { namespace posixmq { class PosixMQHandler : public relpipe::reader::handlers::RelationalReaderStringHandler { private: - + std::wstring_convert> convertor; // TODO: support also other encodings. + shared_ptr mq; + public: PosixMQHandler(std::ostream& output) { + relpipe::common::type::StringX queueName = L"/relpipe"; + mq.reset(PosixMQ::open(convertor.to_bytes(queueName))); + } void startRelation(relpipe::common::type::StringX name, std::vector attributes) override { - + } void attribute(const relpipe::common::type::StringX& value) override { - + // TODO: send only certain attributes + mq->send(convertor.to_bytes(value)); } void endOfPipe() { - + } };