From b338426fc258d4e703ba29064ed6e987d826b62a Mon Sep 17 00:00:00 2001 From: Kelbon Nik Date: Sat, 26 Oct 2024 11:11:13 +0400 Subject: [PATCH] logger and includes --- .clang-format | 1 + .gitignore | 1 + CMakeLists.txt | 10 --- cmake/deps.cmake | 2 +- gbench/bench_main.cpp | 6 +- gbench/files.cpp | 6 +- gbench/fuzzing.hpp | 22 ++--- gbench/types.hpp | 4 +- gtest/api/test_message.cpp | 18 ++-- gtest/gtest_formater.hpp | 4 +- gtest/parsers/fixtures.hpp | 5 +- gtest/test_parser.cpp | 10 +-- include/tgbm/api/common.hpp | 13 +-- include/tgbm/api/const_string.hpp | 2 + include/tgbm/api/templates/default.hpp | 4 +- include/tgbm/api/templates/oneof.hpp | 4 +- include/tgbm/api/templates/oneof_field.hpp | 4 +- include/tgbm/logger.h | 17 ---- include/tgbm/logger.hpp | 32 +++++++ include/tgbm/net/HttpParser.h | 1 + include/tgbm/net/connectiion_pool.hpp | 23 ++--- include/tgbm/net/http11_client.hpp | 1 - include/tgbm/net/http2/protocol.hpp | 12 --- include/tgbm/net/http_base.hpp | 1 - include/tgbm/net/long_poll.hpp | 2 +- include/tgbm/net/tcp_connection.hpp | 10 +-- include/tgbm/tools/StringTools.h | 2 +- include/tgbm/tools/api_utils.hpp | 3 +- include/tgbm/tools/constexpr_string.h | 2 +- include/tgbm/tools/formatters.hpp | 11 +-- include/tgbm/tools/json_tools/all.hpp | 18 ++-- .../tgbm/tools/json_tools/boost_parse_dom.hpp | 19 ++-- .../json_tools/boost_parse_generator.hpp | 6 +- .../tools/json_tools/boost_parse_handler.hpp | 7 +- .../tools/json_tools/boost_serialize_dom.hpp | 13 +-- include/tgbm/tools/json_tools/exceptions.hpp | 5 +- .../tools/json_tools/generator_parser/all.hpp | 16 ++-- .../generator_parser/basic_parser.hpp | 7 +- .../generator_parser/common_api.hpp | 4 +- .../generator_parser/discriminated_api.hpp | 3 +- .../generator_parser/fundamental.hpp | 6 +- .../generator_parser/ignore_parser.hpp | 2 +- .../generator_parser/oneof_field_api_type.hpp | 5 +- .../generator_parser/optional_parser.hpp | 7 +- .../generator_parser/vector_parser.hpp | 3 +- .../tools/json_tools/handler_parser/all.hpp | 18 ++-- .../handler_parser/basic_parser.hpp | 14 +-- .../tools/json_tools/handler_parser/box.hpp | 5 +- .../json_tools/handler_parser/common_api.hpp | 10 ++- .../json_tools/handler_parser/fundamental.hpp | 6 +- .../json_tools/handler_parser/ignore.hpp | 2 +- .../json_tools/handler_parser/optional.hpp | 7 +- .../tools/json_tools/handler_parser/range.hpp | 5 +- .../tgbm/tools/json_tools/parse_dom/all.hpp | 14 +-- .../tgbm/tools/json_tools/parse_dom/array.hpp | 6 +- .../tools/json_tools/parse_dom/common_api.hpp | 7 +- .../parse_dom/discriminated_api.hpp | 7 +- .../json_tools/parse_dom/fundamental.hpp | 8 +- .../parse_dom/oneof_field_api_type.hpp | 11 +-- .../tools/json_tools/parse_dom/optional.hpp | 7 +- .../tgbm/tools/json_tools/rapid_parse_dom.hpp | 18 ++-- .../tools/json_tools/rapid_parse_handler.hpp | 8 +- include/tgbm/tools/macro.hpp | 6 +- include/tgbm/tools/math.hpp | 9 +- include/tgbm/tools/pfr_extension.hpp | 6 +- include/tgbm/tools/rapidjson_to_json.h | 3 +- include/tgbm/tools/scope_exit.h | 10 +-- include/tgbm/tools/traits.hpp | 3 +- src/Api.cpp | 5 +- src/Bot.cpp | 14 +-- src/net/http2_client.cpp | 90 ++++++++++--------- src/net/http2_server.cpp | 62 ++++++------- src/net/long_poll.cpp | 6 +- src/net/ssl_context.cpp | 20 ++--- src/net/tcp_connection.cpp | 16 ++-- 75 files changed, 396 insertions(+), 361 deletions(-) delete mode 100644 include/tgbm/logger.h create mode 100644 include/tgbm/logger.hpp diff --git a/.clang-format b/.clang-format index 01d62525..17e286e1 100644 --- a/.clang-format +++ b/.clang-format @@ -9,3 +9,4 @@ DerivePointerAlignment: false # disables 'Google' option which forces ignoring m PointerAlignment: Left ReferenceAlignment: Left InsertNewlineAtEOF: true +IndentPPDirectives: BeforeHash diff --git a/.gitignore b/.gitignore index e4b16752..d4b264f5 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ src/api_types_cmp.cpp include/tgbm/api/types_all.hpp include/tgbm/api/types_fwd.hpp include/tgbm/api/types.txt +**/tgbm_replace/* .vs/ .vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ba27d0..1aaf55af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,13 +163,3 @@ if (WIN32) message (STATUS "[tgbm] TGBM_WINDOWS_VERSION: ${TGBM_WINDOWS_VERSION}") target_compile_definitions(tgbmlib PUBLIC _WIN32_WINNT=${TGBM_WINDOWS_VERSION}) endif() - -add_executable(tgbm_main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -target_link_libraries(tgbm_main PUBLIC tgbmlib) - -set_target_properties(tgbm_main PROPERTIES - CMAKE_CXX_EXTENSIONS OFF - LINKER_LANGUAGE CXX - CMAKE_CXX_STANDARD_REQUIRED ON - CXX_STANDARD 20) - diff --git a/cmake/deps.cmake b/cmake/deps.cmake index f1e79614..2536a5c3 100644 --- a/cmake/deps.cmake +++ b/cmake/deps.cmake @@ -19,7 +19,7 @@ CPMAddPackage( unset(BOOST_INCLUDE_LIBRARIES) find_package(Boost 1.84 COMPONENTS system asio property_tree pfr json REQUIRED) -CPMAddPackage("gh:fmtlib/fmt#10.2.0") +CPMAddPackage("gh:fmtlib/fmt#11.0.2") CPMAddPackage( NAME kelcoro diff --git a/gbench/bench_main.cpp b/gbench/bench_main.cpp index 3ad24a3d..20e476d5 100644 --- a/gbench/bench_main.cpp +++ b/gbench/bench_main.cpp @@ -1,9 +1,11 @@ #include -#include -#include + #include #include +#include "tgbm/api/types_all.hpp" +#include "tgbm/tools/formatters.hpp" + int main(int argc, char** argv) { auto& storage = fuzzing::GetMutableStorage(); // clang-format off diff --git a/gbench/files.cpp b/gbench/files.cpp index f7be9da2..a5153711 100644 --- a/gbench/files.cpp +++ b/gbench/files.cpp @@ -1,9 +1,9 @@ #include "benchmark/benchmark.h" #include "fuzzing.hpp" #include "types.hpp" -#include -#include -#include +#include "tgbm/api/types_all.hpp" +#include "tgbm/tools/json_tools/all.hpp" +#include "tgbm/tools/json_tools/parse_dom/all.hpp" template void execute_handler_rapid(std::string_view json) { diff --git a/gbench/fuzzing.hpp b/gbench/fuzzing.hpp index 464570d7..eec94159 100644 --- a/gbench/fuzzing.hpp +++ b/gbench/fuzzing.hpp @@ -1,17 +1,18 @@ #pragma once -#include + #include #include #include #include #include #include -#include -#include -#include #include -#include -#include + +#include "tgbm/tools/box.hpp" +#include "tgbm/tools/pfr_extension.hpp" +#include "tgbm/tools/traits.hpp" +#include "tgbm/logger.hpp" +#include "tgbm/tools/json_tools/boost_serialize_dom.hpp" namespace fuzzing { @@ -186,7 +187,7 @@ struct Storage { template void Add(std::string name, Config config) { std::filesystem::path path(config.path); - LOG("Add: {}", path.generic_string()); + TGBM_LOG_INFO("Add: {}", path.generic_string()); std::optional json; if (std::filesystem::exists(path)) { std::fstream file(path); @@ -217,7 +218,7 @@ struct Storage { template void AddArray(std::string name, Config config) { std::filesystem::path path(config.path); - LOG("AddArray: {}", path.generic_string()); + TGBM_LOG_INFO("AddArray: {}", path.generic_string()); std::optional json; if (std::filesystem::exists(path)) { std::fstream file(path); @@ -354,9 +355,8 @@ template <> struct randomizer { static constexpr bool is_nesting = false; static std::string generate(Context context, auto&& generator) { - // TODO: char fix - std::uniform_int_distribution distribution('A', 'Z'); - std::uniform_int_distribution size_distr(0, 15); + std::uniform_int_distribution distribution(size_t('A'), size_t('Z')); + std::uniform_int_distribution size_distr(0, 15); std::uint8_t size = size_distr(generator); std::string result; result.resize(size, '\0'); diff --git a/gbench/types.hpp b/gbench/types.hpp index aa29f0b3..4ce795a8 100644 --- a/gbench/types.hpp +++ b/gbench/types.hpp @@ -1,6 +1,8 @@ #pragma once + #include -#include + +#include "tgbm/api/common.hpp" #include "tgbm/tools/pfr_extension.hpp" namespace types { diff --git a/gtest/api/test_message.cpp b/gtest/api/test_message.cpp index 8b40eae3..2b340ca2 100644 --- a/gtest/api/test_message.cpp +++ b/gtest/api/test_message.cpp @@ -1,15 +1,15 @@ #if 0 -#include + #include -#include -#include -#include -#include -#include -#include "chaotic_test.hpp" -#include -#include + #include "tgbm/tools/to_boost_json.h" + #include "tgbm/api/types_all.hpp" + #include "tgbm/tools/from_boost_json.h" + #include "tgbm/tools/json_tools/parser/all.h" + #include "tgbm/tools/random.h" + #include "chaotic_test.hpp" + #include + #include namespace api = tgbm::api; diff --git a/gtest/gtest_formater.hpp b/gtest/gtest_formater.hpp index 21b41af8..5c0ae9c7 100644 --- a/gtest/gtest_formater.hpp +++ b/gtest/gtest_formater.hpp @@ -1,9 +1,11 @@ #pragma once #include -#include + #include +#include "tgbm/tools/formatters.hpp" + template concept formattable = fmt::is_formattable::value; diff --git a/gtest/parsers/fixtures.hpp b/gtest/parsers/fixtures.hpp index 40d3842c..167c11a3 100644 --- a/gtest/parsers/fixtures.hpp +++ b/gtest/parsers/fixtures.hpp @@ -1,8 +1,9 @@ #pragma once #include #include -#include -#include + +#include "tgbm/api/common.hpp" +#include "tgbm/tools/json_tools/all.hpp" struct DomRapid : testing::Test { template diff --git a/gtest/test_parser.cpp b/gtest/test_parser.cpp index dad44028..f8b6d46d 100644 --- a/gtest/test_parser.cpp +++ b/gtest/test_parser.cpp @@ -2,11 +2,11 @@ #if 0 -#include -#include -#include -#include -#include + #include "tgbm/tools/json_tools/parser/all.h" + #include + #include + #include + #include namespace tests_json_parser { struct Position { diff --git a/include/tgbm/api/common.hpp b/include/tgbm/api/common.hpp index 39ac1c22..58487650 100644 --- a/include/tgbm/api/common.hpp +++ b/include/tgbm/api/common.hpp @@ -4,13 +4,14 @@ #include #include #include -#include -#include -#include -#include -#include #include -#include + +#include "tgbm/tools/StringTools.h" +#include "tgbm/tools/box_union.hpp" +#include "tgbm/api/optional.hpp" +#include "tgbm/api/Integer.hpp" +#include "tgbm/api/floating.hpp" +#include "tgbm/tools/pfr_extension.hpp" namespace tgbm::api { diff --git a/include/tgbm/api/const_string.hpp b/include/tgbm/api/const_string.hpp index 34587f3e..5a81ab09 100644 --- a/include/tgbm/api/const_string.hpp +++ b/include/tgbm/api/const_string.hpp @@ -67,6 +67,8 @@ struct TGBM_TRIVIAL_ABI const_string { return reinterpret_cast(&ptrlen); } char* buffer = (char*)malloc(sizeof(string_impl) + len); + if (!buffer) [[unlikely]] + throw std::bad_alloc{}; string_impl* impl = new (buffer) string_impl(1, len); ptrlen = reinterpret_cast(impl); return impl->data; diff --git a/include/tgbm/api/templates/default.hpp b/include/tgbm/api/templates/default.hpp index 4568dd4f..397ff34a 100644 --- a/include/tgbm/api/templates/default.hpp +++ b/include/tgbm/api/templates/default.hpp @@ -1,10 +1,10 @@ #ifndef API_TYPE_PATH -#error API_TYPE_PATH should be defined + #error API_TYPE_PATH should be defined #endif #ifndef API_TYPE -#error API_TYPE should be defined + #error API_TYPE should be defined #endif namespace tgbm::api { diff --git a/include/tgbm/api/templates/oneof.hpp b/include/tgbm/api/templates/oneof.hpp index 7aeb9dbb..b26e520e 100644 --- a/include/tgbm/api/templates/oneof.hpp +++ b/include/tgbm/api/templates/oneof.hpp @@ -1,10 +1,10 @@ #ifndef API_TYPE_PATH -#error API_TYPE_PATH should be defined + #error API_TYPE_PATH should be defined #endif #ifndef API_TYPE -#error API_TYPE should be defined + #error API_TYPE should be defined #endif namespace tgbm::api { diff --git a/include/tgbm/api/templates/oneof_field.hpp b/include/tgbm/api/templates/oneof_field.hpp index 917c36f9..72b67890 100644 --- a/include/tgbm/api/templates/oneof_field.hpp +++ b/include/tgbm/api/templates/oneof_field.hpp @@ -1,10 +1,10 @@ #ifndef API_TYPE_PATH -#error API_TYPE_PATH should be defined + #error API_TYPE_PATH should be defined #endif #ifndef API_TYPE -#error API_TYPE should be defined + #error API_TYPE should be defined #endif namespace tgbm::api { diff --git a/include/tgbm/logger.h b/include/tgbm/logger.h deleted file mode 100644 index 9ee368ac..00000000 --- a/include/tgbm/logger.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -// TODO rename to TGBM_LOG etc -#define LOG(FMT_STR, ...) \ - ::fmt::format_to(::std::ostreambuf_iterator(std::cout), FMT_STR "\n" __VA_OPT__(, ) __VA_ARGS__) -#define LOG_ERR(FMT_STR, ...) \ - ::fmt::format_to(::std::ostreambuf_iterator(std::cerr), FMT_STR "\n" __VA_OPT__(, ) __VA_ARGS__) - -#ifndef NDEBUG -#define LOG_DEBUG(FMT_STR, ...) LOG(FMT_STR __VA_OPT__(, ) __VA_ARGS__) -#else -#define LOG_DEBUG(FMT_STR, ...) (void)0 -#endif - -#define LOG_WARN(FMT_STR, ...) LOG("[WARN]" FMT_STR __VA_OPT__(, ) __VA_ARGS__) diff --git a/include/tgbm/logger.hpp b/include/tgbm/logger.hpp new file mode 100644 index 00000000..ffd6348c --- /dev/null +++ b/include/tgbm/logger.hpp @@ -0,0 +1,32 @@ +#pragma once +/* + simplest replacable logger + To replace logger user should create tgbm_replace/logger.hpp file + and add tgbm_replace into include dirs +*/ + +#if __has_include("tgbm_replace/logger.hpp") + #include "tgbm_replace/logger.hpp" + #ifndef TGBM_LOG + #error "tgbm_replace/logger.hpp" must define TGBM_LOG(FMT_STR, ...ARGS) + #endif +#else + + #include + #include + #include + #include + + #define TGBM_LOG(FMT_STR, ...) ::fmt::println(stdout, FMT_STR __VA_OPT__(, ) __VA_ARGS__) + +#endif + +#define TGBM_LOG_INFO(FMT_STR, ...) TGBM_LOG("[INFO] " FMT_STR __VA_OPT__(, ) __VA_ARGS__) +#define TGBM_LOG_ERROR(FMT_STR, ...) TGBM_LOG("[ERROR] " FMT_STR __VA_OPT__(, ) __VA_ARGS__) +#define TGBM_LOG_WARN(FMT_STR, ...) TGBM_LOG("[WARN] " FMT_STR __VA_OPT__(, ) __VA_ARGS__) + +#ifndef NDEBUG + #define TGBM_LOG_DEBUG(FMT_STR, ...) TGBM_LOG("[DEBUG] " FMT_STR __VA_OPT__(, ) __VA_ARGS__) +#else + #define TGBM_LOG_DEBUG(FMT_STR, ...) (void)0 +#endif diff --git a/include/tgbm/net/HttpParser.h b/include/tgbm/net/HttpParser.h index 100e3a93..fce6c849 100644 --- a/include/tgbm/net/HttpParser.h +++ b/include/tgbm/net/HttpParser.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "tgbm/tools/macro.hpp" #include "tgbm/tools/StringTools.h" diff --git a/include/tgbm/net/connectiion_pool.hpp b/include/tgbm/net/connectiion_pool.hpp index d253e3a2..e8b6a5eb 100644 --- a/include/tgbm/net/connectiion_pool.hpp +++ b/include/tgbm/net/connectiion_pool.hpp @@ -1,22 +1,20 @@ #pragma once + #include #include -#include -#include #include -#include -#include "tgbm/tools/scope_exit.h" +#include + +#include #include #include #include #include +#include "tgbm/tools/scope_exit.h" #include "tgbm/tools/boost_intrusive.hpp" - -#include "tgbm/logger.h" - #include "tgbm/tools/macro.hpp" namespace tgbm { @@ -41,17 +39,6 @@ struct noop_events_handler_t { } }; -// TODO into another file or smth like, utils -struct null_mutex { - static constexpr void lock() noexcept { - } - static constexpr void unlock() noexcept { - } - static constexpr bool try_lock() noexcept { - return true; - } -}; - // TODO coro allocator multithread (interface) template H = noop_events_handler_t> struct pool_t { diff --git a/include/tgbm/net/http11_client.hpp b/include/tgbm/net/http11_client.hpp index ae104c9b..c5bcf51c 100644 --- a/include/tgbm/net/http11_client.hpp +++ b/include/tgbm/net/http11_client.hpp @@ -4,7 +4,6 @@ #include "tgbm/net/http_client.hpp" #include "tgbm/net/connectiion_pool.hpp" -#include "tgbm/logger.h" #include "tgbm/net/tcp_connection.hpp" diff --git a/include/tgbm/net/http2/protocol.hpp b/include/tgbm/net/http2/protocol.hpp index 87991f56..00ddc58c 100644 --- a/include/tgbm/net/http2/protocol.hpp +++ b/include/tgbm/net/http2/protocol.hpp @@ -581,15 +581,3 @@ inline bool strip_padding(std::span& bytes) { void parse_http2_request_headers(hpack::decoder& d, std::span bytes, http_request& req); } // namespace tgbm::http2 - -namespace fmt { - -template <> -struct formatter<::tgbm::http2::frame_header> : fmt::formatter { - auto format(const ::tgbm::http2::frame_header& header, auto& ctx) -> decltype(ctx.out()) { - return fmt::format_to(ctx.out(), "length: {}\n, type: {}\n, flags: {}\n, stream_id: {}", header.length, - (int)header.type, (int)header.flags, header.stream_id); - } -}; - -} // namespace fmt diff --git a/include/tgbm/net/http_base.hpp b/include/tgbm/net/http_base.hpp index a06b9765..fb204b09 100644 --- a/include/tgbm/net/http_base.hpp +++ b/include/tgbm/net/http_base.hpp @@ -52,7 +52,6 @@ struct http_header_t { std::string value; }; -// TODO use const_string here // client knows authority and scheme and sets it struct http_request { // Host for HTTP1/1, :authority for HTTP2 diff --git a/include/tgbm/net/long_poll.hpp b/include/tgbm/net/long_poll.hpp index 6ef0d5a7..4a2b6dd8 100644 --- a/include/tgbm/net/long_poll.hpp +++ b/include/tgbm/net/long_poll.hpp @@ -5,7 +5,7 @@ #include // TODO разобраться откуда лезет #define YIeld и прикрыть эти хедеры (азио) #ifdef _WIN32 -#undef Yield + #undef Yield #endif #include diff --git a/include/tgbm/net/tcp_connection.hpp b/include/tgbm/net/tcp_connection.hpp index 00dd4afd..d5773379 100644 --- a/include/tgbm/net/tcp_connection.hpp +++ b/include/tgbm/net/tcp_connection.hpp @@ -13,7 +13,7 @@ #include "tgbm/net/errors.hpp" #include "tgbm/tools/macro.hpp" #include "tgbm/net/ssl_context.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include @@ -48,8 +48,8 @@ struct tcp_connection_options { tcp_sock.set_option(send_sz_option); tcp_sock.get_option(send_sz_option); if (send_sz_option.value() != send_buffer_size) { - LOG_WARN("tcp sendbuf size option not fully applied, requested: {}, actual: {}", send_buffer_size, - send_sz_option.value()); + TGBM_LOG_WARN("tcp sendbuf size option not fully applied, requested: {}, actual: {}", + send_buffer_size, send_sz_option.value()); } } { @@ -57,8 +57,8 @@ struct tcp_connection_options { tcp_sock.set_option(rsv_sz_option); tcp_sock.get_option(rsv_sz_option); if (rsv_sz_option.value() != send_buffer_size) { - LOG_WARN("tcp receive buf size option not fully applied, requested: {}, actual: {}", send_buffer_size, - rsv_sz_option.value()); + TGBM_LOG_WARN("tcp receive buf size option not fully applied, requested: {}, actual: {}", + send_buffer_size, rsv_sz_option.value()); } } } diff --git a/include/tgbm/tools/StringTools.h b/include/tgbm/tools/StringTools.h index e65efefe..5b8452b3 100644 --- a/include/tgbm/tools/StringTools.h +++ b/include/tgbm/tools/StringTools.h @@ -10,7 +10,7 @@ namespace tgbm::utils { -template O> +template O url_encode(char c, O out) { static constexpr auto is_legit = [](char c) { switch (c) { diff --git a/include/tgbm/tools/api_utils.hpp b/include/tgbm/tools/api_utils.hpp index bea3d946..7597571d 100644 --- a/include/tgbm/tools/api_utils.hpp +++ b/include/tgbm/tools/api_utils.hpp @@ -1,5 +1,6 @@ #pragma once -#include + +#include "tgbm/tools/pfr_extension.hpp" #include "tgbm/tools/box_union.hpp" #include "tgbm/tools/traits.hpp" diff --git a/include/tgbm/tools/constexpr_string.h b/include/tgbm/tools/constexpr_string.h index 4fdfc4b3..bfc7b4c0 100644 --- a/include/tgbm/tools/constexpr_string.h +++ b/include/tgbm/tools/constexpr_string.h @@ -8,7 +8,7 @@ namespace tgbm::ce { #ifndef TGBM_FIXED_STRING_SIZE -#define TGBM_FIXED_STRING_SIZE 64 + #define TGBM_FIXED_STRING_SIZE 64 #endif constexpr std::size_t k_len_fixed_string = TGBM_FIXED_STRING_SIZE; diff --git a/include/tgbm/tools/formatters.hpp b/include/tgbm/tools/formatters.hpp index 55dc038e..52fa2ed6 100644 --- a/include/tgbm/tools/formatters.hpp +++ b/include/tgbm/tools/formatters.hpp @@ -1,15 +1,16 @@ #pragma once -#include - #include #include -#include -#include -#include + #include #include +#include "tgbm/tools/traits.hpp" +#include "tgbm/tools/pfr_extension.hpp" +#include "tgbm/api/common.hpp" +#include "tgbm/tools/meta.hpp" + namespace fmt { template <> diff --git a/include/tgbm/tools/json_tools/all.hpp b/include/tgbm/tools/json_tools/all.hpp index 4b67b428..d53c2581 100644 --- a/include/tgbm/tools/json_tools/all.hpp +++ b/include/tgbm/tools/json_tools/all.hpp @@ -1,11 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "tgbm/tools/json_tools/boost_parse_dom.hpp" +#include "tgbm/tools/json_tools/boost_parse_generator.hpp" +#include "tgbm/tools/json_tools/boost_parse_handler.hpp" +#include "tgbm/tools/json_tools/generator_parser/all.hpp" +#include "tgbm/tools/json_tools/handler_parser/all.hpp" +#include "tgbm/tools/json_tools/parse_dom/all.hpp" +#include "tgbm/tools/json_tools/rapid_parse_handler.hpp" +#include "tgbm/tools/json_tools/rapid_parse_dom.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" diff --git a/include/tgbm/tools/json_tools/boost_parse_dom.hpp b/include/tgbm/tools/json_tools/boost_parse_dom.hpp index 20822656..a63ddb8d 100644 --- a/include/tgbm/tools/json_tools/boost_parse_dom.hpp +++ b/include/tgbm/tools/json_tools/boost_parse_dom.hpp @@ -1,17 +1,18 @@ #pragma once #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include + +#include "tgbm/tools/box.hpp" +#include "tgbm/tools/pfr_extension.hpp" +#include "tgbm/tools/traits.hpp" +#include "tgbm/tools/meta.hpp" +#include "tgbm/api/common.hpp" +#include "tgbm/tools/api_utils.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" namespace tgbm::json { struct boost_json_traits { diff --git a/include/tgbm/tools/json_tools/boost_parse_generator.hpp b/include/tgbm/tools/json_tools/boost_parse_generator.hpp index 4c413a31..95ef7a62 100644 --- a/include/tgbm/tools/json_tools/boost_parse_generator.hpp +++ b/include/tgbm/tools/json_tools/boost_parse_generator.hpp @@ -1,7 +1,9 @@ #pragma once -#include + #include +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" + namespace fmt { template <> struct formatter<::boost::json::string_view> : formatter { @@ -207,7 +209,7 @@ struct stream_parser { void parse(std::string_view data, bool end) { p.write_some(!end, data.data(), data.size(), ec); if (ec || (end && !p.handler().ended)) { - LOG_ERR("ec: {}, ended: {}", ec.message(), p.handler().ended); + TGBM_LOG_ERROR("ec: {}, ended: {}", ec.message(), p.handler().ended); TGBM_JSON_PARSE_ERROR; } } diff --git a/include/tgbm/tools/json_tools/boost_parse_handler.hpp b/include/tgbm/tools/json_tools/boost_parse_handler.hpp index e63302fe..835f61a9 100644 --- a/include/tgbm/tools/json_tools/boost_parse_handler.hpp +++ b/include/tgbm/tools/json_tools/boost_parse_handler.hpp @@ -1,9 +1,10 @@ #pragma once -#include #include -#include -#include + +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" +#include "tgbm/api/common.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" namespace tgbm::json::boost { diff --git a/include/tgbm/tools/json_tools/boost_serialize_dom.hpp b/include/tgbm/tools/json_tools/boost_serialize_dom.hpp index b5573eb6..17802255 100644 --- a/include/tgbm/tools/json_tools/boost_serialize_dom.hpp +++ b/include/tgbm/tools/json_tools/boost_serialize_dom.hpp @@ -1,12 +1,13 @@ #pragma once #include -#include -#include -#include -#include -#include -#include + +#include "tgbm/tools/box.hpp" +#include "tgbm/tools/pfr_extension.hpp" +#include "tgbm/tools/traits.hpp" +#include "tgbm/api/common.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" +#include "tgbm/tools/api_utils.hpp" namespace boost::json { diff --git a/include/tgbm/tools/json_tools/exceptions.hpp b/include/tgbm/tools/json_tools/exceptions.hpp index 4be21640..dd126d25 100644 --- a/include/tgbm/tools/json_tools/exceptions.hpp +++ b/include/tgbm/tools/json_tools/exceptions.hpp @@ -1,6 +1,7 @@ #pragma once #include -#include "tgbm/logger.h" + +#include "tgbm/logger.hpp" namespace tgbm::json { struct parse_error : std::runtime_error { @@ -18,7 +19,7 @@ struct serialize_error : std::runtime_error { } [[noreturn]] inline void throw_json_serialize_error() { - LOG("reading to throw TGBM_JSON_SERIALIZE_ERROR"); + TGBM_LOG_INFO("reading to throw TGBM_JSON_SERIALIZE_ERROR"); throw serialize_error(); } diff --git a/include/tgbm/tools/json_tools/generator_parser/all.hpp b/include/tgbm/tools/json_tools/generator_parser/all.hpp index de02ad79..fb9c1bd0 100644 --- a/include/tgbm/tools/json_tools/generator_parser/all.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/all.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" +#include "tgbm/tools/json_tools/generator_parser/common_api.hpp" +#include "tgbm/tools/json_tools/generator_parser/discriminated_api.hpp" +#include "tgbm/tools/json_tools/generator_parser/fundamental.hpp" +#include "tgbm/tools/json_tools/generator_parser/ignore_parser.hpp" +#include "tgbm/tools/json_tools/generator_parser/oneof_field_api_type.hpp" +#include "tgbm/tools/json_tools/generator_parser/optional_parser.hpp" +#include "tgbm/tools/json_tools/generator_parser/vector_parser.hpp" diff --git a/include/tgbm/tools/json_tools/generator_parser/basic_parser.hpp b/include/tgbm/tools/json_tools/generator_parser/basic_parser.hpp index 9e4e1543..5a2b55ac 100644 --- a/include/tgbm/tools/json_tools/generator_parser/basic_parser.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/basic_parser.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include -#include +#include "tgbm/tools/pfr_extension.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" +#include "tgbm/logger.hpp" + #include namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/generator_parser/common_api.hpp b/include/tgbm/tools/json_tools/generator_parser/common_api.hpp index 89165eaa..a3d203c6 100644 --- a/include/tgbm/tools/json_tools/generator_parser/common_api.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/common_api.hpp @@ -1,6 +1,8 @@ #pragma once + #include -#include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" #include "tgbm/tools/json_tools/generator_parser/ignore_parser.hpp" #include "tgbm/tools/pfr_extension.hpp" #include "tgbm/tools/traits.hpp" diff --git a/include/tgbm/tools/json_tools/generator_parser/discriminated_api.hpp b/include/tgbm/tools/json_tools/generator_parser/discriminated_api.hpp index aae5ec8d..185346ea 100644 --- a/include/tgbm/tools/json_tools/generator_parser/discriminated_api.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/discriminated_api.hpp @@ -1,5 +1,6 @@ #pragma once -#include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" #include "tgbm/tools/traits.hpp" namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/generator_parser/fundamental.hpp b/include/tgbm/tools/json_tools/generator_parser/fundamental.hpp index 411cc431..8987f19b 100644 --- a/include/tgbm/tools/json_tools/generator_parser/fundamental.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/fundamental.hpp @@ -1,7 +1,9 @@ #pragma once + #include -#include -#include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" +#include "tgbm/api/common.hpp" #include "tgbm/tools/math.hpp" namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/generator_parser/ignore_parser.hpp b/include/tgbm/tools/json_tools/generator_parser/ignore_parser.hpp index 939fbca6..99faa082 100644 --- a/include/tgbm/tools/json_tools/generator_parser/ignore_parser.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/ignore_parser.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/generator_parser/oneof_field_api_type.hpp b/include/tgbm/tools/json_tools/generator_parser/oneof_field_api_type.hpp index 349b6fb6..eab57b00 100644 --- a/include/tgbm/tools/json_tools/generator_parser/oneof_field_api_type.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/oneof_field_api_type.hpp @@ -1,7 +1,10 @@ #pragma once + #include -#include + #include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" #include "tgbm/tools/api_utils.hpp" #include "tgbm/tools/traits.hpp" diff --git a/include/tgbm/tools/json_tools/generator_parser/optional_parser.hpp b/include/tgbm/tools/json_tools/generator_parser/optional_parser.hpp index 71dd5a1b..4d6fc776 100644 --- a/include/tgbm/tools/json_tools/generator_parser/optional_parser.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/optional_parser.hpp @@ -1,7 +1,8 @@ #pragma once -#include -#include -#include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" +#include "tgbm/api/optional.hpp" +#include "tgbm/tools/box.hpp" namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/generator_parser/vector_parser.hpp b/include/tgbm/tools/json_tools/generator_parser/vector_parser.hpp index 97fe2343..f0f16569 100644 --- a/include/tgbm/tools/json_tools/generator_parser/vector_parser.hpp +++ b/include/tgbm/tools/json_tools/generator_parser/vector_parser.hpp @@ -1,5 +1,6 @@ #pragma once -#include + +#include "tgbm/tools/json_tools/generator_parser/basic_parser.hpp" namespace tgbm::generator_parser { diff --git a/include/tgbm/tools/json_tools/handler_parser/all.hpp b/include/tgbm/tools/json_tools/handler_parser/all.hpp index 12a278ad..c443ffc0 100644 --- a/include/tgbm/tools/json_tools/handler_parser/all.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/all.hpp @@ -1,11 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" +#include "tgbm/tools/json_tools/handler_parser/box.hpp" +#include "tgbm/tools/json_tools/handler_parser/common_api.hpp" +#include "tgbm/tools/json_tools/handler_parser/disriminated_api.hpp" +#include "tgbm/tools/json_tools/handler_parser/fundamental.hpp" +#include "tgbm/tools/json_tools/handler_parser/ignore.hpp" +#include "tgbm/tools/json_tools/handler_parser/optional.hpp" +#include "tgbm/tools/json_tools/handler_parser/range.hpp" +#include "tgbm/tools/json_tools/handler_parser/oneof_field_api.hpp" diff --git a/include/tgbm/tools/json_tools/handler_parser/basic_parser.hpp b/include/tgbm/tools/json_tools/handler_parser/basic_parser.hpp index 397a126d..6e79644f 100644 --- a/include/tgbm/tools/json_tools/handler_parser/basic_parser.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/basic_parser.hpp @@ -3,13 +3,13 @@ #include #include #include -#include -#include -#include + #include + #include -#include -#include + +#include "tgbm/tools/json_tools/exceptions.hpp" +#include "tgbm/tools/macro.hpp" namespace tgbm::json::handler_parser { @@ -17,11 +17,11 @@ template struct Parser {}; #ifndef TGBM_STATIC_PARSER_SIZE -#define TGBM_STATIC_PARSER_SIZE 64 + #define TGBM_STATIC_PARSER_SIZE 64 #endif #ifndef TGBM_PARSER_STACK_SIZE -#define TGBM_PARSER_STACK_SIZE 16 + #define TGBM_PARSER_STACK_SIZE 16 #endif enum struct ResultParse { kContinue, kError, kEnd }; diff --git a/include/tgbm/tools/json_tools/handler_parser/box.hpp b/include/tgbm/tools/json_tools/handler_parser/box.hpp index 28ec2216..47c47e39 100644 --- a/include/tgbm/tools/json_tools/handler_parser/box.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/box.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include #include #include +#include "tgbm/tools/box.hpp" +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" + namespace tgbm::json::handler_parser { template diff --git a/include/tgbm/tools/json_tools/handler_parser/common_api.hpp b/include/tgbm/tools/json_tools/handler_parser/common_api.hpp index af08ecd1..ecbdf2b8 100644 --- a/include/tgbm/tools/json_tools/handler_parser/common_api.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/common_api.hpp @@ -1,12 +1,14 @@ #pragma once + #include #include -#include + #include -#include -#include + +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" +#include "tgbm/tools/json_tools/handler_parser/ignore.hpp" +#include "tgbm/tools/StringTools.h" #include "tgbm/tools/traits.hpp" -#include namespace tgbm::json::handler_parser { diff --git a/include/tgbm/tools/json_tools/handler_parser/fundamental.hpp b/include/tgbm/tools/json_tools/handler_parser/fundamental.hpp index 350d1238..cd5e8527 100644 --- a/include/tgbm/tools/json_tools/handler_parser/fundamental.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/fundamental.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" +#include "tgbm/api/Integer.hpp" +#include "tgbm/api/floating.hpp" #include "tgbm/api/common.hpp" namespace tgbm::json::handler_parser { diff --git a/include/tgbm/tools/json_tools/handler_parser/ignore.hpp b/include/tgbm/tools/json_tools/handler_parser/ignore.hpp index 390454d1..49f84ae2 100644 --- a/include/tgbm/tools/json_tools/handler_parser/ignore.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/ignore.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" namespace tgbm::json::handler_parser { diff --git a/include/tgbm/tools/json_tools/handler_parser/optional.hpp b/include/tgbm/tools/json_tools/handler_parser/optional.hpp index 86d3d967..ebd9ebb8 100644 --- a/include/tgbm/tools/json_tools/handler_parser/optional.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/optional.hpp @@ -1,10 +1,9 @@ #pragma once -#include -#include #include -#include -#include + +#include "tgbm/api/optional.hpp" +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" namespace tgbm::json::handler_parser { diff --git a/include/tgbm/tools/json_tools/handler_parser/range.hpp b/include/tgbm/tools/json_tools/handler_parser/range.hpp index 5561b108..2662a4fe 100644 --- a/include/tgbm/tools/json_tools/handler_parser/range.hpp +++ b/include/tgbm/tools/json_tools/handler_parser/range.hpp @@ -1,9 +1,10 @@ #pragma once -#include -#include #include +#include "tgbm/tools/traits.hpp" +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" + namespace tgbm::json::handler_parser { // TODO: string_like // TODO: range_like diff --git a/include/tgbm/tools/json_tools/parse_dom/all.hpp b/include/tgbm/tools/json_tools/parse_dom/all.hpp index 51a09478..af306a0f 100644 --- a/include/tgbm/tools/json_tools/parse_dom/all.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/all.hpp @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include +#include "tgbm/tools/json_tools/parse_dom/array.hpp" +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/parse_dom/common_api.hpp" +#include "tgbm/tools/json_tools/parse_dom/discriminated_api.hpp" +#include "tgbm/tools/json_tools/parse_dom/fundamental.hpp" +#include "tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp" +#include "tgbm/tools/json_tools/parse_dom/optional.hpp" diff --git a/include/tgbm/tools/json_tools/parse_dom/array.hpp b/include/tgbm/tools/json_tools/parse_dom/array.hpp index 318f7369..0b947681 100644 --- a/include/tgbm/tools/json_tools/parse_dom/array.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/array.hpp @@ -1,8 +1,10 @@ #pragma once -#include -#include + #include +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" + namespace tgbm::json::parse_dom { template diff --git a/include/tgbm/tools/json_tools/parse_dom/common_api.hpp b/include/tgbm/tools/json_tools/parse_dom/common_api.hpp index 4458f052..5d58ac64 100644 --- a/include/tgbm/tools/json_tools/parse_dom/common_api.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/common_api.hpp @@ -1,7 +1,8 @@ #pragma once -#include -#include -#include + +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/api/common.hpp" #include "tgbm/tools/pfr_extension.hpp" #include "tgbm/tools/traits.hpp" diff --git a/include/tgbm/tools/json_tools/parse_dom/discriminated_api.hpp b/include/tgbm/tools/json_tools/parse_dom/discriminated_api.hpp index 9a15b690..31be02d9 100644 --- a/include/tgbm/tools/json_tools/parse_dom/discriminated_api.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/discriminated_api.hpp @@ -1,7 +1,8 @@ #pragma once -#include -#include -#include + +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/api/common.hpp" #include "tgbm/tools/traits.hpp" namespace tgbm::json::parse_dom { diff --git a/include/tgbm/tools/json_tools/parse_dom/fundamental.hpp b/include/tgbm/tools/json_tools/parse_dom/fundamental.hpp index 733f68a1..285fa1e5 100644 --- a/include/tgbm/tools/json_tools/parse_dom/fundamental.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/fundamental.hpp @@ -1,9 +1,11 @@ #pragma once + #include -#include -#include -#include #include + +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/api/common.hpp" #include "tgbm/tools/math.hpp" namespace tgbm::json::parse_dom { diff --git a/include/tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp b/include/tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp index c5f4dd9f..f07ba0ff 100644 --- a/include/tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/oneof_field_api_type.hpp @@ -1,9 +1,10 @@ #pragma once -#include -#include -#include -#include -#include + +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/api/common.hpp" +#include "tgbm/tools/api_utils.hpp" +#include "tgbm/tools/traits.hpp" namespace tgbm::json::parse_dom { diff --git a/include/tgbm/tools/json_tools/parse_dom/optional.hpp b/include/tgbm/tools/json_tools/parse_dom/optional.hpp index b85d98f4..e61da244 100644 --- a/include/tgbm/tools/json_tools/parse_dom/optional.hpp +++ b/include/tgbm/tools/json_tools/parse_dom/optional.hpp @@ -1,7 +1,8 @@ #pragma once -#include -#include -#include + +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/api/common.hpp" namespace tgbm::json::parse_dom { diff --git a/include/tgbm/tools/json_tools/rapid_parse_dom.hpp b/include/tgbm/tools/json_tools/rapid_parse_dom.hpp index 7b73a2a8..e15d771f 100644 --- a/include/tgbm/tools/json_tools/rapid_parse_dom.hpp +++ b/include/tgbm/tools/json_tools/rapid_parse_dom.hpp @@ -1,16 +1,18 @@ #pragma once -#include -#include #include #include -#include -#include -#include -#include -#include "tgbm/tools/json_tools/json_traits.hpp" + +#include +#include #include -#include + +#include "tgbm/api/common.hpp" +#include "tgbm/tools/api_utils.hpp" +#include "tgbm/tools/traits.hpp" +#include "tgbm/tools/json_tools/exceptions.hpp" +#include "tgbm/tools/json_tools/json_traits.hpp" +#include "tgbm/tools/json_tools/parse_dom/basic.hpp" namespace tgbm::json { diff --git a/include/tgbm/tools/json_tools/rapid_parse_handler.hpp b/include/tgbm/tools/json_tools/rapid_parse_handler.hpp index 58844985..7f7cd1c9 100644 --- a/include/tgbm/tools/json_tools/rapid_parse_handler.hpp +++ b/include/tgbm/tools/json_tools/rapid_parse_handler.hpp @@ -1,13 +1,15 @@ #pragma once +#include + #include #include #include -#include -#include -#include #include +#include "tgbm/tools/json_tools/handler_parser/basic_parser.hpp" +#include "tgbm/api/common.hpp" + namespace tgbm::json::rapid { namespace details { diff --git a/include/tgbm/tools/macro.hpp b/include/tgbm/tools/macro.hpp index 90174761..1fec66fa 100644 --- a/include/tgbm/tools/macro.hpp +++ b/include/tgbm/tools/macro.hpp @@ -3,13 +3,13 @@ #include "kelcoro/noexport/macro.hpp" #ifdef __clang__ -#define TGBM_TRIVIAL_ABI [[clang::trivial_abi]] + #define TGBM_TRIVIAL_ABI [[clang::trivial_abi]] #else -#define TGBM_TRIVIAL_ABI + #define TGBM_TRIVIAL_ABI #endif #ifndef TGBM_ENABLE_DEBUG -#define TGBM_ENABLE_DEBUG NDEBUG + #define TGBM_ENABLE_DEBUG NDEBUG #endif #ifdef TGBM_ENABLE_DEBUG diff --git a/include/tgbm/tools/math.hpp b/include/tgbm/tools/math.hpp index dd3f05ea..99faeb14 100644 --- a/include/tgbm/tools/math.hpp +++ b/include/tgbm/tools/math.hpp @@ -1,10 +1,13 @@ #pragma once + #include -#include -#include -#include #include +#include + +#include "tgbm/api/common.hpp" +#include "tgbm/tools/formatters.hpp" + namespace tgbm { template diff --git a/include/tgbm/tools/pfr_extension.hpp b/include/tgbm/tools/pfr_extension.hpp index f8e416fe..a0cbf101 100644 --- a/include/tgbm/tools/pfr_extension.hpp +++ b/include/tgbm/tools/pfr_extension.hpp @@ -1,14 +1,14 @@ #pragma once #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-var-template" + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wundefined-var-template" #endif #include #if defined(__clang__) -#pragma clang diagnostic pop + #pragma clang diagnostic pop #endif #include "tgbm/tools/constexpr_string.h" diff --git a/include/tgbm/tools/rapidjson_to_json.h b/include/tgbm/tools/rapidjson_to_json.h index f28afff3..caf1dde1 100644 --- a/include/tgbm/tools/rapidjson_to_json.h +++ b/include/tgbm/tools/rapidjson_to_json.h @@ -2,7 +2,8 @@ #include #include -#include + +#include "tgbm/tools/traits.hpp" namespace tgbm { diff --git a/include/tgbm/tools/scope_exit.h b/include/tgbm/tools/scope_exit.h index d3e83a72..af88a0e9 100644 --- a/include/tgbm/tools/scope_exit.h +++ b/include/tgbm/tools/scope_exit.h @@ -1,17 +1,17 @@ #pragma once #if __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunknown-attributes" + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wunknown-attributes" #endif #include #include #if __cplusplus >= 202002L -#define LOGIC_GUARDS_CONSTEXPR_DCTOR constexpr + #define LOGIC_GUARDS_CONSTEXPR_DCTOR constexpr #else -#define LOGIC_GUARDS_CONSTEXPR_DCTOR + #define LOGIC_GUARDS_CONSTEXPR_DCTOR #endif // both scope_exit and scope_failure use precondition, @@ -92,5 +92,5 @@ struct maker { #define LOGIC_GUARDS_CONCAT(a, b, c) LOGIC_GUARDS_CONCAT_IMPL(a, b, c) #if __clang__ -#pragma clang diagnostic pop + #pragma clang diagnostic pop #endif diff --git a/include/tgbm/tools/traits.hpp b/include/tgbm/tools/traits.hpp index 51e248a0..0d0e4550 100644 --- a/include/tgbm/tools/traits.hpp +++ b/include/tgbm/tools/traits.hpp @@ -2,7 +2,8 @@ #include #include #include -#include + +#include "tgbm/api/optional.hpp" namespace tgbm { template diff --git a/src/Api.cpp b/src/Api.cpp index 110de79a..85000a73 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -5,7 +5,7 @@ #include #include "tgbm/tools/algorithm.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" namespace tgbm { @@ -2317,7 +2317,8 @@ dd::task Api::sendRequest(http_request request, dur if (!result.get("ok", false)) { auto x = result.get_optional("ok"); if (x && !*x) { - LOG_ERR("json with error: {}", std::string_view((char*)response.body.data(), response.body.size())); + TGBM_LOG_ERROR("json with error: {}", + std::string_view((char*)response.body.data(), response.body.size())); } else { throw TGBM_TG_EXCEPTION(tg_errc(result.get("error_code", 0u)), "{}", result.get("description", "")); diff --git a/src/Bot.cpp b/src/Bot.cpp index e75ad89b..bebff976 100644 --- a/src/Bot.cpp +++ b/src/Bot.cpp @@ -6,7 +6,7 @@ #include #include -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include "tgbm/tools/scope_exit.h" namespace tgbm { @@ -41,24 +41,24 @@ dd::task Bot::get_and_handle_updates(std::chrono::seconds update_wait_time _eventHandler.handleUpdate(update); } } catch (std::exception& e) { - LOG_ERR("Bot getUpdates ended with exception, its ignored, err: {}", e.what()); - LOG_ERR("getUpdates ended with exception, http client will be stopped, what: {}", e.what()); + TGBM_LOG_ERROR("Bot getUpdates ended with exception, its ignored, err: {}", e.what()); + TGBM_LOG_ERROR("getUpdates ended with exception, http client will be stopped, what: {}", e.what()); } catch (...) { - LOG_ERR("getUpdates ended with unknown exception, http client will be stopped"); + TGBM_LOG_ERROR("getUpdates ended with unknown exception, http client will be stopped"); } } void Bot::run(std::chrono::seconds update_wait_timeout) { auto handle = get_and_handle_updates(update_wait_timeout).start_and_detach(/*stop_at_end=*/true); - LOG_DEBUG("start bot"); + TGBM_LOG_DEBUG("start bot"); _client->run(); std::exception_ptr e = handle.promise().exception; handle.destroy(); if (e) { - LOG("Bot stopped with exception in getUpdates"); + TGBM_LOG_INFO("Bot stopped with exception in getUpdates"); std::rethrow_exception(e); } else { - LOG("Bot stopped without exception"); + TGBM_LOG_INFO("Bot stopped without exception"); } } diff --git a/src/net/http2_client.cpp b/src/net/http2_client.cpp index 27cc676e..2bf2d5bc 100644 --- a/src/net/http2_client.cpp +++ b/src/net/http2_client.cpp @@ -43,15 +43,13 @@ possible situatuions: #include "tgbm/net/http2/protocol.hpp" #include "tgbm/net/http2_client.hpp" #include "tgbm/net/asio_awaiters.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include "tgbm/tools/scope_exit.h" #include "tgbm/tools/macro.hpp" #include "tgbm/net/errors.hpp" #include "tgbm/tools/reusable_buffer.hpp" #include "tgbm/tools/deadline.hpp" -#include - #include #include @@ -378,7 +376,7 @@ struct http2_connection { forget(node); if (!node.task) return; - LOG_DEBUG("[HTTP2]: stream {} finished, status: {}", node.req.streamid, status); + TGBM_LOG_DEBUG("[HTTP2]: stream {} finished, status: {}", node.req.streamid, status); node.status = status; auto t = std::exchange(node.task, nullptr); if (status == reqerr_e::cancelled) @@ -409,7 +407,8 @@ struct http2_connection { assert(reqs.size() + rsps.size() == timers.size()); // nodes in reqs or in rsps, timers do not own them timers.clear(); - LOG_DEBUG("finish {} requests and {} responses, reason code: {}", reqs.size(), rsps.size(), (int)reason); + TGBM_LOG_DEBUG("finish {} requests and {} responses, reason code: {}", reqs.size(), rsps.size(), + (int)reason); auto forget_and_resume = [&](request_node* node) { finish_request(*node, reason); }; reqs.clear_and_dispose(forget_and_resume); rsps.clear_and_dispose(forget_and_resume); @@ -453,7 +452,7 @@ struct http2_connection { // prevents me to be destroyed while resuming writer/reader etc http2_connection_ptr lock = this; - LOG_DEBUG("[HTTP2] [shutdown] connection, address: {}", (void*)this); + TGBM_LOG_DEBUG("[HTTP2] [shutdown] connection, address: {}", (void*)this); if (is_dropped()) return; // set flag for anyone who will be resumed while shutting down this connection @@ -562,7 +561,7 @@ dd::task send_rst_stream(http2_connection_ptr con, http2::stream_id_t stre io_error_code ec; co_await net.write(con->socket(), bytes, ec); if (ec) - LOG_DEBUG("HTTP/2: cannot rst stream, ec: {}", ec.what()); + TGBM_LOG_DEBUG("[HTTP2]: cannot rst stream, ec: {}", ec.what()); } dd::task send_ping(http2_connection_ptr con, uint64_t data, bool request_pong) { @@ -613,11 +612,11 @@ struct first_settings_frame_visitor { }; static dd::task handle_ping(http2::ping_frame ping, http2_connection_ptr con) { - LOG_DEBUG("[HTTP2]: received ping, data: {}", ping.get_data()); + TGBM_LOG_DEBUG("[HTTP2]: received ping, data: {}", ping.get_data()); if (ping.header.flags & http2::flags::ACK) co_return; if (!co_await send_ping(std::move(con), ping.get_data(), false)) - LOG_ERR("[HTTP2]: cannot handle ping"); + TGBM_LOG_ERROR("[HTTP2]: cannot handle ping"); } static dd::task establish_http2_session(tcp_connection&& asio_con, @@ -673,7 +672,7 @@ static dd::task establish_http2_session(tcp_connection&& a throw network_exception("cannot send accepted settings frame to server, {}", ec.what()); if (std::ranges::equal(buf, bytes)) { // server ACK already received - LOG("HTTP/2 connection successfully established without server settings frame"); + TGBM_LOG_INFO("[HTTP2] connection successfully established without server settings frame"); // con.decoder is default with 4096 bytes con->server_settings.max_frame_size = std::min(con->server_settings.max_frame_size, options.max_send_frame_size); @@ -696,8 +695,8 @@ static dd::task establish_http2_session(tcp_connection&& a if (header.length != 0 || header.stream_id != 0) throw protocol_error{}; con->decoder = hpack::decoder(con->server_settings.header_table_size); - LOG("HTTP/2 connection successfully established, decoder size: {}", - con->server_settings.header_table_size); + TGBM_LOG_INFO("[HTTP2] connection successfully established, decoder size: {}", + con->server_settings.header_table_size); con->server_settings.max_frame_size = std::min(con->server_settings.max_frame_size, options.max_send_frame_size); co_return con; @@ -732,8 +731,8 @@ static dd::task establish_http2_session(tcp_connection&& a void http2_client::notify_connection_waiters(http2_connection_ptr result) noexcept { // assume only i have access to waiters auto waiters = std::move(connection_waiters); - LOG_DEBUG("[HTTP2]: resuming connection waiters, count: {}, connection: {}", waiters.size(), - (void*)result.get()); + TGBM_LOG_DEBUG("[HTTP2]: resuming connection waiters, count: {}, connection: {}", waiters.size(), + (void*)result.get()); assert(connection_waiters.empty()); // check boost really works as expected waiters.clear_and_dispose([&](noexport::waiter_of_connection* w) { assert(!w->result); @@ -747,9 +746,9 @@ void http2_client::notify_connection_waiters(http2_connection_ptr result) noexce dd::job start_pinger_for(http2_connection_ptr con, duration_t interval) { if (!con || con->is_dropped()) co_return; - LOG_DEBUG("[HTTP2]: pinger started for {}", (void*)con.get()); + TGBM_LOG_DEBUG("[HTTP2]: pinger started for {}", (void*)con.get()); on_scope_exit { - LOG_DEBUG("[HTTP2]: pinger for {} completed", (void*)con.get()); + TGBM_LOG_DEBUG("[HTTP2]: pinger for {} completed", (void*)con.get()); }; asio::steady_timer timer(con->socket().get_executor()); io_error_code ec; @@ -771,7 +770,7 @@ dd::job http2_client::start_connecting() { assert(!connection); co_await std::suspend_always{}; // resumed when needed by creator if (stop_requested) { - LOG_DEBUG("[HTTP2] connection tries to create when stop requested, ignored"); + TGBM_LOG_DEBUG("[HTTP2] connection tries to create when stop requested, ignored"); co_return; } if (already_connecting()) @@ -806,7 +805,7 @@ dd::job http2_client::start_connecting() { if (options.ping_interval != duration_t::max()) start_pinger_for(new_connection, options.ping_interval); } catch (std::exception& e) { - LOG_ERR("exception while trying to connect: {}", e.what()); + TGBM_LOG_ERROR("exception while trying to connect: {}", e.what()); } } @@ -879,7 +878,7 @@ dd::task write_pending_data_frames(node_ptr work, size_t handled_bytes, ht con->finish_request(*work, status); }; if (handled_bytes < h2fhl) { - LOG_DEBUG("[HTTP2] required to relocate {} bytes. Handled {}", req.data.size(), handled_bytes); + TGBM_LOG_DEBUG("[HTTP2] required to relocate {} bytes. Handled {}", req.data.size(), handled_bytes); // code above reuses already sended bytes as buffer for frame_header req.data.insert(req.data.begin(), h2fhl - handled_bytes, 0); handled_bytes = h2fhl; @@ -891,9 +890,10 @@ dd::task write_pending_data_frames(node_ptr work, size_t handled_bytes, ht co_return; frame_len = fill_data_header(*work, *con, std::distance(in, data_end), in - h2fhl); if (frame_len == 0) { - LOG_DEBUG("[HTTP2] cannot send bytes now! unhandled: {}, max_frame_len: {}, stream wsz {}, con wsz: {}", - std::distance(in, data_end), con->server_settings.max_frame_size, - work->streamlevel_window_size, con->receiver_window_size); + TGBM_LOG_DEBUG( + "[HTTP2] cannot send bytes now! unhandled: {}, max_frame_len: {}, stream wsz {}, con wsz: {}", + std::distance(in, data_end), con->server_settings.max_frame_size, work->streamlevel_window_size, + con->receiver_window_size); co_await con->idle_yield(); continue; } @@ -905,7 +905,7 @@ dd::task write_pending_data_frames(node_ptr work, size_t handled_bytes, ht if (ec) { if (ec != asio::error::operation_aborted) { status = reqerr_e::network_err; - LOG_DEBUG("[HTTP2]: sending pending data frames ended with network err: {}", ec.what()); + TGBM_LOG_DEBUG("[HTTP2]: sending pending data frames ended with network err: {}", ec.what()); } co_return; } @@ -913,7 +913,7 @@ dd::task write_pending_data_frames(node_ptr work, size_t handled_bytes, ht con->receiver_window_size -= frame_len; work->streamlevel_window_size -= frame_len; } // end loop - LOG_DEBUG("[HTTP2]: pending data frames for stream {} successfully sended", streamid); + TGBM_LOG_DEBUG("[HTTP2]: pending data frames for stream {} successfully sended", streamid); status = reqerr_e::done; co_return; } @@ -988,9 +988,9 @@ dd::task write_pending_data_frames(node_ptr work, size_t handled_bytes, ht // коннекш dd::job http2_client::start_writer_for(http2_connection_ptr con) { assert(con); - LOG_DEBUG("[HTTP2]: writer started for {}", (void*)con.get()); + TGBM_LOG_DEBUG("[HTTP2]: writer started for {}", (void*)con.get()); on_scope_exit { - LOG_DEBUG("[HTTP2]: writer for {} completed", (void*)con.get()); + TGBM_LOG_DEBUG("[HTTP2]: writer for {} completed", (void*)con.get()); }; io_error_code ec; @@ -1039,7 +1039,7 @@ dd::job http2_client::start_writer_for(http2_connection_ptr con) { } // end loop handling requests end: if (ec && ec != asio::error::operation_aborted) - LOG_DEBUG("[HTTP2] connection dropped with network err {}", ec.what()); + TGBM_LOG_DEBUG("[HTTP2] connection dropped with network err {}", ec.what()); drop_connection(reqerr_e::network_err); } @@ -1062,7 +1062,8 @@ static bool handle_utility_frame(http2_frame_t&& frame, http2_connection& con) { server_settings_visitor vtor(con.server_settings); settings_frame::parse(frame.header, frame.data, vtor); if (vtor.header_table_size_decrease) - LOG("[HTTP2]: HPACK table resized, new size {}, old size: {}, IF ERROR HAPPENS AFTER THIS MESSAGE, " + TGBM_LOG_INFO( + "[HTTP2]: HPACK table resized, new size {}, old size: {}, IF ERROR HAPPENS AFTER THIS MESSAGE, " "next time set dynamic table size for client to 0", con.server_settings.header_table_size, con.server_settings.header_table_size + vtor.header_table_size_decrease); @@ -1073,8 +1074,9 @@ static bool handle_utility_frame(http2_frame_t&& frame, http2_connection& con) { return true; case RST_STREAM: if (!con.finish_stream_with_error(rst_stream::parse(frame.header, frame.data))) - LOG_DEBUG("[HTTP2]: server finished stream (id: {}) which is not exists (maybe timeout or canceled)", - frame.header.stream_id); + TGBM_LOG_DEBUG( + "[HTTP2]: server finished stream (id: {}) which is not exists (maybe timeout or canceled)", + frame.header.stream_id); return true; case GOAWAY: goaway_frame::parse_and_throw_goaway(frame.header, frame.data); @@ -1083,10 +1085,10 @@ static bool handle_utility_frame(http2_frame_t&& frame, http2_connection& con) { return true; case PUSH_PROMISE: if (con.client_settings.enable_push) - LOG_DEBUG("[HTTP2]: received PUSH_PROMISE, not supported"); + TGBM_LOG_DEBUG("[HTTP2]: received PUSH_PROMISE, not supported"); return false; case CONTINUATION: - LOG_DEBUG("[HTTP2]: received CONTINUATION, not supported"); + TGBM_LOG_DEBUG("[HTTP2]: received CONTINUATION, not supported"); return false; default: case PRIORITY: @@ -1106,7 +1108,7 @@ static bool handle_utility_frame(http2_frame_t&& frame, http2_connection& con) { if ((frame.header.flags & http2::flags::PADDED) && !http2::strip_padding(frame.data)) return false; if (frame.header.flags & http2::flags::PRIORITY) { - LOG_DEBUG("[HTTP2]: received deprecated priority HEADERS, not supported"); + TGBM_LOG_DEBUG("[HTTP2]: received deprecated priority HEADERS, not supported"); return false; } @@ -1160,7 +1162,8 @@ dd::task send_window_update(http2_connection_ptr con, http2::stream_id_t i co_return false; byte_t buf[http2::window_update_frame::len]; http2::window_update_frame::form(id, inc, buf); - LOG_DEBUG("[HTTP2]: update window, stream: {}, inc: {}, mywindowsiz: {}", id, inc, con->my_window_size); + TGBM_LOG_DEBUG("[HTTP2]: update window, stream: {}, inc: {}, mywindowsiz: {}", id, inc, + con->my_window_size); io_error_code ec; co_await net.write(con->socket(), std::span(buf), ec); co_return !ec; @@ -1172,10 +1175,10 @@ dd::task send_window_update(http2_connection_ptr con, http2::stream_id_t i dd::job http2_client::start_reader_for(http2_connection_ptr _con) { using enum http2::frame_e; using namespace http2; - LOG_DEBUG("[HTTP2]: reader started for {}", (void*)_con.get()); + TGBM_LOG_DEBUG("[HTTP2]: reader started for {}", (void*)_con.get()); assert(_con); on_scope_exit { - LOG_DEBUG("[HTTP2]: reader for {} ended", (void*)_con.get()); + TGBM_LOG_DEBUG("[HTTP2]: reader for {} ended", (void*)_con.get()); }; http2_connection& con = *_con; io_error_code ec; @@ -1226,19 +1229,20 @@ dd::job http2_client::start_reader_for(http2_connection_ptr _con) { } } } catch (protocol_error&) { - LOG("[HTTP2]: protocol error happens"); + TGBM_LOG_INFO("[HTTP2]: protocol error happens"); reason = reqerr_e::protocol_err; goto drop_connection; } catch (http2::goaway_exception& gae) { - LOG_ERR("[HTTP2]: goaway received, info: {}, errc: {}", gae.debug_info, http2::e2str(gae.error_code)); + TGBM_LOG_ERROR("[HTTP2]: goaway received, info: {}, errc: {}", gae.debug_info, + http2::e2str(gae.error_code)); reason = reqerr_e::server_cancelled_request; goto drop_connection; } catch (std::exception& se) { - LOG("[HTTP2]: unexpected exception {}", se.what()); + TGBM_LOG_INFO("[HTTP2]: unexpected exception {}", se.what()); reason = reqerr_e::unknown_err; goto drop_connection; } catch (...) { - LOG("[HTTP2]: unknown exception happens"); + TGBM_LOG_INFO("[HTTP2]: unknown exception happens"); reason = reqerr_e::unknown_err; goto drop_connection; } @@ -1253,7 +1257,7 @@ dd::job http2_client::start_reader_for(http2_connection_ptr _con) { network_error: reason = ec == asio::error::operation_aborted ? reqerr_e::cancelled : reqerr_e::network_err; if (reason == reqerr_e::network_err) - LOG_DEBUG("[HTTP2]: reader drops connection after network err: {}", ec.what()); + TGBM_LOG_DEBUG("[HTTP2]: reader drops connection after network err: {}", ec.what()); drop_connection: drop_connection(static_cast(reason)); connection_dropped: @@ -1335,7 +1339,7 @@ dd::task http2_client::send_request(on_header_fn_ptr on_header, on_data_par request.authority = get_host(); node_ptr node = con->new_request_node(std::move(request), deadline, on_header, on_data_part); - LOG_DEBUG("send_request, path: {}, streamid: {}", request.path, node->req.streamid); + TGBM_LOG_DEBUG("send_request, path: {}, streamid: {}", request.path, node->req.streamid); co_return co_await con->request_finished(*node); } @@ -1351,7 +1355,7 @@ dd::job periodic_task(std::weak_ptr timer, auto todo) { co_await net.sleep(*tmr, interval, ec); if (ec) { if (ec != asio::error::operation_aborted) - LOG_ERR("timer ended with error: {}", ec.what()); + TGBM_LOG_ERROR("timer ended with error: {}", ec.what()); co_return; } } diff --git a/src/net/http2_server.cpp b/src/net/http2_server.cpp index aec8bc51..c19d96f4 100644 --- a/src/net/http2_server.cpp +++ b/src/net/http2_server.cpp @@ -5,7 +5,7 @@ TODO docs about this file #include "tgbm/net/http2_server.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include "tgbm/net/asio_awaiters.hpp" #include "tgbm/net/ssl_context.hpp" @@ -164,7 +164,7 @@ struct client_session { io_error_code ec; co_await net.write(socket(), bytes, ec); if (ec) - LOG_ERR("cannot send goaway for {}", (void*)this); + TGBM_LOG_ERROR("cannot send goaway for {}", (void*)this); } catch (std::bad_alloc&) { // ignore and just shutdown } @@ -195,13 +195,13 @@ dd::job client_session::start_writer() { assert(self->session_ctx.exe.running_in_this_thread()); co_await framebuf.next_work(); if (self->stop_requested()) { - LOG_DEBUG("[HTTP2]: writer for session {} ended after stop request", (void*)this); + TGBM_LOG_DEBUG("[HTTP2]: writer for session {} ended after stop request", (void*)this); co_return; } bytes_t bytes = std::move(framebuf.bytes_to_send); co_await net.write(self->socket(), bytes, ec); if (ec && ec != asio::error::operation_aborted) { - LOG_ERR("[HTTP2]: writer for session {} ended after network err: {}", (void*)this, ec.what()); + TGBM_LOG_ERROR("[HTTP2]: writer for session {} ended after network err: {}", (void*)this, ec.what()); co_return; } } @@ -278,8 +278,8 @@ static bytes_t encode_response_headers(client_session& ses, const http_response& if (ses.table_size_decrease) { uint32_t dec = ses.table_size_decrease; ses.table_size_decrease = 0; - LOG("[HTTP2]: reducing table size after receiving SETTINGS, old size: {}, decrease: {}", - encoder.dyntab.max_size(), dec); + TGBM_LOG_INFO("[HTTP2]: reducing table size after receiving SETTINGS, old size: {}, decrease: {}", + encoder.dyntab.max_size(), dec); if (encoder.dyntab.max_size() - dec) throw protocol_error{}; @@ -325,10 +325,10 @@ void client_session::shutdown() noexcept { io_error_code ec; ec = socket().lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, ec); if (ec) - LOG_ERR("error while shutting down session (tcp part) {}", (void*)this); + TGBM_LOG_ERROR("error while shutting down session (tcp part) {}", (void*)this); ec = socket().shutdown(ec); if (ec) - LOG_ERR("error while shutting down session {}", (void*)this); + TGBM_LOG_ERROR("error while shutting down session {}", (void*)this); } void client_session::receive_window_update(http2::window_update_frame frame) { @@ -337,7 +337,7 @@ void client_session::receive_window_update(http2::window_update_frame frame) { return; } if (frame.header.stream_id > last_opened_stream) { - LOG_WARN("unplemented stream window size increment before stream is open"); + TGBM_LOG_WARN("unplemented stream window size increment before stream is open"); return; } auto it = incomplete_responses.find(frame.header.stream_id); @@ -354,7 +354,7 @@ void client_session::receive_ping(http2::ping_frame frame) { void client_session::receive_rst_stream(http2::rst_stream rst) { bool erased = incomplete_requests.erase(rst.header.stream_id); - LOG_DEBUG("rst stream {}, {}", rst.header.stream_id, erased ? "erased" : "not erased"); + TGBM_LOG_DEBUG("rst stream {}, {}", rst.header.stream_id, erased ? "erased" : "not erased"); } // TODO debug info only under special flag (ifdef) @@ -389,9 +389,8 @@ void client_session::receive_data(http2::frame_header h, std::span data) assert(h.type == http2::frame_e::DATA); if (my_window_size < h.length) { // TODO какую-то настройку или хз, ну по сути тестовый сервер, так что он проверяет всё strict... - send_goaway_and_drop( - http2::errc_e::FLOW_CONTROL_ERROR, - fmt::format("too many DATA sended, can accept {}, received frame {}", my_window_size, h)); + send_goaway_and_drop(http2::errc_e::FLOW_CONTROL_ERROR, + fmt::format("too many DATA sended, can accept {}", my_window_size)); // TODO что делать, чтобы не плодить тыщу таких фреймов пока не отправится? // TODO control flow для стрима return; @@ -489,7 +488,7 @@ dd::job reader_for(client_session_ptr session) try { http2::frame_header framehdr = http2::frame_header::parse(buf); if (!validate_frame_header(framehdr)) { throw goaway_exception(session->last_opened_stream, errc_e::PROTOCOL_ERROR, - fmt::format("invalid frame header: {}", framehdr)); + fmt::format("invalid frame header")); } // read frame data @@ -530,8 +529,8 @@ dd::job reader_for(client_session_ptr session) try { break; case GOAWAY: { goaway_frame f = goaway_frame::parse(framehdr, buf); - LOG_ERR("[HTTP2]: server receives goaway frame, errc: {}, debuginfo: {}", e2str(f.error_code), - f.debug_info); + TGBM_LOG_ERROR("[HTTP2]: server receives goaway frame, errc: {}, debuginfo: {}", e2str(f.error_code), + f.debug_info); session->shutdown(); co_return; } @@ -562,7 +561,7 @@ dd::job reader_for(client_session_ptr session) try { } network_error: if (ec != asio::error::operation_aborted) - LOG_ERR("[HTTP2]: client session ended after network error: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: client session ended after network error: {}", ec.what()); session->shutdown(); co_return; } catch (http2::hpack_error& e) { @@ -590,11 +589,11 @@ dd::job establish_client_session(http2_server_ptr server, client_session_ctx ses std::span preface = buf.get_exactly(preface_sz); co_await net.read(session_ctx.socket, preface, ec); if (ec) { - LOG_ERR("[HTTP2]: client session establishment failed, err: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: client session establishment failed, err: {}", ec.what()); co_return; } if (!std::ranges::equal(preface, std::span(http2::connection_preface))) { - LOG_ERR("[HTTP2]: incorrect client connection for http2, cannot establish session"); + TGBM_LOG_ERROR("[HTTP2]: incorrect client connection for http2, cannot establish session"); co_return; } } @@ -607,13 +606,14 @@ dd::job establish_client_session(http2_server_ptr server, client_session_ctx ses std::span settings_frame = buf.get_exactly(http2::frame_header_len); co_await net.read(session_ctx.socket, settings_frame, ec); if (ec) { - LOG_ERR("[HTTP2]: client session establishment failed, err: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: client session establishment failed, err: {}", ec.what()); co_return; } settings_header = frame_header::parse(settings_frame); } if (settings_header.type != http2::frame_e::SETTINGS) { - LOG_ERR("[HTTP2]: client session establishment failed: incorrect client preface, frame is not SETTINGS"); + TGBM_LOG_ERROR( + "[HTTP2]: client session establishment failed: incorrect client preface, frame is not SETTINGS"); co_return; } @@ -625,7 +625,7 @@ dd::job establish_client_session(http2_server_ptr server, client_session_ctx ses std::span settings_data = buf.get_exactly(settings_header.length); co_await net.read(session_ctx.socket, settings_data, ec); if (ec) { - LOG_ERR("[HTTP2]: client session establishment failed, err: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: client session establishment failed, err: {}", ec.what()); co_return; } settings_frame::parse(settings_header, settings_data, client_settings_visitor(client_settings)); @@ -649,8 +649,8 @@ dd::job establish_client_session(http2_server_ptr server, client_session_ctx ses accepted_settings_frame().send_to(std::back_inserter(bytes)); co_await net.write(session_ctx.socket, bytes, ec); if (ec) { - LOG_ERR("[HTTP2]: client session establishment failed: cannot send ACK frame to client, err: {}", - ec.what()); + TGBM_LOG_ERROR("[HTTP2]: client session establishment failed: cannot send ACK frame to client, err: {}", + ec.what()); co_return; } } @@ -664,9 +664,9 @@ dd::job establish_client_session(http2_server_ptr server, client_session_ctx ses reader_for(new client_session(std::move(server), std::move(session_ctx), client_settings, mysettings)); co_await dd::this_coro::destroy_and_transfer_control_to(reader.handle); } catch (protocol_error& pe) { - LOG_ERR("[HTTP2]: client session failed: {}", pe.what()); + TGBM_LOG_ERROR("[HTTP2]: client session failed: {}", pe.what()); } catch (...) { - LOG_ERR("[HTTP2]: client session failed with unknown exception"); + TGBM_LOG_ERROR("[HTTP2]: client session failed with unknown exception"); } dd::job http2_server::start_accept(asio::ip::tcp::endpoint ep) { @@ -681,27 +681,27 @@ dd::job http2_server::start_accept(asio::ip::tcp::endpoint ep) { .exe = asio::make_strand(io_ctx), .socket = asio::ssl::stream(tcp::socket(session_ctx.exe), sslctx->ctx), }; - LOG_DEBUG("[HTTP2] starting accept!"); + TGBM_LOG_DEBUG("[HTTP2] starting accept!"); co_await net.accept(acceptor, session_ctx.socket.lowest_layer(), ec); if (ec) { if (ec != asio::error::operation_aborted) - LOG_ERR("[HTTP2]: server stops accepting after error: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: server stops accepting after error: {}", ec.what()); co_return; } - LOG_DEBUG("[HTTP2] accepted TCP socket"); + TGBM_LOG_DEBUG("[HTTP2] accepted TCP socket"); co_await net.handshake(session_ctx.socket, asio::ssl::stream_base::server, ec); if (ec) { if (ec == asio::error::operation_aborted) co_return; - LOG_ERR("[HTTP2]: server cannot accept (ssl handshake failure), error: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2]: server cannot accept (ssl handshake failure), error: {}", ec.what()); // do not stop accepting } if (stop_requested()) co_return; - LOG_DEBUG("[HTTP2]: establishing client session"); + TGBM_LOG_DEBUG("[HTTP2]: establishing client session"); establish_client_session(this, std::move(session_ctx)); } diff --git a/src/net/long_poll.cpp b/src/net/long_poll.cpp index fdfd67e3..0b7f9006 100644 --- a/src/net/long_poll.cpp +++ b/src/net/long_poll.cpp @@ -2,7 +2,7 @@ #include "tgbm/Api.h" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" namespace tgbm { @@ -23,7 +23,7 @@ static dd::channel long_poll_with_preconfirm( // ignores update, so its unhanled == will be returned next time (void)co_await api.getUpdates(lastUpdateId, 1, 0, allowUpdates); } - LOG("[updates] getted {} updates", updates.size()); + TGBM_LOG_INFO("[updates] getted {} updates", updates.size()); for (Update::Ptr& item : updates) co_yield std::move(item); } @@ -37,7 +37,7 @@ static dd::channel long_poll_without_preconfirm( std::vector> updates; for (;;) { updates = co_await api.getUpdates(lastUpdateId, limit, timeout.count(), allowUpdates); - LOG("[updates] getted {} updates", updates.size()); + TGBM_LOG_INFO("[updates] getted {} updates", updates.size()); for (Update::Ptr& item : updates) { if (item->updateId >= lastUpdateId) lastUpdateId = item->updateId + 1; diff --git a/src/net/ssl_context.cpp b/src/net/ssl_context.cpp index c2703df9..8c149852 100644 --- a/src/net/ssl_context.cpp +++ b/src/net/ssl_context.cpp @@ -1,12 +1,12 @@ #include "tgbm/net/ssl_context.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include "tgbm/net/errors.hpp" #include #ifdef TGBM_SSL_KEYS_FILE -#define TGBM_ENABLE_WIRESHARK_SUPPORT -#include + #define TGBM_ENABLE_WIRESHARK_SUPPORT + #include #endif namespace tgbm { @@ -22,7 +22,7 @@ static void keylog_callback(const SSL*, const char* line) { if (keylog_file) keylog_file << std::string_view(line); else - LOG_ERR("cannot open keylog file for wireshark support, path: {}", keylog_file_path.string()); + TGBM_LOG_ERROR("cannot open keylog file for wireshark support, path: {}", keylog_file_path.string()); } #endif @@ -38,7 +38,7 @@ ssl_context_ptr make_ssl_context_for_http11(std::spanctx.native_handle(), &keylog_callback); #endif sslctx->ctx.set_default_verify_paths(); @@ -47,9 +47,9 @@ ssl_context_ptr make_ssl_context_for_http11(std::spanctx.load_verify_file(ap.string(), ec); if (ec) - LOG_ERR("error while loading ssl verify file, err: {}, path: {}", ec.what(), p.string()); + TGBM_LOG_ERROR("error while loading ssl verify file, err: {}, path: {}", ec.what(), p.string()); else - LOG("additional SSL certificate loaded, path: {}", p.string()); + TGBM_LOG_INFO("additional SSL certificate loaded, path: {}", p.string()); } sslctx->ctx.set_options(ssl::context::default_workarounds | ssl::context::no_sslv2 | @@ -58,7 +58,7 @@ ssl_context_ptr make_ssl_context_for_http11(std::spanctx.native_handle(), "ECDHE+AESGCM:ECDHE+CHACHA20:!aNULL:!MD5:DEFAULT")) - LOG_WARN("ssl cipher cannot be selected"); + TGBM_LOG_WARN("ssl cipher cannot be selected"); return sslctx; } @@ -80,13 +80,13 @@ ssl_context_ptr make_ssl_context_for_server(std::filesystem::path certificate, io_error_code ec; ec = ctx->ctx.use_certificate_chain_file(std::filesystem::absolute(certificate).string(), ec); if (ec) { - LOG_ERR("cannot load certificate, path {}, err: {}", certificate.string(), ec.what()); + TGBM_LOG_ERROR("cannot load certificate, path {}, err: {}", certificate.string(), ec.what()); return nullptr; } ec = ctx->ctx.use_private_key_file(std::filesystem::absolute(server_private_key).string(), asio::ssl::context::pem, ec); if (ec) { - LOG_ERR("cannot load private file, path {}, err: {}", server_private_key.string(), ec.what()); + TGBM_LOG_ERROR("cannot load private file, path {}, err: {}", server_private_key.string(), ec.what()); return nullptr; } return ctx; diff --git a/src/net/tcp_connection.cpp b/src/net/tcp_connection.cpp index 5c595ca0..1e491859 100644 --- a/src/net/tcp_connection.cpp +++ b/src/net/tcp_connection.cpp @@ -1,6 +1,6 @@ #include "tgbm/net/tcp_connection.hpp" -#include "tgbm/logger.h" +#include "tgbm/logger.hpp" #include "tgbm/net/asio_awaiters.hpp" #include "tgbm/net/errors.hpp" @@ -16,14 +16,14 @@ void tcp_connection::shutdown() noexcept { ec = tcp_sock.cancel(ec); // dont stop on errors, i need to stop connection somehow if (ec) - LOG_ERR("[HTTP2] [shutdown] TCP socket cancel, err {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2] [shutdown] TCP socket cancel, err {}", ec.what()); // Do not do SSL shutdown, because TG does not too, useless errors and wasting time ec = tcp_sock.shutdown(asio::socket_base::shutdown_both, ec); if (ec) - LOG_ERR("[HTTP2] [shutdown] TCP socket shutdown, err: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2] [shutdown] TCP socket shutdown, err: {}", ec.what()); ec = tcp_sock.close(ec); if (ec) - LOG_ERR("[HTTP2] [shutdown], TCP socket close err: {}", ec.what()); + TGBM_LOG_ERROR("[HTTP2] [shutdown], TCP socket close err: {}", ec.what()); } dd::task tcp_connection::create(asio::io_context& io_ctx, std::string host, @@ -38,15 +38,15 @@ dd::task tcp_connection::create(asio::io_context& io_ctx, st io_error_code ec; auto results = co_await net.resolve(resolver, query, ec); if (ec) { - LOG_ERR("[TCP] cannot resolve host: {}: service: {}, err: {}", query.host_name(), query.service_name(), - ec.message()); + TGBM_LOG_ERROR("[TCP] cannot resolve host: {}: service: {}, err: {}", query.host_name(), + query.service_name(), ec.message()); throw network_exception(ec); } auto& tcp_sock = socket.lowest_layer(); co_await net.connect(tcp_sock, results, ec); if (ec) { - LOG_ERR("[TCP] cannot connect to {}, err: {}", host, ec.message()); + TGBM_LOG_ERROR("[TCP] cannot connect to {}, err: {}", host, ec.message()); throw network_exception(ec); } options.apply(tcp_sock); @@ -56,7 +56,7 @@ dd::task tcp_connection::create(asio::io_context& io_ctx, st SSL_set_mode(socket.native_handle(), SSL_MODE_RELEASE_BUFFERS); co_await net.handshake(socket, ssl::stream_base::handshake_type::client, ec); if (ec) { - LOG_ERR("[TCP/SSL] cannot ssl handshake: {}", ec.message()); + TGBM_LOG_ERROR("[TCP/SSL] cannot ssl handshake: {}", ec.message()); throw network_exception(ec); } co_return connection;