Skip to content

Commit

Permalink
feat: 拆分ControlUnit依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 23, 2023
1 parent 0896a74 commit 9ba96d0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 28 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ set(Boost_NO_WARN_NEW_VERSIONS 1)

option(USE_MAADEPS "use third-party libraries built by MaaDeps" ON)
option(BUILD_SAMPLE "build a demo" OFF)
option(WITH_THRIFT "build with thrift" ON)
option(WITH_ADB_CONTROLLER "build with adb controller" ON)
option(WITH_THRIFT_CONTROLLER "build with thrift controller" ON)
option(WITH_DEBUGGING_CONTROLLER "build with debugging controller" ON)
option(WITH_GRPC "build with protobuf and grpc" ON)

if(USE_MAADEPS)
Expand All @@ -23,10 +25,17 @@ include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
# include(${PROJECT_SOURCE_DIR}/cmake/nuget.cmake)

if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
if (WITH_ADB_CONTROLLER)
add_compile_definitions(WITH_ADB_CONTROLLER)
endif()
if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
include(${PROJECT_SOURCE_DIR}/cmake/thrift-gen.cmake)
add_compile_definitions(WITH_THRIFT)
add_compile_definitions(WITH_THRIFT_CONTROLLER)
endif()
if (WITH_DEBUGGING_CONTROLLER)
add_compile_definitions(WITH_DEBUGGING_CONTROLLER)
endif()

if(WITH_GRPC)
include(${PROJECT_SOURCE_DIR}/cmake/grpc-gen.cmake)
add_compile_definitions(WITH_GRPC)
Expand All @@ -37,7 +46,7 @@ find_package(Boost REQUIRED COMPONENTS system)
find_package(ZLIB REQUIRED)
find_package(fastdeploy_ppocr REQUIRED)
find_package(ONNXRuntime)
if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
find_package(Thrift CONFIG REQUIRED)
endif()
if(WITH_GRPC)
Expand Down
3 changes: 3 additions & 0 deletions include/MaaFramework/Instance/MaaController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ extern "C"
MaaCallbackTransparentArg callback_arg);
MaaControllerHandle MAA_FRAMEWORK_API MaaThriftControllerCreate(MaaStringView param, MaaControllerCallback callback,
MaaCallbackTransparentArg callback_arg);
MaaControllerHandle MAA_FRAMEWORK_API MaaDebuggingControllerCreate(
MaaStringView read_path, MaaStringView write_path, MaaDebuggingControllerType type, MaaStringView config,
MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg);

void MAA_FRAMEWORK_API MaaControllerDestroy(MaaControllerHandle ctrl);

Expand Down
21 changes: 14 additions & 7 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
add_subdirectory(MaaUtils)
add_subdirectory(MaaAdbControlUnit)
add_subdirectory(MaaDebuggingControlUnit)
if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)

if (WITH_ADB_CONTROLLER)
add_subdirectory(MaaAdbControlUnit)
endif(WITH_ADB_CONTROLLER)
if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
add_subdirectory(MaaThriftController)
endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
if(WITH_GRPC)
add_subdirectory(MaaRpc)
endif(WITH_GRPC)
endif(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
if (WITH_DEBUGGING_CONTROLLER)
add_subdirectory(MaaDebuggingControlUnit)
endif(WITH_DEBUGGING_CONTROLLER)

add_subdirectory(MaaFramework)
add_subdirectory(MaaToolKit)

if(WITH_GRPC)
add_subdirectory(MaaRpc)
endif(WITH_GRPC)
46 changes: 42 additions & 4 deletions source/MaaFramework/API/MaaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Controller/AdbController.h"
#include "Controller/CustomController.h"
#include "Controller/CustomThriftController.h"
#include "Controller/DebuggingController.h"
#include "Utils/Logger.h"
#include "Utils/Platform.h"

Expand All @@ -27,13 +28,24 @@ MaaControllerHandle MaaAdbControllerCreateV2(MaaStringView adb_path, MaaStringVi
LogFunc << VAR(adb_path) << VAR(address) << VAR(type) << VAR(agent_path) << VAR_VOIDP(callback)
<< VAR_VOIDP(callback_arg);

#ifdef WITH_ADB_CONTROLLER

auto unit_mgr = MAA_ADB_CTRL_UNIT_NS::create_controller_unit(adb_path, address, type, config, agent_path);
if (!unit_mgr) {
LogError << "Failed to create controller unit";
return nullptr;
}

return new MAA_CTRL_NS::AdbController(adb_path, address, std::move(unit_mgr), callback, callback_arg);

#else

#pragma message("The build without adb controller")

LogError << "The build without adb controller";
return nullptr;

#endif // WITH_ADB_CONTROLLER
}

MaaControllerHandle MaaCustomControllerCreate(MaaCustomControllerHandle handle, MaaTransparentArg handle_arg,
Expand All @@ -54,7 +66,7 @@ MaaControllerHandle MaaThriftControllerCreate(MaaStringView param, MaaController
{
LogFunc << VAR(param) << VAR_VOIDP(callback) << VAR_VOIDP(callback_arg);

#ifdef WITH_THRIFT
#ifdef WITH_THRIFT_CONTROLLER

try {
return new MAA_CTRL_NS::CustomThriftController(param, callback, callback_arg);
Expand All @@ -66,12 +78,38 @@ MaaControllerHandle MaaThriftControllerCreate(MaaStringView param, MaaController

#else

#pragma message("The build without thrift")
#pragma message("The build without thrift controller")

LogError << "The build without thrift controller";
return nullptr;

#endif // WITH_THRIFT_CONTROLLER
}

MaaControllerHandle MaaDebuggingControllerCreate(MaaStringView read_path, MaaStringView write_path,
MaaDebuggingControllerType type, MaaStringView config,
MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg)
{
LogFunc << VAR(read_path) << VAR(write_path) << VAR(type) << VAR_VOIDP(callback) << VAR_VOIDP(callback_arg);

#ifdef WITH_DEBUGGING_CONTROLLER

auto unit_mgr = MAA_DBG_CTRL_UNIT_NS::create_controller_unit(read_path, write_path, type, config);
if (!unit_mgr) {
LogError << "Failed to create controller unit";
return nullptr;
}

return new MAA_CTRL_NS::DebuggingController(read_path, write_path, std::move(unit_mgr), callback, callback_arg);

#else

#pragma message("The build without debugging controller")

LogError << "The build without thrift";
LogError << "The build without debugging controller";
return nullptr;

#endif // WITH_THRIFT
#endif // WITH_DEBUGGING_CONTROLLER
}

void MaaControllerDestroy(MaaControllerHandle ctrl)
Expand Down
25 changes: 19 additions & 6 deletions source/MaaFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ target_include_directories(

target_compile_definitions(MaaFramework PRIVATE MAA_FRAMEWORK_EXPORTS)

target_link_libraries(MaaFramework MaaAdbControlUnit MaaDebuggingControlUnit MaaUtils)
if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
target_link_libraries(MaaFramework MaaUtils)
if (WITH_ADB_CONTROLLER)
target_link_libraries(MaaFramework MaaAdbController)
endif(WITH_ADB_CONTROLLER)
if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
target_link_libraries(MaaFramework MaaThriftController)
endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
endif(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
if (WITH_DEBUGGING_CONTROLLER)
target_link_libraries(MaaFramework MaaDebuggingController)
endif(WITH_DEBUGGING_CONTROLLER)
target_link_libraries(MaaFramework ${OpenCV_LIBS} fastdeploy_ppocr ONNXRuntime::ONNXRuntime HeaderOnlyLibraries)

# clang 15之后有ranges if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") find_package(range-v3 REQUIRED)
# target_link_libraries(MaaFramework range-v3::range-v3) endif ()

add_dependencies(MaaFramework MaaAdbControlUnit MaaDebuggingControlUnit MaaUtils)
if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
add_dependencies(MaaFramework MaaUtils)

if (WITH_ADB_CONTROLLER)
add_dependencies(MaaFramework MaaAdbController)
endif(WITH_ADB_CONTROLLER)
if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
add_dependencies(MaaFramework MaaThriftController)
endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE)
endif(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE)
if (WITH_DEBUGGING_CONTROLLER)
add_dependencies(MaaFramework MaaDebuggingController)
endif(WITH_DEBUGGING_CONTROLLER)

install(
TARGETS MaaFramework
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/Controller/CustomThriftController.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef WITH_THRIFT
#ifdef WITH_THRIFT_CONTROLLER

#include "CustomThriftController.h"

Expand Down Expand Up @@ -270,4 +270,4 @@ bool CustomThriftController::_stop_app(AppParam param)

MAA_CTRL_NS_END

#endif // WITH_THRIFT
#endif // WITH_THRIFT_CONTROLLER
4 changes: 2 additions & 2 deletions source/MaaFramework/Controller/CustomThriftController.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#ifdef WITH_THRIFT
#ifdef WITH_THRIFT_CONTROLLER

#include "ControllerMgr.h"

Expand Down Expand Up @@ -45,4 +45,4 @@ class CustomThriftController : public ControllerMgr

MAA_CTRL_NS_END

#endif // WITH_THRIFT
#endif // WITH_THRIFT_CONTROLLER
6 changes: 3 additions & 3 deletions source/MaaFramework/MaaFramework.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;MAA_FRAMEWORK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;MAA_FRAMEWORK_EXPORTS;WITH_ADB_CONTROLLER;WITH_DEBUGGING_CONTROLLER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
Expand Down Expand Up @@ -217,7 +217,7 @@
<WarningLevel>Level4</WarningLevel>
<IntrinsicFunctions>false</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;MAA_FRAMEWORK_EXPORTS;MAA_DEBUG;MAA_DEBUG_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;MAA_FRAMEWORK_EXPORTS;MAA_DEBUG;WITH_ADB_CONTROLLER;WITH_DEBUGGING_CONTROLLER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
Expand All @@ -243,7 +243,7 @@
<WarningLevel>Level4</WarningLevel>
<IntrinsicFunctions>false</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CONSOLE;_DEBUG;MAA_FRAMEWORK_EXPORTS;MAA_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CONSOLE;_DEBUG;MAA_FRAMEWORK_EXPORTS;MAA_DEBUG;WITH_ADB_CONTROLLER;WITH_DEBUGGING_CONTROLLER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
Expand Down

0 comments on commit 9ba96d0

Please sign in to comment.