Skip to content

Commit a8f31b0

Browse files
authored
Merge pull request #30 from markdirish/upstreambranch
Removing sync, continued linting, renaming classes
2 parents 73dd7aa + be5247c commit a8f31b0

12 files changed

+198
-763
lines changed

lib/programCaller.js renamed to lib/ProgramCall.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
const iXml = require('./ixml');
2020

21-
class ProgramCaller {
21+
module.exports = class ProgramCall {
2222
/**
23-
* @description creates a new ProgramCaller object
23+
* @description creates a new ProgramCall object
2424
* @constructor
2525
* @param {string} program
2626
* @param {object} [options]
@@ -100,6 +100,4 @@ class ProgramCaller {
100100
toXML() {
101101
return this.xml + iXml.iXmlNodePgmClose();
102102
}
103-
}
104-
105-
module.exports = ProgramCaller;
103+
};

lib/iconn.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class iConn {
135135
* @param {fuction} callback
136136
* @param {boolean} sync
137137
*/
138-
run(callback, sync) {
138+
run(callback) {
139139
// Build the XML document.
140140
let xml = iXml.iXmlNodeHead() + iXml.iXmlNodeScriptOpen();
141141
for (let i = 0; i < this.cmds.length; i += 1) { xml += this.cmds[i]; }
@@ -172,8 +172,7 @@ class iConn {
172172
this.conn.I_TRANSPORT_CTL,
173173
xml,
174174
this.conn.I_TRANSPORT_REST_XML_OUT_SIZE,
175-
this.I_DEBUG_VERBOSE,
176-
sync);
175+
this.I_DEBUG_VERBOSE);
177176
} else {
178177
callback(iXml.iXmlNodeHead() + iXml.iXmlNodeScriptOpen() + iXml.iXmlNodeError('***Transport error no data***') + iXml.iXmlNodeScriptClose());
179178
}

lib/idataq.js

+18-87
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1717
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818

19-
const xt = require('./itoolkit');
19+
const ProgramCall = require('./ProgramCall');
20+
const { xmlToJson } = require('./utils');
2021

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 {
22+
module.exports = class iDataQueue {
2623
constructor(conn) {
2724
this.conn = conn; // Pass in the connection object.
2825
this.errno = [
@@ -34,139 +31,73 @@ class iDataQueue {
3431
}
3532

3633
sendToDataQueue(name, lib, data, cb) {
37-
const pgm = new xt.iPgm('QSNDDTAQ', { lib: 'QSYS' }); // eslint-disable-line new-cap
34+
const pgm = new ProgramCall('QSNDDTAQ', { lib: 'QSYS' });
3835
pgm.addParam(name, '10A');
3936
pgm.addParam(lib === '' ? '*CURLIB' : lib, '10A');
4037
pgm.addParam(data.length, '5p0');
4138
pgm.addParam(data, `${data.length}A`);
4239

4340
this.conn.add(pgm.toXML());
44-
const async = cb && typeof cb === 'function'; // If there is a callback function param, then it is in asynchronized mode.
4541
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.
4842
const toJson = (str) => { // Convert the XML output into JSON
49-
const output = xt.xmlToJson(str);
43+
const output = xmlToJson(str);
5044
if (Object.prototype.hasOwnProperty.call(output[0], 'success') && output[0].success === true) {
5145
rtValue = true;
5246
} else {
5347
rtValue = str;
5448
}
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-
};
6049

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;
50+
cb(rtValue); // Run the call back function against the returned value.
7251
};
7352

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
53+
this.conn.run(toJson); // Post the input XML and get the response.
8054
}
8155

8256
receiveFromDataQueue(name, lib, length, cb) {
83-
const pgm = new xt.iPgm('QRCVDTAQ', { lib: 'QSYS' }); // eslint-disable-line new-cap
57+
const pgm = new ProgramCall('QRCVDTAQ', { lib: 'QSYS' });
8458
pgm.addParam(name, '10A');
8559
pgm.addParam(lib === '' ? '*CURLIB' : lib, '10A');
8660
pgm.addParam(length, '5p0');
8761
pgm.addParam('', `${length + 1}A`);
8862
pgm.addParam(0, '5p0');
8963

9064
this.conn.add(pgm.toXML());
91-
const async = cb && typeof cb === 'function'; // If there is a callback function param, then it is in asynchronized mode.
9265
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.
66+
9567
const toJson = (str) => { // Convert the XML output into JSON
96-
const output = xt.xmlToJson(str);
68+
const output = xmlToJson(str);
9769
if (Object.prototype.hasOwnProperty.call(output[0], 'success') && output[0].success === true) {
9870
rtValue = output[0].data[3].value;
9971
} else {
10072
rtValue = str;
10173
}
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-
}
11674

117-
return rtValue;
75+
cb(rtValue); // Run the call back function against the returned value.
11876
};
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-
}
12377

124-
return null; // TODO: eslint consistent-return
78+
this.conn.run(toJson); // Post the input XML and get the response.
12579
}
12680

12781
clearDataQueue(name, lib, cb) {
128-
const pgm = new xt.iPgm('QCLRDTAQ', { lib: 'QSYS' }); // eslint-disable-line new-cap
82+
const pgm = new ProgramCall('QCLRDTAQ', { lib: 'QSYS' });
12983
pgm.addParam(name, '10A');
13084
pgm.addParam(lib === '' ? '*CURLIB' : lib, '10A');
13185

13286
this.conn.add(pgm.toXML());
133-
const async = cb && typeof cb === 'function'; // If there is a callback function param, then it is in asynchronized mode.
13487
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.
88+
13789
const toJson = (str) => { // Convert the XML output into JSON
138-
const output = xt.xmlToJson(str);
90+
const output = xmlToJson(str);
13991

14092
if (Object.prototype.hasOwnProperty.call(output[0], 'success') && output[0].success === true) {
14193
rtValue = true;
14294
} else {
14395
rtValue = str;
14496
}
14597

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;
98+
cb(rtValue);
15099
};
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-
}
167100

168-
return null; // TODO: eslint consistent-return
101+
this.conn.run(toJson); // Post the input XML and get the response.
169102
}
170-
}
171-
172-
exports.iDataQueue = iDataQueue;
103+
};

lib/inetwork.js

+24-67
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@
1616
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1717
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818

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);
19+
const ProgramCall = require('./ProgramCall');
20+
const { xmlToJson } = require('./utils');
2421

2522
const IPToNum = (ip) => {
2623
const ipArray = ip.split('.');
27-
let num = Number(ipArray[0]) * 256 * 256 * 256 + Number(ipArray[1])
28-
* 256 * 256 + Number(ipArray[2]) * 256 + Number(ipArray[3]);
29-
num >>>= 0; // TODO: estlint no-bitwise
24+
let num = 0;
25+
26+
/* eslint-disable no-bitwise */
27+
num += parseInt(ipArray[0], 10) << 24;
28+
num += parseInt(ipArray[1], 10) << 16;
29+
num += parseInt(ipArray[2], 10) << 8;
30+
num += parseInt(ipArray[3], 10);
31+
num >>>= 0; // zero-fill right-shift, returns non-negative
32+
/* eslint-enable no-bitwise */
33+
3034
return num;
3135
};
3236

33-
class iNetwork {
37+
module.exports = class iNetwork {
3438
constructor(conn) {
3539
this.conn = conn; // Pass in the connection object.
3640
this.errno = [
@@ -77,19 +81,17 @@ class iNetwork {
7781
['', '256A'], // [31]Domain search list
7882
];
7983

80-
const pgm = new xt.iPgm('QTOCNETSTS', { lib: 'QSYS', func: 'QtocRtvTCPA' }); // eslint-disable-line new-cap
84+
const pgm = new ProgramCall('QTOCNETSTS', { lib: 'QSYS', func: 'QtocRtvTCPA' });
8185
pgm.addParam(outBuf, { io: 'out', len: 'rec1' });
8286
pgm.addParam(0, '10i0', { setlen: 'rec1' });
8387
pgm.addParam('TCPA0300', '8A');
8488
pgm.addParam(this.errno, { io: 'both', len: 'rec2' });
8589
this.conn.add(pgm.toXML());
8690

87-
const async = cb && typeof cb === 'function'; // If there is a callback function param, then it is in asynchronized mode.
8891
let rtValue; // The returned value.
89-
let stop = 0; // A flag indicating whether the process is finished.
90-
let retry = 0; // How many times we have retried.
92+
9193
const toJson = (str) => { // Convert the XML output into JSON
92-
const output = xt.xmlToJson(str);
94+
const output = xmlToJson(str);
9395
if (Object.prototype.hasOwnProperty.call(output[0], 'success') && output[0].success === true) {
9496
rtValue = {
9597
'TCP/IPv4_stack_status': output[0].data[2].value,
@@ -124,31 +126,10 @@ class iNetwork {
124126
Domain_search_list: output[0].data[31].value,
125127
};
126128
} else { rtValue = str; }
127-
if (async) { // If it is in asynchronized mode.
128-
cb(rtValue); // Run the call back function against the returned value.
129-
}
130-
stop = 1;
131-
};
132-
133-
const waitForResult = () => {
134-
retry += 1;
135-
if (stop === 0) {
136-
setTimeout(waitForResult, retryInterval);
137-
return null;
138-
}
139-
if (retry >= retryTimes) {
140-
return timeoutMsg;
141-
}
142-
143-
return rtValue;
129+
cb(rtValue); // Run the call back function against the returned value.
144130
};
145131

146-
this.conn.run(toJson, !async); // Post the input XML and get the response.
147-
if (!async) { // If it is in synchronized mode.
148-
return waitForResult(); // Run the user defined call back function against the returned value.
149-
}
150-
151-
return null; // TODO: eslint consistent-return
132+
this.conn.run(toJson); // Post the input XML and get the response.
152133
}
153134

154135
getNetInterfaceData(ipaddr, cb) {
@@ -220,20 +201,18 @@ class iNetwork {
220201
[1, '10i0'],
221202
[IPToNum(address), '10i0'],
222203
];
223-
const pgm = new xt.iPgm('QTOCNETSTS', { lib: 'QSYS', func: 'QtocRtvNetIfcDta' }); // eslint-disable-line new-cap
204+
const pgm = new ProgramCall('QTOCNETSTS', { lib: 'QSYS', func: 'QtocRtvNetIfcDta' });
224205
pgm.addParam(outBuf, { io: 'out', len: 'rec1' });
225206
pgm.addParam(0, '10i0', { setlen: 'rec1' });
226207
pgm.addParam('NIFD0100', '8A');
227208
pgm.addParam(request);
228209
pgm.addParam(this.errno, { io: 'both', len: 'rec2' });
229210
this.conn.add(pgm.toXML());
230211

231-
const async = cb && typeof cb === 'function'; // If there is a callback function param, then it is in asynchronized mode.
232212
let rtValue; // The returned value.
233-
let stop = 0; // A flag indicating whether the process is finished.
234-
let retry = 0; // How many times we have retried.
213+
235214
const toJson = (str) => { // Convert the XML output into JSON
236-
const output = xt.xmlToJson(str);
215+
const output = xmlToJson(str);
237216
if (Object.prototype.hasOwnProperty.call(output[0], 'success') && output[0].success === true) {
238217
rtValue = {
239218
Internet_address: output[0].data[2].value,
@@ -284,32 +263,10 @@ class iNetwork {
284263
Preferred_interface_Internet_address_binary: output[0].data[58].value,
285264
};
286265
} else { rtValue = str; }
287-
if (async) { // If it is in asynchronized mode.
288-
cb(rtValue); // Run the call back function against the returned value.
289-
}
290-
stop = 1;
291-
};
292-
293-
const waitForResult = () => {
294-
retry += 1;
295-
if (stop === 0) {
296-
setTimeout(waitForResult, retryInterval);
297-
return null;
298-
}
299-
if (retry >= retryTimes) {
300-
return timeoutMsg;
301-
}
302266

303-
return rtValue;
267+
cb(rtValue); // Run the call back function against the returned value.
304268
};
305269

306-
this.conn.run(toJson, !async); // Post the input XML and get the response.
307-
if (!async) { // If it is in synchronized mode.
308-
return waitForResult(); // Run the user defined call back function against the returned value.
309-
}
310-
311-
return null; // TODO: eslint consistent-return
270+
this.conn.run(toJson); // Post the input XML and get the response.
312271
}
313-
}
314-
315-
exports.iNetwork = iNetwork;
272+
};

0 commit comments

Comments
 (0)