-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (44 loc) · 1.21 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const os = require('os'); // x64
const NativeP4NodeApi = require(["./lib/p4nodeapi", os.platform(), os.arch()].join('_')).P4NodeApi;
module.exports.P4Connection = function(_config) {
var m_config = {
"user":"",
"password":"",
"port":"",
"client":"",
"json":false
};
for (var key in m_config) {
if (_config.hasOwnProperty(key))
m_config[key] = _config[key];
}
var _con = new NativeP4NodeApi({
'user':m_config.user,
'password':m_config.password,
'port':m_config.port,
'client':m_config.client,
'json':m_config.json
});
var queue = null;
this.run = function(args, input) {
if (typeof(args)=="string")
args = args.split(" ");
return queue = (queue || Promise.resolve()).catch(function() {
return true;
}).then(function () {
return new Promise(function (resolve, reject) {
_con.run(args, input || "", function (err, ress) {
if(err) {
reject(err);
} else {
resolve(ress);
}
});
});
});
};
this.close = function () {
_con.close();
};
return this;
};