k2hdkc 1.0.13 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +40 -0
- package/build/cjs/index.js +285 -0
- package/build/esm/index.js +282 -0
- package/buildutils/make_node_prebuild_variables.sh +361 -0
- package/buildutils/node_prebuild.sh +373 -0
- package/buildutils/node_prebuild_install.sh +309 -0
- package/index.js +4 -1
- package/index.mjs +149 -0
- package/package.json +74 -18
- package/src/index.ts +367 -0
- package/src/k2hdkc.cc +21 -8
- package/src/k2hdkc_cbs.cc +27 -41
- package/src/k2hdkc_cbs.h +15 -11
- package/src/k2hdkc_common.h +3 -3
- package/src/k2hdkc_node.cc +1889 -1655
- package/src/k2hdkc_node.h +69 -63
- package/src/k2hdkc_node_async.h +1020 -932
- package/types/index.d.ts +1258 -0
- package/ChangeLog +0 -138
- package/src/binding.gyp +0 -69
package/src/k2hdkc_cbs.cc
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
#include <fullock/flckbaselist.tcc>
|
|
20
20
|
#include "k2hdkc_cbs.h"
|
|
21
21
|
|
|
22
|
-
using namespace v8;
|
|
23
22
|
using namespace std;
|
|
24
23
|
using namespace fullock;
|
|
25
24
|
|
|
@@ -37,68 +36,55 @@ StackEmitCB::~StackEmitCB()
|
|
|
37
36
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
// This method does not lock, thus must lock before calling this.
|
|
42
|
-
//
|
|
43
|
-
Nan::Callback* StackEmitCB::RawFind(const char* pemitname)
|
|
39
|
+
bool StackEmitCB::Set(const std::string& emitter, const Napi::Function& cb)
|
|
44
40
|
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
42
|
+
|
|
43
|
+
// clear if existed
|
|
44
|
+
auto it = EmitCbsMap.find(emitter);
|
|
45
|
+
if(EmitCbsMap.end() != it){
|
|
46
|
+
it->second.Reset();
|
|
47
|
+
EmitCbsMap.erase(it);
|
|
52
48
|
}
|
|
53
|
-
return cbfunc;
|
|
54
|
-
}
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
// Insert new persistent reference
|
|
51
|
+
Napi::FunctionReference ref = Napi::Persistent(cb);
|
|
52
|
+
EmitCbsMap.emplace(emitter, std::move(ref));
|
|
53
|
+
|
|
60
54
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
61
55
|
|
|
62
|
-
return
|
|
56
|
+
return true;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
bool StackEmitCB::
|
|
59
|
+
bool StackEmitCB::Unset(const std::string& emitter)
|
|
66
60
|
{
|
|
67
|
-
string stremit = pemitname ? pemitname : "";
|
|
68
|
-
if(stremit.empty()){
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
61
|
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
73
62
|
|
|
74
|
-
|
|
75
|
-
if(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if(cbfunc){
|
|
79
|
-
EmitCbsMap[stremit] = cbfunc;
|
|
63
|
+
auto it = EmitCbsMap.find(emitter);
|
|
64
|
+
if(EmitCbsMap.end() == it){
|
|
65
|
+
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
66
|
+
return false;
|
|
80
67
|
}
|
|
68
|
+
it->second.Reset();
|
|
69
|
+
EmitCbsMap.erase(it);
|
|
70
|
+
|
|
81
71
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
82
72
|
|
|
83
73
|
return true;
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
|
|
76
|
+
Napi::FunctionReference* StackEmitCB::Find(const std::string& emitter)
|
|
87
77
|
{
|
|
88
|
-
string stremit = pemitname ? pemitname : "";
|
|
89
|
-
if(stremit.empty()){
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
78
|
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
if(
|
|
97
|
-
|
|
80
|
+
auto it = EmitCbsMap.find(emitter);
|
|
81
|
+
if(EmitCbsMap.end() == it){
|
|
82
|
+
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
83
|
+
return nullptr;
|
|
98
84
|
}
|
|
99
85
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
100
86
|
|
|
101
|
-
return
|
|
87
|
+
return &it->second;
|
|
102
88
|
}
|
|
103
89
|
|
|
104
90
|
/*
|
package/src/k2hdkc_cbs.h
CHANGED
|
@@ -18,32 +18,36 @@
|
|
|
18
18
|
#ifndef K2HDKC_CBS_H
|
|
19
19
|
#define K2HDKC_CBS_H
|
|
20
20
|
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <unordered_map>
|
|
21
23
|
#include "k2hdkc_common.h"
|
|
22
24
|
|
|
23
25
|
//---------------------------------------------------------
|
|
24
26
|
// Typedefs
|
|
25
27
|
//---------------------------------------------------------
|
|
26
|
-
typedef std::
|
|
28
|
+
typedef std::unordered_map<std::string, Napi::FunctionReference> cbsmap;
|
|
27
29
|
|
|
28
30
|
//---------------------------------------------------------
|
|
29
31
|
// StackEmitCB Class
|
|
30
32
|
//---------------------------------------------------------
|
|
31
33
|
class StackEmitCB
|
|
32
34
|
{
|
|
33
|
-
protected:
|
|
34
|
-
cbsmap EmitCbsMap;
|
|
35
|
-
volatile int lockval; // lock variable for mapping
|
|
36
|
-
|
|
37
|
-
protected:
|
|
38
|
-
Nan::Callback* RawFind(const char* pemitname);
|
|
39
|
-
|
|
40
35
|
public:
|
|
41
36
|
StackEmitCB();
|
|
42
37
|
virtual ~StackEmitCB();
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
bool Set(const
|
|
46
|
-
|
|
39
|
+
// Set returns true if set succeeded
|
|
40
|
+
bool Set(const std::string& emitter, const Napi::Function& cb);
|
|
41
|
+
|
|
42
|
+
// Unset returns true if removed
|
|
43
|
+
bool Unset(const std::string& emitter);
|
|
44
|
+
|
|
45
|
+
// Find returns pointer to FunctionReference if set, otherwise nullptr
|
|
46
|
+
Napi::FunctionReference* Find(const std::string& emitter);
|
|
47
|
+
|
|
48
|
+
private:
|
|
49
|
+
cbsmap EmitCbsMap;
|
|
50
|
+
volatile int lockval; // lock variable for mapping
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
#endif
|
package/src/k2hdkc_common.h
CHANGED
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
//---------------------------------------------------------
|
|
22
22
|
// common headers
|
|
23
23
|
//---------------------------------------------------------
|
|
24
|
-
#include <
|
|
24
|
+
#include <cstddef>
|
|
25
|
+
|
|
25
26
|
#include <k2hdkc/k2hdkccommon.h>
|
|
26
27
|
#include <k2hdkc/k2hdkc.h>
|
|
27
28
|
#include <k2hdkc/k2hdkcslave.h>
|
|
28
29
|
#include <k2hdkc/k2hdkccom.h>
|
|
29
30
|
#include <k2hdkc/k2hdkcutil.h>
|
|
30
31
|
|
|
31
|
-
#include <
|
|
32
|
-
|
|
32
|
+
#include <napi.h>
|
|
33
33
|
#include <string>
|
|
34
34
|
#include <iostream>
|
|
35
35
|
#include <map>
|