45 namespace socket { |
45 namespace socket { |
46 |
46 |
47 void SocketCommand::process(std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
47 void SocketCommand::process(std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
48 vector<AttributeMetadata> metadata; |
48 vector<AttributeMetadata> metadata; |
49 |
49 |
50 std::shared_ptr<Socket> socket = std::make_shared<Socket>(); // TODO: create a TCP, UDP… socket |
50 std::vector<SocketOption> options; |
|
51 for (auto o : configuration.options) options.push_back({convertor.to_bytes(o.name), convertor.to_bytes(o.value)}); |
|
52 std::shared_ptr<Socket> socket = SocketFactory::find(options)->open(options); |
51 |
53 |
52 writer->startRelation(configuration.relation,{ |
54 writer->startRelation(configuration.relation,{ |
53 {L"queue", TypeId::STRING}, |
55 {L"host", TypeId::STRING}, |
|
56 {L"port", TypeId::INTEGER}, |
|
57 {L"pid", TypeId::INTEGER}, |
|
58 {L"gid", TypeId::INTEGER}, |
|
59 {L"uid", TypeId::INTEGER}, |
54 {L"text", TypeId::STRING}, |
60 {L"text", TypeId::STRING}, |
55 {L"data", TypeId::STRING} |
61 {L"data", TypeId::STRING} |
56 }, true); |
62 }, true); |
57 |
63 |
58 for (int i = configuration.messageCount; continueProcessing && i > 0; i--) { |
64 for (int i = configuration.messageCount; continueProcessing && i > 0; i--) { |
59 // TODO: maybe rather call mq_timedreceive() inside and check continueProcessing (to be able to stop even when no messages are comming) |
65 // TODO: maybe rather call mq_timedreceive() inside and check continueProcessing (to be able to stop even when no messages are comming) |
60 std::string message = socket->receive(); |
66 IncomingMessage message = socket->receive(); |
61 |
67 |
62 writer->writeAttribute(configuration.queue); |
68 writer->writeAttribute(convertor.from_bytes(message.remoteHost)); |
63 writer->writeAttribute(Hex::toTxt(message)); |
69 writer->writeAttribute(std::to_wstring(message.remotePort)); |
64 writer->writeAttribute(Hex::toHex(message)); |
70 writer->writeAttribute(std::to_wstring(message.remotePID)); |
|
71 writer->writeAttribute(std::to_wstring(message.remoteGID)); |
|
72 writer->writeAttribute(std::to_wstring(message.remoteUID)); |
|
73 writer->writeAttribute(Hex::toTxt(message.data)); |
|
74 writer->writeAttribute(Hex::toHex(message.data)); |
65 } |
75 } |
66 |
76 |
67 } |
77 } |
68 |
78 |
69 SocketCommand::~SocketCommand() { |
79 SocketCommand::~SocketCommand() { |