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(
113 &self,
114 self_id: &ActrId,
115 caller_id: Option<&ActrId>,
116 request_id: &str,
117 credential: &AIdCredential,
118 ) -> RuntimeContext {
119 RuntimeContext::new(
120 self_id.clone(),
121 caller_id.cloned(),
122 request_id.to_string(),
123 self.inproc_gate.clone(), self.outproc_gate.clone(), self.data_stream_registry.clone(), self.media_frame_registry.clone(), self.signaling_client.clone(),
128 credential.clone(),
129 )
130 }
131
132 pub fn create_bootstrap(&self, self_id: &ActrId, credential: &AIdCredential) -> RuntimeContext {
138 RuntimeContext::new(
139 self_id.clone(),
140 None,
141 uuid::Uuid::new_v4().to_string(),
142 self.inproc_gate.clone(),
143 self.outproc_gate.clone(),
144 self.data_stream_registry.clone(),
145 self.media_frame_registry.clone(),
146 self.signaling_client.clone(),
147 credential.clone(),
148 )
149 }
150}