pub struct AgentClient { /* private fields */ }Expand description
Agent client for remote custom component execution.
Connects to an AgentServer to delegate custom recognition and action execution to a separate process.
Implementations§
Source§impl AgentClient
impl AgentClient
Sourcepub fn new(identifier: Option<&str>) -> MaaResult<Self>
pub fn new(identifier: Option<&str>) -> MaaResult<Self>
Create a new agent client.
Uses IPC mode by default. On older Windows versions that don’t support AF_UNIX (before Build 17063), it will automatically fall back to TCP mode.
§Arguments
identifier- Optional connection identifier for matching specific AgentServer
§Example
use maa_framework::agent_client::AgentClient;
// Create with auto-generated identifier
let client = AgentClient::new(None).expect("Failed to create client");
// Create with specific identifier
let client = AgentClient::new(Some("my_agent")).expect("Failed to create client");
let id = client.identifier().expect("Failed to get identifier");
println!("Identifier: {}", id);Sourcepub fn create_tcp(port: u16) -> MaaResult<Self>
pub fn create_tcp(port: u16) -> MaaResult<Self>
Create an agent client with TCP connection.
The client listens on 127.0.0.1 at the specified port.
If 0 is passed, an available port is automatically selected.
AgentServer can use the port number from identifier()
to connect via TCP.
§Arguments
port- TCP port (0-65535), 0 for auto-select
§Example
use maa_framework::agent_client::AgentClient;
let client = AgentClient::create_tcp(0).expect("Failed to create TCP client");
let port = client.identifier().expect("Failed to get port");
println!("Listening on port: {}", port);Sourcepub fn identifier(&self) -> Option<String>
pub fn identifier(&self) -> Option<String>
Get the connection identifier.
Sourcepub fn bind(&mut self, resource: Resource) -> MaaResult<()>
pub fn bind(&mut self, resource: Resource) -> MaaResult<()>
Bind a resource to receive custom recognitions and actions from AgentServer.
Takes ownership of the Resource to ensure it stays alive while bound.
Sourcepub fn register_resource_sink(&mut self, resource: Resource) -> MaaResult<()>
pub fn register_resource_sink(&mut self, resource: Resource) -> MaaResult<()>
Register resource event sink to forward events to AgentServer.
Sourcepub fn register_controller_sink(
&mut self,
controller: Controller,
) -> MaaResult<()>
pub fn register_controller_sink( &mut self, controller: Controller, ) -> MaaResult<()>
Register controller event sink to forward events to AgentServer.
Sourcepub fn register_tasker_sink(&mut self, tasker: Tasker) -> MaaResult<()>
pub fn register_tasker_sink(&mut self, tasker: Tasker) -> MaaResult<()>
Register tasker event sink to forward events to AgentServer.
Sourcepub fn register_sinks(
&mut self,
resource: Resource,
controller: Controller,
tasker: Tasker,
) -> MaaResult<()>
pub fn register_sinks( &mut self, resource: Resource, controller: Controller, tasker: Tasker, ) -> MaaResult<()>
Register all event sinks (resource, controller, tasker) at once.
Sourcepub fn disconnect(&self) -> MaaResult<()>
pub fn disconnect(&self) -> MaaResult<()>
Disconnect from the AgentServer.
Sourcepub fn set_timeout(&self, milliseconds: i64) -> MaaResult<()>
pub fn set_timeout(&self, milliseconds: i64) -> MaaResult<()>
Sourcepub fn custom_recognition_list(&self) -> MaaResult<Vec<String>>
pub fn custom_recognition_list(&self) -> MaaResult<Vec<String>>
Get the list of custom recognitions available on the AgentServer.
Sourcepub fn custom_action_list(&self) -> MaaResult<Vec<String>>
pub fn custom_action_list(&self) -> MaaResult<Vec<String>>
Get the list of custom actions available on the AgentServer.
Sourcepub fn raw(&self) -> *mut MaaAgentClient
pub fn raw(&self) -> *mut MaaAgentClient
Get the raw handle pointer.