Skip to main content

AgentClient

Struct AgentClient 

Source
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

Source

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

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

pub fn identifier(&self) -> Option<String>

Get the connection identifier.

Source

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.

Source

pub fn register_resource_sink(&mut self, resource: Resource) -> MaaResult<()>

Register resource event sink to forward events to AgentServer.

Source

pub fn register_controller_sink( &mut self, controller: Controller, ) -> MaaResult<()>

Register controller event sink to forward events to AgentServer.

Source

pub fn register_tasker_sink(&mut self, tasker: Tasker) -> MaaResult<()>

Register tasker event sink to forward events to AgentServer.

Source

pub fn register_sinks( &mut self, resource: Resource, controller: Controller, tasker: Tasker, ) -> MaaResult<()>

Register all event sinks (resource, controller, tasker) at once.

Source

pub fn connect(&self) -> MaaResult<()>

Connect to the AgentServer.

On failure, registrations added by this connection attempt are removed and MaaFramework attempts to shut down the remote session before returning an error.

Source

pub fn disconnect(&self) -> MaaResult<()>

Disconnect from the AgentServer.

Source

pub fn connected(&self) -> bool

Check if currently connected to AgentServer.

Source

pub fn alive(&self) -> bool

Check if the connection is alive.

Source

pub fn set_timeout(&self, milliseconds: i64) -> MaaResult<()>

Set the connection timeout.

§Arguments
  • milliseconds - Timeout in milliseconds
Source

pub fn custom_recognition_list(&self) -> MaaResult<Vec<String>>

Get the list of custom recognitions available on the AgentServer.

Source

pub fn custom_action_list(&self) -> MaaResult<Vec<String>>

Get the list of custom actions available on the AgentServer.

Source

pub fn raw(&self) -> *mut MaaAgentClient

Get the raw handle pointer.

Trait Implementations§

Source§

impl Drop for AgentClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for AgentClient

Source§

impl Sync for AgentClient

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.