Skip to main content

%Atelier.v7.TerminalAgent

Class %Atelier.v7.TerminalAgent Extends %CSP.WebSocket

This class serves as an agent for terminal I/O.

Parameters

SECURITYRESOURCE

Parameter SECURITYRESOURCE = "%Development";

Require development resource

DEBUGTARGET

Parameter DEBUGTARGET [ Internal ] = "ChildProcess";

The method name of "debug target" that we launch for the child process

ENABLEINTERRUPTEXPR

Parameter ENABLEINTERRUPTEXPR [ Internal ] = "$SYSTEM.Util.SetInterruptEnable(1)";

Expression to enable external interrupts for the current process

TIMEOUT

Parameter TIMEOUT [ Internal ] = 0.02;

InitState

Parameter InitState [ Internal ] = 0;

The terminal is waiting for the configuration message from the client

PromptState

Parameter PromptState [ Internal ] = 1;

The terminal is waiting for command input from the user

ReadState

Parameter ReadState [ Internal ] = 2;

The terminal is waiting for READ input from the user

ExecuteState

Parameter ExecuteState [ Internal ] = 3;

The terminal is executing user's input

Properties

Trace

Property Trace As %Boolean [ InitialExpression = {$GET(^IRIS.Temp.Atelier("terminal")) > 0} ];

This holds the TRACE flag

TraceNode

Property TraceNode As %Integer [ Internal ];

This holds the TRACE global node for this session

DeviceList

Property DeviceList As %List [ Internal ];

This holds the device list for $SYSTEM.Socket.Select

WebSocketDevice

Property WebSocketDevice As %String [ Internal ];

This holds the WebSocket device

State

Property State As %String [ InitialExpression = {..#InitState}, Internal ];

The state the the terminal is in

Debug

Property Debug As %Debugger.System [ Internal ];

This holds the debugger instance. We use the debugger to control the child process.

EnableInterruptBeforePrompt

Property EnableInterruptBeforePrompt As %Boolean [ InitialExpression = 0, Internal ];

If true, enable before sending the prompt message

RawMode

Property RawMode As %Boolean [ InitialExpression = 0, Internal ];

If true, ANSI escape codes will not be included in any text sent to the client

ChildProcessDKey

Property ChildProcessDKey As %String [ Internal ];

The last value of $KEY set by a child process READ.

SyntaxColor

Property SyntaxColor As %SyntaxColor [ Internal ];

The %SyntaxColor instance used to color prompt input

ChildProcessPrincipalDevice

Property ChildProcessPrincipalDevice As %String [ Internal ];

The value of $PRINCIPAL for the child process.

Methods

InitTrace

Method InitTrace() [ Internal, Private ]

Intialize the trace (if requested)

TraceMsg

Method TraceMsg(pMsg As %String) [ Internal, Private ]

Log a trace if tracing enabled

TerminalPrompt

ClassMethod TerminalPrompt(pRawMode As %Boolean = 0) As %String [ Internal ]

Create the terminal prompt string. This method is called in the child process.

ReadFromWebSocket

Method ReadFromWebSocket(Output pUserMsg As %DynamicObject) As %Status [ Internal, Private ]

Read data from the WebSocket device and convert it to a %DynamicObject

ReadFromDebugDev

Method ReadFromDebugDev(Output pOutput As %String) As %Status [ Internal, Private ]

Read output from the child process

InterruptChildProcess

Method InterruptChildProcess() As %Status [ Internal, Private ]

Send an to the child process

SendMessageToWebSocket

Method SendMessageToWebSocket(pMsg As %DynamicObject) As %Status [ Internal, Private ]

Send the JSON message to the WebSocket

SendPromptToWebSocket

Method SendPromptToWebSocket() As %Status [ Internal, Private ]

Send the terminal prompt message to the WebSocket

SendOutputToWebSocket

Method SendOutputToWebSocket(pOutput As %String) As %Status [ CodeMode = expression, Internal, Private ]

Send the child process's output to the WebSocket

SendReadToWebSocket

Method SendReadToWebSocket() As %Status [ CodeMode = expression, Internal, Private ]

Send the read message to the WebSocket. No text is needed since it should already have been sent.

SanitizePromptInput

Method SanitizePromptInput(pInput As %String) As %String [ CodeMode = expression, Internal, Private ]

Sanitize user input in response to a prompt

SyntaxCheckInput

Method SyntaxCheckInput(pInput As %String) As %String [ Internal, Private ]

Check if user input is valid INT syntax. If not, return the error output that should be sent to the user.

SyntaxColorInput

Method SyntaxColorInput(pInput As %String, Output pOutput As %String) As %Status

Returns pInput with ANSI escape codes that color the text

OnPreServer

Method OnPreServer() As %Status

Event handler for the PreServer event: this is invoked before starting the WebSockets Server.

OnPostServer

Method OnPostServer() As %Status

Event handler for the PostServer event: this is invoked after closing the WebSockets Server.

Server

Method Server() As %Status

The WebSocket Server. Use the Read and Write methods to receive data from, and send data to, the client. Call the EndServer method to gracefully terminate the WebSocket Server.

ChildProcess

ClassMethod ChildProcess() [ Internal ]

Dummy method to use as the "debug target" in the child process.

ExceptionHandler

ClassMethod ExceptionHandler(pEx As %Exception.AbstractException, pRawMode As %Boolean = 0) As %String [ Internal ]

Helper method used for processing exceptions caused by user input