1use aios_spec::traits::ActionExecutor;
9use aios_spec::traits::ActionResult;
10use aios_spec::ActionType;
11use aios_spec::AuthorizedAction;
12use std::time::Instant;
13
14pub struct DefaultActionExecutor;
24
25impl ActionExecutor for DefaultActionExecutor {
26 fn execute(&self, authorized: &AuthorizedAction) -> ActionResult {
27 let start = Instant::now();
28 let action = &authorized.action;
29 let action_name = format!("{:?}", action.action_type);
30
31 let (success, error) = match action.action_type {
32 ActionType::PreWarmProcess => {
33 if let Some(ref target) = action.target {
34 tracing::info!(
35 target = %target,
36 urgency = ?action.urgency,
37 "PreWarmProcess: stub (zygote fork not yet implemented)"
38 );
39 (true, None)
40 } else {
41 (false, Some("PreWarmProcess requires a target app".into()))
42 }
43 },
44 ActionType::PrefetchFile => {
45 tracing::info!(
46 target = ?action.target,
47 urgency = ?action.urgency,
48 "PrefetchFile: stub (posix_fadvise not yet implemented)"
49 );
50 (true, None)
51 },
52 ActionType::KeepAlive => {
53 if let Some(ref target) = action.target {
54 tracing::info!(
55 target = %target,
56 urgency = ?action.urgency,
57 "KeepAlive: stub (oom_score_adj write not yet implemented)"
58 );
59 (true, None)
60 } else {
61 tracing::info!("KeepAlive: no target specified, skipping");
62 (true, None)
63 }
64 },
65 ActionType::ReleaseMemory => {
66 tracing::info!(
67 target = ?action.target,
68 urgency = ?action.urgency,
69 "ReleaseMemory: stub (/proc/pid/reclaim not yet implemented)"
70 );
71 (true, None)
72 },
73 ActionType::NoOp => {
74 tracing::debug!("NoOp executed");
75 (true, None)
76 },
77 };
78
79 ActionResult {
80 action_type: action_name,
81 target: action.target.clone(),
82 success,
83 error,
84 latency_us: start.elapsed().as_micros() as u64,
85 }
86 }
87}
88
89impl Default for DefaultActionExecutor {
90 fn default() -> Self {
91 Self
92 }
93}