author | František Kučera <franta-hg@frantovo.cz> |
Fri, 06 May 2022 23:09:56 +0200 | |
branch | v_0 |
changeset 1 | 4993a084b8ba |
parent 0 | 7fdf75648c0a |
child 2 | 0799eaf338b9 |
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 |
||
1
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
#include <mosquittopp.h> |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
28 |
|
0 | 29 |
#include <relpipe/writer/RelationalWriter.h> |
30 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
31 |
#include <relpipe/writer/AttributeMetadata.h> |
|
32 |
#include <relpipe/writer/Factory.h> |
|
33 |
#include <relpipe/writer/TypeId.h> |
|
34 |
||
35 |
#include <relpipe/cli/CLI.h> |
|
36 |
||
37 |
#include "MQTTCommand.h" |
|
38 |
#include "Hex.h" |
|
39 |
||
40 |
using namespace std; |
|
41 |
using namespace relpipe::cli; |
|
42 |
using namespace relpipe::writer; |
|
43 |
||
44 |
namespace relpipe { |
|
45 |
namespace in { |
|
46 |
namespace mqtt { |
|
47 |
||
48 |
void MQTTCommand::process(std::shared_ptr<writer::RelationalWriter> writer, Configuration& configuration) { |
|
49 |
vector<AttributeMetadata> metadata; |
|
50 |
||
1
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
{ |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
52 |
// TODO: remove |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
int major, minor, patch; |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
mosqpp::lib_version(&major, &minor, &patch); |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
std::cerr << "mosquitto version: " << major << "." << minor << "." << patch << std::endl; |
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
} |
0 | 57 |
|
58 |
writer->startRelation(configuration.relation,{ |
|
59 |
{L"queue", TypeId::STRING}, |
|
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) |
|
1
4993a084b8ba
link to mosquittopp library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
std::string message = "TODO"; // FIXME: receive message |
0 | 67 |
|
68 |
writer->writeAttribute(configuration.queue); |
|
69 |
writer->writeAttribute(Hex::toTxt(message)); |
|
70 |
writer->writeAttribute(Hex::toHex(message)); |
|
71 |
} |
|
72 |
||
73 |
} |
|
74 |
||
75 |
MQTTCommand::~MQTTCommand() { |
|
76 |
} |
|
77 |
||
78 |
} |
|
79 |
} |
|
80 |
} |