summaryrefslogtreecommitdiff
path: root/crates/system_action/action_macros/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-13 11:17:00 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-13 11:17:00 +0800
commit860fb317bca61ce66a2c98df933aa666dae0a43f (patch)
tree1aa4440e23b6344097958888aeef231ba4d9e9ba /crates/system_action/action_macros/src
parent635ded4f6815d738dd9b9b711aa4c7cf302d340b (diff)
feat: Add JSON-based action invocation to ActionPool
- Extend action_gen macro to generate JSON serialization logic - Implement generic action processing using JSON text for type-agnostic calls - Add callback mechanism with action name and arguments in ActionPool - Update client and server registries to use new callback system - Improve action system flexibility at the cost of serialization overhead
Diffstat (limited to 'crates/system_action/action_macros/src')
-rw-r--r--crates/system_action/action_macros/src/lib.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs
index 04e974a..683efcb 100644
--- a/crates/system_action/action_macros/src/lib.rs
+++ b/crates/system_action/action_macros/src/lib.rs
@@ -37,6 +37,9 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok
let action_name_ident = &fn_name;
+ let register_this_action = quote::format_ident!("register_{}", action_name_ident);
+ let proc_this_action = quote::format_ident!("proc_{}", action_name_ident);
+
quote! {
#[derive(Debug, Clone, Default)]
#fn_vis struct #struct_name;
@@ -55,22 +58,23 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok
}
}
- impl #struct_name {
- #fn_vis fn register_to_pool(pool: &mut action_system::action_pool::ActionPool) {
- pool.register::<#struct_name, #arg_type, #return_type>();
- }
+ #fn_vis fn #register_this_action(pool: &mut action_system::action_pool::ActionPool) {
+ pool.register::<#struct_name, #arg_type, #return_type>();
+ }
- #fn_vis async fn process_at_pool<'a>(
- pool: &'a action_system::action_pool::ActionPool,
- ctx: action_system::action::ActionContext,
- #arg_param_name: #arg_type
- ) -> Result<#return_type, tcp_connection::error::TcpTargetError> {
- pool.process::<#arg_type, #return_type>(
- Box::leak(string_proc::snake_case!(stringify!(#action_name_ident)).into_boxed_str()),
- ctx,
- #arg_param_name
- ).await
- }
+ #fn_vis async fn #proc_this_action(
+ pool: &action_system::action_pool::ActionPool,
+ ctx: action_system::action::ActionContext,
+ #arg_param_name: #arg_type
+ ) -> Result<#return_type, tcp_connection::error::TcpTargetError> {
+ pool.process::<#arg_type, #return_type>(
+ Box::leak(string_proc::snake_case!(stringify!(#action_name_ident)).into_boxed_str()),
+ ctx,
+ serde_json::to_string(&#arg_param_name)
+ .map_err(|e| {
+ tcp_connection::error::TcpTargetError::Serialization(e.to_string())
+ })?
+ ).await
}
#[allow(dead_code)]