* @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
| 1899 | * @returns Unique ID for this callback. Required when unregistering this callback. |
| 1900 | *************************************************************/ |
| 1901 | int 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". |