author | František Kučera <franta-hg@frantovo.cz> |
Fri, 04 Mar 2022 21:30:08 +0100 | |
branch | v_0 |
changeset 3 | be6f2e307a65 |
parent 0 | a64022f9684e |
permissions | -rw-r--r-- |
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include <cstdlib> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
#include <memory> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <relpipe/cli/CLI.h> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <relpipe/cli/RelpipeCLIException.h> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <relpipe/reader/Factory.h> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include <relpipe/reader/RelationalReader.h> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
#include <relpipe/reader/RelpipeReaderException.h> |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
#include "PosixMQHandler.h" |
3
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
29 |
#include "CLIParser.h" |
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
30 |
#include "Configuration.h" |
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
using namespace relpipe::cli; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
using namespace relpipe::reader; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
using namespace relpipe::out::posixmq; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
int main(int argc, char**argv) { |
3
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
37 |
setlocale(LC_ALL, ""); |
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
CLI::untieStdIO(); |
3
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
39 |
CLI cli(argc, argv); |
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
40 |
|
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
try { |
3
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
CLIParser cliParser; |
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
45 |
Configuration configuration = cliParser.parse(cli.arguments()); |
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
3
be6f2e307a65
configuration + option: --unlink-on-close
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
PosixMQHandler handler(configuration); |
0
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
reader->addHandler(&handler); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
reader->process(); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
} catch (RelpipeCLIException e) { |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
resultCode = e.getExitCode(); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
} catch (RelpipeReaderException e) { |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
} |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
|
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
return resultCode; |
a64022f9684e
new project relpipe-out-posixmq
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
} |