From cd20793bcb64bd394011efb37734a99522a88540 Mon Sep 17 00:00:00 2001 From: Elias Karakoulakis Date: Thu, 15 Sep 2016 08:30:51 +0300 Subject: [PATCH] fix indentation --- src/callbacks.cc | 853 ++++++++++++++++++++++++----------------------- 1 file changed, 427 insertions(+), 426 deletions(-) diff --git a/src/callbacks.cc b/src/callbacks.cc index 4b6f6fc4..9c72cfbd 100644 --- a/src/callbacks.cc +++ b/src/callbacks.cc @@ -23,459 +23,460 @@ using namespace OpenZWave; namespace OZW { - // - uv_async_t async; +// +uv_async_t async; - // - Nan::Callback *emit_cb; +// +Nan::Callback *emit_cb; - // Message passing queue between OpenZWave callback and v8 async handler. - mutex zqueue_mutex; - std::queue zqueue; +// Message passing queue between OpenZWave callback and v8 async handler. +mutex zqueue_mutex; +std::queue zqueue; - // Node state. - mutex znodes_mutex; - std::map znodes; +// Node state. +mutex znodes_mutex; +std::map znodes; - mutex zscenes_mutex; - std::list zscenes; - /* - * 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(); +mutex zscenes_mutex; +std::list zscenes; +/* +* 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(); - // only valueId-related callbacks carry an actual OZW ValueID - if (notif->type <= OpenZWave::Notification::Type_ValueRefreshed) { - notif->values.push_front(cb->GetValueID()); - } - notif->help = getNotifHelpMsg(cb); - /* - * 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; + notif->type = cb->GetType(); + notif->homeid = cb->GetHomeId(); + notif->nodeid = cb->GetNodeId(); + // only valueId-related callbacks carry an actual OZW ValueID + if (notif->type <= OpenZWave::Notification::Type_ValueRefreshed) { + notif->values.push_front(cb->GetValueID()); + } + notif->help = getNotifHelpMsg(cb); + /* + * 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; #if OPENZWAVE_SECURITY == 1 - case OpenZWave::Notification::Type_ControllerCommand: - notif->event = cb->GetEvent(); - notif->notification = cb->GetNotification(); - break; + case OpenZWave::Notification::Type_ControllerCommand: + notif->event = cb->GetEvent(); + notif->notification = cb->GetNotification(); + break; #endif - } + } - { - mutex::scoped_lock sl(zqueue_mutex); - zqueue.push(notif); - } - uv_async_send(&async); - } + { + mutex::scoped_lock sl(zqueue_mutex); + zqueue.push(notif); + } + uv_async_send(&async); +} // ##### LEGACY MODE ###### // #if OPENZWAVE_SECURITY != 1 // -// ######################## // - /* - * 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 ) - // =================================================================== - { + // ######################## // +/* +* 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->event = _err; - notif->notification = _state; - notif->homeid = 0; // use as guard value for legacy mode - notif->help = std::string( - "Controller State: ").append(getControllerStateAsStr(_state) - ).append(", Error: ").append(getControllerErrorAsStr(_err)); - { - mutex::scoped_lock sl(zqueue_mutex); - zqueue.push(notif); - } - uv_async_send(&async); - } + NotifInfo *notif = new NotifInfo(); + notif->event = _err; + notif->notification = _state; + notif->homeid = 0; // use as guard value for legacy mode + notif->help = std::string("Controller State: ") + .append(getControllerStateAsStr(_state)) + .append(", Error: ") + .append(getControllerErrorAsStr(_err)); + { + mutex::scoped_lock sl(zqueue_mutex); + zqueue.push(notif); + } + uv_async_send(&async); +} - // =================================================================== - void handleControllerCommand(NotifInfo *notif) - // =================================================================== - { - Nan::HandleScope scope; +// =================================================================== +void handleControllerCommand(NotifInfo *notif) +// =================================================================== +{ + Nan::HandleScope scope; - Local < v8::Value > info[16]; - info[0] = Nan::New("controller command").ToLocalChecked(); - info[1] = Nan::New(notif->nodeid); - info[2] = Nan::New(notif->event); // Driver::ControllerCommand - info[3] = Nan::New(notif->notification); // Driver::ControllerCommand - info[4] = Nan::New(notif->help.c_str()).ToLocalChecked(); - emit_cb->Call(5, info); - } + Local info[16]; + info[0] = Nan::New("controller command").ToLocalChecked(); + info[1] = Nan::New(notif->nodeid); + info[2] = Nan::New(notif->event); // Driver::ControllerCommand + info[3] = Nan::New(notif->notification); // Driver::ControllerCommand + info[4] = Nan::New(notif->help.c_str()).ToLocalChecked(); + emit_cb->Call(5, info); +} // ##### END OF LEGACY MODE ###### // #endif +/* + * handle normal OpenZWave notifications + */ +// =================================================================== +void handleNotification(NotifInfo *notif) +// =================================================================== +{ + Nan::HandleScope scope; + NodeInfo *node; + OpenZWave::Manager *mgr = OpenZWave::Manager::Get(); + Local emitinfo[16]; + Local cbinfo = Nan::New(); + // + switch (notif->type) { + // ################ + case OpenZWave::Notification::Type_ValueAdded: { + // ################ + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); - /* - * handle normal OpenZWave notifications - */ - // =================================================================== - void handleNotification(NotifInfo *notif) - // =================================================================== - { - Nan::HandleScope scope; - - NodeInfo *node; - OpenZWave::Manager* mgr = OpenZWave::Manager::Get(); - Local < v8::Value > emitinfo[16]; - Local < Object > cbinfo = Nan::New(); - // - switch (notif->type) { - // ################ - case OpenZWave::Notification::Type_ValueAdded: { - // ################ - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - - if ((node = get_node_info(notif->nodeid))) { - mutex::scoped_lock sl(znodes_mutex); - node->values.push_back(value); - } + if ((node = get_node_info(notif->nodeid))) { + mutex::scoped_lock sl(znodes_mutex); + node->values.push_back(value); + } - emitinfo[0] = Nan::New("value added").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_ValueRemoved: { - // ################## - OpenZWave::ValueID value = notif->values.front(); - std::list::iterator vit; - if ((node = get_node_info(notif->nodeid))) { - for (vit = node->values.begin(); vit != node->values.end(); ++vit) { - if ((*vit) == notif->values.front()) { - node->values.erase(vit); - break; - } - } - } - emitinfo[0] = Nan::New("value removed").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = Nan::New(value.GetInstance()); - emitinfo[4] = Nan::New(value.GetIndex()); - emit_cb->Call(5, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_ValueChanged: { - // ################## - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - emitinfo[0] = Nan::New("value changed").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); - break; - } - // #################### - case OpenZWave::Notification::Type_ValueRefreshed: { - // #################### - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - emitinfo[0] = Nan::New("value refreshed").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); - break; - } - // ############# - case OpenZWave::Notification::Type_NodeNew: - // ############# - /* NodeNew is triggered when a node is discovered which is not - * found in the OpenZWave XML file. As we do not use that file - * simply ignore those notifications for now. - * - * NodeAdded is when we actually have a new node to set up. - */ - break; - // ############### - case OpenZWave::Notification::Type_NodeAdded: { - // ############### - node = new NodeInfo(); - node->homeid = notif->homeid; - node->nodeid = notif->nodeid; - node->polled = false; - { - mutex::scoped_lock sl(znodes_mutex); - znodes[ notif->nodeid ] = node; - } - emitinfo[0] = Nan::New("node added").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emit_cb->Call(2, emitinfo); - break; - } - // ################# - case OpenZWave::Notification::Type_NodeRemoved: { - // ################# - { - mutex::scoped_lock sl(znodes_mutex); - znodes.erase(notif->nodeid); - } - emitinfo[0] = Nan::New("node removed").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emit_cb->Call(2, emitinfo); - break; - } - // ###################### - case OpenZWave::Notification::Type_NodeProtocolInfo: { - // ###################### - /* - * Ignore intermediate notifications about a node status, we - * wait until the node is ready before retrieving information. - */ - break; - } - // ################ - case OpenZWave::Notification::Type_NodeNaming: { - // ################ - getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); - emitinfo[0] = Nan::New("node naming").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = cbinfo; - emit_cb->Call(3, emitinfo); - break; - } - // ############### - case OpenZWave::Notification::Type_NodeEvent: { - // ############### - emitinfo[0] = Nan::New("node event").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->event); - emit_cb->Call(3, emitinfo); - break; - } - // ##################### - case OpenZWave::Notification::Type_PollingDisabled: { - // ##################### - if ((node = get_node_info(notif->nodeid))) { - node->polled = false; - emitinfo[0] = Nan::New("polling disabled").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emit_cb->Call(2, emitinfo); - } - break; - } - // #################### - case OpenZWave::Notification::Type_PollingEnabled: { - // #################### - if ((node = get_node_info(notif->nodeid))) { - node->polled = true; - emitinfo[0] = Nan::New("polling enabled").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emit_cb->Call(2, emitinfo); - } - break; - } - // ################ - case OpenZWave::Notification::Type_SceneEvent: { - // ################ - emitinfo[0] = Nan::New("scene event").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->sceneid); - emit_cb->Call(3, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_CreateButton: { - // ################## - emitinfo[0] = Nan::New("create button").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->buttonid); - emit_cb->Call(3, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_DeleteButton: { - // ################## - emitinfo[0] = Nan::New("delete button").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->buttonid); - emit_cb->Call(3, emitinfo); - break; - } - // ############## - case OpenZWave::Notification::Type_ButtonOn: { - // ############## - emitinfo[0] = Nan::New("button on").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->buttonid); - emit_cb->Call(3, emitinfo); - break; - } - // ############### - case OpenZWave::Notification::Type_ButtonOff: { - // ############### - emitinfo[0] = Nan::New("button off").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->buttonid); - emit_cb->Call(3, emitinfo); - break; - } - // ################# - case OpenZWave::Notification::Type_DriverReady: { - // ################# - // the driver is ready, set our global homeid - homeid = notif->homeid; - emitinfo[0] = Nan::New("driver ready").ToLocalChecked(); - emitinfo[1] = Nan::New(homeid); - emit_cb->Call(2, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_DriverFailed: { - // ################## - emitinfo[0] = Nan::New("driver failed").ToLocalChecked(); - emit_cb->Call(1, emitinfo); - break; - } - // ################################## - case OpenZWave::Notification::Type_EssentialNodeQueriesComplete: { - // ################################## - getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); - emitinfo[0] = Nan::New("node available").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = cbinfo; - emit_cb->Call(3, emitinfo); - break; - } - /* - * The node is now fully ready for operation. - */ - // ######################### - case OpenZWave::Notification::Type_NodeQueriesComplete: { - // ######################### - getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); - emitinfo[0] = Nan::New("node ready").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = cbinfo; - emit_cb->Call(3, emitinfo); - break; - } - /* - * The network scan has been completed. Currently we do not - * care about dead nodes - is there anything we can do anyway? - */ - // ######################### - case OpenZWave::Notification::Type_AwakeNodesQueried: - case OpenZWave::Notification::Type_AllNodesQueried: - case OpenZWave::Notification::Type_AllNodesQueriedSomeDead: { - // ############################# - emitinfo[0] = Nan::New("scan complete").ToLocalChecked(); - emit_cb->Call(1, emitinfo); - break; - } - // ################## - case OpenZWave::Notification::Type_Notification: { - // ######################### - emitinfo[0] = Nan::New("notification").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->notification); - emitinfo[3] = Nan::New(notif->help.c_str()).ToLocalChecked(); - emit_cb->Call(4, emitinfo); - break; - } - case OpenZWave::Notification::Type_DriverRemoved: - case OpenZWave::Notification::Type_Group: - /* The associations for the node have changed. The - * application should rebuild any group information it - * holds about the node. - */ -// todo - break; + emitinfo[0] = Nan::New("value added").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_ValueRemoved: { + // ################## + OpenZWave::ValueID value = notif->values.front(); + std::list::iterator vit; + if ((node = get_node_info(notif->nodeid))) { + for (vit = node->values.begin(); vit != node->values.end(); ++vit) { + if ((*vit) == notif->values.front()) { + node->values.erase(vit); + break; + } + } + } + emitinfo[0] = Nan::New("value removed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = Nan::New(value.GetInstance()); + emitinfo[4] = Nan::New(value.GetIndex()); + emit_cb->Call(5, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_ValueChanged: { + // ################## + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + emitinfo[0] = Nan::New("value changed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); + break; + } + // #################### + case OpenZWave::Notification::Type_ValueRefreshed: { + // #################### + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + emitinfo[0] = Nan::New("value refreshed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); + break; + } + // ############# + case OpenZWave::Notification::Type_NodeNew: + // ############# + /* NodeNew is triggered when a node is discovered which is not + * found in the OpenZWave XML file. As we do not use that file + * simply ignore those notifications for now. + * + * NodeAdded is when we actually have a new node to set up. + */ + break; + // ############### + case OpenZWave::Notification::Type_NodeAdded: { + // ############### + node = new NodeInfo(); + node->homeid = notif->homeid; + node->nodeid = notif->nodeid; + node->polled = false; + { + mutex::scoped_lock sl(znodes_mutex); + znodes[notif->nodeid] = node; + } + emitinfo[0] = Nan::New("node added").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emit_cb->Call(2, emitinfo); + break; + } + // ################# + case OpenZWave::Notification::Type_NodeRemoved: { + // ################# + { + mutex::scoped_lock sl(znodes_mutex); + znodes.erase(notif->nodeid); + } + emitinfo[0] = Nan::New("node removed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emit_cb->Call(2, emitinfo); + break; + } + // ###################### + case OpenZWave::Notification::Type_NodeProtocolInfo: { + // ###################### + /* + * Ignore intermediate notifications about a node status, we + * wait until the node is ready before retrieving information. + */ + break; + } + // ################ + case OpenZWave::Notification::Type_NodeNaming: { + // ################ + getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); + emitinfo[0] = Nan::New("node naming").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = cbinfo; + emit_cb->Call(3, emitinfo); + break; + } + // ############### + case OpenZWave::Notification::Type_NodeEvent: { + // ############### + emitinfo[0] = Nan::New("node event").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->event); + emitinfo[3] = Nan::New(notif->help.c_str()).ToLocalChecked(); + emit_cb->Call(4, emitinfo); + break; + } + // ##################### + case OpenZWave::Notification::Type_PollingDisabled: { + // ##################### + if ((node = get_node_info(notif->nodeid))) { + node->polled = false; + emitinfo[0] = Nan::New("polling disabled").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emit_cb->Call(2, emitinfo); + } + break; + } + // #################### + case OpenZWave::Notification::Type_PollingEnabled: { + // #################### + if ((node = get_node_info(notif->nodeid))) { + node->polled = true; + emitinfo[0] = Nan::New("polling enabled").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emit_cb->Call(2, emitinfo); + } + break; + } + // ################ + case OpenZWave::Notification::Type_SceneEvent: { + // ################ + emitinfo[0] = Nan::New("scene event").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->sceneid); + emit_cb->Call(3, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_CreateButton: { + // ################## + emitinfo[0] = Nan::New("create button").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_DeleteButton: { + // ################## + emitinfo[0] = Nan::New("delete button").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + // ############## + case OpenZWave::Notification::Type_ButtonOn: { + // ############## + emitinfo[0] = Nan::New("button on").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + // ############### + case OpenZWave::Notification::Type_ButtonOff: { + // ############### + emitinfo[0] = Nan::New("button off").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + // ################# + case OpenZWave::Notification::Type_DriverReady: { + // ################# + // the driver is ready, set our global homeid + homeid = notif->homeid; + emitinfo[0] = Nan::New("driver ready").ToLocalChecked(); + emitinfo[1] = Nan::New(homeid); + emit_cb->Call(2, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_DriverFailed: { + // ################## + emitinfo[0] = Nan::New("driver failed").ToLocalChecked(); + emit_cb->Call(1, emitinfo); + break; + } + // ################################## + case OpenZWave::Notification::Type_EssentialNodeQueriesComplete: { + // ################################## + getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); + emitinfo[0] = Nan::New("node available").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = cbinfo; + emit_cb->Call(3, emitinfo); + break; + } + /* + * The node is now fully ready for operation. + */ + // ######################### + case OpenZWave::Notification::Type_NodeQueriesComplete: { + // ######################### + getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); + emitinfo[0] = Nan::New("node ready").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = cbinfo; + emit_cb->Call(3, emitinfo); + break; + } + /* + * The network scan has been completed. Currently we do not + * care about dead nodes - is there anything we can do anyway? + */ + // ######################### + case OpenZWave::Notification::Type_AwakeNodesQueried: + case OpenZWave::Notification::Type_AllNodesQueried: + case OpenZWave::Notification::Type_AllNodesQueriedSomeDead: { + // ############################# + emitinfo[0] = Nan::New("scan complete").ToLocalChecked(); + emit_cb->Call(1, emitinfo); + break; + } + // ################## + case OpenZWave::Notification::Type_Notification: { + // ######################### + emitinfo[0] = Nan::New("notification").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->notification); + emitinfo[3] = Nan::New(notif->help.c_str()).ToLocalChecked(); + emit_cb->Call(4, emitinfo); + break; + } + case OpenZWave::Notification::Type_DriverRemoved: + case OpenZWave::Notification::Type_Group: + /* The associations for the node have changed. The + * application should rebuild any group information it + * holds about the node. + */ + // todo + break; #if OPENZWAVE_SECURITY == 1 - case OpenZWave::Notification::Type_ControllerCommand: - emitinfo[0] = Nan::New("controller command").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->event); // Driver::ControllerCommand - emitinfo[3] = Nan::New(notif->notification); // Driver::ControllerState - emitinfo[4] = Nan::New(notif->help.c_str()).ToLocalChecked(); - emit_cb->Call(5, emitinfo); - break; - case OpenZWave::Notification::Type_NodeReset: - emitinfo[0] = Nan::New("node reset").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->event); // Driver::ControllerCommand - emitinfo[3] = Nan::New(notif->notification); // Driver::ControllerState - emit_cb->Call(4, emitinfo); - break; + case OpenZWave::Notification::Type_ControllerCommand: + emitinfo[0] = Nan::New("controller command").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->event); // Driver::ControllerCommand + emitinfo[3] = + Nan::New(notif->notification); // Driver::ControllerState + emitinfo[4] = Nan::New(notif->help.c_str()).ToLocalChecked(); + emit_cb->Call(5, emitinfo); + break; + case OpenZWave::Notification::Type_NodeReset: + emitinfo[0] = Nan::New("node reset").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->event); // Driver::ControllerCommand + emitinfo[3] = + Nan::New(notif->notification); // Driver::ControllerState + emit_cb->Call(4, emitinfo); + break; #endif - default: - fprintf(stderr, "Unhandled OpenZWave notification: %d\n", notif->type); - break; - } // end switch - } + default: + fprintf(stderr, "Unhandled OpenZWave notification: %d\n", notif->type); + break; + } // end switch +} - /* - * Async handler, triggered by the OpenZWave callback. - */ - // =================================================================== - void async_cb_handler(uv_async_t *handle) - // =================================================================== - { - NotifInfo *notif; +/* +* Async handler, triggered by the OpenZWave callback. +*/ +// =================================================================== +void async_cb_handler(uv_async_t *handle) +// =================================================================== +{ + NotifInfo *notif; - mutex::scoped_lock sl(zqueue_mutex); + mutex::scoped_lock sl(zqueue_mutex); - while (!zqueue.empty()) { - notif = zqueue.front(); + while (!zqueue.empty()) { + notif = zqueue.front(); #if OPENZWAVE_SECURITY != 1 - if (notif->homeid == 0) { - handleControllerCommand(notif); - } else { - handleNotification(notif); - } + if (notif->homeid == 0) { + handleControllerCommand(notif); + } else { + handleNotification(notif); + } #else - handleNotification(notif); + handleNotification(notif); #endif - delete notif; - zqueue.pop(); - } - } - - void async_cb_handler(uv_async_t *handle, int status) - { - async_cb_handler(handle); - } + delete notif; + zqueue.pop(); + } +} +void async_cb_handler(uv_async_t *handle, int status) { + async_cb_handler(handle); +} }