xmario/xSDL/xController.cpp

35 lines
681 B
C++

#include "xController.h"
xController::xController():
_handlers()
{}
xController::~xController(){
_handlers.clear();
}
// called in scheduling
void xController::handleEvent(SDL_Event* event){
_mutex.lock();
for( set<xEventHandler*>::iterator it = _handlers.begin() ; it != _handlers.end() ; it++ ){
xEventHandler* handler = (*it);
handler->handle(event);
}
_mutex.unlock();
}
// bind a new handler
void xController::attachEvent(xEventHandler* handler){
_mutex.lock();
_handlers.insert(handler);
_mutex.unlock();
}
// removes an existing handler
void xController::detachEvent(xEventHandler* handler){
_mutex.lock();
_handlers.erase(handler);
_mutex.unlock();
}