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

Method RegisterForUpdateEvent

Core/ClientSML/src/sml_ClientKernel.cpp:1947–1978  ·  view source on GitHub ↗

* @brief Register for an "UpdateEvent". * Multiple handlers can be registered for the same event. * @param smlEventId The event we're interested in (see the list below for valid values) * @param handler A function that will be called when the event happens * @param pUserData Arbitrary data that will be passed back to the handler function when the event happens. * @param addT

Source from the content-addressed store, hash-verified

1945* @returns A unique ID for this callback (used to unregister the callback later)
1946*************************************************************/
1947int Kernel::RegisterForUpdateEvent(smlUpdateEventId id, UpdateEventHandler handler, void* pUserData, bool addToBack)
1948{
1949 // Start by checking if this id, handler, pUSerData combination has already been registered
1950 TestUpdateCallbackFull test(id, handler, pUserData) ;
1951
1952 // See if this handler is already registered
1953 UpdateEventHandlerPlusData plus(0, 0, 0, 0) ;
1954 bool found = m_UpdateEventMap.findFirstValueByTest(&test, &plus) ;
1955
1956 if (found && plus.m_Handler != 0)
1957 {
1958 return plus.getCallbackID() ;
1959 }
1960
1961 // If we have no handlers registered with the kernel, then we need
1962 // to register for this event. No need to do this multiple times.
1963 if (m_UpdateEventMap.getListSize(id) == 0)
1964 {
1965 RegisterForEventWithKernel(id, NULL) ;
1966 }
1967
1968 // Record the handler
1969 // We use a struct rather than a pointer to a struct, so there's no need to new/delete
1970 // everything as the objects are added and deleted.
1971 m_CallbackIDCounter++ ;
1972
1973 UpdateEventHandlerPlusData handlerPlus(id, handler, pUserData, m_CallbackIDCounter) ;
1974 m_UpdateEventMap.add(id, handlerPlus, addToBack) ;
1975
1976 // Return the ID. We use this later to unregister the callback
1977 return m_CallbackIDCounter ;
1978}
1979
1980/*************************************************************
1981* @brief Register for an "StringEvent".

Callers 11

RunTest1Function · 0.80
RunTest2Function · 0.80
RunTest3Function · 0.80
RunTest4Function · 0.80
TEST_DEFINITIONFunction · 0.80
doTestMethod · 0.80
RegisterForEventsFunction · 0.80
TestPythonSML.pyFile · 0.80

Calls 4

findFirstValueByTestMethod · 0.45
getCallbackIDMethod · 0.45
getListSizeMethod · 0.45
addMethod · 0.45

Tested by 7

RunTest1Function · 0.64
RunTest2Function · 0.64
RunTest3Function · 0.64
RunTest4Function · 0.64
TEST_DEFINITIONFunction · 0.64
doTestMethod · 0.64
RegisterForEventsFunction · 0.64