Skip to main content

toolkit/runtime/
system_context.rs

1//! System Context - runtime internals exposed to system gears
2
3use std::sync::Arc;
4use uuid::Uuid;
5
6use crate::runtime::{GearManager, GrpcInstallerStore};
7
8/// System-level context provided to system gears during the wiring phase.
9///
10/// This gives system gears access to runtime internals like the gear manager
11/// and gRPC installer store. Only gears with the "system" capability receive this.
12///
13/// Normal user gears do not see `SystemContext` - they only get `GearCtx` during init.
14pub struct SystemContext {
15    /// Process-level instance ID (shared by all gears in this process)
16    instance_id: Uuid,
17
18    /// Gear instance registry and manager
19    pub gear_manager: Arc<GearManager>,
20
21    /// gRPC service installer store
22    pub grpc_installers: Arc<GrpcInstallerStore>,
23}
24
25impl SystemContext {
26    /// Create a new system context from runtime components
27    pub fn new(
28        instance_id: Uuid,
29        gear_manager: Arc<GearManager>,
30        grpc_installers: Arc<GrpcInstallerStore>,
31    ) -> Self {
32        Self {
33            instance_id,
34            gear_manager,
35            grpc_installers,
36        }
37    }
38
39    /// Returns the process-level instance ID.
40    ///
41    /// This is a unique identifier for this process instance, shared by all gears
42    /// in the same process. It is generated once at bootstrap.
43    #[inline]
44    #[must_use]
45    pub fn instance_id(&self) -> Uuid {
46        self.instance_id
47    }
48}