* @brief Invoke the list of callbacks matching the doctype of the incoming message. * * @param pIncomingMsg The SML message that should be passed to the callbacks. * @returns The response message (or NULL if there is no response from any callback). *************************************************************/
| 405 | * @returns The response message (or NULL if there is no response from any callback). |
| 406 | *************************************************************/ |
| 407 | ElementXML* Connection::InvokeCallbacks(ElementXML* pIncomingMsg) |
| 408 | { |
| 409 | ClearError() ; |
| 410 | |
| 411 | MessageSML* pIncomingSML = (MessageSML*)pIncomingMsg ; // MessageSML is a soarxml::ElementXML, not sml::ElementXML |
| 412 | |
| 413 | // Check that we were passed a valid message. |
| 414 | if (pIncomingMsg == NULL) |
| 415 | { |
| 416 | SetError(Error::kInvalidArgument) ; |
| 417 | return NULL ; |
| 418 | } |
| 419 | |
| 420 | // Retrieve the type of this message |
| 421 | char const* pType = pIncomingSML->GetDocType() ; |
| 422 | |
| 423 | // Check that this message has a valid doc type (all valid SML do) |
| 424 | if (pType == NULL) |
| 425 | { |
| 426 | SetError(Error::kNoDocType) ; |
| 427 | return NULL ; |
| 428 | } |
| 429 | |
| 430 | // Decide if this message is a "call" which requires a "response" |
| 431 | bool isIncomingCall = pIncomingSML->IsCall() ; |
| 432 | |
| 433 | // See if we have a list of callbacks for this type |
| 434 | CallbackList* pList = GetCallbackList(pType) ; |
| 435 | |
| 436 | // Nobody was interested in this type of message, so we're done. |
| 437 | if (pList == NULL) |
| 438 | { |
| 439 | return NULL ; |
| 440 | } |
| 441 | |
| 442 | CallbackListIter iter = pList->begin() ; |
| 443 | |
| 444 | // Walk the list of callbacks in turn until we reach |
| 445 | // the end or one returns a message. |
| 446 | while (iter != pList->end()) |
| 447 | { |
| 448 | Callback* pCallback = *iter ; |
| 449 | iter++ ; |
| 450 | |
| 451 | ElementXML* pResponse = pCallback->Invoke(pIncomingMsg) ; |
| 452 | |
| 453 | if (pResponse != NULL) |
| 454 | { |
| 455 | if (isIncomingCall) |
| 456 | { |
| 457 | return pResponse ; |
| 458 | } |
| 459 | |
| 460 | // This callback was not for a call and should not return a result. |
| 461 | // Delete the result and ignore it. |
| 462 | pResponse->ReleaseRefOnHandle() ; |
| 463 | pResponse = NULL ; |
| 464 | } |
no test coverage detected