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

Method RegisterForSystemEvent

Core/ClientSML/src/sml_ClientKernel.cpp:1901–1932  ·  view source on GitHub ↗

* @brief Register for a "SystemEvent". * 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 addTo

Source from the content-addressed store, hash-verified

1899* @returns Unique ID for this callback. Required when unregistering this callback.
1900*************************************************************/
1901int Kernel::RegisterForSystemEvent(smlSystemEventId id, SystemEventHandler handler, void* pUserData, bool addToBack)
1902{
1903 // Start by checking if this id, handler, pUSerData combination has already been registered
1904 TestSystemCallbackFull test(id, handler, pUserData) ;
1905
1906 // See if this handler is already registered
1907 SystemEventHandlerPlusData plus(0, 0, 0, 0) ;
1908 bool found = m_SystemEventMap.findFirstValueByTest(&test, &plus) ;
1909
1910 if (found && plus.m_Handler != 0)
1911 {
1912 return plus.getCallbackID() ;
1913 }
1914
1915 // If we have no handlers registered with the kernel, then we need
1916 // to register for this event. No need to do this multiple times.
1917 if (m_SystemEventMap.getListSize(id) == 0)
1918 {
1919 RegisterForEventWithKernel(id, NULL) ;
1920 }
1921
1922 // Record the handler
1923 // We use a struct rather than a pointer to a struct, so there's no need to new/delete
1924 // everything as the objects are added and deleted.
1925 m_CallbackIDCounter++ ;
1926
1927 SystemEventHandlerPlusData handlerPlus(id, handler, pUserData, m_CallbackIDCounter) ;
1928 m_SystemEventMap.add(id, handlerPlus, addToBack) ;
1929
1930 // Return the ID. We use this later to unregister the callback
1931 return m_CallbackIDCounter ;
1932}
1933
1934/*************************************************************
1935* @brief Register for an "UpdateEvent".

Callers 13

TestMethod · 0.95
mainFunction · 0.80
destroySoarMethod · 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 5

TestMethod · 0.76
destroySoarMethod · 0.64
RegisterForEventsFunction · 0.64
initializeMethod · 0.64