Skip to main content

memscope_rs/metadata/
engine.rs

1//! Metadata Engine - Centralized metadata management
2//!
3//! This module provides the MetadataEngine which is responsible for
4//! managing all metadata including variables, scopes, threads, types,
5//! and pointers across the memscope system.
6
7use crate::metadata::registry::VariableRegistry;
8use crate::metadata::scope::ScopeTracker;
9use crate::metadata::thread::ThreadRegistry;
10use std::sync::Arc;
11
12/// Metadata Engine - Centralized metadata management
13///
14/// The MetadataEngine is responsible for managing all metadata in the
15/// system including variables, scopes, threads, types, and pointers.
16/// It provides a unified interface for accessing and updating metadata.
17///
18/// Key properties:
19/// - Centralized: Single source of truth for all metadata
20/// - Thread-safe: All operations are thread-safe via Arc
21/// - Efficient: Optimized for fast lookups and updates
22pub struct MetadataEngine {
23    /// Variable registry
24    pub variable_registry: Arc<VariableRegistry>,
25    /// Scope tracker
26    pub scope_tracker: Arc<ScopeTracker>,
27    /// Thread registry
28    pub thread_registry: Arc<ThreadRegistry>,
29}
30
31impl MetadataEngine {
32    /// Create a new MetadataEngine
33    pub fn new() -> Self {
34        Self {
35            variable_registry: Arc::new(VariableRegistry::new()),
36            scope_tracker: Arc::new(ScopeTracker::new()),
37            thread_registry: Arc::new(ThreadRegistry::new()),
38        }
39    }
40
41    /// Get the variable registry
42    pub fn variables(&self) -> &Arc<VariableRegistry> {
43        &self.variable_registry
44    }
45
46    /// Get the scope tracker
47    pub fn scopes(&self) -> &Arc<ScopeTracker> {
48        &self.scope_tracker
49    }
50
51    /// Get the thread registry
52    pub fn threads(&self) -> &Arc<ThreadRegistry> {
53        &self.thread_registry
54    }
55}
56
57impl Default for MetadataEngine {
58    fn default() -> Self {
59        Self::new()
60    }
61}
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_metadata_engine_creation() {
69        let engine = MetadataEngine::new();
70        assert!(Arc::strong_count(&engine.variable_registry) >= 1);
71        assert!(Arc::strong_count(&engine.scope_tracker) >= 1);
72        assert!(Arc::strong_count(&engine.thread_registry) >= 1);
73    }
74
75    #[test]
76    fn test_metadata_engine_default() {
77        let engine = MetadataEngine::default();
78        assert!(Arc::strong_count(&engine.variable_registry) >= 1);
79    }
80}