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
impl Tasker
Sourcepub unsafe fn from_raw(ptr: *mut MaaTasker, owns: bool) -> MaaResult<Self>
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.
Sourcepub fn bind_resource(&self, res: &Resource) -> MaaResult<()>
pub fn bind_resource(&self, res: &Resource) -> MaaResult<()>
Bind a resource to this tasker.
Sourcepub fn bind_controller(&self, ctrl: &Controller) -> MaaResult<()>
pub fn bind_controller(&self, ctrl: &Controller) -> MaaResult<()>
Bind a controller to this tasker.
Sourcepub fn get_recognition_detail(
&self,
reco_id: MaaId,
) -> MaaResult<Option<RecognitionDetail>>
pub fn get_recognition_detail( &self, reco_id: MaaId, ) -> MaaResult<Option<RecognitionDetail>>
Get recognition details by ID.
Sourcepub fn get_action_detail(
&self,
act_id: MaaId,
) -> MaaResult<Option<ActionDetail>>
pub fn get_action_detail( &self, act_id: MaaId, ) -> MaaResult<Option<ActionDetail>>
Get action details by ID.
Sourcepub fn get_node_detail(&self, node_id: MaaId) -> MaaResult<Option<NodeDetail>>
pub fn get_node_detail(&self, node_id: MaaId) -> MaaResult<Option<NodeDetail>>
Get node details by ID.
Sourcepub fn get_task_detail(&self, task_id: MaaId) -> MaaResult<Option<TaskDetail>>
pub fn get_task_detail(&self, task_id: MaaId) -> MaaResult<Option<TaskDetail>>
Get task details by ID.
Sourcepub fn post_task(
&self,
entry: &str,
pipeline_override: &str,
) -> MaaResult<TaskJob<'static, TaskDetail>>
pub fn post_task( &self, entry: &str, pipeline_override: &str, ) -> MaaResult<TaskJob<'static, TaskDetail>>
Sourcepub fn post_task_json(
&self,
entry: &str,
pipeline_override: &Value,
) -> MaaResult<TaskJob<'static, TaskDetail>>
pub fn post_task_json( &self, entry: &str, pipeline_override: &Value, ) -> MaaResult<TaskJob<'static, TaskDetail>>
Sourcepub fn inited(&self) -> bool
pub fn inited(&self) -> bool
Check if the tasker has been initialized (resource and controller bound).
Sourcepub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
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.
Sourcepub fn remove_sink(&self, sink_id: MaaSinkId)
pub fn remove_sink(&self, sink_id: MaaSinkId)
Sourcepub fn clear_sinks(&self)
pub fn clear_sinks(&self)
Clear all tasker sinks.
pub fn register_callback<F>(&self, callback: F) -> MaaResult<MaaId>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the tasker is currently running.
Sourcepub fn add_context_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
pub fn add_context_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
Add a context event sink callback. Returns a sink ID for later removal.
Sourcepub fn add_context_event_sink(
&self,
sink: Box<dyn EventSink>,
) -> MaaResult<MaaSinkId>
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.
Sourcepub fn remove_context_sink(&self, sink_id: MaaSinkId)
pub fn remove_context_sink(&self, sink_id: MaaSinkId)
Remove a context sink by ID.
Sourcepub fn clear_context_sinks(&self)
pub fn clear_context_sinks(&self)
Clear all context sinks.
Sourcepub fn clear_cache(&self) -> MaaResult<()>
pub fn clear_cache(&self) -> MaaResult<()>
Clear all cached data.
Sourcepub fn override_pipeline(
&self,
task_id: MaaId,
pipeline_override: &str,
) -> MaaResult<bool>
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.
Sourcepub fn get_latest_node(&self, node_name: &str) -> MaaResult<Option<MaaId>>
pub fn get_latest_node(&self, node_name: &str) -> MaaResult<Option<MaaId>>
Get the latest node ID for a given node name.
Sourcepub fn bind(
&self,
resource: &Resource,
controller: &Controller,
) -> MaaResult<()>
pub fn bind( &self, resource: &Resource, controller: &Controller, ) -> MaaResult<()>
Convenience method to bind both resource and controller at once.
Sourcepub fn resource(&self) -> Option<ResourceRef<'_>>
pub fn resource(&self) -> Option<ResourceRef<'_>>
Sourcepub fn controller(&self) -> Option<ControllerRef<'_>>
pub fn controller(&self) -> Option<ControllerRef<'_>>
Sourcepub fn resource_handle(&self) -> *mut MaaResource
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.
Sourcepub fn controller_handle(&self) -> *mut MaaController
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.
Sourcepub fn post_recognition(
&self,
reco_type: &str,
reco_param: &str,
image: &MaaImageBuffer,
) -> MaaResult<TaskJob<'static, RecognitionDetail>>
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 stringimage- The image to perform recognition on
Sourcepub fn post_action(
&self,
action_type: &str,
action_param: &str,
box_rect: &Rect,
reco_detail: &str,
) -> MaaResult<TaskJob<'static, ActionDetail>>
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 stringbox_rect- The target rectangle for the actionreco_detail- Recognition detail from previous recognition (can be empty)
Sourcepub fn set_save_draw(save: bool) -> MaaResult<()>
pub fn set_save_draw(save: bool) -> MaaResult<()>
Set whether to save debug drawings.
Sourcepub fn set_stdout_level(level: MaaLoggingLevel) -> MaaResult<()>
pub fn set_stdout_level(level: MaaLoggingLevel) -> MaaResult<()>
Set the stdout logging level.
Sourcepub fn set_debug_mode(debug: bool) -> MaaResult<()>
pub fn set_debug_mode(debug: bool) -> MaaResult<()>
Enable or disable debug mode (raw image capture, etc).
Sourcepub fn set_save_on_error(save: bool) -> MaaResult<()>
pub fn set_save_on_error(save: bool) -> MaaResult<()>
Set whether to save screenshots on error.
Sourcepub fn set_draw_quality(quality: i32) -> MaaResult<()>
pub fn set_draw_quality(quality: i32) -> MaaResult<()>
Set the JPEG quality for debug drawings (0-100).
Sourcepub fn set_reco_image_cache_limit(limit: usize) -> MaaResult<()>
pub fn set_reco_image_cache_limit(limit: usize) -> MaaResult<()>
Set the limit for recognition image cache.