#include "xController.h" xController::xController(): _handlers() {} xController::~xController(){ _handlers.clear(); } // called in scheduling void xController::handleEvent(SDL_Event* event){ _mutex.lock(); map::iterator found = _handlers.find( (SDL_EventType) event->type ); // ignore no handler found if( found == _handlers.end() ){ _mutex.unlock(); return; } (*found->second)(event); _mutex.unlock(); } // bind a new handler void xController::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ){ _mutex.lock(); _handlers[ t ] = handler; _mutex.unlock(); } // removes an existing handler void xController::detachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ){ _mutex.lock(); _handlers.erase(t); _mutex.unlock(); }