From c2ec60b001e01d84f0e140b686a4d876aa3959cd Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 10 Oct 2023 15:00:30 +0800 Subject: [PATCH] perf: re-structure header and fix build error on macOS --- cmake/config.cmake | 12 +++++------- sample/cpp/main.cpp | 4 +--- source/MaaFramework/Controller/CustomController.cpp | 1 + source/MaaFramework/Controller/CustomController.h | 2 +- source/MaaFramework/Vision/CustomRecognizer.cpp | 1 + source/MaaFramework/Vision/CustomRecognizer.h | 2 +- source/MaaRpc/implement/Buffer.cpp | 1 + source/MaaRpc/implement/Buffer.h | 2 +- source/MaaRpc/implement/Config.cpp | 1 + source/MaaRpc/implement/Controller.cpp | 11 +++++++---- source/MaaRpc/implement/Controller.h | 4 ++-- source/MaaRpc/implement/Device.cpp | 1 + source/MaaRpc/implement/Instance.cpp | 13 ++++++++----- source/MaaRpc/implement/Instance.h | 8 ++++---- source/MaaRpc/implement/Resource.h | 2 +- source/MaaRpc/implement/SyncContext.cpp | 1 + source/MaaRpc/implement/SyncContext.h | 2 +- source/MaaRpc/implement/Utility.cpp | 1 + source/MaaRpc/implement/Utility.h | 2 +- 19 files changed, 40 insertions(+), 31 deletions(-) diff --git a/cmake/config.cmake b/cmake/config.cmake index a5335e80b..1eae4e9c1 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -30,13 +30,11 @@ endif () if (APPLE) set(CMAKE_INSTALL_RPATH "@loader_path;@executable_path") - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_compile_definitions(MAA_USE_FMTLIB) - add_compile_options("-Wno-deprecated-declarations") # supress tmpnam - if ("${MAADEPS_TRIPLET}" STREQUAL "maa-arm64-osx") - add_compile_options("-arch;arm64") - add_link_options("-arch;arm64") - endif () + add_compile_definitions(MAA_USE_FMTLIB) + add_compile_options("-Wno-deprecated-declarations") # supress tmpnam + if ("${MAADEPS_TRIPLET}" STREQUAL "maa-arm64-osx") + add_compile_options("-arch;arm64") + add_link_options("-arch;arm64") endif () elseif (UNIX) set(CMAKE_INSTALL_RPATH "$ORIGIN") diff --git a/sample/cpp/main.cpp b/sample/cpp/main.cpp index e476b5471..fee82b14a 100644 --- a/sample/cpp/main.cpp +++ b/sample/cpp/main.cpp @@ -1,11 +1,9 @@ -#include "MaaFramework/MaaAPI.h" - #include #include #include #include -#include "MaaFramework/Task/MaaCustomRecognizer.h" +#include "MaaFramework/MaaAPI.h" #include "MaaToolKit/MaaToolKitAPI.h" #ifdef _WIN32 diff --git a/source/MaaFramework/Controller/CustomController.cpp b/source/MaaFramework/Controller/CustomController.cpp index b970b3499..1ab960f76 100644 --- a/source/MaaFramework/Controller/CustomController.cpp +++ b/source/MaaFramework/Controller/CustomController.cpp @@ -4,6 +4,7 @@ #include "Buffer/StringBuffer.hpp" #include "Utils/Logger.h" #include "Utils/NoWarningCV.hpp" +#include "MaaFramework/Instance/MaaCustomController.h" MAA_CTRL_NS_BEGIN diff --git a/source/MaaFramework/Controller/CustomController.h b/source/MaaFramework/Controller/CustomController.h index 48e15f9af..b0856c3fe 100644 --- a/source/MaaFramework/Controller/CustomController.h +++ b/source/MaaFramework/Controller/CustomController.h @@ -1,6 +1,6 @@ #pragma once #include "ControllerMgr.h" -#include "MaaFramework/Instance/MaaCustomController.h" +#include "MaaFramework/MaaDef.h" MAA_CTRL_NS_BEGIN diff --git a/source/MaaFramework/Vision/CustomRecognizer.cpp b/source/MaaFramework/Vision/CustomRecognizer.cpp index 05f5c5e5b..6e1cf0cef 100644 --- a/source/MaaFramework/Vision/CustomRecognizer.cpp +++ b/source/MaaFramework/Vision/CustomRecognizer.cpp @@ -4,6 +4,7 @@ #include "Buffer/ImageBuffer.hpp" #include "Buffer/StringBuffer.hpp" +#include "MaaFramework/Task/MaaCustomRecognizer.h" #include "Task/SyncContext.h" #include "Utils/Logger.h" diff --git a/source/MaaFramework/Vision/CustomRecognizer.h b/source/MaaFramework/Vision/CustomRecognizer.h index 6ac962166..54ccdf7c5 100644 --- a/source/MaaFramework/Vision/CustomRecognizer.h +++ b/source/MaaFramework/Vision/CustomRecognizer.h @@ -5,7 +5,7 @@ #include #include "Instance/InstanceInternalAPI.hpp" -#include "MaaFramework/Task/MaaCustomRecognizer.h" +#include "MaaFramework/MaaDef.h" #include "VisionBase.h" #include "VisionTypes.h" diff --git a/source/MaaRpc/implement/Buffer.cpp b/source/MaaRpc/implement/Buffer.cpp index 5905e77ef..0b14ce404 100644 --- a/source/MaaRpc/implement/Buffer.cpp +++ b/source/MaaRpc/implement/Buffer.cpp @@ -1,5 +1,6 @@ #include "Buffer.h" #include "Macro.h" +#include "MaaFramework/MaaAPI.h" #include "Utility.h" using namespace ::grpc; diff --git a/source/MaaRpc/implement/Buffer.h b/source/MaaRpc/implement/Buffer.h index f1f3febee..cb4d05fc9 100644 --- a/source/MaaRpc/implement/Buffer.h +++ b/source/MaaRpc/implement/Buffer.h @@ -1,7 +1,7 @@ #pragma once #include "AtomicMap.h" -#include "MaaFramework/Utility/MaaBuffer.h" +#include "MaaFramework/MaaDef.h" #include "buffer.grpc.pb.h" class ImageImpl final : public ::maarpc::Image::Service diff --git a/source/MaaRpc/implement/Config.cpp b/source/MaaRpc/implement/Config.cpp index 0989b76b9..8201d2d00 100644 --- a/source/MaaRpc/implement/Config.cpp +++ b/source/MaaRpc/implement/Config.cpp @@ -1,4 +1,5 @@ #include "Config.h" +#include "MaaToolKit/MaaToolKitAPI.h" using namespace ::grpc; diff --git a/source/MaaRpc/implement/Controller.cpp b/source/MaaRpc/implement/Controller.cpp index 52d9075e4..8e4f389a4 100644 --- a/source/MaaRpc/implement/Controller.cpp +++ b/source/MaaRpc/implement/Controller.cpp @@ -1,8 +1,9 @@ #include "Controller.h" -#include "MaaFramework/Instance/MaaCustomController.h" -#include "MaaFramework/Utility/MaaBuffer.h" +#include "MaaFramework/MaaAPI.h" #include "Macro.h" +#include + using namespace ::grpc; Status ControllerImpl::create_adb(::grpc::ServerContext* context, const ::maarpc::AdbControllerRequest* request, @@ -304,8 +305,10 @@ Status ControllerImpl::create_custom( return Status(NOT_FOUND, "id not exists"); } - auto info = std::make_shared(stream, image_impl_); - + // build error on macOS + // auto info = std::make_shared(stream, image_impl_); + std::shared_ptr info(new CustomControllerInfo{ stream, image_impl_ }); + auto id = make_uuid(); ::maarpc::CustomControllerResponse response; diff --git a/source/MaaRpc/implement/Controller.h b/source/MaaRpc/implement/Controller.h index 25105ffb1..54466d991 100644 --- a/source/MaaRpc/implement/Controller.h +++ b/source/MaaRpc/implement/Controller.h @@ -2,7 +2,7 @@ #include "AtomicMap.h" #include "Buffer.h" -#include "MaaFramework/Instance/MaaController.h" +#include "MaaFramework/MaaDef.h" #include "Utility.h" #include "controller.grpc.pb.h" @@ -13,7 +13,7 @@ class ControllerImpl final : public ::maarpc::Controller::Service public: struct CustomControllerInfo { - ::grpc::ServerReaderWriter<::maarpc::CustomControllerResponse, ::maarpc::CustomControllerRequest>* stream; + ::grpc::ServerReaderWriter<::maarpc::CustomControllerResponse, ::maarpc::CustomControllerRequest>* stream = nullptr; std::shared_ptr image_impl = nullptr; std::binary_semaphore finish { 0 }; }; diff --git a/source/MaaRpc/implement/Device.cpp b/source/MaaRpc/implement/Device.cpp index 5ec756400..f914f8c90 100644 --- a/source/MaaRpc/implement/Device.cpp +++ b/source/MaaRpc/implement/Device.cpp @@ -1,4 +1,5 @@ #include "Device.h" +#include "MaaToolKit/MaaToolKitAPI.h" #include "Macro.h" using namespace ::grpc; diff --git a/source/MaaRpc/implement/Instance.cpp b/source/MaaRpc/implement/Instance.cpp index ae84b06b7..4eecf4e89 100644 --- a/source/MaaRpc/implement/Instance.cpp +++ b/source/MaaRpc/implement/Instance.cpp @@ -1,6 +1,5 @@ #include "Instance.h" -#include "MaaFramework/Task/MaaCustomAction.h" -#include "MaaFramework/Task/MaaCustomRecognizer.h" +#include "MaaFramework/MaaAPI.h" #include "Macro.h" using namespace ::grpc; @@ -105,7 +104,9 @@ Status InstanceImpl::register_custom_recognizer( MAA_GRPC_GET_HANDLE_FROM(this, handle, init().handle) - auto info = std::make_shared(request->init().name(), stream, image_impl_, syncctx_impl_); + // build error on macOS + // auto info = std::make_shared(request->init().name(), stream, image_impl_, syncctx_impl_); + std::shared_ptr info(new CustomRecognizerInfo{ request->init().name(), stream, image_impl_, syncctx_impl_ }); ::maarpc::CustomRecognizerResponse response; stream->Write(response); @@ -231,8 +232,10 @@ Status InstanceImpl::register_custom_action( MAA_GRPC_GET_HANDLE_FROM(this, handle, init().handle) - auto info = std::make_shared(request->init().name(), stream, syncctx_impl_); - + // build error on macOS + // auto info = std::make_shared(request->init().name(), stream, syncctx_impl_); + std::shared_ptr info(new CustomActionInfo{ request->init().name(), stream, syncctx_impl_ }); + ::maarpc::CustomActionResponse response; stream->Write(response); diff --git a/source/MaaRpc/implement/Instance.h b/source/MaaRpc/implement/Instance.h index 1c21afdf9..7cea9fdfc 100644 --- a/source/MaaRpc/implement/Instance.h +++ b/source/MaaRpc/implement/Instance.h @@ -3,7 +3,7 @@ #include "AtomicMap.h" #include "Buffer.h" #include "Controller.h" -#include "MaaFramework/Instance/MaaInstance.h" +#include "MaaFramework/MaaDef.h" #include "Resource.h" #include "SyncContext.h" #include "Utility.h" @@ -15,7 +15,7 @@ class InstanceImpl final : public ::maarpc::Instance::Service struct CustomRecognizerInfo { std::string name; - ::grpc::ServerReaderWriter<::maarpc::CustomRecognizerResponse, ::maarpc::CustomRecognizerRequest>* stream; + ::grpc::ServerReaderWriter<::maarpc::CustomRecognizerResponse, ::maarpc::CustomRecognizerRequest>* stream = nullptr; std::shared_ptr image_impl = nullptr; std::shared_ptr syncctx_impl = nullptr; std::binary_semaphore finish { 0 }; @@ -23,8 +23,8 @@ class InstanceImpl final : public ::maarpc::Instance::Service struct CustomActionInfo { std::string name; - ::grpc::ServerReaderWriter<::maarpc::CustomActionResponse, ::maarpc::CustomActionRequest>* stream; - std::shared_ptr syncctx_impl; + ::grpc::ServerReaderWriter<::maarpc::CustomActionResponse, ::maarpc::CustomActionRequest>* stream = nullptr; + std::shared_ptr syncctx_impl = nullptr; std::binary_semaphore finish { 0 }; }; diff --git a/source/MaaRpc/implement/Resource.h b/source/MaaRpc/implement/Resource.h index fdd1fb62e..d38710a2f 100644 --- a/source/MaaRpc/implement/Resource.h +++ b/source/MaaRpc/implement/Resource.h @@ -1,7 +1,7 @@ #pragma once #include "AtomicMap.h" -#include "MaaFramework/Instance/MaaResource.h" +#include "MaaFramework/MaaDef.h" #include "Utility.h" #include "resource.grpc.pb.h" diff --git a/source/MaaRpc/implement/SyncContext.cpp b/source/MaaRpc/implement/SyncContext.cpp index a5fb0ba29..c6e00a3cf 100644 --- a/source/MaaRpc/implement/SyncContext.cpp +++ b/source/MaaRpc/implement/SyncContext.cpp @@ -1,5 +1,6 @@ #include "SyncContext.h" #include "Macro.h" +#include "MaaFramework/MaaAPI.h" using namespace ::grpc; diff --git a/source/MaaRpc/implement/SyncContext.h b/source/MaaRpc/implement/SyncContext.h index 84401ca30..d1234b40b 100644 --- a/source/MaaRpc/implement/SyncContext.h +++ b/source/MaaRpc/implement/SyncContext.h @@ -2,7 +2,7 @@ #include "AtomicMap.h" #include "Buffer.h" -#include "MaaFramework/Task/MaaSyncContext.h" +#include "MaaFramework/MaaDef.h" #include "sync.context.grpc.pb.h" class SyncContextImpl final : public ::maarpc::SyncContext::Service diff --git a/source/MaaRpc/implement/Utility.cpp b/source/MaaRpc/implement/Utility.cpp index 0d453ba8e..5048debb5 100644 --- a/source/MaaRpc/implement/Utility.cpp +++ b/source/MaaRpc/implement/Utility.cpp @@ -1,6 +1,7 @@ #include "Utility.h" #include "MaaFramework/MaaAPI.h" #include "Macro.h" + #include #include diff --git a/source/MaaRpc/implement/Utility.h b/source/MaaRpc/implement/Utility.h index 621767dc3..55b9a67b4 100644 --- a/source/MaaRpc/implement/Utility.h +++ b/source/MaaRpc/implement/Utility.h @@ -1,7 +1,7 @@ #pragma once #include "AtomicMap.h" -#include "MaaFramework/Utility/MaaUtility.h" +#include "MaaFramework/MaaDef.h" #include "utility.grpc.pb.h" #include