diff -r 000000000000 -r e8f15f432efc src/SocketCommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SocketCommand.cpp Sun May 01 18:42:53 2022 +0200 @@ -0,0 +1,74 @@ +/** + * 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 . + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "SocketCommand.h" +#include "Socket.h" +#include "Hex.h" + +using namespace std; +using namespace relpipe::cli; +using namespace relpipe::writer; + +namespace relpipe { +namespace in { +namespace socket { + +void SocketCommand::process(std::shared_ptr writer, Configuration& configuration) { + vector metadata; + + std::shared_ptr mq(Socket::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose)); + + writer->startRelation(configuration.relation,{ + {L"queue", TypeId::STRING}, + {L"text", TypeId::STRING}, + {L"data", TypeId::STRING} + }, true); + + 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(); + + writer->writeAttribute(configuration.queue); + writer->writeAttribute(Hex::toTxt(message)); + writer->writeAttribute(Hex::toHex(message)); + } + +} + +SocketCommand::~SocketCommand() { +} + +} +} +}