26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_UTILITIES_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_UTILITIES_H_
51template <
typename Type>
53 auto result = endpoint.lock();
60template <
typename Type>
61std::shared_ptr<Type>
lock(
const std::weak_ptr<Type> &endpoint) {
62 auto result = endpoint.lock();
65 "The weak_ptr should be not expired, when calling any Handler "
71template <
typename Type>
72const std::shared_ptr<Type> &
lock(std::shared_ptr<Type> &endpoint) {
78 auto result = url.get_host();
80 auto port = url.get_port();
89 std::weak_ptr<mrs::interface::EndpointBase> wp) {
90 auto endpoint =
lock(wp);
91 if (!endpoint)
return {};
97 const std::shared_ptr<DbObjectEndpoint> &endpoint) {
98 auto parent = endpoint->get_parent_ptr();
99 if (!parent)
return {};
101 return std::dynamic_pointer_cast<DbSchemaEndpoint>(parent);
105 const std::shared_ptr<DbSchemaEndpoint> &endpoint) {
106 auto parent = endpoint->get_parent_ptr();
107 if (!parent)
return {};
109 return std::dynamic_pointer_cast<DbServiceEndpoint>(parent);
115 if (!parent)
return {};
117 return std::dynamic_pointer_cast<ContentSetEndpoint>(parent);
121 const std::shared_ptr<ContentFileEndpoint> &endpoint) {
122 auto parent = endpoint->get_parent_ptr();
123 if (!parent)
return {};
125 return std::dynamic_pointer_cast<ContentSetEndpoint>(parent);
129 const std::shared_ptr<ContentSetEndpoint> &endpoint) {
130 auto parent = endpoint->get_parent_ptr();
131 if (!parent)
return {};
133 return std::dynamic_pointer_cast<DbServiceEndpoint>(parent);
137 std::optional<std::string>
options,
138 std::optional<std::string> parent_options) {
139 static const std::set<std::string> k_non_inherited_options{
140 "directoryIndexDirective",
"defaultStaticContent",
"defaultRedirects"};
142 k_non_inherited_options);
146 const std::shared_ptr<DbServiceEndpoint> &endpoint) {
147 return endpoint->get()->options;
151 const std::shared_ptr<DbSchemaEndpoint> &endpoint) {
152 const auto &option = endpoint->get()->options;
155 std::dynamic_pointer_cast<DbServiceEndpoint>(endpoint->get_parent_ptr());
156 if (!parent)
return option;
163 const std::shared_ptr<DbObjectEndpoint> &endpoint) {
164 const auto &option = endpoint->get()->options;
167 std::dynamic_pointer_cast<DbSchemaEndpoint>(endpoint->get_parent_ptr());
168 if (!parent)
return option;
175 const std::shared_ptr<ContentSetEndpoint> &endpoint) {
176 const auto &option = endpoint->get()->options;
179 std::dynamic_pointer_cast<DbServiceEndpoint>(endpoint->get_parent_ptr());
180 if (!parent)
return option;
187 const std::shared_ptr<ContentFileEndpoint> &endpoint) {
188 const auto &option = endpoint->get()->options;
191 std::dynamic_pointer_cast<ContentSetEndpoint>(endpoint->get_parent_ptr());
192 if (!parent)
return option;
199 std::shared_ptr<DbServiceEndpoint> &endpoint) {
200 auto entry = endpoint->get();
202 return entry->url_protocols;
205template <
typename Endpo
int>
208 if (!parent)
return {};
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4618
Definition: content_file_endpoint.h:41
const EndpointBasePtr get_parent_ptr() const
Definition: endpoint_base.h:184
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
std::string merge_objects(const std::string &j1, const std::string &j2, const std::set< std::string > &skip_attributes)
Definition: merge.cc:34
constexpr key_type ServiceUnavailable
Definition: status_code.h:96
Request::Uri Uri
Definition: request.cc:36
std::shared_ptr< Type > lock_or_throw_unavail(std::weak_ptr< Type > &endpoint)
Definition: utilities.h:52
std::optional< std::string > get_endpoint_options(const std::shared_ptr< DbServiceEndpoint > &endpoint)
Definition: utilities.h:145
std::shared_ptr< DbSchemaEndpoint > lock_parent(const std::shared_ptr< DbObjectEndpoint > &endpoint)
Definition: utilities.h:96
const uint64_t k_default_items_on_page
Definition: utilities.h:49
std::optional< std::string > merge_options(std::optional< std::string > options, std::optional< std::string > parent_options)
Definition: utilities.h:136
std::string get_endpoint_host(const ::http::base::Uri &url)
Definition: utilities.h:77
std::shared_ptr< Type > lock(const std::weak_ptr< Type > &endpoint)
Definition: utilities.h:61
Protocols get_endpoint_protocol(std::shared_ptr< DbServiceEndpoint > &endpoint)
Definition: utilities.h:198
std::set< std::string > Protocols
Definition: utilities.h:47
Definition: authorize_manager.h:48
Definition: options.cc:57
struct result result
Definition: result.h:34
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: completion_hash.h:35