Skip to content

Commit 6606896

Browse files
Startup routine support
1 parent eb9638c commit 6606896

6 files changed

Lines changed: 55 additions & 24 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"printableName": "Cache Web Terminal",
66
"description": "Web-based terminal emulator for Caché administering.",
77
"author": "ZitRo",
8-
"version": "4.0.0-beta.6",
8+
"version": "4.0.0-beta.7",
99
"gaID": "UA-83005064-2",
1010
"releaseNumber": 26,
1111
"scripts": {

src/client/js/localization/dictionary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,9 @@ export default {
330330
"jsErr": {
331331
en: "JavaScript error occurred: %s",
332332
ru: "Произошла ошибка JavaScript: %s"
333+
},
334+
"wsNormalClose": {
335+
en: "Session ended.",
336+
ru: "Сессия закончена."
333337
}
334338
};

src/client/js/server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function reconnect () {
7878

7979
function onClose (e) {
8080
CONNECTED = false;
81-
if (e.code !== 1000) {
81+
if (e.code !== 1000 && e.code !== 1005) {
8282
printLine(`\r\n${ localize(`wsConnLost`, e.code, e.reason ? " " + e.reason : "") }`);
8383
printLine(localize(`reConn`, RECONNECT_IN / 1000));
8484
reconnectTimeout = setTimeout(reconnect, RECONNECT_IN);

src/cls/WebTerminal/Core.cls

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,35 @@ ClassMethod WaitCommand() As %String [ ProcedureBlock = 1 ]
6969
}
7070

7171
/// Starts new terminal loop. Must be called with JOB command.
72-
ClassMethod Loop() As %Status
72+
ClassMethod Loop(StartupRoutine As %String = "") As %Status
7373
{
7474
if ($ZPARENT = 0) {
75-
write "This method is for JOB use only."
76-
return 0
77-
}
78-
open "terminal"::"^%X364"
79-
use $io::"^" _ $ZName
80-
kill // kill any temporary variables ProcedureBlock may have
81-
for {
82-
do ##class(%Device).ReDirectIO($$$YES)
83-
set $ZERROR = ""
84-
try { xecute ..WaitCommand() } catch {}
85-
do ##class(%Device).ReDirectIO($$$NO)
86-
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, $ZERROR))
87-
}
88-
quit $$$OK
75+
write "This method is for JOB use only."
76+
return 0
77+
}
78+
open "terminal"::"^%X364"
79+
use $io::"^" _ $ZName
80+
if (StartupRoutine '= "") {
81+
do ##class(%Device).ReDirectIO($$$YES)
82+
try {
83+
do @StartupRoutine
84+
do ##class(%Device).ReDirectIO($$$NO)
85+
} catch {
86+
do ##class(%Device).ReDirectIO($$$NO)
87+
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, $ZERROR))
88+
}
89+
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, ""))
90+
return $$$OK
91+
}
92+
kill // kill any temporary variables ProcedureBlock may have
93+
for {
94+
do ##class(%Device).ReDirectIO($$$YES)
95+
set $ZERROR = ""
96+
try { xecute ..WaitCommand() } catch {}
97+
do ##class(%Device).ReDirectIO($$$NO)
98+
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, $ZERROR))
99+
}
100+
return $$$OK
89101
}
90102

91103
}

src/cls/WebTerminal/Engine.cls

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Property corePID As %Numeric [ InitialExpression = 0 ];
1818
/// The last known namespace in child process.
1919
Property childNamespace As %String;
2020

21+
Property StartupRoutine As %String;
22+
2123
/// Output flag
2224
Property echo As %Boolean [ InitialExpression = 1 ];
2325

@@ -117,6 +119,10 @@ Method RequireAuthorization() As %List
117119
do ##class(Security.Users).Get(username, .userProps)
118120
znspace ns
119121

122+
if ($get(userProps("Routine")) '= "") {
123+
set ..StartupRoutine = userProps("Routine")
124+
}
125+
120126
if $get(userProps("Enabled")) '= 1 {
121127
return $LB("User " _ username _ " is not enabled in the system")
122128
}
@@ -145,14 +151,20 @@ Method ProcessRequest(handler As %String, data) As %Status [ Private ]
145151
/// Main method for every new client.
146152
Method ClientLoop() As %Status [ Private ]
147153
{
148-
job ##class(WebTerminal.Core).Loop():($NAMESPACE)
154+
job ##class(WebTerminal.Core).Loop(..StartupRoutine):($NAMESPACE)
149155
if ($TEST '= 1) {
150156
do ..Send("error", "%noJob")
151157
return $$$NOTOK
152158
}
153159
set ..corePID = $ZCHILD
154160
set ..childNamespace = $NAMESPACE
155-
do ..Send("prompt", ..childNamespace)
161+
if (..StartupRoutine = "") {
162+
do ..Send("prompt", ..childNamespace)
163+
} else {
164+
set message = ##class(%ZEN.proxyObject).%New()
165+
set status = $CLASSMETHOD("WebTerminal.Handlers", "Execute", $this, "", 1)
166+
goto loopEnd
167+
}
156168
//try { // temp
157169
for {
158170
set message = ..GetMessage()
@@ -171,7 +183,9 @@ Method ClientLoop() As %Status [ Private ]
171183
continue
172184
}
173185
}
186+
loopEnd
174187
//} catch (e) { do ..Send("o", $System.Status.GetErrorText(e)) } // temp
188+
return $$$OK
175189
}
176190

177191
/// This method sends basic login info to the user. Use this method to set client variables
@@ -203,12 +217,11 @@ Method Server() As %Status
203217
set ..CurrentNamespace = $Namespace
204218
do ..SendLoginInfo()
205219
do ..ClientLoop()
206-
do ..Send("oLocalized", "%wsAbnormal")
220+
do ..Send("oLocalized", "%wsNormalClose"_$C(13,10))
207221
} else {
208222
do ..Send("oLocalized", "%wsRefuse(" _ authMessage _ ")")
209-
do ..EndServer()
210223
}
211-
224+
do ..EndServer()
212225
quit $$$OK
213226
}
214227

src/cls/WebTerminal/Handlers.cls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Class WebTerminal.Handlers
1111

1212
/// data can be either string or %ZEN.proxyObject. In case of proxyObject, the command is hold in
1313
/// data.command property, and it may have some other control properties.
14-
ClassMethod Execute (client As WebTerminal.Engine, data) As %Status
14+
ClassMethod Execute (client As WebTerminal.Engine, data, bareStart As %Boolean = 0) As %Status
1515
{
16+
if (bareStart) goto loop
1617
if $IsObject(data) {
1718
set command = data.command
1819
if (data.echo = 0) {
@@ -23,6 +24,7 @@ ClassMethod Execute (client As WebTerminal.Engine, data) As %Status
2324
}
2425
do client.Send("o", $CHAR(13, 10))
2526
do client.SendChunk(client.corePID, "m", command)
27+
loop
2628
for {
2729
set message = client.ReceiveChunk()
2830
set flag = $LISTGET(message, 1)
@@ -57,7 +59,7 @@ ClassMethod Execute (client As WebTerminal.Engine, data) As %Status
5759
set client.echo = 1
5860
}
5961
}
60-
do:('($IsObject(data) && (data.prompt = 0))) client.Send("prompt", client.childNamespace)
62+
do:('($IsObject(data) && (data.prompt = 0)) && '(bareStart = 1)) client.Send("prompt", client.childNamespace)
6163
return $$$OK
6264
}
6365

0 commit comments

Comments
 (0)