----------------------------------------------------------------------------- Transmit a queued message to the Z-Wave controller -----------------------------------------------------------------------------
| 1101 | // Transmit a queued message to the Z-Wave controller |
| 1102 | //----------------------------------------------------------------------------- |
| 1103 | bool Driver::WriteNextMsg |
| 1104 | ( |
| 1105 | MsgQueue const _queue |
| 1106 | ) |
| 1107 | { |
| 1108 | |
| 1109 | // There are messages to send, so get the one at the front of the queue |
| 1110 | m_sendMutex->Lock(); |
| 1111 | MsgQueueItem item = m_msgQueue[_queue].front(); |
| 1112 | |
| 1113 | if( MsgQueueCmd_SendMsg == item.m_command ) |
| 1114 | { |
| 1115 | // Send a message |
| 1116 | m_currentMsg = item.m_msg; |
| 1117 | m_currentMsgQueueSource = _queue; |
| 1118 | m_msgQueue[_queue].pop_front(); |
| 1119 | if( m_msgQueue[_queue].empty() ) |
| 1120 | { |
| 1121 | m_queueEvent[_queue]->Reset(); |
| 1122 | } |
| 1123 | if (m_nonceReportSent > 0) { |
| 1124 | MsgQueueItem item_new; |
| 1125 | item_new.m_command = MsgQueueCmd_SendMsg; |
| 1126 | item_new.m_nodeId = item.m_msg->GetTargetNodeId(); |
| 1127 | item_new.m_retry = item.m_retry; |
| 1128 | item_new.m_msg = new Msg(*item.m_msg); |
| 1129 | m_msgQueue[_queue].push_front(item_new); |
| 1130 | m_queueEvent[_queue]->Set(); |
| 1131 | } |
| 1132 | m_sendMutex->Unlock(); |
| 1133 | return WriteMsg( "WriteNextMsg" ); |
| 1134 | } |
| 1135 | else if( MsgQueueCmd_QueryStageComplete == item.m_command ) |
| 1136 | { |
| 1137 | // Move to the next query stage |
| 1138 | m_currentMsg = NULL; |
| 1139 | Node::QueryStage stage = item.m_queryStage; |
| 1140 | m_msgQueue[_queue].pop_front(); |
| 1141 | if( m_msgQueue[_queue].empty() ) |
| 1142 | { |
| 1143 | m_queueEvent[_queue]->Reset(); |
| 1144 | } |
| 1145 | m_sendMutex->Unlock(); |
| 1146 | |
| 1147 | Node* node = GetNodeUnsafe( item.m_nodeId ); |
| 1148 | if( node != NULL ) |
| 1149 | { |
| 1150 | Log::Write( LogLevel_Detail, node->GetNodeId(), "Query Stage Complete (%s)", node->GetQueryStageName( stage ).c_str() ); |
| 1151 | if( !item.m_retry ) |
| 1152 | { |
| 1153 | node->QueryStageComplete( stage ); |
| 1154 | } |
| 1155 | node->AdvanceQueries(); |
| 1156 | return true; |
| 1157 | } |
| 1158 | } |
| 1159 | else if( MsgQueueCmd_Controller == item.m_command ) |
| 1160 | { |
nothing calls this directly
no test coverage detected