* @brief Take an incoming command and call the appropriate * handler to process it. *************************************************************/
| 576 | * handler to process it. |
| 577 | *************************************************************/ |
| 578 | bool KernelSML::ProcessCommand(char const* pCommandName, Connection* pConnection, AnalyzeXML* pIncoming, soarxml::ElementXML* pResponse) |
| 579 | { |
| 580 | // Look up the function that handles this command |
| 581 | CommandFunction pFunction = m_CommandMap[pCommandName] ; |
| 582 | |
| 583 | if (!pFunction) |
| 584 | { |
| 585 | // There is no handler for this command |
| 586 | std::stringstream msg; |
| 587 | msg << "Command " << pCommandName << " is not recognized by the kernel" ; |
| 588 | |
| 589 | AddErrorMsg(pConnection, pResponse, msg.str().c_str()) ; |
| 590 | return false ; |
| 591 | } |
| 592 | |
| 593 | // Look up the agent name parameter (most commands have this) |
| 594 | char const* pAgentName = pIncoming->GetArgString(sml_Names::kParamAgent) ; |
| 595 | |
| 596 | AgentSML* pAgentSML = NULL ; |
| 597 | |
| 598 | if (pAgentName) |
| 599 | { |
| 600 | pAgentSML = GetAgentSML(pAgentName) ; |
| 601 | |
| 602 | if (!pAgentSML) |
| 603 | { |
| 604 | // Failed to find this agent |
| 605 | std::stringstream msg; |
| 606 | msg << "Could not find an agent with name: " << pAgentName ; |
| 607 | AddErrorMsg(pConnection, pResponse, msg.str().c_str()) ; |
| 608 | return false ; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Call to the handler (this is a pointer to member call so it's a bit odd) |
| 613 | bool result = (this->*pFunction)(pAgentSML, pCommandName, pConnection, pIncoming, pResponse) ; |
| 614 | |
| 615 | // If we return false, we report a generic error about the call. |
| 616 | if (!result) |
| 617 | { |
| 618 | std::stringstream msg; |
| 619 | msg << "The call " << pCommandName << " failed to execute correctly." ; |
| 620 | AddErrorMsg(pConnection, pResponse, msg.str().c_str()) ; |
| 621 | return false ; |
| 622 | } |
| 623 | |
| 624 | return true ; |
| 625 | } |
| 626 | |
| 627 | /************************************************************* |
| 628 | * @brief Takes an incoming SML message and responds with |
no test coverage detected