author | František Kučera <franta-hg@frantovo.cz> |
Sun, 21 Aug 2022 00:16:50 +0200 | |
branch | v_0 |
changeset 3 | 2b57c8683ffe |
parent 1 | d93ea7346b66 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#include <cstdlib> |
|
18 |
#include <vector> |
|
19 |
#include <memory> |
|
20 |
#include <locale> |
|
21 |
#include <regex> |
|
22 |
#include <algorithm> |
|
23 |
#include <unistd.h> |
|
24 |
#include <sstream> |
|
25 |
#include <iomanip> |
|
26 |
||
27 |
#include <relpipe/writer/RelationalWriter.h> |
|
28 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
29 |
#include <relpipe/writer/AttributeMetadata.h> |
|
30 |
#include <relpipe/writer/Factory.h> |
|
31 |
#include <relpipe/writer/TypeId.h> |
|
32 |
||
33 |
#include <relpipe/cli/CLI.h> |
|
34 |
||
35 |
#include "SocketCommand.h" |
|
36 |
#include "Socket.h" |
|
37 |
#include "Hex.h" |
|
38 |
||
39 |
using namespace std; |
|
40 |
using namespace relpipe::cli; |
|
41 |
using namespace relpipe::writer; |
|
42 |
||
43 |
namespace relpipe { |
|
44 |
namespace in { |
|
45 |
namespace socket { |
|
46 |
||
47 |
void SocketCommand::process(std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
|
48 |
vector<AttributeMetadata> metadata; |
|
49 |
||
3
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
50 |
std::vector<SocketOption> options; |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
51 |
for (auto o : configuration.options) options.push_back({convertor.to_bytes(o.name), convertor.to_bytes(o.value)}); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
52 |
std::shared_ptr<Socket> socket = SocketFactory::find(options)->open(options); |
0 | 53 |
|
54 |
writer->startRelation(configuration.relation,{ |
|
3
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
55 |
{L"host", TypeId::STRING}, |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
56 |
{L"port", TypeId::INTEGER}, |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
57 |
{L"pid", TypeId::INTEGER}, |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
58 |
{L"gid", TypeId::INTEGER}, |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
59 |
{L"uid", TypeId::INTEGER}, |
0 | 60 |
{L"text", TypeId::STRING}, |
61 |
{L"data", TypeId::STRING} |
|
62 |
}, true); |
|
63 |
||
64 |
for (int i = configuration.messageCount; continueProcessing && i > 0; i--) { |
|
65 |
// TODO: maybe rather call mq_timedreceive() inside and check continueProcessing (to be able to stop even when no messages are comming) |
|
3
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
66 |
IncomingMessage message = socket->receive(); |
0 | 67 |
|
3
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
68 |
writer->writeAttribute(convertor.from_bytes(message.remoteHost)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
69 |
writer->writeAttribute(std::to_wstring(message.remotePort)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
70 |
writer->writeAttribute(std::to_wstring(message.remotePID)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
71 |
writer->writeAttribute(std::to_wstring(message.remoteGID)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
72 |
writer->writeAttribute(std::to_wstring(message.remoteUID)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
73 |
writer->writeAttribute(Hex::toTxt(message.data)); |
2b57c8683ffe
synchronize interface and common classes with relpipe-out-socket + implement basic UDPServerSocket::receive()
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
74 |
writer->writeAttribute(Hex::toHex(message.data)); |
0 | 75 |
} |
76 |
||
77 |
} |
|
78 |
||
79 |
SocketCommand::~SocketCommand() { |
|
80 |
} |
|
81 |
||
82 |
} |
|
83 |
} |
|
84 |
} |