author | František Kučera <franta-hg@frantovo.cz> |
Wed, 27 Apr 2022 01:47:35 +0200 | |
branch | v_0 |
changeset 1 | 6a2ae23c53c4 |
parent 0 | 5499cbd842ab |
child 2 | c6b1ae438ab3 |
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> |
|
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
#include <csignal> |
0 | 19 |
#include <vector> |
20 |
#include <memory> |
|
21 |
#include <regex> |
|
22 |
#include <algorithm> |
|
23 |
#include <unistd.h> |
|
24 |
||
25 |
#include <relpipe/writer/RelationalWriter.h> |
|
26 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
27 |
#include <relpipe/writer/AttributeMetadata.h> |
|
28 |
#include <relpipe/writer/Factory.h> |
|
29 |
#include <relpipe/writer/TypeId.h> |
|
30 |
||
31 |
#include <relpipe/cli/CLI.h> |
|
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
32 |
#include <condition_variable> |
0 | 33 |
|
34 |
#include "KafkaCommand.h" |
|
35 |
#include "CLIParser.h" |
|
36 |
#include "Configuration.h" |
|
37 |
||
38 |
using namespace relpipe::cli; |
|
39 |
using namespace relpipe::writer; |
|
40 |
using namespace relpipe::in::kafka; |
|
41 |
||
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
42 |
static std::shared_ptr<KafkaCommand> kafkaCommand = nullptr; |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
43 |
|
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
void finish(int sig) { |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
45 |
if (kafkaCommand) kafkaCommand->finish(sig); |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
46 |
} |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
|
0 | 48 |
int main(int argc, char** argv) { |
49 |
setlocale(LC_ALL, ""); |
|
50 |
CLI::untieStdIO(); |
|
51 |
CLI cli(argc, argv); |
|
52 |
||
53 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
54 |
||
55 |
try { |
|
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
signal(SIGHUP, finish); |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
57 |
signal(SIGINT, finish); |
0 | 58 |
CLIParser cliParser; |
59 |
Configuration configuration = cliParser.parse(cli.arguments()); |
|
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
kafkaCommand.reset(new KafkaCommand()); |
0 | 61 |
std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
1
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
writer->setBufferingMode(BufferingMode::ENVIRONMENT, BufferingMode::RECORD); |
6a2ae23c53c4
first version of Kafka consumer
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
kafkaCommand->process(writer, configuration); |
0 | 64 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
65 |
} catch (RelpipeCLIException e) { |
|
66 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
|
67 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
68 |
resultCode = e.getExitCode(); |
|
69 |
} catch (RelpipeWriterException e) { |
|
70 |
fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessage().c_str()); |
|
71 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
72 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
73 |
} |
|
74 |
||
75 |
return resultCode; |
|
76 |
} |