summaryrefslogtreecommitdiff
path: root/crates/vcs_actions/src/registry
diff options
context:
space:
mode:
Diffstat (limited to 'crates/vcs_actions/src/registry')
-rw-r--r--crates/vcs_actions/src/registry/client_registry.rs60
-rw-r--r--crates/vcs_actions/src/registry/server_registry.rs9
2 files changed, 69 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(())
+}
diff --git a/crates/vcs_actions/src/registry/server_registry.rs b/crates/vcs_actions/src/registry/server_registry.rs
index e69de29..b449b68 100644
--- a/crates/vcs_actions/src/registry/server_registry.rs
+++ b/crates/vcs_actions/src/registry/server_registry.rs
@@ -0,0 +1,9 @@
+use action_system::action_pool::ActionPool;
+
+use crate::actions::local_actions::register_hello_world_action;
+
+pub fn server_action_pool() -> ActionPool {
+ let mut pool = ActionPool::new();
+ register_hello_world_action(&mut pool);
+ pool
+}