From ffededc58950554de831fbe481f67ab7bf2947ba Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 24 Jul 2022 15:59:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20core=20=E6=96=B0=E5=A2=9E=20GetUUID=20?= =?UTF-8?q?=E5=92=8C=20GetTasksList=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/AsstCaller.h | 4 ++- src/MeoAssistant/Assistant.cpp | 15 ++++++++++++ src/MeoAssistant/Assistant.h | 4 ++- src/MeoAssistant/AsstCaller.cpp | 43 ++++++++++++++++++++++++--------- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/include/AsstCaller.h b/include/AsstCaller.h index b60172ff40..88e59db40b 100644 --- a/include/AsstCaller.h +++ b/include/AsstCaller.h @@ -28,8 +28,10 @@ extern "C" { bool ASSTAPI AsstStart(AsstHandle handle); bool ASSTAPI AsstStop(AsstHandle handle); - unsigned long long ASSTAPI AsstGetImage(AsstHandle handle, void* buff, unsigned long long buff_size); bool ASSTAPI AsstCtrlerClick(AsstHandle handle, int x, int y, bool block); + unsigned long long ASSTAPI AsstGetImage(AsstHandle handle, void* buff, unsigned long long buff_size); + unsigned long long ASSTAPI AsstGetUUID(AsstHandle handle, char* buff, unsigned long long buff_size); + unsigned long long ASSTAPI AsstGetTasksList(AsstHandle handle, TaskId* buff, unsigned long long buff_size); ASSTAPI_PORT const char* ASST_CALL AsstGetVersion(); void ASSTAPI AsstLog(const char* level, const char* message); diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index 40dcea766b..942414c75d 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -171,6 +171,21 @@ bool asst::Assistant::ctrler_click(int x, int y, bool block) return true; } +std::string asst::Assistant::get_uuid() const +{ + return m_uuid; +} + +std::vector asst::Assistant::get_tasks_list() const +{ + std::vector result; + std::unique_lock lock(m_mutex); + for (const auto& [id, _] : m_tasks_list) { + result.emplace_back(id); + } + return result; +} + bool asst::Assistant::start(bool block) { LogTraceFunction; diff --git a/src/MeoAssistant/Assistant.h b/src/MeoAssistant/Assistant.h index 329d3d0f6c..f87ebe4fcf 100644 --- a/src/MeoAssistant/Assistant.h +++ b/src/MeoAssistant/Assistant.h @@ -44,6 +44,8 @@ namespace asst std::vector get_image() const; bool ctrler_click(int x, int y, bool block = true); + std::string get_uuid() const; + std::vector get_tasks_list() const; private: void working_proc(); @@ -67,7 +69,7 @@ namespace asst void* m_callback_arg = nullptr; bool m_thread_idle = true; - std::mutex m_mutex; + mutable std::mutex m_mutex; std::condition_variable m_condvar; std::queue> m_msg_queue; diff --git a/src/MeoAssistant/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp index 3845f368bb..c33ea2e8c3 100644 --- a/src/MeoAssistant/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -128,6 +128,14 @@ bool AsstSetTaskParams(AsstHandle handle, TaskId id, const char* params) return handle->set_task_params(id, params ? params : ""); } +bool AsstCtrlerClick(AsstHandle handle, int x, int y, bool block) +{ + if (!inited || handle == nullptr) { + return false; + } + return handle->ctrler_click(x, y, block); +} + unsigned long long AsstGetImage(AsstHandle handle, void* buff, unsigned long long buff_size) { if (!inited || handle == nullptr || buff == nullptr) { @@ -142,22 +150,33 @@ unsigned long long AsstGetImage(AsstHandle handle, void* buff, unsigned long lon return data_size; } -bool AsstCtrlerClick(AsstHandle handle, int x, int y, bool block) +unsigned long long ASSTAPI AsstGetUUID(AsstHandle handle, char* buff, unsigned long long buff_size) { - if (!inited || handle == nullptr) { - return false; + if (!inited || handle == nullptr || buff == nullptr) { + return 0; } - return handle->ctrler_click(x, y, block); + auto uuid = handle->get_uuid(); + size_t data_size = uuid.size(); + if (buff_size < data_size) { + return 0; + } + memcpy(buff, uuid.data(), data_size); + return data_size; } -//bool AsstSetParam(AsstHandle handle, const char* type, const char* param, const char* value) -//{ -// if (handle == nullptr) { -// return false; -// } -// -// return handle->set_param(type, param, value); -//} +unsigned long long ASSTAPI AsstGetTasksList(AsstHandle handle, TaskId* buff, unsigned long long buff_size) +{ + if (!inited || handle == nullptr || buff == nullptr) { + return 0; + } + auto tasks = handle->get_tasks_list(); + size_t data_size = tasks.size(); + if (buff_size < data_size) { + return 0; + } + memcpy(buff, tasks.data(), data_size); + return data_size; +} const char* AsstGetVersion() {