Skip to content

Commit 4cf474c

Browse files
authored
Merge pull request #300 from OpenZWave/feature/openzwave16
add preprocessor wrappers for OZW exceptions
2 parents c7b7f33 + 469c38e commit 4cf474c

21 files changed

+519
-372
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ Fix scene values type 'list' (Partially fix #266) #267
3232

3333
# 1.4.8
3434
add support for SmartOS #272
35+
36+
# (next)
37+
Updated Raspbian Readme to fix bug when installing on Raspbian stretch #271
38+
iBetter typescript integration #263

binding.gyp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"defines": [
2828
"OPENZWAVE_ETC=<(OZW_ETC)/config",
2929
"OPENZWAVE_DOC=<!@(node -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
30-
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)"
30+
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
31+
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
32+
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)"
3133
],
3234
"cflags": [ "-Wno-ignored-qualifiers -Wno-write-strings -Wno-unknown-pragmas" ],
3335
"link_settings": {
@@ -52,7 +54,9 @@
5254
"defines": [
5355
"OPENZWAVE_ETC=<(OZW_ETC)/config",
5456
"OPENZWAVE_DOC=<!@(node -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
55-
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)"
57+
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
58+
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
59+
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)"
5660
],
5761
"link_settings": {
5862
"libraries": [
@@ -82,7 +86,9 @@
8286
"defines": [
8387
"OPENZWAVE_ETC=<!@(<(NODE) -p -e \"'<(OZW_ETC)'.length ? '<(OZW_ETC)' : '/usr/local/etc/openzwave'\")",
8488
"OPENZWAVE_DOC=<!@(<(NODE) -p -e \"'<(OZW_DOC)'.length ? '<(OZW_DOC)' : '/usr/local/share/doc/openzwave'\")",
85-
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)"
89+
"OPENZWAVE_SECURITY=<!@(find <(OZW_INC) -name ZWSecurity.h | wc -l)",
90+
"OPENZWAVE_EXCEPTIONS=<!@(find <(OZW_INC) -name OZWException.h | wc -l)",
91+
"OPENZWAVE_BITSET=<!@(find <(OZW_INC) -name ValueBitSet.h | wc -l)",
8692
],
8793
"link_settings": {
8894
"libraries": ["-lopenzwave"]
@@ -92,7 +98,15 @@
9298
"<(OZW_INC)",
9399
"<(OZW_INC)/value_classes"
94100
],
95-
"cflags": [ "-Wno-ignored-qualifiers -Wno-write-strings -Wno-unknown-pragmas" ],
101+
"cflags": [
102+
"-Wno-ignored-qualifiers",
103+
"-Wno-write-strings",
104+
"-Wno-unknown-pragmas",
105+
"<!@(find <(OZW_INC) -name OZWException.h -exec echo -n \"-fexceptions\" \\;)"
106+
],
107+
"cflags_cc!": [
108+
"<!@(find <(OZW_INC) -name OZWException.h -exec echo -n \"-fno-exceptions\" \\;)"
109+
]
96110
}],
97111
['OS=="win"', {
98112
"variables": {
@@ -105,14 +119,22 @@
105119
],
106120
"defines": [
107121
"OPENZWAVE_ETC=<(OZW_HOME)/config",
108-
"OPENZWAVE_SECURITY=1"
122+
"OPENZWAVE_SECURITY=1",
123+
"OPENZWAVE_EXCEPTIONS=1",
124+
"OPENZWAVE_BITSET=1"
109125
],
110126
'msvs_settings': {
127+
'VCCLCompilerTool': {
128+
'ExceptionHandling': 1
129+
},
111130
'VCLinkerTool': {
112-
'AdditionalDependencies': ['setupapi.lib', '<(OZW_HOME)/bin/OpenZWave.lib']
131+
'AdditionalDependencies': ['setupapi.lib', '<(OZW_HOME)/bin/OpenZWave.lib', 'dnsapi.lib', 'ws2_32.lib']
113132
}
114-
}
133+
},
134+
"link_settings": {
135+
"libraries": ["dnsapi.lib", "ws2_32.lib"]
136+
}
115137
}]
116-
],
138+
]
117139
}]
118140
}

lib/install-ozw.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ var ozwGyp = {
8181
"sources/": [
8282
['exclude', 'cpp/src/platform/unix/'],
8383
['exclude', 'cpp/src/platform/winRT/']
84-
]
84+
],
85+
"link_settings": {
86+
"libraries": ["dnsapi.lib", "ws2_32.lib"]
87+
}
8588
}],
8689
]
8790
}

lib/openzwave-shared.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ require("./polyfill");
2222
var debugAddon = __dirname + "/../build/Debug/openzwave_shared.node";
2323
var releaseAddon = __dirname + "/../build/Release/openzwave_shared.node";
2424
var addonFileName = fs.existsSync(debugAddon) ? debugAddon : releaseAddon;
25+
26+
//console.log("loading "+addonFileName);
2527
var addonModule = require(addonFileName);
2628

2729
for (var k in EventEmitter.prototype) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "./lib/openzwave-shared.js",
66
"types": "./types/openzwave-shared.d.ts",
77
"dependencies": {
8-
"nan": ">=2.10.0"
8+
"nan": ">=2.14.0"
99
},
1010
"scripts": {
1111
"test": "node test.js",

src/callbacks.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace OZW {
2626
//
2727
uv_async_t async;
2828

29-
//
29+
// the Nan::Callback reference needs to be exposed as a globar var
30+
// because most of the callbacks (that need to bubble up to JS-space) will emanate from the C++ land
3031
Nan::Callback *emit_cb;
3132
Nan::CopyablePersistentTraits<v8::Object>::CopyablePersistent ctx_obj;
3233
Nan::AsyncResource *resource;
@@ -77,13 +78,15 @@ void ozw_watcher_callback(OpenZWave::Notification const *cb, void *ctx)
7778
case OpenZWave::Notification::Type_ButtonOff:
7879
notif->buttonid = cb->GetButtonId();
7980
break;
81+
#if OPENZWAVE_SCENES
8082
case OpenZWave::Notification::Type_SceneEvent:
8183
notif->sceneid = cb->GetSceneId();
8284
break;
85+
#endif
8386
case OpenZWave::Notification::Type_Notification:
8487
notif->notification = cb->GetNotification();
8588
break;
86-
#if OPENZWAVE_SECURITY == 1
89+
#if OPENZWAVE_SECURITY
8790
case OpenZWave::Notification::Type_ControllerCommand:
8891
notif->event = cb->GetEvent();
8992
notif->notification = cb->GetNotification();
@@ -100,7 +103,7 @@ void ozw_watcher_callback(OpenZWave::Notification const *cb, void *ctx)
100103

101104
// ##### LEGACY MODE ###### //
102105
#if OPENZWAVE_SECURITY != 1 //
103-
// ######################## //
106+
// ######################## //
104107
/*
105108
* OpenZWave callback, registered in Manager::BeginControllerCommand.
106109
* Just push onto queue and trigger the handler in v8 land.

src/openzwave-config.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ namespace OZW {
3333
uint8 param = Nan::To<Number>(info[1]).ToLocalChecked()->Value();
3434
int32 value = Nan::To<Number>(info[2]).ToLocalChecked()->Value();
3535
if (info.Length() < 4) {
36-
OpenZWave::Manager::Get()->SetConfigParam(homeid, nodeid, param, value);
36+
OZWManager( SetConfigParam, homeid, nodeid, param, value);
3737
}
3838
else {
3939
uint8 size = Nan::To<Number>(info[3]).ToLocalChecked()->Value();
40-
OpenZWave::Manager::Get()->SetConfigParam(homeid, nodeid, param, value, size);
40+
OZWManager( SetConfigParam, homeid, nodeid, param, value, size);
4141
}
4242
}
4343

@@ -64,7 +64,7 @@ namespace OZW {
6464
CheckMinArgs(2, "nodeid, param");
6565
uint8 nodeid = Nan::To<Number>(info[0]).ToLocalChecked()->Value();
6666
uint8 param = Nan::To<Number>(info[1]).ToLocalChecked()->Value();
67-
OpenZWave::Manager::Get()->RequestConfigParam(homeid, nodeid, param);
67+
OZWManager( RequestConfigParam, homeid, nodeid, param);
6868
}
6969

7070

@@ -79,7 +79,7 @@ namespace OZW {
7979
Nan::HandleScope scope;
8080
CheckMinArgs(1, "nodeid");
8181
uint8 nodeid = Nan::To<Number>(info[0]).ToLocalChecked()->Value();
82-
OpenZWave::Manager::Get()->RequestAllConfigParams (homeid, nodeid);
82+
OZWManager( RequestAllConfigParams, homeid, nodeid);
8383
}
8484

8585
}

src/openzwave-driver.cc

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,25 @@ namespace OZW {
3333

3434
uv_async_init(uv_default_loop(), &async, async_cb_handler);
3535

36-
Local<Function> callbackHandle = Nan::Get( info.This(),
37-
Nan::New<String>("emit").ToLocalChecked()
38-
).ToLocalChecked()
39-
.As<Function>();
40-
41-
emit_cb = new Nan::Callback(callbackHandle);
42-
4336
OZW* self = ObjectWrap::Unwrap<OZW>(info.This());
44-
37+
::std::string version("");
38+
#if OPENZWAVE_EXCEPTIONS
39+
try {
40+
#endif
4541
OpenZWave::Options::Create(self->config_path, self->userpath, self->option_overrides);
4642
OpenZWave::Options::Get()->Lock();
47-
4843
OpenZWave::Manager::Create();
49-
OpenZWave::Manager* mgr = OpenZWave::Manager::Get();
50-
mgr->AddWatcher(ozw_watcher_callback, NULL);
51-
mgr->AddDriver(path);
52-
::std::string version(OpenZWave::Manager::getVersionAsString());
53-
44+
OZWManager(AddWatcher, ozw_watcher_callback, NULL);
45+
OZWManager(AddDriver, path);
46+
version = OpenZWave::Manager::getVersionAsString();
47+
#if OPENZWAVE_EXCEPTIONS
48+
} catch ( OpenZWave::OZWException& e ) {
49+
char buffer [100];
50+
sprintf(buffer, "Exception connecting in %s(%d): %s",
51+
e.GetFile().c_str(), e.GetLine(), e.GetMsg().c_str());
52+
Nan::ThrowError( buffer );
53+
}
54+
#endif
5455
Local < v8::Value > cbinfo[16];
5556
cbinfo[0] = Nan::New<String>("connected").ToLocalChecked();
5657
cbinfo[1] = Nan::New<String>(version).ToLocalChecked();
@@ -110,12 +111,27 @@ namespace OZW {
110111
CheckMinArgs(1, "path");
111112
::std::string path(*Nan::Utf8String( info[0] ));
112113

113-
OpenZWave::Manager::Get()->RemoveDriver(path);
114-
OpenZWave::Manager::Get()->RemoveWatcher(ozw_watcher_callback, NULL);
114+
OZWManager( RemoveDriver, path );
115+
OZWManager( RemoveWatcher, ozw_watcher_callback, NULL);
116+
#if OPENZWAVE_EXCEPTIONS
117+
try {
118+
#endif
115119
OpenZWave::Manager::Destroy();
116120
OpenZWave::Options::Destroy();
117-
118-
delete emit_cb;
121+
#if OPENZWAVE_EXCEPTIONS
122+
} catch ( OpenZWave::OZWException& e ) {
123+
char buffer [100];
124+
sprintf(buffer, "Exception disconnecting in %s(%d): %s",
125+
e.GetFile().c_str(), e.GetLine(), e.GetMsg().c_str());
126+
Nan::ThrowError( buffer );
127+
}
128+
#endif
129+
// FIXME: seems some recent innocuous change in NaN causes the context (ctx_obj) to be freed.
130+
// Therefore, deleting this V8 resource will cause V8 to crash. NOT deleting it could memleak
131+
// when you're reloading the driver.
132+
//
133+
// delete emit_cb;
134+
//
119135
}
120136

121137
/*
@@ -127,15 +143,15 @@ namespace OZW {
127143
// ===================================================================
128144
{
129145
Nan::HandleScope scope;
130-
OpenZWave::Manager::Get()->ResetController(homeid);
146+
OZWManager(ResetController, homeid);
131147
}
132148

133149
// ===================================================================
134150
NAN_METHOD(OZW::SoftReset)
135151
// ===================================================================
136152
{
137153
Nan::HandleScope scope;
138-
OpenZWave::Manager::Get()->SoftReset(homeid);
154+
OZWManager(SoftReset, homeid);
139155
}
140156

141157

@@ -144,7 +160,8 @@ namespace OZW {
144160
// ===================================================================
145161
{
146162
Nan::HandleScope scope;
147-
uint8 ctrlid = OpenZWave::Manager::Get()->GetControllerNodeId (homeid);
163+
uint8 ctrlid = -1;
164+
OZWManagerAssign(ctrlid, GetControllerNodeId, homeid);
148165
info.GetReturnValue().Set(
149166
Nan::New<Integer>(ctrlid)
150167
);
@@ -155,7 +172,8 @@ namespace OZW {
155172
// ===================================================================
156173
{
157174
Nan::HandleScope scope;
158-
uint8 sucid = OpenZWave::Manager::Get()->GetSUCNodeId (homeid);
175+
uint8 sucid = -1;
176+
OZWManagerAssign(sucid, GetSUCNodeId, homeid);
159177
info.GetReturnValue().Set(
160178
Nan::New<Integer>(sucid)
161179
);
@@ -171,7 +189,8 @@ namespace OZW {
171189
// ===================================================================
172190
{
173191
Nan::HandleScope scope;
174-
bool isprimary = OpenZWave::Manager::Get()->IsPrimaryController (homeid);
192+
bool isprimary = false;
193+
OZWManagerAssign(isprimary, IsPrimaryController, homeid);
175194
info.GetReturnValue().Set(Nan::New<Boolean>(isprimary));
176195
}
177196

@@ -185,7 +204,8 @@ namespace OZW {
185204
// ===================================================================
186205
{
187206
Nan::HandleScope scope;
188-
bool issuc = OpenZWave::Manager::Get()->IsStaticUpdateController (homeid);
207+
bool issuc = false;
208+
OZWManagerAssign(issuc, IsStaticUpdateController, homeid);
189209
info.GetReturnValue().Set(Nan::New<Boolean>(issuc));
190210
}
191211

@@ -198,7 +218,8 @@ namespace OZW {
198218
// ===================================================================
199219
{
200220
Nan::HandleScope scope;
201-
bool isbridge = OpenZWave::Manager::Get()->IsBridgeController (homeid);
221+
bool isbridge = false;
222+
OZWManagerAssign(isbridge, IsBridgeController, homeid);
202223
info.GetReturnValue().Set(Nan::New<Boolean>(isbridge));
203224
}
204225

@@ -209,7 +230,8 @@ namespace OZW {
209230
// ===================================================================
210231
{
211232
Nan::HandleScope scope;
212-
::std::string libver = OpenZWave::Manager::Get()->GetLibraryVersion (homeid);
233+
::std::string libver("");
234+
OZWManagerAssign(libver, GetLibraryVersion, homeid);
213235
info.GetReturnValue().Set(
214236
Nan::New<String>(
215237
libver.c_str()
@@ -237,7 +259,8 @@ namespace OZW {
237259
// ===================================================================
238260
{
239261
Nan::HandleScope scope;
240-
::std::string libtype = OpenZWave::Manager::Get()->GetLibraryTypeName (homeid);
262+
::std::string libtype("");
263+
OZWManagerAssign(libtype, GetLibraryTypeName, homeid);
241264
info.GetReturnValue().Set(
242265
Nan::New<String>(
243266
libtype.c_str()
@@ -250,7 +273,8 @@ namespace OZW {
250273
// ===================================================================
251274
{
252275
Nan::HandleScope scope;
253-
uint32 cnt = OpenZWave::Manager::Get()->GetSendQueueCount (homeid);
276+
uint32 cnt = 0;
277+
OZWManagerAssign(cnt, GetSendQueueCount, homeid);
254278
info.GetReturnValue().Set(Nan::New<Integer>(cnt));
255279
}
256280

0 commit comments

Comments
 (0)