Skip to content

Commit 48d999f

Browse files
Renaming Controller as Main (#748)
* refactoring private variables location in controller class * removing extra layer of componentViewer main and changing controller name to main * updating tests and files in accordance with new class names --------- Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent bf818df commit 48d999f

File tree

7 files changed

+186
-279
lines changed

7 files changed

+186
-279
lines changed

src/desktop/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const activate = async (context: vscode.ExtensionContext): Promise<void>
5757
// Live Watch view
5858
liveWatchTreeDataProvider.activate(gdbtargetDebugTracker);
5959
// Component Viewer
60-
await componentViewer.activate(gdbtargetDebugTracker);
60+
componentViewer.activate(gdbtargetDebugTracker);
6161

6262
logger.debug('Extension Pack activated');
6363
};

src/views/component-viewer/component-viewer-controller.ts

Lines changed: 0 additions & 185 deletions
This file was deleted.

src/views/component-viewer/component-viewer-main.ts

Lines changed: 161 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,171 @@
1515
*/
1616

1717
import * as vscode from 'vscode';
18-
import { ComponentViewerController } from './component-viewer-controller';
19-
import { GDBTargetDebugTracker } from '../../debug-session';
18+
import { GDBTargetDebugTracker, GDBTargetDebugSession, SessionStackItem } from '../../debug-session';
19+
import { ComponentViewerInstance } from './component-viewer-instance';
20+
import { URI } from 'vscode-uri';
21+
import { ComponentViewerTreeDataProvider } from './component-viewer-tree-view';
22+
2023

2124
export class ComponentViewer {
22-
private componentViewerController: ComponentViewerController;
25+
private activeSession: GDBTargetDebugSession | undefined;
26+
private instances: ComponentViewerInstance[] = [];
27+
private componentViewerTreeDataProvider: ComponentViewerTreeDataProvider | undefined;
28+
private _context: vscode.ExtensionContext;
29+
private _instanceUpdateCounter: number = 0;
30+
private _updateSemaphoreFlag: boolean = false;
31+
32+
public constructor(context: vscode.ExtensionContext) {
33+
this._context = context;
34+
}
35+
36+
public activate(tracker: GDBTargetDebugTracker): void {
37+
/* Create Tree Viewer */
38+
this.componentViewerTreeDataProvider = new ComponentViewerTreeDataProvider();
39+
const treeProviderDisposable = vscode.window.registerTreeDataProvider('cmsis-debugger.componentViewer', this.componentViewerTreeDataProvider);
40+
this._context.subscriptions.push(
41+
treeProviderDisposable);
42+
// Subscribe to debug tracker events to update active session
43+
this.subscribetoDebugTrackerEvents(this._context, tracker);
44+
}
45+
46+
protected async readScvdFiles(tracker: GDBTargetDebugTracker,session?: GDBTargetDebugSession): Promise<void> {
47+
if (!session) {
48+
return;
49+
}
50+
const cbuildRunReader = await session.getCbuildRun();
51+
if (!cbuildRunReader) {
52+
return;
53+
}
54+
// Get SCVD file paths from cbuild-run reader
55+
const scvdFilesPaths: string [] = cbuildRunReader.getScvdFilePaths();
56+
if (scvdFilesPaths.length === 0) {
57+
return undefined;
58+
}
59+
const cbuildRunInstances: ComponentViewerInstance[] = [];
60+
for (const scvdFilePath of scvdFilesPaths) {
61+
const instance = new ComponentViewerInstance();
62+
if (this.activeSession !== undefined) {
63+
await instance.readModel(URI.file(scvdFilePath), this.activeSession, tracker);
64+
cbuildRunInstances.push(instance);
65+
}
66+
}
67+
this.instances = cbuildRunInstances;
68+
}
69+
70+
private loadingCounter: number = 0;
71+
private async loadCbuildRunInstances(session: GDBTargetDebugSession, tracker: GDBTargetDebugTracker) : Promise<void> {
72+
this.loadingCounter++;
73+
console.log(`Loading SCVD files from cbuild-run, attempt #${this.loadingCounter}`);
74+
// Try to read SCVD files from cbuild-run file first
75+
await this.readScvdFiles(tracker, session);
76+
// Are there any SCVD files found in cbuild-run?
77+
if (this.instances.length > 0) {
78+
await this.updateInstances();
79+
return;
80+
}
81+
}
82+
83+
private subscribetoDebugTrackerEvents(context: vscode.ExtensionContext, tracker: GDBTargetDebugTracker): void {
84+
const onWillStopSessionDisposable = tracker.onWillStopSession(async (session) => {
85+
await this.handleOnWillStopSession(session);
86+
});
87+
const onConnectedDisposable = tracker.onConnected(async (session) => {
88+
await this.handleOnConnected(session, tracker);
89+
});
90+
const onDidChangeActiveStackItemDisposable = tracker.onDidChangeActiveStackItem(async (stackTraceItem) => {
91+
await this.handleOnDidChangeActiveStackItem(stackTraceItem);
92+
});
93+
const onDidChangeActiveDebugSessionDisposable = tracker.onDidChangeActiveDebugSession(async (session) => {
94+
await this.handleOnDidChangeActiveDebugSession(session);
95+
});
96+
const onStopped = tracker.onStopped(async (session) => {
97+
await this.handleOnStopped(session.session);
98+
});
99+
// clear all disposables on extension deactivation
100+
context.subscriptions.push(
101+
onWillStopSessionDisposable,
102+
onConnectedDisposable,
103+
onDidChangeActiveStackItemDisposable,
104+
onDidChangeActiveDebugSessionDisposable,
105+
onStopped
106+
);
107+
}
108+
109+
private async handleOnStopped(session: GDBTargetDebugSession): Promise<void> {
110+
// Clear active session if it is NOT the one being stopped
111+
if (this.activeSession?.session.id !== session.session.id) {
112+
this.activeSession = undefined;
113+
}
114+
// Update component viewer instance(s)
115+
await this.updateInstances();
116+
}
117+
118+
private async handleOnWillStopSession(session: GDBTargetDebugSession): Promise<void> {
119+
// Clear active session if it is the one being stopped
120+
if (this.activeSession?.session.id === session.session.id) {
121+
this.activeSession = undefined;
122+
}
123+
// Update component viewer instance(s)
124+
await this.updateInstances();
125+
}
126+
127+
private async handleOnConnected(session: GDBTargetDebugSession, tracker: GDBTargetDebugTracker): Promise<void> {
128+
// if new session is not the current active session, erase old instances and read the new ones
129+
if (this.activeSession?.session.id !== session.session.id) {
130+
this.instances = [];
131+
this.componentViewerTreeDataProvider?.deleteModels();
132+
}
133+
// Update debug session
134+
this.activeSession = session;
135+
// Load SCVD files from cbuild-run
136+
await this.loadCbuildRunInstances(session, tracker);
137+
// Subscribe to refresh events of the started session
138+
session.refreshTimer.onRefresh(async (refreshSession) => {
139+
if (this.activeSession?.session.id === refreshSession.session.id) {
140+
// Update component viewer instance(s)
141+
await this.updateInstances();
142+
}
143+
});
144+
}
145+
146+
private async handleOnDidChangeActiveStackItem(stackTraceItem: SessionStackItem): Promise<void> {
147+
if ((stackTraceItem.item as vscode.DebugStackFrame).frameId !== undefined) {
148+
// Update instance(s) with new stack frame info
149+
await this.updateInstances();
150+
}
151+
}
23152

24-
public constructor( context: vscode.ExtensionContext
25-
) {
26-
this.componentViewerController = new ComponentViewerController(context);
153+
private async handleOnDidChangeActiveDebugSession(session: GDBTargetDebugSession | undefined): Promise<void> {
154+
// Update debug session
155+
this.activeSession = session;
156+
// Update component viewer instance(s)
157+
await this.updateInstances();
27158
}
28159

29-
public activate(tracker: GDBTargetDebugTracker) {
30-
return this.componentViewerController.activate(tracker);
160+
private async updateInstances(): Promise<void> {
161+
if (this._updateSemaphoreFlag) {
162+
return;
163+
}
164+
this._updateSemaphoreFlag = true;
165+
this._instanceUpdateCounter = 0;
166+
if (!this.activeSession) {
167+
this.componentViewerTreeDataProvider?.deleteModels();
168+
this._updateSemaphoreFlag = false;
169+
return;
170+
}
171+
if (this.instances.length === 0) {
172+
this._updateSemaphoreFlag = false;
173+
return;
174+
}
175+
this.componentViewerTreeDataProvider?.resetModelCache();
176+
for (const instance of this.instances) {
177+
this._instanceUpdateCounter++;
178+
console.log(`Updating Component Viewer Instance #${this._instanceUpdateCounter}`);
179+
await instance.update();
180+
this.componentViewerTreeDataProvider?.addGuiOut(instance.getGuiTree());
181+
}
182+
this.componentViewerTreeDataProvider?.showModelData();
183+
this._updateSemaphoreFlag = false;
31184
}
32185
}

src/views/component-viewer/component-viewer-tree-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class ComponentViewerTreeDataProvider implements vscode.TreeDataProvider<
7474
this._objectOutRoots = [];
7575
}
7676

77-
public async addGuiOut(guiOut: ScvdGuiInterface[] | undefined) {
77+
public addGuiOut(guiOut: ScvdGuiInterface[] | undefined) {
7878
if (guiOut !== undefined) {
7979
guiOut.forEach(item => this._scvdModel.push(item));
8080
}

0 commit comments

Comments
 (0)