ark_api_ffi/entrypoints/behavior.rs
1//! Behavior module entrypoints
2
3/// `ark_behavior_register` - Register a behavior module
4///
5/// Register a behavior module by returning a serialized JSON vector of bytes of local registration info.
6pub type BehaviorRegisterFn = fn();
7
8/// `ark_behavior_persist` - Persists the whole dynamic state of a behavior module
9///
10/// Allows saving the whole state of a behavior module, notably before trying to re-spawn the
11/// behavior module after it failed.
12///
13/// The persistence format choice is left to the behavior module, and it has to be same used in the
14/// corresponding `ark_behavior_restore` function.
15///
16/// If this function panics, the attempt to re-spawm the behavior module is aborted, and the
17/// initial error that caused the behavior module panic is reported to the user.
18///
19/// For persisting singular behavior instances, prefer to use the `ark_behavior_instance_persist`
20/// function instead.
21///
22/// This uses Ark's return slice mechanism to store the persisted vector of raw bytes.
23pub type BehaviorPersistFn = fn();
24
25/// `ark_behavior_restore` - Restores the whole dynamic state of a behavior module
26///
27/// This will be passed the state created by `ark_behavior_persist`, so as to restore the whole
28/// module's dynamic state. The same serialization format chosen in `ark_behavior_persist` must be
29/// used by this function.
30///
31/// If this function panics, the attempt to re-spawm the behavior module is aborted, and the
32/// initial error that caused the behavior module panic is reported to the user.
33pub type BehaviorRestoreFn = fn(state_ptr: u32, state_size: u32);
34
35/// `ark_behavior_instance_create` - Create a behavior instance
36///
37/// Create a behavior instance of the specific type with the provided serialized parameters.
38pub type BehaviorInstanceCreateFn = fn(local_type_id: u32, params_ptr: u32, params_len: u32) -> u64;
39
40/// `ark_behavior_instance_destroy` - Destroy a behavior instance
41///
42/// This frees the memory of the instance and the instance can no longer be accessed.
43pub type BehaviorInstanceDestroyFn = fn(instance_id: u64);
44
45/// `ark_behavior_instance_clone` - Clone a behavior instance to create a new identical instance
46pub type BehaviorInstanceCloneFn = fn(instance_id: u64) -> u64;
47
48/// `ark_behavior_instance_persist` - Persist a behavior instance by serializing it to a blob
49///
50/// Return the size of the serialized representation. The memory buffer itself is returned
51/// through the Ark return slice mechanism `ark::core::return_slice`.
52pub type BehaviorInstancePersistFn = fn(instance_id: u64);
53
54/// `ark_behavior_instance_restore` - Restore a behavior instance by deserializing it from a persistent representation
55///
56/// On success returns a behavior instance id.
57pub type BehaviorInstanceRestoreFn = fn(local_type_id: u32, blob_ptr: u32, blob_size: u32) -> u64;
58
59/// `ark_behavior_instance_handle_message` - Have the specified instance process the provided message
60///
61/// During the execution of this entry point, the behavior instance has access to the Behavior API.
62/// Through this API a behavior instance can get aspect data and write outgoing messages back to the owning controller module.
63pub type BehaviorInstanceHandleMessageFn =
64 fn(instance_id: u64, actor_id: u32, message_blob_ptr: u32, message_blob_size: u32);
65
66/// `ark_behavior_instances_handle_messages` - Process the provided messages
67///
68/// During the execution of this entry point, the behavior instance has access to the Behavior API.
69/// Through this API a behavior instance can get aspect data and write outgoing messages back to the owning controller module.
70pub type BehaviorInstancesHandleMessagesFn = fn(encoded_slice_ptr: u32, encoded_slice_len: u32);
71
72pub const BEHAVIOR_REGISTER: &str = "ark_behavior_register";
73pub const BEHAVIOR_PERSIST: &str = "ark_behavior_persist";
74pub const BEHAVIOR_RESTORE: &str = "ark_behavior_restore";
75pub const BEHAVIOR_INSTANCE_CREATE: &str = "ark_behavior_instance_create";
76pub const BEHAVIOR_INSTANCE_DESTROY: &str = "ark_behavior_instance_destroy";
77pub const BEHAVIOR_INSTANCE_CLONE: &str = "ark_behavior_instance_clone";
78pub const BEHAVIOR_INSTANCE_PERSIST: &str = "ark_behavior_instance_persist";
79pub const BEHAVIOR_INSTANCE_RESTORE: &str = "ark_behavior_instance_restore";
80pub const BEHAVIOR_INSTANCE_HANDLE_MESSAGE: &str = "ark_behavior_instance_handle_message";
81pub const BEHAVIOR_INSTANCES_HANDLE_MESSAGES: &str = "ark_behavior_instances_handle_messages";