From 92d7fd69e0e71f72908016af84fbe8e963bfbdcb Mon Sep 17 00:00:00 2001 From: nekosu Date: Mon, 13 Nov 2023 00:26:30 +0800 Subject: [PATCH] refactor: minify boost including --- .../MaaRestful/Handle/CallbackDispatcher.cpp | 18 ++++++++++++++++ .../MaaRestful/Handle/CallbackDispatcher.hpp | 21 +++++++++++++++++++ source/MaaRestful/Helper/Forward.hpp | 3 +++ source/MaaRestful/Helper/Uuid.cpp | 11 ++++++++++ source/MaaRestful/Helper/Uuid.hpp | 9 ++++++++ source/MaaRpc/implement/Utility.cpp | 6 +++--- source/include/Utils/Boost.hpp | 12 +++++++---- 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 source/MaaRestful/Handle/CallbackDispatcher.cpp create mode 100644 source/MaaRestful/Handle/CallbackDispatcher.hpp create mode 100644 source/MaaRestful/Helper/Uuid.cpp create mode 100644 source/MaaRestful/Helper/Uuid.hpp diff --git a/source/MaaRestful/Handle/CallbackDispatcher.cpp b/source/MaaRestful/Handle/CallbackDispatcher.cpp new file mode 100644 index 000000000..c95d8abd3 --- /dev/null +++ b/source/MaaRestful/Handle/CallbackDispatcher.cpp @@ -0,0 +1,18 @@ +#include "Handle/CallbackDispatcher.hpp" +#include "Utils/Format.hpp" + +MAA_RESTFUL_NS_BEGIN + +std::mutex CallbackDispatcher::mtx_; +std::map> CallbackDispatcher::callbacks_; + +using namespace boost::beast::http; + +bool CallbackDispatcher::handle(Context& ctx, UrlSegments segs) +{ + std::ignore = ctx; + std::ignore = segs; + return false; +} + +MAA_RESTFUL_NS_END diff --git a/source/MaaRestful/Handle/CallbackDispatcher.hpp b/source/MaaRestful/Handle/CallbackDispatcher.hpp new file mode 100644 index 000000000..c69808507 --- /dev/null +++ b/source/MaaRestful/Handle/CallbackDispatcher.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "Handle/Context.hpp" +#include "Helper/UrlSegments.hpp" + +#include +#include +#include +#include + +MAA_RESTFUL_NS_BEGIN + +struct CallbackDispatcher +{ + bool handle(Context& ctx, UrlSegments segs); + + static std::mutex mtx_; + static std::map> callbacks_; +}; + +MAA_RESTFUL_NS_END diff --git a/source/MaaRestful/Helper/Forward.hpp b/source/MaaRestful/Helper/Forward.hpp index 3c4ff7195..1a21dcd38 100644 --- a/source/MaaRestful/Helper/Forward.hpp +++ b/source/MaaRestful/Helper/Forward.hpp @@ -1,5 +1,8 @@ #pragma once +#define BOOST_WANT_UUID +#define BOOST_WANT_BEAST + #include "Conf/Conf.h" #include "Utils/Boost.hpp" diff --git a/source/MaaRestful/Helper/Uuid.cpp b/source/MaaRestful/Helper/Uuid.cpp new file mode 100644 index 000000000..1824b3c6c --- /dev/null +++ b/source/MaaRestful/Helper/Uuid.cpp @@ -0,0 +1,11 @@ +#include "Helper/Uuid.hpp" + +MAA_RESTFUL_NS_BEGIN + +auto uuid_generator = boost::uuids::random_generator(); +std::string make_uuid() +{ + return boost::uuids::to_string(uuid_generator()); +} + +MAA_RESTFUL_NS_END diff --git a/source/MaaRestful/Helper/Uuid.hpp b/source/MaaRestful/Helper/Uuid.hpp new file mode 100644 index 000000000..bba0fac97 --- /dev/null +++ b/source/MaaRestful/Helper/Uuid.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "Helper/Forward.hpp" + +MAA_RESTFUL_NS_BEGIN + +std::string make_uuid(); + +MAA_RESTFUL_NS_END \ No newline at end of file diff --git a/source/MaaRpc/implement/Utility.cpp b/source/MaaRpc/implement/Utility.cpp index c77d389d6..11c457561 100644 --- a/source/MaaRpc/implement/Utility.cpp +++ b/source/MaaRpc/implement/Utility.cpp @@ -1,11 +1,11 @@ +#define BOOST_WANT_UUID + #include "Utility.h" #include "MaaFramework/MaaAPI.h" #include "Macro.h" +#include "Utils/Boost.hpp" #include "Utils/Logger.h" -#include -#include - using namespace ::grpc; auto uuid_generator = boost::uuids::random_generator(); diff --git a/source/include/Utils/Boost.hpp b/source/include/Utils/Boost.hpp index 87a350f57..e29989d74 100644 --- a/source/include/Utils/Boost.hpp +++ b/source/include/Utils/Boost.hpp @@ -16,18 +16,22 @@ MAA_SUPPRESS_BOOST_WARNINGS_BEGIN #include #include #include -#include -#include -#include #ifdef _WIN32 #include #endif -#ifdef WITH_RESTFUL +#ifdef BOOST_WANT_UUID +#include +#include +#include +#endif + +#ifdef BOOST_WANT_BEAST #include #include #include #include #endif + MAA_SUPPRESS_BOOST_WARNINGS_END