/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * Copyright 2020-2021 Couchbase, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include "core/protocol/hello_feature.hxx" #include "core/response_handler.hxx" #include "core/utils/movable_function.hxx" #include "mcbp_context.hxx" #include "mcbp_message.hxx" #include #include #include #include #include #include #include #include namespace asio { class io_context; namespace ssl { class context; } // namespace ssl } // namespace asio namespace couchbase::core { struct origin; class config_listener; #ifdef COUCHBASE_CXX_CLIENT_COLUMNAR namespace columnar { class background_bootstrap_listener; } // namespace columnar #endif namespace topology { struct configuration; } // namespace topology namespace diag { class ping_reporter; struct endpoint_diag_info; } // namespace diag namespace impl { struct bootstrap_error; class bootstrap_state_listener; } // namespace impl namespace io { class mcbp_session_impl; using command_handler = utils::movable_function< void(std::error_code, retry_reason, io::mcbp_message&&, std::optional)>; class mcbp_session { public: mcbp_session() = delete; ~mcbp_session() = default; mcbp_session(const mcbp_session& other) = default; auto operator=(const mcbp_session& other) -> mcbp_session& = default; mcbp_session(mcbp_session&& other) = default; auto operator=(mcbp_session&& other) -> mcbp_session& = default; mcbp_session(const std::string& client_id, asio::io_context& ctx, couchbase::core::origin origin, std::shared_ptr state_listener, std::optional bucket_name = {}, std::vector known_features = {}); mcbp_session(const std::string& client_id, asio::io_context& ctx, asio::ssl::context& tls, couchbase::core::origin origin, std::shared_ptr state_listener, std::optional bucket_name = {}, std::vector known_features = {}); [[nodiscard]] auto log_prefix() const -> const std::string&; [[nodiscard]] auto cancel(std::uint32_t opaque, std::error_code ec, retry_reason reason) -> bool; [[nodiscard]] auto is_stopped() const -> bool; [[nodiscard]] auto is_bootstrapped() const -> bool; [[nodiscard]] auto next_opaque() -> std::uint32_t; [[nodiscard]] auto get_collection_uid(const std::string& collection_path) -> std::optional; [[nodiscard]] auto context() const -> mcbp_context; [[nodiscard]] auto supports_feature(protocol::hello_feature feature) -> bool; [[nodiscard]] auto supported_features() const -> std::vector; [[nodiscard]] auto id() const -> const std::string&; [[nodiscard]] auto remote_address() const -> std::string; [[nodiscard]] auto local_address() const -> std::string; [[nodiscard]] auto bootstrap_address() const -> const std::string&; [[nodiscard]] auto bootstrap_hostname() const -> const std::string&; [[nodiscard]] auto bootstrap_port() const -> const std::string&; [[nodiscard]] auto bootstrap_port_number() const -> std::uint16_t; [[nodiscard]] auto last_bootstrap_error() && -> std::optional; [[nodiscard]] auto last_bootstrap_error() const& -> const std::optional&; void write_and_flush(std::vector&& buffer); void write_and_subscribe(const std::shared_ptr&, const std::shared_ptr& handler); void write_and_subscribe(std::uint32_t opaque, std::vector&& data, command_handler&& handler); void bootstrap(utils::movable_function&& handler, bool retry_on_bucket_not_found = false); void on_stop(utils::movable_function handler); void stop(retry_reason reason); [[nodiscard]] auto index() const -> std::size_t; [[nodiscard]] auto has_config() const -> bool; [[nodiscard]] auto config() const -> std::optional; [[nodiscard]] auto diag_info() const -> diag::endpoint_diag_info; void on_configuration_update(std::shared_ptr handler); void ping(const std::shared_ptr& handler, std::optional = {}) const; [[nodiscard]] auto supports_gcccp() const -> bool; [[nodiscard]] auto decode_error_code(std::uint16_t code) -> std::optional; void handle_not_my_vbucket(const io::mcbp_message& msg) const; void update_collection_uid(const std::string& path, std::uint32_t uid); #ifdef COUCHBASE_CXX_CLIENT_COLUMNAR void add_background_bootstrap_listener( std::shared_ptr listener); #endif private: std::shared_ptr impl_{ nullptr }; }; } // namespace io } // namespace couchbase::core