mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 10:10:45 +08:00
perf: update signatures of functions in Controller
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
|
||||
#include "Utils/Platform.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <regex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -24,14 +20,9 @@
|
||||
#endif
|
||||
|
||||
#include "AdbController.h"
|
||||
#include "MaatouchController.h"
|
||||
#include "MinitouchController.h"
|
||||
|
||||
#include "Common/AsstTypes.h"
|
||||
#include "Config/GeneralConfig.h"
|
||||
#include "Utils/Logger.hpp"
|
||||
#include "Utils/StringMisc.hpp"
|
||||
#include "Utils/WorkingDir.hpp"
|
||||
|
||||
asst::Controller::Controller(const AsstCallback& callback, Assistant* inst)
|
||||
: InstHelper(inst), m_callback(callback), m_rand_engine(std::random_device {}())
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#include "Utils/Logger.hpp"
|
||||
|
||||
std::optional<int> asst::AdbLiteIO::call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time)
|
||||
std::optional<int> asst::AdbLiteIO::call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time)
|
||||
{
|
||||
// TODO: 从上面的 call_command_win32/posix 里抽取出 socket 接收的部分
|
||||
if (recv_by_socket) {
|
||||
@@ -204,7 +204,7 @@ bool asst::AdbLiteIO::remove_quotes(std::string& data)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool asst::IOHandlerAdbLite::write(const std::string_view data)
|
||||
bool asst::IOHandlerAdbLite::write(std::string_view data)
|
||||
{
|
||||
try {
|
||||
m_handle->write(data);
|
||||
@@ -223,6 +223,6 @@ std::string asst::IOHandlerAdbLite::read(unsigned timeout_sec)
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Log.error("IOHandler read failed:", e.what());
|
||||
return NULL;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace asst
|
||||
AdbLiteIO(AdbLiteIO&&) = delete;
|
||||
virtual ~AdbLiteIO() = default;
|
||||
|
||||
virtual std::optional<int> call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time) override;
|
||||
virtual std::optional<int> call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time) override;
|
||||
|
||||
virtual std::shared_ptr<IOHandler> interactive_shell(const std::string& cmd) override;
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace asst
|
||||
public:
|
||||
virtual ~PlatformIO() = default;
|
||||
|
||||
virtual std::optional<int> call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time) = 0;
|
||||
virtual std::optional<int> call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time) = 0;
|
||||
|
||||
virtual std::optional<unsigned short> init_socket(const std::string& local_address) = 0;
|
||||
virtual void close_socket() noexcept = 0;
|
||||
@@ -39,7 +39,7 @@ namespace asst
|
||||
public:
|
||||
virtual ~IOHandler() = default;
|
||||
|
||||
virtual bool write(const std::string_view data) = 0;
|
||||
virtual bool write(std::string_view data) = 0;
|
||||
virtual std::string read(unsigned timeout_sec) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ asst::PosixIO::~PosixIO()
|
||||
|
||||
std::optional<int> asst::PosixIO::call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time)
|
||||
std::chrono::steady_clock::time_point start_time)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
|
||||
@@ -252,7 +252,7 @@ asst::IOHandlerPosix::~IOHandlerPosix()
|
||||
if (m_process > 0) ::kill(m_process, SIGTERM);
|
||||
}
|
||||
|
||||
bool asst::IOHandlerPosix::write(const std::string_view data)
|
||||
bool asst::IOHandlerPosix::write(std::string_view data)
|
||||
{
|
||||
if (m_process < 0 || m_write_fd < 0) return false;
|
||||
if (::write(m_write_fd, data.data(), data.length()) >= 0) return true;
|
||||
@@ -262,7 +262,7 @@ bool asst::IOHandlerPosix::write(const std::string_view data)
|
||||
|
||||
std::string asst::IOHandlerPosix::read(unsigned timeout_sec)
|
||||
{
|
||||
if (m_process < 0 || m_read_fd < 0) return NULL;
|
||||
if (m_process < 0 || m_read_fd < 0) return {};
|
||||
std::string ret_str;
|
||||
constexpr int PipeReadBuffSize = 4096ULL;
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ namespace asst
|
||||
PosixIO(PosixIO&&) = delete;
|
||||
virtual ~PosixIO();
|
||||
|
||||
virtual std::optional<int> call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time) override;
|
||||
virtual std::optional<int> call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time) override;
|
||||
|
||||
virtual std::optional<unsigned short> init_socket(const std::string& local_address) override;
|
||||
virtual void close_socket() noexcept override;
|
||||
@@ -48,9 +48,9 @@ namespace asst
|
||||
}
|
||||
IOHandlerPosix(const IOHandlerPosix&) = delete;
|
||||
IOHandlerPosix(IOHandlerPosix&&) = delete;
|
||||
virtual ~IOHandlerPosix();
|
||||
virtual ~IOHandlerPosix() override;
|
||||
|
||||
virtual bool write(const std::string_view data) override;
|
||||
virtual bool write(std::string_view data) override;
|
||||
virtual std::string read(unsigned timeout_sec) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -20,9 +20,9 @@ asst::Win32IO::~Win32IO()
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<int> asst::Win32IO::call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time)
|
||||
std::optional<int> asst::Win32IO::call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
|
||||
@@ -384,7 +384,7 @@ std::string asst::IOHandlerWin32::read(unsigned timeout_sec)
|
||||
return pipe_buffer.get();
|
||||
}
|
||||
|
||||
bool asst::IOHandlerWin32::write(const std::string_view data)
|
||||
bool asst::IOHandlerWin32::write(std::string_view data)
|
||||
{
|
||||
if (m_write == INVALID_HANDLE_VALUE) {
|
||||
Log.error("IOHandler write handle invalid", m_write);
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace asst
|
||||
Win32IO(Win32IO&&) = delete;
|
||||
virtual ~Win32IO();
|
||||
|
||||
virtual std::optional<int> call_command(const std::string& cmd, const bool recv_by_socket,
|
||||
std::string& pipe_data, std::string& sock_data, const int64_t timeout,
|
||||
const std::chrono::steady_clock::time_point start_time) override;
|
||||
virtual std::optional<int> call_command(const std::string& cmd, bool recv_by_socket, std::string& pipe_data,
|
||||
std::string& sock_data, int64_t timeout,
|
||||
std::chrono::steady_clock::time_point start_time) override;
|
||||
|
||||
virtual std::optional<unsigned short> init_socket(const std::string& local_address) override;
|
||||
virtual void close_socket() noexcept override;
|
||||
@@ -68,7 +68,7 @@ namespace asst
|
||||
IOHandlerWin32(IOHandlerWin32&&) = delete;
|
||||
virtual ~IOHandlerWin32();
|
||||
|
||||
virtual bool write(const std::string_view data) override;
|
||||
virtual bool write(std::string_view data) override;
|
||||
virtual std::string read(unsigned timeout_sec) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -17,7 +17,7 @@ std::shared_ptr<asst::Status> asst::InstHelper::status() const
|
||||
}
|
||||
bool asst::InstHelper::need_exit() const
|
||||
{
|
||||
return m_inst ? m_inst->need_exit() : false;
|
||||
return m_inst != nullptr && m_inst->need_exit();
|
||||
}
|
||||
|
||||
bool asst::InstHelper::sleep(unsigned millisecond) const
|
||||
|
||||
Reference in New Issue
Block a user