-
Notifications
You must be signed in to change notification settings - Fork 8
/
binding.js
70 lines (58 loc) · 1.89 KB
/
binding.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/******************************************************************************
* *
* @file test.js *
* @author Clément Désiles <[email protected]> *
* @date 2013/02/13 *
* @licence MIT *
* *
* Sample to test the nodejs bindings to PCSC *
* *
*****************************************************************************/
// Script requirements
// -------------------
var util = require('util');
var events = require('events');
var fork = require('child_process').fork;
var node_pcsc = __dirname + '/lib/node-pcsc.js';
var Bindings = function() {
// Call super constructor
events.EventEmitter.call( this );
// PCSC sub-process reference
this.pcsc = null;
};
util.inherits(Bindings, events.EventEmitter);
/**
* Init the pcsc sub-process
* @return {Boolean} operation status
*/
Bindings.prototype.init = function() {
// Protection against multiple init
if (this.pcsc) return false;
// Fork the sub-process
this.pcsc = fork(node_pcsc);
// Message appropriation
var self = this;
this.pcsc.on('message', function(message) {
switch (message.name) {
case 'readerStateChange':
self.emit('evt', message);
break;
};
});
// Ack
return true;
};
/**
* Kill the pcsc sub-process
* @return {Boolean} operation status
*/
Bindings.prototype.release = function() {
if (this.pcsc) {
this.pcsc.kill('SIGTERM');
}
this.pcsc = null;
return true;
};
// Export an instance
module.exports = new Bindings();