diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-27 17:59:19 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-27 17:59:19 +0800 |
| commit | 5e150adf0e3d8b3843779eddd83469d1b1ba84bc (patch) | |
| tree | aedbd6cd10757da9c9d401a818ed1471f377d54b /crates/system_action/src | |
| parent | 49ad7a152cf849c8d91ee6b686da31f9c252f77c (diff) | |
| parent | 368687c943a13427b5338a30fb7b55558420f4de (diff) | |
Merge pull request #26 from JustEnoughVCS/jvcs_dev
Jvcs dev
Diffstat (limited to 'crates/system_action/src')
| -rw-r--r-- | crates/system_action/src/action.rs | 27 | ||||
| -rw-r--r-- | crates/system_action/src/action_pool.rs | 12 | ||||
| -rw-r--r-- | crates/system_action/src/lib.rs | 5 |
3 files changed, 29 insertions, 15 deletions
diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs index 8a6180a..9eef1db 100644 --- a/crates/system_action/src/action.rs +++ b/crates/system_action/src/action.rs @@ -23,7 +23,10 @@ where #[derive(Default)] pub struct ActionContext { /// Whether the action is executed locally or remotely - local: bool, + proc_on_local: bool, + + /// Whether the action being executed in the current context is a remote action + is_remote_action: bool, /// The name of the action being executed action_name: String, @@ -42,7 +45,7 @@ impl ActionContext { /// Generate local context pub fn local() -> Self { ActionContext { - local: true, + proc_on_local: true, ..Default::default() } } @@ -50,7 +53,7 @@ impl ActionContext { /// Generate remote context pub fn remote() -> Self { ActionContext { - local: false, + proc_on_local: false, ..Default::default() } } @@ -75,13 +78,23 @@ impl ActionContext { impl ActionContext { /// Whether the action is executed locally - pub fn is_local(&self) -> bool { - self.local + pub fn is_proc_on_local(&self) -> bool { + self.proc_on_local } /// Whether the action is executed remotely - pub fn is_remote(&self) -> bool { - !self.local + pub fn is_proc_on_remote(&self) -> bool { + !self.proc_on_local + } + + /// Whether the action being executed in the current context is a remote action + pub fn is_remote_action(&self) -> bool { + self.is_remote_action + } + + /// Set whether the action being executed in the current context is a remote action + pub fn set_is_remote_action(&mut self, is_remote_action: bool) { + self.is_remote_action = is_remote_action; } /// Get the connection instance in the current context diff --git a/crates/system_action/src/action_pool.rs b/crates/system_action/src/action_pool.rs index c28de1e..c3ad4a1 100644 --- a/crates/system_action/src/action_pool.rs +++ b/crates/system_action/src/action_pool.rs @@ -7,7 +7,7 @@ use tcp_connection::error::TcpTargetError; use crate::action::{Action, ActionContext}; type ProcBeginCallback = for<'a> fn( - &'a ActionContext, + &'a mut ActionContext, args: &'a (dyn std::any::Any + Send + Sync), ) -> ProcBeginFuture<'a>; type ProcEndCallback = fn() -> ProcEndFuture; @@ -94,9 +94,9 @@ impl ActionPool { if let Some(action) = self.actions.get(action_name) { // Set action name and args in context for callbacks let context = context.set_action_name(action_name.to_string()); - let context = context.set_action_args(args_json.clone()); + let mut context = context.set_action_args(args_json.clone()); - self.exec_on_proc_begin(&context, &args_json).await?; + self.exec_on_proc_begin(&mut context, &args_json).await?; let result = action.process_json_erased(context, args_json).await?; self.exec_on_proc_end().await?; Ok(result) @@ -114,7 +114,7 @@ impl ActionPool { pub async fn process<'a, Args, Return>( &'a self, action_name: &'a str, - context: ActionContext, + mut context: ActionContext, args: Args, ) -> Result<Return, TcpTargetError> where @@ -122,7 +122,7 @@ impl ActionPool { Return: serde::Serialize + Send + 'static, { if let Some(action) = self.actions.get(action_name) { - self.exec_on_proc_begin(&context, &args).await?; + self.exec_on_proc_begin(&mut context, &args).await?; let result = action.process_erased(context, Box::new(args)).await?; let result = *result .downcast::<Return>() @@ -137,7 +137,7 @@ impl ActionPool { /// Executes the process begin callback if set async fn exec_on_proc_begin( &self, - context: &ActionContext, + context: &mut ActionContext, args: &(dyn std::any::Any + Send + Sync), ) -> Result<(), TcpTargetError> { if let Some(callback) = &self.on_proc_begin { diff --git a/crates/system_action/src/lib.rs b/crates/system_action/src/lib.rs index 07be1bb..12ae999 100644 --- a/crates/system_action/src/lib.rs +++ b/crates/system_action/src/lib.rs @@ -1,5 +1,6 @@ -pub use action_system_macros::*; -pub extern crate action_system_macros as macros; +pub mod macros { + pub use action_system_macros::*; +} pub mod action; pub mod action_pool; |
