----------------------------------------------------------------------------- Queue a message to be sent to the Z-Wave PC Interface -----------------------------------------------------------------------------
| 1033 | // Queue a message to be sent to the Z-Wave PC Interface |
| 1034 | //----------------------------------------------------------------------------- |
| 1035 | void Driver::SendMsg |
| 1036 | ( |
| 1037 | Msg* _msg, |
| 1038 | MsgQueue const _queue |
| 1039 | ) |
| 1040 | { |
| 1041 | MsgQueueItem item; |
| 1042 | |
| 1043 | item.m_command = MsgQueueCmd_SendMsg; |
| 1044 | item.m_msg = _msg; |
| 1045 | /* make sure the HomeId is Set on this message */ |
| 1046 | _msg->SetHomeId(m_homeId); |
| 1047 | _msg->Finalize(); |
| 1048 | { |
| 1049 | LockGuard LG(m_nodeMutex); |
| 1050 | if( Node* node = GetNode(_msg->GetTargetNodeId()) ) |
| 1051 | { |
| 1052 | /* if the node Supports the Security Class - check if this message is meant to be encapsulated */ |
| 1053 | if ( node->GetCommandClass(Security::StaticGetCommandClassId()) ) |
| 1054 | { |
| 1055 | CommandClass *cc = node->GetCommandClass(_msg->GetSendingCommandClass()); |
| 1056 | if ( (cc) && (cc->IsSecured()) ) |
| 1057 | { |
| 1058 | Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Setting Encryption Flag on Message For Command Class %s", cc->GetCommandClassName().c_str()); |
| 1059 | item.m_msg->setEncrypted(); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | // If the message is for a sleeping node, we queue it in the node itself. |
| 1064 | if( !node->IsListeningDevice() ) |
| 1065 | { |
| 1066 | if( WakeUp* wakeUp = static_cast<WakeUp*>( node->GetCommandClass( WakeUp::StaticGetCommandClassId() ) ) ) |
| 1067 | { |
| 1068 | if( !wakeUp->IsAwake() ) |
| 1069 | { |
| 1070 | Log::Write( LogLevel_Detail, "" ); |
| 1071 | // Handle saving multi-step controller commands |
| 1072 | if( m_currentControllerCommand != NULL ) |
| 1073 | { |
| 1074 | Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_Controller], c_controllerCommandNames[m_currentControllerCommand->m_controllerCommand] ); |
| 1075 | delete _msg; |
| 1076 | item.m_command = MsgQueueCmd_Controller; |
| 1077 | item.m_cci = new ControllerCommandItem( *m_currentControllerCommand ); |
| 1078 | item.m_msg = NULL; |
| 1079 | UpdateControllerState( ControllerState_Sleeping ); |
| 1080 | } |
| 1081 | else |
| 1082 | { |
| 1083 | Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[MsgQueue_WakeUp], _msg->GetAsString().c_str() ); |
| 1084 | } |
| 1085 | wakeUp->QueueMsg( item ); |
| 1086 | return; |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | Log::Write( LogLevel_Detail, GetNodeNumber( _msg ), "Queuing (%s) %s", c_sendQueueNames[_queue], _msg->GetAsString().c_str() ); |