diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-13 14:27:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-13 14:27:59 +0800 |
| commit | b9bbfb31bee88f6b10a9cc5b49e7618bef9d0be5 (patch) | |
| tree | ef02095c73635b5ace574c26dfcb999017e34897 /crates/vcs_actions/src/registry/client_registry.rs | |
| parent | c1d862d6df58173c24604e4dda33db8ce3be3ad7 (diff) | |
| parent | 4810f56e6a49b60923eb850d5944457650c81c75 (diff) | |
Merge pull request #21 from JustEnoughVCS/jvcs_dev
Jvcs dev
Diffstat (limited to 'crates/vcs_actions/src/registry/client_registry.rs')
| -rw-r--r-- | crates/vcs_actions/src/registry/client_registry.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/vcs_actions/src/registry/client_registry.rs b/crates/vcs_actions/src/registry/client_registry.rs index e69de29..5939bed 100644 --- a/crates/vcs_actions/src/registry/client_registry.rs +++ b/crates/vcs_actions/src/registry/client_registry.rs @@ -0,0 +1,60 @@ +use action_system::{action::ActionContext, action_pool::ActionPool}; +use tcp_connection::error::TcpTargetError; + +use crate::{ + actions::local_actions::register_hello_world_action, connection::protocol::RemoteActionInvoke, +}; + +fn register_actions(pool: &mut ActionPool) { + // Pool register here + register_hello_world_action(pool); +} + +pub fn client_action_pool() -> ActionPool { + // Create pool + let mut pool = ActionPool::new(); + + // Register actions + register_actions(&mut pool); + + // Add process events + pool.set_on_proc_begin(|ctx, args| Box::pin(on_proc_begin(ctx, args))); + + // Return + pool +} + +async fn on_proc_begin( + ctx: &ActionContext, + _args: &(dyn std::any::Any + Send + Sync), +) -> Result<(), TcpTargetError> { + // Is ctx remote + let is_remote = ctx.is_remote(); + + // Action name and arguments + let action_name = ctx.action_name().to_string(); + let action_args_json = ctx.action_args_json().clone(); + + // Get instance + let Some(instance) = ctx.instance() else { + return Err(TcpTargetError::Unsupported( + "Missing ConnectionInstance in current context, this ActionPool does not support this call" + .to_string())); + }; + + // If it's remote, invoke action at server + if is_remote { + // Build protocol message + let msg = RemoteActionInvoke { + action_name, + action_args_json, + }; + + // Send + let mut instance = instance.lock().await; + instance.write_msgpack(&msg).await?; + } + + // Return OK, wait for client to execute Action locally + Ok(()) +} |
