-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
213 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "MaaAgentClientDef.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
MAA_AGENT_CLIENT_API MaaAgentClient* MaaAgentClientCreate(MaaNotificationCallback notify, void* notify_trans_arg); | ||
|
||
MAA_AGENT_CLIENT_API void MaaAgentClientDestroy(MaaAgentClient* client); | ||
|
||
MAA_AGENT_CLIENT_API MaaBool | ||
MaaAgentClientStartChild(MaaAgentClient* client, const char* child_exec, const MaaStringListBuffer* child_args); | ||
|
||
MAA_AGENT_CLIENT_API MaaBool MaaAgentClientBindResource(MaaAgentClient* client, MaaResource* res); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include "MaaFramework/MaaDef.h" // IWYU pragma: export | ||
|
||
typedef struct MaaAgentClient MaaAgentClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "MaaAgentClient/MaaAgentClientAPI.h" | ||
|
||
#include "Client/AgentClient.h" | ||
#include "Utils/Buffer/StringBuffer.hpp" | ||
#include "Utils/Logger.h" | ||
#include "Utils/Platform.h" | ||
|
||
MaaAgentClient* MaaAgentClientCreate(MaaNotificationCallback notify, void* notify_trans_arg) | ||
{ | ||
LogFunc << VAR_VOIDP(notify) << VAR_VOIDP(notify_trans_arg); | ||
|
||
return new MAA_AGENT_CLIENT_NS::AgentClient(notify, notify_trans_arg); | ||
} | ||
|
||
void MaaAgentClientDestroy(MaaAgentClient* client) | ||
{ | ||
LogFunc << VAR_VOIDP(client); | ||
|
||
if (client == nullptr) { | ||
LogError << "handle is null"; | ||
return; | ||
} | ||
|
||
delete client; | ||
} | ||
|
||
MaaBool MaaAgentClientStartChild(MaaAgentClient* client, const char* child_exec, const MaaStringListBuffer* child_args) | ||
{ | ||
LogFunc << VAR_VOIDP(client) << VAR(child_exec) << VAR(child_args); | ||
|
||
if (!client) { | ||
LogError << "handle is null"; | ||
return false; | ||
} | ||
|
||
std::vector<std::string> args; | ||
|
||
if (child_args) { | ||
size_t size = child_args->size(); | ||
for (size_t i = 0; i < size; ++i) { | ||
args.emplace_back(child_args->at(i).get()); | ||
} | ||
} | ||
|
||
return client->start_clild(MAA_NS::path(child_exec), args); | ||
} | ||
|
||
MaaBool MaaAgentClientBindResource(MaaAgentClient* client, MaaResource* res) | ||
{ | ||
LogFunc << VAR_VOIDP(client) << VAR_VOIDP(res); | ||
|
||
if (!client || !res) { | ||
LogError << "handle is null"; | ||
return false; | ||
} | ||
|
||
return client->bind_resource(res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "MaaAgentClient/MaaAgentClientDef.h" | ||
|
||
struct MaaAgentClient | ||
{ | ||
public: | ||
virtual ~MaaAgentClient() = default; | ||
|
||
virtual bool start_clild(const std::filesystem::path& child_exec, const std::vector<std::string>& child_args) = 0; | ||
virtual bool bind_resource(MaaResource* resource) = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
file(GLOB_RECURSE maa_agent_client_src *.h *.hpp *.cpp) | ||
file(GLOB_RECURSE maa_agent_client_header ${MAA_PUBLIC_INC}/MaaAgentClient/*) | ||
|
||
add_library(MaaAgentClient SHARED ${maa_agent_client_src} ${maa_agent_client_header}) | ||
|
||
target_include_directories( | ||
MaaAgentClient | ||
PUBLIC $<BUILD_INTERFACE:${MAA_PUBLIC_INC}> $<INSTALL_INTERFACE:include> | ||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${MAA_PRIVATE_INC} ${MAA_PUBLIC_INC}) | ||
|
||
target_compile_definitions(MaaAgentClient PRIVATE MAA_AGENT_CLIENT_EXPORTS) | ||
|
||
target_link_libraries(MaaAgentClient PRIVATE MaaUtils MaaFramework LibraryHolder HeaderOnlyLibraries) | ||
|
||
add_dependencies(MaaAgentClient MaaUtils MaaFramework) | ||
|
||
install( | ||
TARGETS MaaAgentClient | ||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION bin | ||
ARCHIVE DESTINATION lib) | ||
|
||
if(WIN32) | ||
install(FILES $<TARGET_PDB_FILE:MaaAgentClient> DESTINATION symbol OPTIONAL) | ||
endif() | ||
|
||
install(DIRECTORY "${MAA_PUBLIC_INC}/MaaAgentClient" DESTINATION "include") | ||
|
||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_agent_client_src}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "AgentClient.h" | ||
|
||
MAA_AGENT_CLIENT_NS_BEGIN | ||
|
||
AgentClient::AgentClient(MaaNotificationCallback notify, void* notify_trans_arg) | ||
: notifier_(notify, notify_trans_arg) | ||
{ | ||
LogFunc << VAR_VOIDP(notify) << VAR_VOIDP(notify_trans_arg); | ||
} | ||
|
||
bool AgentClient::start_clild(const std::filesystem::path& child_exec, const std::vector<std::string>& child_args) | ||
{ | ||
LogFunc << VAR(child_exec) << VAR(child_args); | ||
|
||
return false; | ||
} | ||
|
||
bool AgentClient::bind_resource(MaaResource* resource) | ||
{ | ||
LogInfo << VAR_VOIDP(this) << VAR_VOIDP(resource); | ||
|
||
resource_ = resource; | ||
|
||
return true; | ||
} | ||
|
||
MAA_AGENT_CLIENT_NS_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
#include "API/MaaAgentClientTypes.h" | ||
#include "Conf/Conf.h" | ||
#include "Utils/MessageNotifier.hpp" | ||
|
||
MAA_AGENT_CLIENT_NS_BEGIN | ||
|
||
class AgentClient : public MaaAgentClient | ||
{ | ||
public: | ||
AgentClient(MaaNotificationCallback notify, void* notify_trans_arg); | ||
virtual ~AgentClient() override = default; | ||
|
||
virtual bool start_clild(const std::filesystem::path& child_exec, const std::vector<std::string>& child_args) override; | ||
virtual bool bind_resource(MaaResource* resource) override; | ||
|
||
private: | ||
MaaResource* resource_ = nullptr; | ||
MessageNotifier notifier_; | ||
}; | ||
|
||
MAA_AGENT_CLIENT_NS_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters