MCPcopy Create free account
hub / github.com/SoarGroup/Soar / Commit

Method Commit

Core/ClientSML/src/sml_ClientWorkingMemory.cpp:1327–1380  ·  view source on GitHub ↗

* @brief Send the most recent list of changes to working memory * over to the kernel. *************************************************************/

Source from the content-addressed store, hash-verified

1325* over to the kernel.
1326*************************************************************/
1327bool WorkingMemory::Commit()
1328{
1329 int deltas = m_DeltaList.GetSize() ;
1330
1331 // If nothing has changed, we have no work to do.
1332 // This allows us to call Commit() multiple times without causing problems
1333 // as later calls will be ignored if the current set of changes has been sent already.
1334 if (deltas == 0)
1335 {
1336 return true ;
1337 }
1338
1339 // Build the SML message we're doing to send.
1340 ElementXML* pMsg = GetConnection()->CreateSMLCommand(sml_Names::kCommand_Input) ;
1341
1342 // Add the agent parameter and as a side-effect, get a pointer to the <command> tag. This is an optimization.
1343 ElementXML_Handle hCommand = GetConnection()->AddParameterToSMLCommand(pMsg, sml_Names::kParamAgent, GetAgentName()) ;
1344 ElementXML command(hCommand) ;
1345
1346 // Build the list of WME changes
1347 for (int i = 0 ; i < deltas ; i++)
1348 {
1349 // Get the next change
1350 TagWme* pDelta = m_DeltaList.GetDelta(i) ;
1351
1352 // Add it as a child of the command tag
1353 // (the command takes ownership of the delta)
1354 command.AddChild(pDelta) ;
1355 }
1356
1357 // This is important. We are working with a subpart of pMsg.
1358 // If we retain ownership of the handle and delete the object
1359 // it will release the handle...deleting part of our message.
1360 command.Detach() ;
1361
1362 // We have transfered the list of deltas over to pMsg
1363 // so we need to clear the list, but not delete the tags that it contains.
1364 m_DeltaList.Clear(false) ;
1365
1366#ifdef _DEBUG
1367 // Generate a text form of the XML so we can look at it in the debugger.
1368 char* pStr = pMsg->GenerateXMLString(true) ;
1369 pMsg->DeleteString(pStr) ;
1370#endif
1371
1372 // Send the message
1373 AnalyzeXML response ;
1374 bool ok = GetConnection()->SendMessageGetResponse(&response, pMsg) ;
1375
1376 // Clean up
1377 delete pMsg ;
1378
1379 return ok ;
1380}
1381
1382/*************************************************************
1383* @brief Resend the complete input link to the kernel

Callers

nothing calls this directly

Calls 9

CreateSMLCommandMethod · 0.80
GetConnectionFunction · 0.70
AddChildMethod · 0.45
DetachMethod · 0.45
ClearMethod · 0.45
GenerateXMLStringMethod · 0.45
DeleteStringMethod · 0.45

Tested by

no test coverage detected