Skip to content

Commit

Permalink
Fix Deactivation of TSP Toolkit (#74)
Browse files Browse the repository at this point in the history
- Change `kicList` member from `readonly` to `private` with accessor
- Add logging
- change `fetch*` methods to be `get` functions
- Update progress bar to use something the isn't 50% (it didn't look
like it was actually a progress bar
- Change terminal to be transient so it isn't recreated on VSCode
restart
  • Loading branch information
esarver authored Nov 19, 2024
1 parent e0cf4cf commit 54a253a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ const base_api = {
(x) => x.terminalPid == term_pid,
)

const connDetails = kicCell?.fetchConnDetials()
const connDetails = kicCell?.connDetails
kicCell?.sendTextToTerminal(".exit")
let found = false
await kicCell?.getTerminalState().then(
Expand Down
10 changes: 2 additions & 8 deletions src/instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,10 +1446,7 @@ export class InstrumentsExplorer {
//Use the existing terminal to reset
for (const kicCell of this._kicProcessMgr.kicList) {
if (inputNode != undefined) {
if (
inputNode.FetchConnectionAddr() ==
kicCell.fetchConnAddr()
) {
if (inputNode.FetchConnectionAddr() == kicCell.connAddr) {
kicCell.sendTextToTerminal(".reset\n")
}
}
Expand Down Expand Up @@ -1558,10 +1555,7 @@ export class InstrumentsExplorer {

for (const kicCell of this._kicProcessMgr.kicList) {
if (inputNode != undefined) {
if (
inputNode.FetchConnectionAddr() ==
kicCell.fetchConnAddr()
) {
if (inputNode.FetchConnectionAddr() == kicCell.connAddr) {
const fw_file = await vscode.window.showOpenDialog({
filters: {
"All files (*.*)": ["*"],
Expand Down
41 changes: 27 additions & 14 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class ConnectionDetails {
*/
export class KicProcessMgr {
//kicList holds the up to date instrument connections
readonly kicList = new Array<KicCell>()
private _kicList = new Array<KicCell>()
public debugTermPid: Thenable<number | undefined> | undefined
public doReconnect = false
private _reconnectInstrDetails: ConnectionDetails | undefined
Expand All @@ -210,12 +210,21 @@ export class KicProcessMgr {
}

async dispose(): Promise<void> {
const disposer: Array<Promise<void>> = new Array<Promise<void>>()
for (const k of this.kicList) {
disposer.push(k.dispose())
const LOGLOC = {
file: "resourceManager.ts",
func: "KicProcessMgr.dispose()",
}
Log.trace("Disposing KicProcessMgr...", LOGLOC)
for (const k of this._kicList) {
Log.trace(`Killing ${await k.terminalPid}: ${k.connAddr}`, LOGLOC)
await k.dispose()
}

await Promise.allSettled(disposer)
Log.trace("KicProcessMgr Disposed...", LOGLOC)
}

public get kicList(): Array<KicCell> {
return this.kicList
}

/**
Expand All @@ -240,15 +249,15 @@ export class KicProcessMgr {
}
Log.trace("Creating Kic Cell", LOGLOC)
const newCell = new KicCell()
const [info, verified_name] = await newCell.initialiseComponents(
const [info, verified_name] = await newCell.initializeComponents(
name,
unique_id,
connType,
maxerr,
filePath,
)
this.debugTermPid = newCell.terminalPid
this.kicList.push(newCell)
this._kicList.push(newCell)
this.doReconnect = true

return [info, verified_name]
Expand Down Expand Up @@ -313,7 +322,10 @@ export class KicCell extends EventEmitter {
}
const pid = await this._term?.processId
if (pid !== undefined) {
Log.debug(`Killing PID ${pid}`, LOGLOC)
Log.trace(
`Killing PID ${pid}, connection to ${this.connAddr}`,
LOGLOC,
)
process.kill(pid)
}
this._term?.dispose()
Expand Down Expand Up @@ -346,7 +358,7 @@ export class KicCell extends EventEmitter {
/**
* Used to create the components that establish communication with the instrument
* */
public async initialiseComponents(
public async initializeComponents(
name: string,
unique_id: string,
connType: string,
Expand All @@ -356,7 +368,7 @@ export class KicCell extends EventEmitter {
//#ToDo: need to verify if maxerr is required
const LOGLOC: SourceLocation = {
file: "resourceManager.ts",
func: `KicCell.initialiseComponents("${name}", "${unique_id}", "${connType}", "${maxerr ?? ""}", "${filePath ?? ""}")`,
func: `KicCell.initializeComponents("${name}", "${unique_id}", "${connType}", "${maxerr ?? ""}", "${filePath ?? ""}")`,
}
return await vscode.window.withProgress(
{
Expand Down Expand Up @@ -415,7 +427,7 @@ export class KicCell extends EventEmitter {
}

progress.report({
increment: 50,
increment: 37,
message: "Getting instrument information",
})
Log.trace("Getting instrument information", LOGLOC)
Expand Down Expand Up @@ -492,6 +504,7 @@ export class KicCell extends EventEmitter {
name: name,
shellPath: EXECUTABLE,
shellArgs: terminal_args,
isTransient: true, // Don't try to reinitialize the terminal when restarting vscode
iconPath: {
light: vscode.Uri.file(
join(
Expand Down Expand Up @@ -546,7 +559,7 @@ export class KicCell extends EventEmitter {
Log.trace(`Connected to ${info.trim()}`, LOGLOC)

progress.report({
increment: 40,
increment: 53,
message: `Connected to instrument with model ${_info.model} and S/N ${_info.serial_number}`,
})
return new Promise((resolve) => resolve([info, verified_name]))
Expand All @@ -572,15 +585,15 @@ export class KicCell extends EventEmitter {
}, 0)
}

public fetchConnAddr(): string {
public get connAddr(): string {
return this._uniqueID
}

public sendTextToTerminal(input: string) {
this._term?.sendText(input)
}

public fetchConnDetials(): ConnectionDetails | undefined {
public get connDetails(): ConnectionDetails | undefined {
return this._connDetails
}
}
Expand Down

0 comments on commit 54a253a

Please sign in to comment.