author | František Kučera <franta-hg@frantovo.cz> |
Sat, 23 Jul 2022 21:36:01 +0200 | |
branch | v_0 |
changeset 3 | 3891db9e45b7 |
parent 2 | f724d805c34a |
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> |
|
1 | 25 |
|
26 |
#include <zmq.hpp> |
|
0 | 27 |
|
28 |
#include <relpipe/writer/RelationalWriter.h> |
|
29 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
30 |
#include <relpipe/writer/AttributeMetadata.h> |
|
31 |
#include <relpipe/writer/Factory.h> |
|
32 |
#include <relpipe/writer/TypeId.h> |
|
33 |
||
34 |
#include <relpipe/cli/CLI.h> |
|
35 |
||
36 |
#include "ZeroMQCommand.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 zeromq { |
|
46 |
||
47 |
void ZeroMQCommand::process(std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
|
1 | 48 |
zmq::context_t zmqContext; |
49 |
zmq::socket_t zmqSocket(zmqContext, zmq::socket_type::pull); |
|
3
3891db9e45b7
rename --endpoint-url to --connection-string
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
50 |
zmqSocket.bind(convertor.to_bytes(configuration.connectionString)); |
0 | 51 |
|
2 | 52 |
|
53 |
if (false) { |
|
54 |
// TODO: optionally generate and print keys and/or do encryption |
|
55 |
char server_public_key[41]; |
|
56 |
char server_secret_key[41]; |
|
57 |
zmq_curve_keypair(server_public_key, server_secret_key); |
|
58 |
std::cerr << "Server public key: " << std::string(server_public_key) << std::endl; |
|
59 |
std::cerr << "Server secret key: " << std::string(server_secret_key) << std::endl; |
|
60 |
} |
|
61 |
||
0 | 62 |
writer->startRelation(configuration.relation,{ |
63 |
{L"text", TypeId::STRING}, |
|
64 |
{L"data", TypeId::STRING} |
|
65 |
}, true); |
|
66 |
||
67 |
for (int i = configuration.messageCount; continueProcessing && i > 0; i--) { |
|
1 | 68 |
zmq::message_t msg; |
69 |
zmqSocket.recv(&msg, 0); // FIXME: check return value |
|
70 |
std::string message(msg.data<char>(), msg.size()); |
|
0 | 71 |
|
72 |
writer->writeAttribute(Hex::toTxt(message)); |
|
73 |
writer->writeAttribute(Hex::toHex(message)); |
|
74 |
} |
|
75 |
||
76 |
} |
|
77 |
||
78 |
ZeroMQCommand::~ZeroMQCommand() { |
|
79 |
} |
|
80 |
||
81 |
} |
|
82 |
} |
|
83 |
} |