@@ -179,40 +179,79 @@ void RuntimeTarget::notifyDomainStateChanged(
179179 Domain domain,
180180 bool enabled,
181181 const RuntimeAgent& notifyingAgent) {
182- bool runtimeAndLogStatusBefore = false , runtimeAndLogStatusAfter = false ;
183- if (domain == Domain::Log || domain == Domain::Runtime) {
184- runtimeAndLogStatusBefore =
185- agentsByEnabledDomain_[Domain::Runtime]. contains (¬ifyingAgent) &&
186- agentsByEnabledDomain_[ Domain::Log]. contains (¬ifyingAgent);
187- }
188-
189- if (enabled) {
190- agentsByEnabledDomain_[domain]. insert (¬ifyingAgent );
191- } else {
192- agentsByEnabledDomain_[domain]. erase (¬ifyingAgent );
193- }
194- threadSafeDomainStatus_[domain] = !agentsByEnabledDomain_[domain]. empty ();
182+ auto [domainStateChangedLocally, domainStateChangedGlobally] =
183+ processDomainChange ( domain, enabled, notifyingAgent);
184+
185+ switch (domain) {
186+ case Domain::Log:
187+ case Domain::Runtime: {
188+ if (domain == Domain::Runtime) {
189+ if (domainStateChangedGlobally && enabled) {
190+ // installConsoleCreateTask( );
191+ } else if (domainStateChangedGlobally) {
192+ // stubConsoleCreateTask( );
193+ }
194+ }
195195
196- if (domain == Domain::Log || domain == Domain::Runtime) {
197- runtimeAndLogStatusAfter =
198- agentsByEnabledDomain_[Domain::Runtime].contains (¬ifyingAgent) &&
199- agentsByEnabledDomain_[Domain::Log].contains (¬ifyingAgent);
196+ auto otherDomain = domain == Domain::Log ? Domain::Runtime : Domain::Log;
197+ // There should be an agent that enables both Log and Runtime domains.
198+ if (!agentsByEnabledDomain_[otherDomain].contains (¬ifyingAgent)) {
199+ break ;
200+ }
200201
201- if (runtimeAndLogStatusBefore != runtimeAndLogStatusAfter) {
202- if (runtimeAndLogStatusAfter) {
202+ if (domainStateChangedGlobally && enabled) {
203+ assert (agentsWithRuntimeAndLogDomainsEnabled_ == 0 );
204+ emitDebuggerSessionCreated ();
205+ ++agentsWithRuntimeAndLogDomainsEnabled_;
206+ } else if (domainStateChangedGlobally) {
207+ assert (agentsWithRuntimeAndLogDomainsEnabled_ == 1 );
208+ emitDebuggerSessionDestroyed ();
209+ --agentsWithRuntimeAndLogDomainsEnabled_;
210+ } else if (domainStateChangedLocally && enabled) {
211+ // This is a case when given domain was already enabled by other Agent,
212+ // so global state didn't change.
203213 if (++agentsWithRuntimeAndLogDomainsEnabled_ == 1 ) {
204214 emitDebuggerSessionCreated ();
205215 }
206- } else {
207- assert (agentsWithRuntimeAndLogDomainsEnabled_ > 0 );
216+ } else if (domainStateChangedLocally) {
208217 if (--agentsWithRuntimeAndLogDomainsEnabled_ == 0 ) {
209218 emitDebuggerSessionDestroyed ();
210219 }
211220 }
221+
222+ break ;
223+ }
224+ case Domain::Network:
225+ break ;
226+ case Domain::kMaxValue : {
227+ throw std::logic_error (" Unexpected kMaxValue domain value provided" );
212228 }
213229 }
214230}
215231
232+ std::pair<bool , bool > RuntimeTarget::processDomainChange (
233+ Domain domain,
234+ bool enabled,
235+ const RuntimeAgent& notifyingAgent) {
236+ bool domainHadAgentsBefore = !agentsByEnabledDomain_[domain].empty ();
237+ bool domainHasBeenEnabledBefore =
238+ agentsByEnabledDomain_[domain].contains (¬ifyingAgent);
239+
240+ if (enabled) {
241+ agentsByEnabledDomain_[domain].insert (¬ifyingAgent);
242+ } else {
243+ agentsByEnabledDomain_[domain].erase (¬ifyingAgent);
244+ }
245+ threadSafeDomainStatus_[domain] = !agentsByEnabledDomain_[domain].empty ();
246+
247+ bool domainHasAgentsAfter = !agentsByEnabledDomain_[domain].empty ();
248+
249+ return {
250+ domainHasBeenEnabledBefore ^ enabled,
251+ domainHadAgentsBefore ^ domainHasAgentsAfter,
252+ };
253+ }
254+
216255bool RuntimeTarget::isDomainEnabled (Domain domain) const {
217256 return threadSafeDomainStatus_[domain];
218257}
0 commit comments