actr_runtime/
context_factory.rs1use crate::context::RuntimeContext;
6use crate::inbound::{DataStreamRegistry, MediaFrameRegistry};
7use crate::outbound::OutGate;
8use crate::transport::InprocTransportManager;
9use crate::wire::webrtc::SignalingClient;
10use actr_protocol::{AIdCredential, ActrId};
11use std::sync::Arc;
12
13#[derive(Clone)]
21pub struct ContextFactory {
22 pub(crate) inproc_gate: OutGate,
24
25 pub(crate) outproc_gate: Option<OutGate>,
27
28 pub(crate) shell_to_workload: Arc<InprocTransportManager>,
30
31 pub(crate) workload_to_shell: Arc<InprocTransportManager>,
33
34 pub(crate) data_stream_registry: Arc<DataStreamRegistry>,
36
37 pub(crate) media_frame_registry: Arc<MediaFrameRegistry>,
39
40 pub(crate) signaling_client: Arc<dyn SignalingClient>,
42}
43
44impl ContextFactory {
45 pub fn new(
63 inproc_gate: OutGate,
64 shell_to_workload: Arc<InprocTransportManager>,
65 workload_to_shell: Arc<InprocTransportManager>,
66 data_stream_registry: Arc<DataStreamRegistry>,
67 media_frame_registry: Arc<MediaFrameRegistry>,
68 signaling_client: Arc<dyn SignalingClient>,
69 ) -> Self {
70 Self {
71 inproc_gate,
72 outproc_gate: None, shell_to_workload,
74 workload_to_shell,
75 data_stream_registry,
76 media_frame_registry,
77 signaling_client,
78 }
79 }
80
81 pub fn set_outproc_gate(&mut self, gate: OutGate) {
87 tracing::debug!("🔄 Setting outproc OutGate in ContextFactory");
88 self.outproc_gate = Some(gate);
89 }
90
91 pub fn shell_to_workload(&self) -> Arc<InprocTransportManager> {
93 self.shell_to_workload.clone()
94 }
95
96 pub fn workload_to_shell(&self) -> Arc<InprocTransportManager> {
98 self.workload_to_shell.clone()
99 }
100
101 pub fn create(
114 &self,
115 self_id: &ActrId,
116 caller_id: Option<&ActrId>,
117 trace_id: &str,
118 request_id: &str,
119 credential: &AIdCredential,
120 ) -> RuntimeContext {
121 RuntimeContext::new(
122 self_id.clone(),
123 caller_id.cloned(),
124 trace_id.to_string(),
125 request_id.to_string(),
126 self.inproc_gate.clone(), self.outproc_gate.clone(), self.data_stream_registry.clone(), self.media_frame_registry.clone(), self.signaling_client.clone(),
131 credential.clone(),
132 )
133 }
134
135 pub fn create_bootstrap(&self, self_id: &ActrId, credential: &AIdCredential) -> RuntimeContext {
141 RuntimeContext::new(
142 self_id.clone(),
143 None,
144 uuid::Uuid::new_v4().to_string(),
145 uuid::Uuid::new_v4().to_string(),
146 self.inproc_gate.clone(),
147 self.outproc_gate.clone(),
148 self.data_stream_registry.clone(),
149 self.media_frame_registry.clone(),
150 self.signaling_client.clone(),
151 credential.clone(),
152 )
153 }
154}