MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
destination.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_DESTINATION_INCLUDED
27#define MYSQL_HARNESS_DESTINATION_INCLUDED
28
29#include "harness_export.h"
30
31#include <cstdint>
32#include <string>
33#include <system_error>
34#include <variant>
35
37
38namespace mysql_harness {
39
40class HARNESS_EXPORT TcpDestination {
41 public:
42 TcpDestination() = default;
43
44 TcpDestination(std::string hostname, uint16_t port)
45 : hostname_(std::move(hostname)), port_(port) {}
46
47 TcpDestination(const TcpDestination &) = default;
49
52
53 ~TcpDestination() = default;
54
55 auto operator<=>(const TcpDestination &) const = default;
56
57 const std::string &hostname() const { return hostname_; }
58 void hostname(const std::string &hn) { hostname_ = hn; }
59
60 uint16_t port() const { return port_; }
61 void port(uint16_t prt) { port_ = prt; }
62
63 std::string str() const;
64
65 private:
66 std::string hostname_;
67 uint16_t port_{};
68};
69
70class HARNESS_EXPORT LocalDestination {
71 public:
72 LocalDestination() = default;
73
74 LocalDestination(std::string path) : path_(std::move(path)) {}
75
78
81
82 ~LocalDestination() = default;
83
84 auto operator<=>(const LocalDestination &) const = default;
85
86 std::string path() const { return path_; }
87 void path(const std::string &pa) { path_ = pa; }
88
89 std::string str() const;
90
91 private:
92 std::string path_;
93};
94
95class HARNESS_EXPORT Destination {
96 public:
97 Destination(TcpDestination dest) : dest_(std::move(dest)) {}
98 Destination(LocalDestination dest) : dest_(std::move(dest)) {}
99
100 auto operator<=>(const Destination &) const = default;
101
102 bool is_tcp() const { return std::holds_alternative<TcpDestination>(dest_); }
103 bool is_local() const { return !is_tcp(); }
104
105 std::string str() const;
106
107 TcpDestination &as_tcp() { return std::get<TcpDestination>(dest_); }
108 const TcpDestination &as_tcp() const {
109 return std::get<TcpDestination>(dest_);
110 }
111
112 LocalDestination &as_local() { return std::get<LocalDestination>(dest_); }
113 const LocalDestination &as_local() const {
114 return std::get<LocalDestination>(dest_);
115 }
116
117 private:
118 std::variant<TcpDestination, LocalDestination> dest_;
119};
120
121/**
122 * create a TcpDestination from a string.
123 *
124 * - ipv4
125 * - ipv6
126 * - hostname
127 *
128 * followed by optional port.
129 *
130 * If IPv6 is followed by port, the address port is expected to be wrapped in
131 * '[]'
132 */
134make_tcp_destination(std::string dest);
135
136} // namespace mysql_harness
137
138#endif
Definition: destination.h:95
Destination(LocalDestination dest)
Definition: destination.h:98
auto operator<=>(const Destination &) const =default
Destination(TcpDestination dest)
Definition: destination.h:97
LocalDestination & as_local()
Definition: destination.h:112
const LocalDestination & as_local() const
Definition: destination.h:113
std::variant< TcpDestination, LocalDestination > dest_
Definition: destination.h:118
bool is_tcp() const
Definition: destination.h:102
TcpDestination & as_tcp()
Definition: destination.h:107
bool is_local() const
Definition: destination.h:103
const TcpDestination & as_tcp() const
Definition: destination.h:108
Definition: destination.h:70
std::string path() const
Definition: destination.h:86
LocalDestination(const LocalDestination &)=default
void path(const std::string &pa)
Definition: destination.h:87
auto operator<=>(const LocalDestination &) const =default
LocalDestination(LocalDestination &&)=default
LocalDestination & operator=(LocalDestination &&)=default
std::string path_
Definition: destination.h:92
LocalDestination & operator=(const LocalDestination &)=default
LocalDestination(std::string path)
Definition: destination.h:74
Definition: destination.h:40
auto operator<=>(const TcpDestination &) const =default
TcpDestination & operator=(TcpDestination &&)=default
TcpDestination(TcpDestination &&)=default
std::string hostname_
Definition: destination.h:66
TcpDestination & operator=(const TcpDestination &)=default
void port(uint16_t prt)
Definition: destination.h:61
TcpDestination(const TcpDestination &)=default
void hostname(const std::string &hn)
Definition: destination.h:58
TcpDestination(std::string hostname, uint16_t port)
Definition: destination.h:44
uint16_t port() const
Definition: destination.h:60
const std::string & hostname() const
Definition: destination.h:57
Definition: expected.h:286
static char * path
Definition: mysqldump.cc:149
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1117
Definition: common.h:44
stdx::expected< TcpDestination, std::error_code > HARNESS_EXPORT make_tcp_destination(std::string dest)
create a TcpDestination from a string.
Definition: destination.cc:170
Definition: gcs_xcom_synode.h:64
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33