* @brief This function is called when an event is received * from the Soar kernel. * * @param pIncoming The event command * @param pResponse The reply (the result of executing this rhs function) *************************************************************/
| 656 | * @param pResponse The reply (the result of executing this rhs function) |
| 657 | *************************************************************/ |
| 658 | void Kernel::ReceivedRhsEvent(smlRhsEventId id, AnalyzeXML* pIncoming, ElementXML* pResponse) |
| 659 | { |
| 660 | // Get the function name and the argument to the function |
| 661 | // (We pass a single string but it could be parsed further to other values by the client) |
| 662 | char const* pFunctionName = pIncoming->GetArgString(sml_Names::kParamFunction) ; |
| 663 | char const* pArgument = pIncoming->GetArgString(sml_Names::kParamValue) ; |
| 664 | char const* pAgentName = pIncoming->GetArgString(sml_Names::kParamName) ; |
| 665 | |
| 666 | if (!pFunctionName) |
| 667 | { |
| 668 | // Should always include a function name |
| 669 | SetError(Error::kInvalidArgument) ; |
| 670 | return ; |
| 671 | } |
| 672 | |
| 673 | // Look up the handler(s) from the map |
| 674 | RhsEventMap::ValueList* pHandlers = m_RhsEventMap.getList(pFunctionName) ; |
| 675 | |
| 676 | if (!pHandlers) |
| 677 | { |
| 678 | return ; |
| 679 | } |
| 680 | |
| 681 | // Look up the agent |
| 682 | Agent* pAgent = pAgentName ? GetAgent(pAgentName) : NULL ; |
| 683 | |
| 684 | // Go through the list of event handlers calling each in turn...except |
| 685 | // we only execute the first handler (registering multipler handlers for the same RHS function is not supported |
| 686 | // because these functions return a value -- it wouldn't be clear which to use. We could change this to call all |
| 687 | // registered handlers and only use the first or last value returned.) |
| 688 | RhsEventMap::ValueListIter iter = pHandlers->begin() ; |
| 689 | |
| 690 | if (iter == pHandlers->end()) |
| 691 | { |
| 692 | return ; |
| 693 | } |
| 694 | |
| 695 | RhsEventHandlerPlusData handlerWithData = *iter ; |
| 696 | |
| 697 | RhsEventHandler handler = handlerWithData.m_Handler ; |
| 698 | void* pUserData = handlerWithData.getUserData() ; |
| 699 | |
| 700 | // Call the handler |
| 701 | std::string result = handler(id, pUserData, pAgent, pFunctionName, pArgument) ; |
| 702 | |
| 703 | // If we got back a result then fill in the value in the response message. |
| 704 | GetConnection()->AddSimpleResultToSMLResponse(pResponse, result.c_str()) ; |
| 705 | } |
| 706 | |
| 707 | Kernel* Kernel::CreateKernelInCurrentThread(bool optimized, int portToListenOn) |
| 708 | { |
nothing calls this directly
no test coverage detected