modkit/runtime/system_context.rs
1//! System Context - runtime internals exposed to system modules
2
3use std::sync::Arc;
4use uuid::Uuid;
5
6use crate::runtime::{GrpcInstallerStore, ModuleManager};
7
8/// System-level context provided to system modules during the wiring phase.
9///
10/// This gives system modules access to runtime internals like the module manager
11/// and gRPC installer store. Only modules with the "system" capability receive this.
12///
13/// Normal user modules do not see `SystemContext` - they only get `ModuleCtx` during init.
14pub struct SystemContext {
15 /// Process-level instance ID (shared by all modules in this process)
16 instance_id: Uuid,
17
18 /// Module instance registry and manager
19 pub module_manager: Arc<ModuleManager>,
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 module_manager: Arc<ModuleManager>,
30 grpc_installers: Arc<GrpcInstallerStore>,
31 ) -> Self {
32 Self {
33 instance_id,
34 module_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 modules
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}