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

Method RegisterForStringEvent

Core/ClientSML/src/sml_ClientKernel.cpp:1993–2024  ·  view source on GitHub ↗

* @brief Register for an "StringEvent". * 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

1991* @returns A unique ID for this callback (used to unregister the callback later)
1992*************************************************************/
1993int Kernel::RegisterForStringEvent(smlStringEventId id, StringEventHandler handler, void* pUserData, bool addToBack)
1994{
1995 // Start by checking if this id, handler, pUserData combination has already been registered
1996 TestStringCallbackFull test(id, handler, pUserData) ;
1997
1998 // See if this handler is already registered
1999 StringEventHandlerPlusData plus(0, 0, 0, 0) ;
2000 bool found = m_StringEventMap.findFirstValueByTest(&test, &plus) ;
2001
2002 if (found && plus.m_Handler != 0)
2003 {
2004 return plus.getCallbackID() ;
2005 }
2006
2007 // If we have no handlers registered with the kernel, then we need
2008 // to register for this event. No need to do this multiple times.
2009 if (m_StringEventMap.getListSize(id) == 0)
2010 {
2011 RegisterForEventWithKernel(id, NULL) ;
2012 }
2013
2014 // Record the handler
2015 // We use a struct rather than a pointer to a struct, so there's no need to new/delete
2016 // everything as the objects are added and deleted.
2017 m_CallbackIDCounter++ ;
2018
2019 StringEventHandlerPlusData handlerPlus(id, handler, pUserData, m_CallbackIDCounter) ;
2020 m_StringEventMap.add(id, handlerPlus, addToBack) ;
2021
2022 // Return the ID. We use this later to unregister the callback
2023 return m_CallbackIDCounter ;
2024}
2025
2026/*************************************************************
2027* @brief Register for an "AgentEvent".

Calls 4

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

Tested by 2

TEST_DEFINITIONFunction · 0.64
RegisterForEventsFunction · 0.64