Skip to content

Commit

Permalink
started reorganising callback code
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarak committed Jun 9, 2015
1 parent 2b34787 commit a85de3c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 96 deletions.
3 changes: 1 addition & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"target_name": "openzwave_shared",
"sources": [
"src/openzwave.cc",
"src/openzwave-callbacks.cc",
"src/openzwave-config.cc",
"src/openzwave-driver.cc",
"src/openzwave-groups.cc",
Expand All @@ -13,7 +12,7 @@
"src/openzwave-scenes.cc",
"src/openzwave-values.cc",
"src/utils.cc",
"src/v8-callbacks.cc",
"src/callbacks.cc",
],
'conditions': [
['OS=="linux"', {
Expand Down
71 changes: 71 additions & 0 deletions src/v8-callbacks.cc → src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,79 @@

using namespace v8;
using namespace node;
using namespace OpenZWave;

namespace OZW {

/*
* OpenZWave callback, registered in Driver::AddWatcher.
* Just push onto queue and trigger the handler
* in v8 land.
*/
// ===================================================================
void ozw_watcher_callback(OpenZWave::Notification const *cb, void *ctx)
// ===================================================================
{
NotifInfo *notif = new NotifInfo();

notif->type = cb->GetType();
notif->homeid = cb->GetHomeId();
notif->nodeid = cb->GetNodeId();
notif->values.push_front(cb->GetValueID());
// its not a ControllerState notification: set to -1
notif->state = (OpenZWave::Driver::ControllerState) -1;
/*
* Some values are only set on particular notifications, and
* assertions in openzwave prevent us from trying to fetch them
* unconditionally.
*/
switch (notif->type) {
case OpenZWave::Notification::Type_Group:
notif->groupidx = cb->GetGroupIdx();
break;
case OpenZWave::Notification::Type_NodeEvent:
notif->event = cb->GetEvent();
break;
case OpenZWave::Notification::Type_CreateButton:
case OpenZWave::Notification::Type_DeleteButton:
case OpenZWave::Notification::Type_ButtonOn:
case OpenZWave::Notification::Type_ButtonOff:
notif->buttonid = cb->GetButtonId();
break;
case OpenZWave::Notification::Type_SceneEvent:
notif->sceneid = cb->GetSceneId();
break;
case OpenZWave::Notification::Type_Notification:
notif->notification = cb->GetNotification();
break;
}

{
mutex::scoped_lock sl(zqueue_mutex);
zqueue.push(notif);
}
uv_async_send(&async);
}

/*
* OpenZWave callback, registered in Manager::BeginControllerCommand.
* Just push onto queue and trigger the handler in v8 land.
*/
// ===================================================================
void ozw_ctrlcmd_callback(Driver::ControllerState _state, Driver::ControllerError _err, void *context )
// ===================================================================
{
NotifInfo *notif = new NotifInfo();
notif->state = _state;
notif->err = _err;
{
mutex::scoped_lock sl(zqueue_mutex);
zqueue.push(notif);
}
uv_async_send(&async);
}

/*
* handle normal OpenZWave notifications
*/
// ===================================================================
Expand Down Expand Up @@ -267,4 +337,5 @@ namespace OZW {
zqueue.pop();
}
}

}
92 changes: 0 additions & 92 deletions src/openzwave-callbacks.cc

This file was deleted.

6 changes: 4 additions & 2 deletions src/openzwave-driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ namespace OZW {
OpenZWave::Manager::Get()->AddWatcher(ozw_watcher_callback, NULL);
OpenZWave::Manager::Get()->AddDriver(path);

Handle<v8::Value> argv[1] = { NanNew<String>("connected") };
MakeCallback(context_obj, "emit", 1, argv);
Local<Function> cb = args[0].As<Function>();
const unsigned argc = 1;
Local<Value> argv[argc] = { NanNew("connected") };
NanMakeCallback(NanGetCurrentContext()->Global(), cb, argc, argv);

NanReturnUndefined();
}
Expand Down

0 comments on commit a85de3c

Please sign in to comment.