* @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
| 1945 | * @returns A unique ID for this callback (used to unregister the callback later) |
| 1946 | *************************************************************/ |
| 1947 | int 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". |