Skip to content

Commit

Permalink
feat: Debugging Controller (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO authored Oct 23, 2023
1 parent 8bcdda2 commit 6311125
Show file tree
Hide file tree
Showing 26 changed files with 787 additions and 34 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
8 changes: 6 additions & 2 deletions MAA.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
# Visual Studio Version 16
VisualStudioVersion = 16.0.33927.289
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{11F02235-5785-408B-9651-8A4B41FF36F4}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -17,6 +17,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaFramework", "source\MaaF
ProjectSection(ProjectDependencies) = postProject
{27862F0F-109D-40C8-B48B-9461D15222E3} = {27862F0F-109D-40C8-B48B-9461D15222E3}
{DD48546D-48D4-4C84-BAC4-6126D0B5BFB3} = {DD48546D-48D4-4C84-BAC4-6126D0B5BFB3}
{E750209E-FE9B-4897-875A-61BFA73F51F3} = {E750209E-FE9B-4897-875A-61BFA73F51F3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaAdbControlUnit", "source\MaaAdbControlUnit\MaaAdbControlUnit.vcxproj", "{DD48546D-48D4-4C84-BAC4-6126D0B5BFB3}"
Expand All @@ -34,6 +35,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaToolKit", "source\MaaToo
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaDebuggingControlUnit", "source\MaaDebuggingControlUnit\MaaDebuggingControlUnit.vcxproj", "{E750209E-FE9B-4897-875A-61BFA73F51F3}"
ProjectSection(ProjectDependencies) = postProject
{27862F0F-109D-40C8-B48B-9461D15222E3} = {27862F0F-109D-40C8-B48B-9461D15222E3}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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
18 changes: 18 additions & 0 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ enum MaaAdbControllerTypeEnum
MaaAdbControllerType_Screencap_Mask = 0xFF0000,
};

typedef int32_t MaaDebuggingControllerType;
enum MaaDebuggingControllerTypeEnum
{
MaaDebuggingController_Invalid = 0,

MaaDebuggingControllerType_Touch_Ignore = 1,
MaaDebuggingControllerType_Touch_Mask = 0xFF,

MaaDebuggingControllerType_Key_Ignore = 1 << 8,
MaaDebuggingControllerType_Key_Mask = 0xFF00,

MaaDebuggingControllerType_Input_Preset_Ignore =
MaaDebuggingControllerType_Touch_Ignore | MaaDebuggingControllerType_Key_Ignore,

MaaDebuggingControllerType_Screencap_ReadIndex = 1 << 16,
MaaDebuggingControllerType_Screencap_Mask = 0xFF0000,
};

typedef void* MaaTransparentArg;
typedef MaaTransparentArg MaaCallbackTransparentArg;

Expand Down
20 changes: 14 additions & 6 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
add_subdirectory(MaaUtils)
add_subdirectory(MaaAdbControlUnit)
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)
2 changes: 1 addition & 1 deletion source/MaaAdbControlUnit/MaaAdbControlUnit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ControlUnit\ControlUnitAPI.h" />
<ClInclude Include="..\include\ControlUnit\AdbControlUnitAPI.h" />
<ClInclude Include="ControlUnitMgr.h" />
<ClInclude Include="General\Activity.h" />
<ClInclude Include="General\Connection.h" />
Expand Down
20 changes: 20 additions & 0 deletions source/MaaDebuggingControlUnit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
file(GLOB_RECURSE maa_debugging_control_unit_src *.h *.hpp *.cpp ../include)

add_library(MaaDebuggingControlUnit SHARED ${maa_debugging_control_unit_src})

target_include_directories(MaaDebuggingControlUnit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../../include)

target_link_libraries(MaaDebuggingControlUnit MaaUtils HeaderOnlyLibraries ${OpenCV_LIBS})

target_compile_definitions(MaaDebuggingControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS)

add_dependencies(MaaDebuggingControlUnit MaaUtils)

install(
TARGETS MaaDebuggingControlUnit
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_debugging_control_unit_src})
44 changes: 44 additions & 0 deletions source/MaaDebuggingControlUnit/ControlUnitMgr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "ControlUnitMgr.h"

#include <meojson/json.hpp>

#include "General/VirtualInfo.h"
#include "Screencap/ReadIndex.h"
#include "Utils/Logger.h"

#pragma message("MaaControlUnit MAA_VERSION: " MAA_VERSION)

MAA_DBG_CTRL_UNIT_NS_BEGIN

std::shared_ptr<ControlUnitAPI> create_controller_unit(MaaStringView read_path, MaaStringView wirte_path,
MaaDebuggingControllerType type, MaaStringView config)
{
LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type);

auto filepath = MAA_NS::path(read_path);
std::ignore = wirte_path;

std::shared_ptr<ScreencapAPI> screencap_unit = nullptr;
auto screencap_type = type & MaaDebuggingControllerType_Screencap_Mask;

switch (screencap_type) {
case MaaDebuggingControllerType_Screencap_ReadIndex:
screencap_unit = std::make_shared<ReadIndex>(filepath);
break;
}

auto device_info_unit = std::make_shared<VirtualInfo>(filepath);
bool parsed = device_info_unit->parse(config);
if (!parsed) {
LogError << "failed to parse config" << VAR(config);
return nullptr;
}

auto unit_mgr = std::make_shared<ControlUnitMgr>();
unit_mgr->set_screencap_obj(std::move(screencap_unit));
unit_mgr->set_device_info_obj(std::move(device_info_unit));

return unit_mgr;
}

MAA_DBG_CTRL_UNIT_NS_END
25 changes: 25 additions & 0 deletions source/MaaDebuggingControlUnit/ControlUnitMgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "ControlUnit/DebuggingControlUnitAPI.h"

MAA_DBG_CTRL_UNIT_NS_BEGIN

class ControlUnitMgr : public ControlUnitAPI
{
public:
virtual ~ControlUnitMgr() override = default;

public: // from ControlUnitAPI
virtual std::shared_ptr<DeviceInfoAPI> device_info_obj() override { return device_info_; }
virtual std::shared_ptr<ScreencapAPI> screencap_obj() override { return screencap_; }

public:
void set_device_info_obj(std::shared_ptr<DeviceInfoAPI> obj) { device_info_ = std::move(obj); }
void set_screencap_obj(std::shared_ptr<ScreencapAPI> obj) { screencap_ = std::move(obj); }

private:
std::shared_ptr<DeviceInfoAPI> device_info_ = nullptr;
std::shared_ptr<ScreencapAPI> screencap_ = nullptr;
};

MAA_DBG_CTRL_UNIT_NS_END
6 changes: 6 additions & 0 deletions source/MaaDebuggingControlUnit/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<MaaDepsPropsFile>$(MSBuildThisFileDirectory)..\..\MaaDeps\msbuild\maadeps.props</MaaDepsPropsFile>
</PropertyGroup>
<Import Condition="Exists('$(MaaDepsPropsFile)')" Project="$(MaaDepsPropsFile)" />
</Project>
14 changes: 14 additions & 0 deletions source/MaaDebuggingControlUnit/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<MaaDepsTargetsFile>$(MSBuildThisFileDirectory)..\..\MaaDeps\msbuild\maadeps.targets</MaaDepsTargetsFile>
<MaaDepsDisableFlagFile>$(MSBuildThisFileDirectory)..\..\MSBUILD_DISABLE_MAADEPS</MaaDepsDisableFlagFile>
<MaaDepsExists Condition="Exists('$(MaaDepsTargetsFile)')">true</MaaDepsExists>
<MaaDepsDisableFlagExists Condition="Exists('$(MaaDepsDisableFlagFile)')">true</MaaDepsDisableFlagExists>
<MaaDepsMissingMessage>Missing third-party dependencies, run `python maadeps-download.py`. / 缺少第三方依赖,请运行 `python maadeps-download.py`。
Alternatively, run `python maadeps-build.py` to build third-party dependencies from source, or create a file named `MSBUILD_DISABLE_MAADEPS` next to MAA.sln file and bring your own libraries to MSBuild.</MaaDepsMissingMessage>
</PropertyGroup>
<Target Name="MessageMaaDepsNotExists" BeforeTargets="ClCompile" Condition="$(MaaDepsExists) != 'true' and '$(MaaDepsDisableFlagExists)' != true">
<Error Text="$(MaaDepsMissingMessage)" />
</Target>
<Import Condition="$(MaaDepsExists) == 'true'" Project="$(MaaDepsTargetsFile)" />
</Project>
25 changes: 25 additions & 0 deletions source/MaaDebuggingControlUnit/General/VirtualInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "ControlUnitMgr.h"

#include "Utils/ImageIo.h"
#include "Utils/Logger.h"
#include "VirtualInfo.h"

MAA_DBG_CTRL_UNIT_NS_BEGIN

bool VirtualInfo::parse(const json::value& config)
{
auto device_info = config.find("device_info");
if (!device_info) {
LogError << "device_info not found" << VAR(config);
return false;
}

uuid_ = device_info->get("uuid", path_to_utf8_string(path_));
resolution_.width = device_info->get("screen_width", 0);
resolution_.height = device_info->get("screen_height", 0);
orientation_ = device_info->get("orientation", 0);

return true;
}

MAA_DBG_CTRL_UNIT_NS_END
31 changes: 31 additions & 0 deletions source/MaaDebuggingControlUnit/General/VirtualInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "ControlUnit/DebuggingControlUnitAPI.h"

#include <filesystem>

MAA_DBG_CTRL_UNIT_NS_BEGIN

class VirtualInfo : public DeviceInfoAPI
{
public:
VirtualInfo(std::filesystem::path path) : path_(std::move(path)) {}
virtual ~VirtualInfo() override = default;

public: // from DeviceInfoAPI
virtual std::string get_uuid() const override { return uuid_; }
virtual DeviceResolution get_resolution() const override { return resolution_; }
virtual int get_orientation() const override { return orientation_; }

public:
bool parse(const json::value& config);

private:
std::filesystem::path path_;

std::string uuid_;
DeviceResolution resolution_;
int orientation_;
};

MAA_DBG_CTRL_UNIT_NS_END
Loading

0 comments on commit 6311125

Please sign in to comment.