Mountain/ApplicationState/State/FeatureState/Debug/
DebugState.rs1use std::{
28 collections::HashMap,
29 sync::{Arc, Mutex as StandardMutex},
30};
31
32use crate::dev_log;
33
34#[derive(Clone, Debug)]
36pub struct DebugConfigurationProviderRegistration {
37 pub ProviderHandle:u32,
39 pub SideCarIdentifier:String,
41}
42
43#[derive(Clone, Debug)]
45pub struct DebugAdapterDescriptorFactoryRegistration {
46 pub FactoryHandle:u32,
48 pub SideCarIdentifier:String,
50}
51
52#[derive(Clone)]
54pub struct DebugState {
55 pub DebugConfigurationProviders:Arc<StandardMutex<HashMap<String, DebugConfigurationProviderRegistration>>>,
57 pub DebugAdapterDescriptorFactories:Arc<StandardMutex<HashMap<String, DebugAdapterDescriptorFactoryRegistration>>>,
59}
60
61impl Default for DebugState {
62 fn default() -> Self {
63 dev_log!("exthost", "[DebugState] Initializing default debug state...");
64
65 Self {
66 DebugConfigurationProviders:Arc::new(StandardMutex::new(HashMap::new())),
67 DebugAdapterDescriptorFactories:Arc::new(StandardMutex::new(HashMap::new())),
68 }
69 }
70}
71
72impl DebugState {
73 pub fn RegisterDebugConfigurationProvider(
75 &self,
76 debug_type:String,
77 provider_handle:u32,
78 sidecar_identifier:String,
79 ) -> Result<(), String> {
80 let mut guard = self
81 .DebugConfigurationProviders
82 .lock()
83 .map_err(|e| format!("Failed to lock debug configuration providers: {}", e))?;
84
85 guard.insert(
86 debug_type,
87 DebugConfigurationProviderRegistration {
88 ProviderHandle:provider_handle,
89 SideCarIdentifier:sidecar_identifier,
90 },
91 );
92
93 Ok(())
94 }
95
96 pub fn GetDebugConfigurationProvider(&self, debug_type:&str) -> Option<DebugConfigurationProviderRegistration> {
98 self.DebugConfigurationProviders
99 .lock()
100 .ok()
101 .and_then(|guard| guard.get(debug_type).cloned())
102 }
103
104 pub fn RegisterDebugAdapterDescriptorFactory(
106 &self,
107 debug_type:String,
108 factory_handle:u32,
109 sidecar_identifier:String,
110 ) -> Result<(), String> {
111 let mut guard = self
112 .DebugAdapterDescriptorFactories
113 .lock()
114 .map_err(|e| format!("Failed to lock debug adapter descriptor factories: {}", e))?;
115
116 guard.insert(
117 debug_type,
118 DebugAdapterDescriptorFactoryRegistration {
119 FactoryHandle:factory_handle,
120 SideCarIdentifier:sidecar_identifier,
121 },
122 );
123
124 Ok(())
125 }
126
127 pub fn GetDebugAdapterDescriptorFactory(
129 &self,
130 debug_type:&str,
131 ) -> Option<DebugAdapterDescriptorFactoryRegistration> {
132 self.DebugAdapterDescriptorFactories
133 .lock()
134 .ok()
135 .and_then(|guard| guard.get(debug_type).cloned())
136 }
137
138 pub fn GetAllDebugConfigurationProviders(&self) -> HashMap<String, DebugConfigurationProviderRegistration> {
140 self.DebugConfigurationProviders
141 .lock()
142 .ok()
143 .map(|guard| guard.clone())
144 .unwrap_or_default()
145 }
146
147 pub fn GetAllDebugAdapterDescriptorFactories(&self) -> HashMap<String, DebugAdapterDescriptorFactoryRegistration> {
149 self.DebugAdapterDescriptorFactories
150 .lock()
151 .ok()
152 .map(|guard| guard.clone())
153 .unwrap_or_default()
154 }
155}