* @brief Retrieve any messages we've been sent and process them. * * Returns true if at least one message has been read. *************************************************************/
| 311 | * Returns true if at least one message has been read. |
| 312 | *************************************************************/ |
| 313 | bool EmbeddedConnectionAsynch::ReceiveMessages(bool allMessages) |
| 314 | { |
| 315 | // Make sure only one thread is sending messages at a time |
| 316 | // (This allows us to run a separate thread in clients polling for events even |
| 317 | // when the client is sleeping, but we don't want them both to be sending/receiving at the same time). |
| 318 | soar_thread::Lock lock(&m_ClientMutex) ; |
| 319 | |
| 320 | bool receivedMessage = false ; |
| 321 | |
| 322 | ElementXML* pIncomingMsg = PopIncomingMessageQueue() ; |
| 323 | |
| 324 | // While we have messages waiting to come in keep reading them |
| 325 | while (pIncomingMsg) |
| 326 | { |
| 327 | // Record that we got at least one message |
| 328 | receivedMessage = true ; |
| 329 | |
| 330 | // Pass this message back to the client and possibly get their response |
| 331 | ElementXML* pResponse = this->InvokeCallbacks(pIncomingMsg) ; |
| 332 | |
| 333 | // If we got a response to the incoming message, send that response back. |
| 334 | if (pResponse) |
| 335 | { |
| 336 | SendMsg(pResponse) ; |
| 337 | } |
| 338 | |
| 339 | // We're done with the response |
| 340 | delete pResponse ; |
| 341 | |
| 342 | // Record the last incoming message |
| 343 | delete m_pLastResponse ; |
| 344 | m_pLastResponse = pIncomingMsg ; |
| 345 | |
| 346 | // If we're only asked to read one message, we're done. |
| 347 | if (!allMessages) |
| 348 | { |
| 349 | break ; |
| 350 | } |
| 351 | |
| 352 | // Get the next message from the queue |
| 353 | pIncomingMsg = PopIncomingMessageQueue() ; |
| 354 | } |
| 355 | |
| 356 | return receivedMessage ; |
| 357 | } |
nothing calls this directly
no test coverage detected