Skip to content

Commit

Permalink
perf: 优化post_find_device_with_adb实现,修复path编码问题
Browse files Browse the repository at this point in the history
fix #173
  • Loading branch information
MistEO committed Mar 14, 2024
1 parent 847d683 commit 07e4dc4
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion source/MaaToolkit/API/MaaToolkitDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ MaaBool MaaToolkitPostFindDeviceWithAdb(MaaStringView adb_path)
{
LogFunc;

return device_mgr.post_find_device_with_adb(adb_path);
return device_mgr.post_find_device_with_adb(MAA_NS::path(adb_path));
}

MaaBool MaaToolkitIsFindDeviceCompleted()
Expand Down
4 changes: 2 additions & 2 deletions source/MaaToolkit/AdbDevice/DeviceAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <ostream>
#include <string>
#include <string_view>
#include <filesystem>
#include <vector>

#include "Conf/Conf.h"
Expand Down Expand Up @@ -57,7 +57,7 @@ struct MaaToolkitDeviceMgrAPI
virtual ~MaaToolkitDeviceMgrAPI() = default;

virtual bool post_find_device() = 0;
virtual bool post_find_device_with_adb(std::string adb_path) = 0;
virtual bool post_find_device_with_adb(std::filesystem::path adb_path) = 0;
virtual bool is_find_completed() const = 0;
virtual const std::optional<std::vector<Device>>& get_devices() = 0;
};
7 changes: 4 additions & 3 deletions source/MaaToolkit/AdbDevice/DeviceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ bool DeviceMgr::post_find_device()
}

devices_ = std::nullopt;
find_device_future_ = std::async(std::launch::async, [=]() { return find_device_impl(); });
find_device_future_ =
std::async(std::launch::async, [=, this]() { return find_device_impl(); });
return true;
}

bool DeviceMgr::post_find_device_with_adb(std::string adb_path)
bool DeviceMgr::post_find_device_with_adb(std::filesystem::path adb_path)
{
LogFunc;

Expand All @@ -38,7 +39,7 @@ bool DeviceMgr::post_find_device_with_adb(std::string adb_path)

devices_ = std::nullopt;
find_device_future_ =
std::async(std::launch::async, [=]() { return find_device_with_adb_impl(adb_path); });
std::async(std::launch::async, [=, this]() { return find_device_with_adb_impl(adb_path); });
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions source/MaaToolkit/AdbDevice/DeviceMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class DeviceMgr : public MaaToolkitDeviceMgrAPI
};

virtual bool post_find_device() override final;
virtual bool post_find_device_with_adb(std::string adb_path) override final;
virtual bool post_find_device_with_adb(std::filesystem::path adb_path) override final;
virtual bool is_find_completed() const override final;
virtual const std::optional<std::vector<Device>>& get_devices() override final;

protected:
virtual std::vector<Device> find_device_impl() = 0;
virtual std::vector<Device> find_device_with_adb_impl(std::string adb_path) = 0;
virtual std::vector<Device> find_device_with_adb_impl(std::filesystem::path adb_path) = 0;

protected:
std::vector<std::string> request_adb_serials(
Expand Down
2 changes: 1 addition & 1 deletion source/MaaToolkit/AdbDevice/DeviceMgrLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::vector<Device> DeviceMgrLinux::find_device_impl()
return {};
}

std::vector<Device> DeviceMgrLinux::find_device_with_adb_impl(std::string adb_path)
std::vector<Device> DeviceMgrLinux::find_device_with_adb_impl(std::filesystem::path adb_path)
{
std::ignore = adb_path;
return {};
Expand Down
2 changes: 1 addition & 1 deletion source/MaaToolkit/AdbDevice/DeviceMgrLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeviceMgrLinux

public: // from DeviceMgr
virtual std::vector<Device> find_device_impl() override;
virtual std::vector<Device> find_device_with_adb_impl(std::string adb_path) override;
virtual std::vector<Device> find_device_with_adb_impl(std::filesystem::path adb_path) override;

private:
DeviceMgrLinux() = default;
Expand Down
10 changes: 5 additions & 5 deletions source/MaaToolkit/AdbDevice/DeviceMgrMacOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ std::vector<Device> DeviceMgrMacOS::find_device_impl()
return result;
}

std::vector<Device> DeviceMgrMacOS::find_device_with_adb_impl(std::string adb_path)
std::vector<Device> DeviceMgrMacOS::find_device_with_adb_impl(std::filesystem::path adb_path)
{
std::vector<Device> result;

auto serials = request_adb_serials(path(adb_path), json::object());
auto serials = request_adb_serials(adb_path, json::object());

for (const std::string& ser : serials) {
Device device;
device.name = adb_path;
device.adb_path = adb_path;
device.adb_path = path_to_utf8_string(adb_path);
device.name = device.adb_path;
device.adb_serial = ser;
device.adb_config = json::object().to_string();
device.adb_controller_type =
check_adb_controller_type(device.adb_path, device.adb_serial, device.adb_config);
check_adb_controller_type(adb_path, device.adb_serial, device.adb_config);
result.emplace_back(std::move(device));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion source/MaaToolkit/AdbDevice/DeviceMgrMacOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeviceMgrMacOS

public: // from DeviceMgr
virtual std::vector<Device> find_device_impl() override;
virtual std::vector<Device> find_device_with_adb_impl(std::string adb_path) override;
virtual std::vector<Device> find_device_with_adb_impl(std::filesystem::path adb_path) override;

private:
DeviceMgrMacOS() = default;
Expand Down
10 changes: 5 additions & 5 deletions source/MaaToolkit/AdbDevice/DeviceMgrWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ std::vector<Device> DeviceMgrWin32::find_device_impl()
return result;
}

std::vector<Device> DeviceMgrWin32::find_device_with_adb_impl(std::string adb_path)
std::vector<Device> DeviceMgrWin32::find_device_with_adb_impl(std::filesystem::path adb_path)
{
std::vector<Device> result;

auto serials = request_adb_serials(path(adb_path), json::object());
auto serials = request_adb_serials(adb_path, json::object());

for (const std::string& ser : serials) {
Device device;
device.name = adb_path;
device.adb_path = adb_path;
device.adb_path = path_to_utf8_string(adb_path);
device.name = device.adb_path;
device.adb_serial = ser;
device.adb_config = json::object().to_string();
device.adb_controller_type =
check_adb_controller_type(device.adb_path, device.adb_serial, device.adb_config);
check_adb_controller_type(adb_path, device.adb_serial, device.adb_config);
result.emplace_back(std::move(device));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion source/MaaToolkit/AdbDevice/DeviceMgrWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeviceMgrWin32

public: // from DeviceMgr
virtual std::vector<Device> find_device_impl() override;
virtual std::vector<Device> find_device_with_adb_impl(std::string adb_path) override;
virtual std::vector<Device> find_device_with_adb_impl(std::filesystem::path adb_path) override;

private:
DeviceMgrWin32() = default;
Expand Down

0 comments on commit 07e4dc4

Please sign in to comment.