--- 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)
--- 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 <cstring>
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);
--- 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 <relpipe/reader/handlers/RelationalReaderStringHandler.h>
#include <relpipe/reader/handlers/AttributeMetadata.h>
+#include "PosixMQ.h"
+
namespace relpipe {
namespace out {
namespace posixmq {
class PosixMQHandler : public relpipe::reader::handlers::RelationalReaderStringHandler {
private:
-
+ std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
+ shared_ptr<PosixMQ> 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<relpipe::reader::handlers::AttributeMetadata> attributes) override {
-
+
}
void attribute(const relpipe::common::type::StringX& value) override {
-
+ // TODO: send only certain attributes
+ mq->send(convertor.to_bytes(value));
}
void endOfPipe() {
-
+
}
};