* @brief If this message is an XML trace message returns * the agent pointer this message is for. * Otherwise returns NULL. * This function is just to boost performance on trace messages * which are really performance critical. *************************************************************/
| 343 | * which are really performance critical. |
| 344 | *************************************************************/ |
| 345 | Agent* Kernel::IsXMLTraceEvent(ElementXML* pIncomingMsg) |
| 346 | { |
| 347 | // The message we're looking for has this structure: |
| 348 | // <sml><command></command><trace></trace></sml> |
| 349 | // This is deliberately unusual so this simple test screens out |
| 350 | // almost all messages in one go. It does make us more brittle (for detecting |
| 351 | // xml trace messages) but I think that's a fair trade-off. |
| 352 | if (pIncomingMsg->GetNumberChildren() != 2) |
| 353 | { |
| 354 | return NULL ; |
| 355 | } |
| 356 | |
| 357 | ElementXML command(NULL) ; |
| 358 | ElementXML trace(NULL) ; |
| 359 | pIncomingMsg->GetChild(&command, 0) ; |
| 360 | pIncomingMsg->GetChild(&trace, 1) ; |
| 361 | |
| 362 | if (trace.IsTag(sml_Names::kTagTrace) && command.IsTag(sml_Names::kTagCommand) && command.GetNumberChildren() > 0) |
| 363 | { |
| 364 | ElementXML agentArg(NULL) ; |
| 365 | command.GetChild(&agentArg, 0) ; |
| 366 | |
| 367 | #ifdef _DEBUG |
| 368 | char const* pParam = agentArg.GetAttribute(sml_Names::kArgParam) ; |
| 369 | assert(pParam && strcmp(pParam, sml_Names::kParamAgent) == 0) ; |
| 370 | #endif |
| 371 | // Get the agent's name |
| 372 | char const* pAgentName = agentArg.GetCharacterData() ; |
| 373 | |
| 374 | if (!pAgentName || pAgentName[0] == 0) |
| 375 | { |
| 376 | return NULL ; |
| 377 | } |
| 378 | |
| 379 | // Look up the agent |
| 380 | Agent* pAgent = GetAgent(pAgentName) ; |
| 381 | |
| 382 | // If this fails, we got a trace event for a now deleted agent |
| 383 | // (must have been flushed after the agent was destroyed). |
| 384 | // Returning null is probably as good as we do here so |
| 385 | // always return pAgent (even if it's null). |
| 386 | return pAgent ; |
| 387 | } |
| 388 | |
| 389 | return NULL ; |
| 390 | } |
| 391 | |
| 392 | /************************************************************* |
| 393 | * @brief This function is called (indirectly) when we receive a "call" SML |
nothing calls this directly
no test coverage detected