Skip to main content

Tasker

Struct Tasker 

Source
pub struct Tasker { /* private fields */ }
Expand description

Task manager for executing pipelines.

Tasker is the central component that coordinates:

  • Resource binding (images, models)
  • Controller binding (device connection)
  • Task execution (pipelines)
  • Event handling (callbacks)

Implementations§

Source§

impl Tasker

Source

pub fn new() -> MaaResult<Self>

Create a new Tasker instance.

Source

pub unsafe fn from_raw(ptr: *mut MaaTasker, owns: bool) -> MaaResult<Self>

Create a Tasker from a raw pointer.

§Safety

The pointer must be valid. If owns is true, the Tasker will destroy the handle when dropped.

Source

pub fn bind_resource(&self, res: &Resource) -> MaaResult<()>

Bind a resource to this tasker.

Source

pub fn bind_controller(&self, ctrl: &Controller) -> MaaResult<()>

Bind a controller to this tasker.

Source

pub fn get_recognition_detail( &self, reco_id: MaaId, ) -> MaaResult<Option<RecognitionDetail>>

Get recognition details by ID.

Source

pub fn get_action_detail( &self, act_id: MaaId, ) -> MaaResult<Option<ActionDetail>>

Get action details by ID.

Source

pub fn get_node_detail(&self, node_id: MaaId) -> MaaResult<Option<NodeDetail>>

Get node details by ID.

Source

pub fn get_task_detail(&self, task_id: MaaId) -> MaaResult<Option<TaskDetail>>

Get task details by ID.

Source

pub fn post_task( &self, entry: &str, pipeline_override: &str, ) -> MaaResult<TaskJob<'static, TaskDetail>>

Post a task for execution.

§Arguments
  • entry - The task entry point name
  • pipeline_override - JSON string for parameter overrides
§Returns

A TaskJob that can be used to wait for completion and get results.

Source

pub fn post_task_json( &self, entry: &str, pipeline_override: &Value, ) -> MaaResult<TaskJob<'static, TaskDetail>>

Post a task with JSON pipeline override.

Convenience method that accepts serde_json::Value for pipeline overrides.

§Example
use serde_json::json;
let job = tasker.post_task_json("StartTask", &json!({
    "StartTask": { "next": ["SecondTask"] }
}))?;
Source

pub fn inited(&self) -> bool

Check if the tasker has been initialized (resource and controller bound).

Source

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

Get the underlying raw tasker handle.

Source

pub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
where F: Fn(&str, &str) + Send + Sync + 'static,

Add a tasker event sink callback.

This registers a callback that will be invoked for all tasker events including task start, task completion, and status changes.

§Arguments
  • callback - Closure that receives (message, detail_json) for each event
§Returns

Sink ID for later removal via remove_sink()

Source

pub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>

Register a strongly-typed event sink.

This method registers an implementation of the EventSink trait to receive structured notifications from this tasker.

§Arguments
  • sink - The event sink implementation (must be boxed).
§Returns

A MaaSinkId which can be used to manually remove the sink later via remove_sink. The sink will be automatically unregistered and dropped when the Tasker is dropped.

Source

pub fn remove_sink(&self, sink_id: MaaSinkId)

Remove a tasker sink by ID.

§Arguments
  • sink_id - ID returned from add_sink()
Source

pub fn clear_sinks(&self)

Clear all tasker sinks.

Source

pub fn register_callback<F>(&self, callback: F) -> MaaResult<MaaId>
where F: Fn(&str, &str) + Send + Sync + 'static,

👎Deprecated since 0.5.1: Use add_sink() instead
Source

pub fn post_stop(&self) -> MaaResult<MaaId>

Request the tasker to stop all running tasks.

Source

pub fn is_running(&self) -> bool

Check if the tasker is currently running.

Source

pub fn running(&self) -> bool

Check if the tasker is currently running (alias for is_running).

Source

pub fn stopping(&self) -> bool

Check if the tasker is currently stopping.

Source

pub fn add_context_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
where F: Fn(&str, &str) + Send + Sync + 'static,

Add a context event sink callback. Returns a sink ID for later removal.

Source

pub fn add_context_event_sink( &self, sink: Box<dyn EventSink>, ) -> MaaResult<MaaSinkId>

Register a strongly-typed context event sink.

This receives detailed execution events like Node.Recognition, Node.Action, etc.

§Arguments
  • sink - The event sink implementation (must be boxed).
§Returns

A MaaSinkId which can be used to manually remove the sink later via remove_context_sink.

Source

pub fn remove_context_sink(&self, sink_id: MaaSinkId)

Remove a context sink by ID.

Source

pub fn clear_context_sinks(&self)

Clear all context sinks.

Source

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

Clear all cached data.

Source

pub fn override_pipeline( &self, task_id: MaaId, pipeline_override: &str, ) -> MaaResult<bool>

Override pipeline configuration for a specific task.

§Arguments
  • task_id - The ID of the task to update.
  • pipeline_override - The JSON string containing the new configuration.
Source

pub fn get_latest_node(&self, node_name: &str) -> MaaResult<Option<MaaId>>

Get the latest node ID for a given node name.

Source

pub fn bind( &self, resource: &Resource, controller: &Controller, ) -> MaaResult<()>

Convenience method to bind both resource and controller at once.

Source

pub fn resource(&self) -> Option<ResourceRef<'_>>

Get a borrowed view of the bound resource.

Returns None if no resource is bound.

§Example
if let Some(res) = tasker.resource() {
    println!("Loaded: {}", res.loaded());
}
Source

pub fn controller(&self) -> Option<ControllerRef<'_>>

Get a borrowed view of the bound controller.

Returns None if no controller is bound.

§Example
if let Some(ctrl) = tasker.controller() {
    println!("Connected: {}", ctrl.connected());
}
Source

pub fn resource_handle(&self) -> *mut MaaResource

Get the bound resource handle (raw pointer).

Returns the raw pointer to the resource. The caller should not destroy this handle.

Source

pub fn controller_handle(&self) -> *mut MaaController

Get the bound controller handle (raw pointer).

Returns the raw pointer to the controller. The caller should not destroy this handle.

Source

pub fn post_recognition( &self, reco_type: &str, reco_param: &str, image: &MaaImageBuffer, ) -> MaaResult<TaskJob<'static, RecognitionDetail>>

Post a recognition task directly without executing through a pipeline.

§Arguments
  • reco_type - Recognition type (e.g., “TemplateMatch”, “OCR”)
  • reco_param - Recognition parameters as JSON string
  • image - The image to perform recognition on
Source

pub fn post_action( &self, action_type: &str, action_param: &str, box_rect: &Rect, reco_detail: &str, ) -> MaaResult<TaskJob<'static, ActionDetail>>

Post an action task directly without executing through a pipeline.

§Arguments
  • action_type - Action type (e.g., “Click”, “Swipe”)
  • action_param - Action parameters as JSON string
  • box_rect - The target rectangle for the action
  • reco_detail - Recognition detail from previous recognition (can be empty)
Source

pub fn set_log_dir<P: AsRef<Path>>(path: P) -> MaaResult<()>

Set the global log directory.

Source

pub fn set_save_draw(save: bool) -> MaaResult<()>

Set whether to save debug drawings.

Source

pub fn set_stdout_level(level: MaaLoggingLevel) -> MaaResult<()>

Set the stdout logging level.

Source

pub fn set_debug_mode(debug: bool) -> MaaResult<()>

Enable or disable debug mode (raw image capture, etc).

Source

pub fn set_save_on_error(save: bool) -> MaaResult<()>

Set whether to save screenshots on error.

Source

pub fn set_draw_quality(quality: i32) -> MaaResult<()>

Set the JPEG quality for debug drawings (0-100).

Source

pub fn set_reco_image_cache_limit(limit: usize) -> MaaResult<()>

Set the limit for recognition image cache.

Source

pub fn load_plugin<P: AsRef<Path>>(path: P) -> MaaResult<()>

Load a plugin from the specified path.

Trait Implementations§

Source§

impl Clone for Tasker

Source§

fn clone(&self) -> Tasker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Send for Tasker

Source§

impl Sync for Tasker

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.