author | František Kučera <franta-hg@frantovo.cz> |
Sat, 30 Jul 2022 00:16:40 +0200 | |
branch | v_0 |
changeset 5 | e57e2a2798b2 |
parent 4 | 8d036e5e5fcc |
child 7 | e6f005f3edfe |
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 |
#pragma once |
|
18 |
||
19 |
#include <string> |
|
5
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
20 |
#include <vector> |
1
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
21 |
#include <cstring> |
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
#include <unistd.h> |
0 | 23 |
#include <stdexcept> |
1
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
24 |
#include <arpa/inet.h> |
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
#include <sys/types.h> |
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
#include <sys/socket.h> |
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
#include <netinet/in.h> |
0 | 28 |
|
29 |
namespace relpipe { |
|
30 |
namespace out { |
|
31 |
namespace socket { |
|
32 |
||
33 |
class Socket { |
|
34 |
public: |
|
2 | 35 |
virtual ~Socket() = default; |
36 |
virtual void send(const std::string& message) = 0; |
|
37 |
virtual const std::string receive() = 0; |
|
38 |
}; |
|
1
e3265afd1111
first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
39 |
|
4
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
40 |
class SocketOption { |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
41 |
public: |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
42 |
const std::string name; |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
43 |
const std::string value; |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
44 |
|
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
45 |
SocketOption(const std::string name, const std::string value) : name(name), value(value) { |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
46 |
} |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
47 |
|
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
48 |
virtual ~SocketOption() = default; |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
49 |
}; |
8d036e5e5fcc
configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
50 |
|
5
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
51 |
using SocketOptions = std::vector<SocketOption>; |
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
52 |
|
2 | 53 |
class SocketFactory { |
54 |
public: |
|
55 |
virtual ~SocketFactory() = default; |
|
5
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
56 |
virtual bool canHandle(const SocketOptions& options) = 0; |
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
57 |
virtual std::shared_ptr<Socket> open(const SocketOptions& options) = 0; |
e57e2a2798b2
configuration: protocol, role, mode, host, port, path
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
58 |
static std::shared_ptr<SocketFactory> find(const SocketOptions& options); |
2 | 59 |
}; |
0 | 60 |
|
61 |
||
62 |
} |
|
63 |
} |
|
64 |
} |