Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/mysql/impl/internal/sansio/connection_state.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CONNECTION_STATE_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CONNECTION_STATE_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 #include <boost/mysql/error_code.hpp>
0013 #include <boost/mysql/handshake_params.hpp>
0014 #include <boost/mysql/statement.hpp>
0015 
0016 #include <boost/mysql/detail/algo_params.hpp>
0017 #include <boost/mysql/detail/any_resumable_ref.hpp>
0018 
0019 #include <boost/mysql/impl/internal/sansio/close_connection.hpp>
0020 #include <boost/mysql/impl/internal/sansio/close_statement.hpp>
0021 #include <boost/mysql/impl/internal/sansio/connect.hpp>
0022 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0023 #include <boost/mysql/impl/internal/sansio/execute.hpp>
0024 #include <boost/mysql/impl/internal/sansio/handshake.hpp>
0025 #include <boost/mysql/impl/internal/sansio/ping.hpp>
0026 #include <boost/mysql/impl/internal/sansio/prepare_statement.hpp>
0027 #include <boost/mysql/impl/internal/sansio/quit_connection.hpp>
0028 #include <boost/mysql/impl/internal/sansio/read_resultset_head.hpp>
0029 #include <boost/mysql/impl/internal/sansio/read_some_rows.hpp>
0030 #include <boost/mysql/impl/internal/sansio/read_some_rows_dynamic.hpp>
0031 #include <boost/mysql/impl/internal/sansio/reset_connection.hpp>
0032 #include <boost/mysql/impl/internal/sansio/run_pipeline.hpp>
0033 #include <boost/mysql/impl/internal/sansio/set_character_set.hpp>
0034 #include <boost/mysql/impl/internal/sansio/start_execution.hpp>
0035 #include <boost/mysql/impl/internal/sansio/top_level_algo.hpp>
0036 
0037 #include <boost/variant2/variant.hpp>
0038 
0039 #include <cstddef>
0040 
0041 namespace boost {
0042 namespace mysql {
0043 namespace detail {
0044 
0045 // clang-format off
0046 template <class AlgoParams> struct get_algo;
0047 template <> struct get_algo<connect_algo_params> { using type = connect_algo; };
0048 template <> struct get_algo<handshake_algo_params> { using type = handshake_algo; };
0049 template <> struct get_algo<execute_algo_params> { using type = execute_algo; };
0050 template <> struct get_algo<start_execution_algo_params> { using type = start_execution_algo; };
0051 template <> struct get_algo<read_resultset_head_algo_params> { using type = read_resultset_head_algo; };
0052 template <> struct get_algo<read_some_rows_algo_params> { using type = read_some_rows_algo; };
0053 template <> struct get_algo<read_some_rows_dynamic_algo_params> { using type = read_some_rows_dynamic_algo; };
0054 template <> struct get_algo<prepare_statement_algo_params> { using type = prepare_statement_algo; };
0055 template <> struct get_algo<set_character_set_algo_params> { using type = set_character_set_algo; };
0056 template <> struct get_algo<quit_connection_algo_params> { using type = quit_connection_algo; };
0057 template <> struct get_algo<close_connection_algo_params> { using type = close_connection_algo; };
0058 template <> struct get_algo<run_pipeline_algo_params> { using type = run_pipeline_algo; };
0059 template <class AlgoParams> using get_algo_t = typename get_algo<AlgoParams>::type;
0060 // clang-format on
0061 
0062 class connection_state
0063 {
0064     // Helper
0065     template <class... Algos>
0066     using make_any_algo_type = variant2::variant<top_level_algo<Algos>...>;
0067 
0068     using any_algo = make_any_algo_type<
0069         connect_algo,
0070         handshake_algo,
0071         execute_algo,
0072         start_execution_algo,
0073         read_resultset_head_algo,
0074         read_some_rows_algo,
0075         read_some_rows_dynamic_algo,
0076         prepare_statement_algo,
0077         set_character_set_algo,
0078         quit_connection_algo,
0079         close_connection_algo,
0080         run_pipeline_algo>;
0081 
0082     connection_state_data st_data_;
0083     any_algo algo_;
0084 
0085 public:
0086     // We initialize the algo state with a dummy value. This will be overwritten
0087     // by setup() before the first algorithm starts running. Doing this avoids
0088     // the need for a special null algo
0089     connection_state(std::size_t read_buffer_size, std::size_t max_buffer_size, bool transport_supports_ssl)
0090         : st_data_(read_buffer_size, max_buffer_size, transport_supports_ssl),
0091           algo_(top_level_algo<quit_connection_algo>(
0092               st_data_,
0093               quit_connection_algo_params{&st_data_.shared_diag}
0094           ))
0095     {
0096     }
0097 
0098     const connection_state_data& data() const { return st_data_; }
0099     connection_state_data& data() { return st_data_; }
0100 
0101     template <class AlgoParams>
0102     any_resumable_ref setup(AlgoParams params)
0103     {
0104         return any_resumable_ref(algo_.emplace<top_level_algo<get_algo_t<AlgoParams>>>(st_data_, params));
0105     }
0106 
0107     any_resumable_ref setup(close_statement_algo_params params)
0108     {
0109         return setup(setup_close_statement_pipeline(st_data_, params));
0110     }
0111 
0112     any_resumable_ref setup(reset_connection_algo_params params)
0113     {
0114         return setup(setup_reset_connection_pipeline(st_data_, params));
0115     }
0116 
0117     any_resumable_ref setup(ping_algo_params params) { return setup(setup_ping_pipeline(st_data_, params)); }
0118 
0119     template <typename AlgoParams>
0120     typename AlgoParams::result_type result() const
0121     {
0122         return variant2::get<top_level_algo<get_algo_t<AlgoParams>>>(algo_).inner_algo().result(st_data_);
0123     }
0124 };
0125 
0126 }  // namespace detail
0127 }  // namespace mysql
0128 }  // namespace boost
0129 
0130 #endif