src/Socket.h
author František Kučera <franta-hg@frantovo.cz>
Fri, 29 Jul 2022 18:03:49 +0200
branchv_0
changeset 4 8d036e5e5fcc
parent 3 e701e06ff561
child 5 e57e2a2798b2
permissions -rw-r--r--
configuration: --connection-string --connection-option (role, mode)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
924e354948df establish project
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
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <string>
1
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    20
#include <cstring>
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    21
#include <unistd.h>
0
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <stdexcept>
1
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    23
#include <arpa/inet.h>
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    24
#include <sys/types.h>
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    25
#include <sys/socket.h>
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    26
#include <netinet/in.h>
0
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace relpipe {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
namespace out {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
namespace socket {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
class Socket {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
public:
2
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    34
	virtual ~Socket() = default;
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    35
	virtual void send(const std::string& message) = 0;
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    36
	virtual const std::string receive() = 0;
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    37
};
1
e3265afd1111 first version: TCP-only + fixed parameters
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    38
4
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    39
class SocketOption {
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    40
public:
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    41
	const std::string name;
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    42
	const std::string value;
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    43
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    44
	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
    45
	}
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
	virtual ~SocketOption() = default;
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    48
};
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    49
2
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    50
class SocketFactory {
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    51
public:
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    52
	virtual ~SocketFactory() = default;
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    53
	virtual bool canHandle(const std::string& connectionString) = 0;
4
8d036e5e5fcc configuration: --connection-string --connection-option (role, mode)
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    54
	virtual std::shared_ptr<Socket> open(const std::string& connectionString) = 0;
3
e701e06ff561 add some factories: generic/template version
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    55
	static std::shared_ptr<SocketFactory> find(const std::string& connectionString);
2
fb399fd4f053 add some factories
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    56
};
0
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
}
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
}
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
}