Skip to content

Commit

Permalink
perf: re-structure header and fix build error on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 10, 2023
1 parent 038d964 commit bcf2441
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 31 deletions.
12 changes: 5 additions & 7 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions sample/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "MaaFramework/MaaAPI.h"

#include <array>
#include <filesystem>
#include <iostream>
#include <string>

#include "MaaFramework/Task/MaaCustomRecognizer.h"
#include "MaaFramework/MaaAPI.h"
#include "MaaToolKit/MaaToolKitAPI.h"

#ifdef _WIN32
Expand Down
1 change: 1 addition & 0 deletions source/MaaFramework/Controller/CustomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Controller/CustomController.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "ControllerMgr.h"
#include "MaaFramework/Instance/MaaCustomController.h"
#include "MaaFramework/MaaDef.h"

MAA_CTRL_NS_BEGIN

Expand Down
1 change: 1 addition & 0 deletions source/MaaFramework/Vision/CustomRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Vision/CustomRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <meojson/json.hpp>

#include "Instance/InstanceInternalAPI.hpp"
#include "MaaFramework/Task/MaaCustomRecognizer.h"
#include "MaaFramework/MaaDef.h"
#include "VisionBase.h"
#include "VisionTypes.h"

Expand Down
1 change: 1 addition & 0 deletions source/MaaRpc/implement/Buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Buffer.h"
#include "Macro.h"
#include "MaaFramework/MaaAPI.h"
#include "Utility.h"

using namespace ::grpc;
Expand Down
2 changes: 1 addition & 1 deletion source/MaaRpc/implement/Buffer.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions source/MaaRpc/implement/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Config.h"
#include "MaaToolKit/MaaToolKitAPI.h"

using namespace ::grpc;

Expand Down
9 changes: 5 additions & 4 deletions source/MaaRpc/implement/Controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Controller.h"
#include "MaaFramework/Instance/MaaCustomController.h"
#include "MaaFramework/Utility/MaaBuffer.h"
#include "MaaFramework/MaaAPI.h"
#include "Macro.h"

using namespace ::grpc;
Expand Down Expand Up @@ -304,8 +303,10 @@ Status ControllerImpl::create_custom(
return Status(NOT_FOUND, "id not exists");
}

auto info = std::make_shared<CustomControllerInfo>(stream, image_impl_);

// build error on macOS
// auto info = std::make_shared<CustomControllerInfo>(stream, image_impl_);
std::shared_ptr<CustomControllerInfo> info(new CustomControllerInfo{ stream, image_impl_ });

auto id = make_uuid();

::maarpc::CustomControllerResponse response;
Expand Down
4 changes: 2 additions & 2 deletions source/MaaRpc/implement/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<ImageImpl> image_impl = nullptr;
std::binary_semaphore finish { 0 };
};
Expand Down
1 change: 1 addition & 0 deletions source/MaaRpc/implement/Device.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Device.h"
#include "MaaToolKit/MaaToolKitAPI.h"
#include "Macro.h"

using namespace ::grpc;
Expand Down
13 changes: 8 additions & 5 deletions source/MaaRpc/implement/Instance.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -105,7 +104,9 @@ Status InstanceImpl::register_custom_recognizer(

MAA_GRPC_GET_HANDLE_FROM(this, handle, init().handle)

auto info = std::make_shared<CustomRecognizerInfo>(request->init().name(), stream, image_impl_, syncctx_impl_);
// build error on macOS
// auto info = std::make_shared<CustomRecognizerInfo>(request->init().name(), stream, image_impl_, syncctx_impl_);
std::shared_ptr<CustomRecognizerInfo> info(new CustomRecognizerInfo{ request->init().name(), stream, image_impl_, syncctx_impl_ });

::maarpc::CustomRecognizerResponse response;
stream->Write(response);
Expand Down Expand Up @@ -231,8 +232,10 @@ Status InstanceImpl::register_custom_action(

MAA_GRPC_GET_HANDLE_FROM(this, handle, init().handle)

auto info = std::make_shared<CustomActionInfo>(request->init().name(), stream, syncctx_impl_);

// build error on macOS
// auto info = std::make_shared<CustomActionInfo>(request->init().name(), stream, syncctx_impl_);
std::shared_ptr<CustomActionInfo> info(new CustomActionInfo{ request->init().name(), stream, syncctx_impl_ });

::maarpc::CustomActionResponse response;
stream->Write(response);

Expand Down
8 changes: 4 additions & 4 deletions source/MaaRpc/implement/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,16 +15,16 @@ 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<ImageImpl> image_impl = nullptr;
std::shared_ptr<SyncContextImpl> syncctx_impl = nullptr;
std::binary_semaphore finish { 0 };
};
struct CustomActionInfo
{
std::string name;
::grpc::ServerReaderWriter<::maarpc::CustomActionResponse, ::maarpc::CustomActionRequest>* stream;
std::shared_ptr<SyncContextImpl> syncctx_impl;
::grpc::ServerReaderWriter<::maarpc::CustomActionResponse, ::maarpc::CustomActionRequest>* stream = nullptr;
std::shared_ptr<SyncContextImpl> syncctx_impl = nullptr;
std::binary_semaphore finish { 0 };
};

Expand Down
2 changes: 1 addition & 1 deletion source/MaaRpc/implement/Resource.h
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
1 change: 1 addition & 0 deletions source/MaaRpc/implement/SyncContext.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SyncContext.h"
#include "Macro.h"
#include "MaaFramework/MaaAPI.h"

using namespace ::grpc;

Expand Down
2 changes: 1 addition & 1 deletion source/MaaRpc/implement/SyncContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/MaaRpc/implement/Utility.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Utility.h"
#include "MaaFramework/MaaAPI.h"
#include "Macro.h"

#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

Expand Down
2 changes: 1 addition & 1 deletion source/MaaRpc/implement/Utility.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "AtomicMap.h"
#include "MaaFramework/Utility/MaaUtility.h"
#include "MaaFramework/MaaDef.h"
#include "utility.grpc.pb.h"

#include <memory>
Expand Down

0 comments on commit bcf2441

Please sign in to comment.