feat: core 新增 GetUUID 和 GetTasksList 接口

This commit is contained in:
MistEO
2022-07-24 15:59:45 +08:00
parent 10291bfa3d
commit ffededc589
4 changed files with 52 additions and 14 deletions

View File

@@ -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);

View File

@@ -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<Assistant::TaskId> asst::Assistant::get_tasks_list() const
{
std::vector<TaskId> result;
std::unique_lock<std::mutex> lock(m_mutex);
for (const auto& [id, _] : m_tasks_list) {
result.emplace_back(id);
}
return result;
}
bool asst::Assistant::start(bool block)
{
LogTraceFunction;

View File

@@ -44,6 +44,8 @@ namespace asst
std::vector<uchar> get_image() const;
bool ctrler_click(int x, int y, bool block = true);
std::string get_uuid() const;
std::vector<TaskId> 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<std::pair<AsstMsg, json::value>> m_msg_queue;

View File

@@ -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()
{