1
- // Copyright (c) International Business Machines Corp. 2017
2
- // All Rights Reserved
3
-
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5
- // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6
- // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
-
8
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
-
10
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
13
- // IN THE SOFTWARE.
14
-
15
- const xt = require ( './itoolkit' ) ;
16
- const timeoutMsg = "Timeout!" ;
17
- const retryInterval = 100 ; // wait 0.1 second to retry to get result in sync mode.
18
- let retryTimes = Math . round ( xt . timeout / retryInterval ) ;
19
-
20
- class iDataQueue {
21
- constructor ( conn ) {
22
- this . conn = conn ; //Pass in the connection object.
23
- this . errno = [
24
- [ 0 , "10i0" ] ,
25
- [ 0 , "10i0" , { "setlen" :"rec2" } ] ,
26
- [ "" , "7A" ] ,
27
- [ "" , "1A" ]
28
- ] ;
29
- }
30
-
31
- sendToDataQueue ( name , lib , data , cb ) {
32
- let pgm = new xt . iPgm ( "QSNDDTAQ" , { "lib" :"QSYS" } ) ;
33
- pgm . addParam ( name , "10A" ) ;
34
- pgm . addParam ( lib == "" ?"*CURLIB" :lib , "10A" ) ;
35
- pgm . addParam ( data . length , "5p0" ) ;
36
- pgm . addParam ( data , data . length + "A" ) ;
37
-
38
- this . conn . add ( pgm . toXML ( ) ) ;
39
- let async = cb && xt . getClass ( cb ) == "Function" ; //If there is a callback function param, then it is in asynchronized mode.
40
- let rtValue ; // The returned value.
41
- let stop = 0 ; // A flag indicating whether the process is finished.
42
- let retry = 0 ; // How many times we have retried.
43
- const toJson = ( str ) => { // Convert the XML output into JSON
44
- let output = xt . xmlToJson ( str ) ;
45
- if ( output [ 0 ] . hasOwnProperty ( "success" ) && output [ 0 ] . success == true )
46
- rtValue = true ;
47
- else
48
- rtValue = str ;
49
- if ( async ) // If it is in asynchronized mode.
50
- cb ( rtValue ) ; // Run the call back function against the returned value.
51
- stop = 1 ;
52
- }
53
- const waitForResult = ( ) => {
54
- retry ++ ;
55
- if ( stop == 0 )
56
- setTimeout ( waitForResult , retryInterval ) ; // Check whether the result is retrieved
57
- else if ( retry >= retryTimes )
58
- return timeoutMsg ;
59
- else
60
- return rtValue ;
61
- }
62
- this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
63
- if ( ! async ) // If it is in synchronized mode.
64
- return waitForResult ( ) ; // Run the user defined call back function against the returned value.
65
- }
66
-
67
- receiveFromDataQueue ( name , lib , length , cb ) {
68
- let pgm = new xt . iPgm ( "QRCVDTAQ" , { "lib" :"QSYS" } ) ;
69
- pgm . addParam ( name , "10A" ) ;
70
- pgm . addParam ( lib == "" ?"*CURLIB" :lib , "10A" ) ;
71
- pgm . addParam ( length , "5p0" ) ;
72
- pgm . addParam ( "" , length + 1 + "A" ) ;
73
- pgm . addParam ( 0 , "5p0" ) ;
74
-
75
- this . conn . add ( pgm . toXML ( ) ) ;
76
- let async = cb && xt . getClass ( cb ) == "Function" ; //If there is a callback function param, then it is in asynchronized mode.
77
- let rtValue ; // The returned value.
78
- let stop = 0 ; // A flag indicating whether the process is finished.
79
- let retry = 0 ; // How many times we have retried.
80
- const toJson = ( str ) => { // Convert the XML output into JSON
81
- let output = xt . xmlToJson ( str ) ;
82
- if ( output [ 0 ] . hasOwnProperty ( "success" ) && output [ 0 ] . success == true )
83
- rtValue = output [ 0 ] . data [ 3 ] . value ;
84
- else
85
- rtValue = str ;
86
- if ( async ) // If it is in asynchronized mode.
87
- cb ( rtValue ) ; // Run the call back function against the returned value.
88
- stop = 1 ;
89
- }
90
- const waitForResult = ( ) => {
91
- retry ++ ;
92
- if ( stop == 0 )
93
- setTimeout ( waitForResult , retryInterval ) ; // Check whether the result is retrieved
94
- else if ( retry >= retryTimes )
95
- return timeoutMsg ;
96
- else
97
- return rtValue ;
98
- }
99
- this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
100
- if ( ! async ) // If it is in synchronized mode.
101
- return waitForResult ( ) ; // Run the user defined call back function against the returned value.
102
- }
103
-
104
- clearDataQueue ( name , lib , cb ) {
105
- let pgm = new xt . iPgm ( "QCLRDTAQ" , { "lib" :"QSYS" } ) ;
106
- pgm . addParam ( name , "10A" ) ;
107
- pgm . addParam ( lib == "" ?"*CURLIB" :lib , "10A" ) ;
108
-
109
- this . conn . add ( pgm . toXML ( ) ) ;
110
- let async = cb && xt . getClass ( cb ) == "Function" ; //If there is a callback function param, then it is in asynchronized mode.
111
- let rtValue ; // The returned value.
112
- let stop = 0 ; // A flag indicating whether the process is finished.
113
- let retry = 0 ; // How many times we have retried.
114
- const toJson = ( str ) => { // Convert the XML output into JSON
115
- let output = xt . xmlToJson ( str ) ;
116
- if ( output [ 0 ] . hasOwnProperty ( "success" ) && output [ 0 ] . success == true )
117
- rtValue = true ;
118
- else
119
- rtValue = str ;
120
- if ( async ) // If it is in asynchronized mode.
121
- cb ( rtValue ) ; // Run the call back function against the returned value.
122
- stop = 1 ;
123
- }
124
- const waitForResult = ( ) => {
125
- retry ++ ;
126
- if ( stop == 0 )
127
- setTimeout ( waitForResult , retryInterval ) ; // Check whether the result is retrieved
128
- else if ( retry >= retryTimes )
129
- return timeoutMsg ;
130
- else
131
- return rtValue ;
132
- }
133
- this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
134
- if ( ! async ) // If it is in synchronized mode.
135
- return waitForResult ( ) ; // Run the user defined call back function against the returned value.
136
- }
137
- }
138
-
139
- exports . iDataQueue = iDataQueue ;
1
+ // Copyright (c) International Business Machines Corp. 2019
2
+ // All Rights Reserved
3
+
4
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5
+ // associated documentation files (the "Software"), to deal in the Software without restriction,
6
+ // including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
+ // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+
10
+ // The above copyright notice and this permission notice shall be included in all copies or
11
+ // substantial portions of the Software.
12
+
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14
+ // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+ const xt = require ( './itoolkit' ) ;
20
+
21
+ const timeoutMsg = 'Timeout!' ;
22
+ const retryInterval = 100 ; // wait 0.1 second to retry to get result in sync mode.
23
+ const retryTimes = Math . round ( xt . timeout / retryInterval ) ;
24
+
25
+ class iDataQueue {
26
+ constructor ( conn ) {
27
+ this . conn = conn ; // Pass in the connection object.
28
+ this . errno = [
29
+ [ 0 , '10i0' ] ,
30
+ [ 0 , '10i0' , { setlen : 'rec2' } ] ,
31
+ [ '' , '7A' ] ,
32
+ [ '' , '1A' ] ,
33
+ ] ;
34
+ }
35
+
36
+ sendToDataQueue ( name , lib , data , cb ) {
37
+ const pgm = new xt . iPgm ( 'QSNDDTAQ' , { lib : 'QSYS' } ) ; // eslint-disable-line new-cap
38
+ pgm . addParam ( name , '10A' ) ;
39
+ pgm . addParam ( lib === '' ? '*CURLIB' : lib , '10A' ) ;
40
+ pgm . addParam ( data . length , '5p0' ) ;
41
+ pgm . addParam ( data , `${ data . length } A` ) ;
42
+
43
+ this . conn . add ( pgm . toXML ( ) ) ;
44
+ const async = cb && xt . getClass ( cb ) === 'Function' ; // If there is a callback function param, then it is in asynchronized mode.
45
+ let rtValue ; // The returned value.
46
+ let stop = 0 ; // A flag indicating whether the process is finished.
47
+ let retry = 0 ; // How many times we have retried.
48
+ const toJson = ( str ) => { // Convert the XML output into JSON
49
+ const output = xt . xmlToJson ( str ) ;
50
+ if ( Object . prototype . hasOwnProperty . call ( output [ 0 ] , 'success' ) && output [ 0 ] . success === true ) {
51
+ rtValue = true ;
52
+ } else {
53
+ rtValue = str ;
54
+ }
55
+ if ( async ) { // If it is in asynchronized mode.
56
+ cb ( rtValue ) ; // Run the call back function against the returned value.
57
+ }
58
+ stop = 1 ;
59
+ } ;
60
+
61
+ const waitForResult = ( ) => {
62
+ retry += 1 ;
63
+ if ( stop === 0 ) {
64
+ setTimeout ( waitForResult , retryInterval ) ;
65
+ return null ;
66
+ }
67
+ if ( retry >= retryTimes ) {
68
+ return timeoutMsg ;
69
+ }
70
+
71
+ return rtValue ;
72
+ } ;
73
+
74
+ this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
75
+ if ( ! async ) { // If it is in synchronized mode.
76
+ return waitForResult ( ) ;
77
+ } // Run the user defined call back function against the returned value.
78
+
79
+ return null ; // TODO: eslint consistent-return
80
+ }
81
+
82
+ receiveFromDataQueue ( name , lib , length , cb ) {
83
+ const pgm = new xt . iPgm ( 'QRCVDTAQ' , { lib : 'QSYS' } ) ; // eslint-disable-line new-cap
84
+ pgm . addParam ( name , '10A' ) ;
85
+ pgm . addParam ( lib === '' ? '*CURLIB' : lib , '10A' ) ;
86
+ pgm . addParam ( length , '5p0' ) ;
87
+ pgm . addParam ( '' , `${ length + 1 } A` ) ;
88
+ pgm . addParam ( 0 , '5p0' ) ;
89
+
90
+ this . conn . add ( pgm . toXML ( ) ) ;
91
+ const async = cb && xt . getClass ( cb ) === 'Function' ; // If there is a callback function param, then it is in asynchronized mode.
92
+ let rtValue ; // The returned value.
93
+ let stop = 0 ; // A flag indicating whether the process is finished.
94
+ let retry = 0 ; // How many times we have retried.
95
+ const toJson = ( str ) => { // Convert the XML output into JSON
96
+ const output = xt . xmlToJson ( str ) ;
97
+ if ( Object . prototype . hasOwnProperty . call ( output [ 0 ] , 'success' ) && output [ 0 ] . success === true ) {
98
+ rtValue = output [ 0 ] . data [ 3 ] . value ;
99
+ } else {
100
+ rtValue = str ;
101
+ }
102
+ if ( async ) { // If it is in asynchronized mode.
103
+ cb ( rtValue ) ; // Run the call back function against the returned value.
104
+ }
105
+ stop = 1 ;
106
+ } ;
107
+ const waitForResult = ( ) => {
108
+ retry += 1 ;
109
+ if ( stop === 0 ) {
110
+ setTimeout ( waitForResult , retryInterval ) ;
111
+ return null ;
112
+ }
113
+ if ( retry >= retryTimes ) {
114
+ return timeoutMsg ;
115
+ }
116
+
117
+ return rtValue ;
118
+ } ;
119
+ this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
120
+ if ( ! async ) { // If it is in synchronized mode.
121
+ return waitForResult ( ) ; // Run the user defined call back function against the returned value.
122
+ }
123
+
124
+ return null ; // TODO: eslint consistent-return
125
+ }
126
+
127
+ clearDataQueue ( name , lib , cb ) {
128
+ const pgm = new xt . iPgm ( 'QCLRDTAQ' , { lib : 'QSYS' } ) ; // eslint-disable-line new-cap
129
+ pgm . addParam ( name , '10A' ) ;
130
+ pgm . addParam ( lib === '' ? '*CURLIB' : lib , '10A' ) ;
131
+
132
+ this . conn . add ( pgm . toXML ( ) ) ;
133
+ const async = cb && xt . getClass ( cb ) === 'Function' ; // If there is a callback function param, then it is in asynchronized mode.
134
+ let rtValue ; // The returned value.
135
+ let stop = 0 ; // A flag indicating whether the process is finished.
136
+ let retry = 0 ; // How many times we have retried.
137
+ const toJson = ( str ) => { // Convert the XML output into JSON
138
+ const output = xt . xmlToJson ( str ) ;
139
+
140
+ if ( Object . prototype . hasOwnProperty . call ( output [ 0 ] , 'success' ) && output [ 0 ] . success === true ) {
141
+ rtValue = true ;
142
+ } else {
143
+ rtValue = str ;
144
+ }
145
+
146
+ if ( async ) { // If it is in asynchronized mode.
147
+ cb ( rtValue ) ;
148
+ } // Run the call back function against the returned value.
149
+ stop = 1 ;
150
+ } ;
151
+ const waitForResult = ( ) => {
152
+ retry += 1 ;
153
+ if ( stop === 0 ) {
154
+ setTimeout ( waitForResult , retryInterval ) ;
155
+ return null ;
156
+ }
157
+ if ( retry >= retryTimes ) {
158
+ return timeoutMsg ;
159
+ }
160
+
161
+ return rtValue ;
162
+ } ;
163
+ this . conn . run ( toJson , ! async ) ; // Post the input XML and get the response.
164
+ if ( ! async ) { // If it is in synchronized mode.
165
+ return waitForResult ( ) ; // Run the user defined call back function against the returned value.
166
+ }
167
+
168
+ return null ; // TODO: eslint consistent-return
169
+ }
170
+ }
171
+
172
+ exports . iDataQueue = iDataQueue ;
0 commit comments