all test done
This commit is contained in:
		@@ -27,6 +27,7 @@ interface::XFDispatcher * interface::XFDispatcher::getInstance() {
 | 
			
		||||
// TODO done: Implement code for XFDispatcher class
 | 
			
		||||
 | 
			
		||||
XFDispatcher::XFDispatcher() {
 | 
			
		||||
    this->pMutex_ = interface::XFMutex::create();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XFDispatcher::~XFDispatcher() {
 | 
			
		||||
@@ -47,7 +48,9 @@ void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const {
 | 
			
		||||
 | 
			
		||||
void XFDispatcher::pushEvent(XFEvent *pEvent) {
 | 
			
		||||
    //Trace::out("[DEBUG] - Push Event");
 | 
			
		||||
    this->pMutex_->lock();
 | 
			
		||||
    events_.push(pEvent, false);
 | 
			
		||||
    this->pMutex_->unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) {
 | 
			
		||||
@@ -60,13 +63,19 @@ void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBeha
 | 
			
		||||
 | 
			
		||||
void XFDispatcher::executeOnce() {
 | 
			
		||||
    if(!this->events_.empty()) {
 | 
			
		||||
        dispatchEvent(this->events_.front());
 | 
			
		||||
 | 
			
		||||
        this->pMutex_->lock();
 | 
			
		||||
        const XFEvent *ev = this->events_.front();
 | 
			
		||||
        this->events_.pop();
 | 
			
		||||
        this->pMutex_->unlock();
 | 
			
		||||
 | 
			
		||||
        dispatchEvent(ev);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int XFDispatcher::execute(const void *param) {
 | 
			
		||||
    (void) param;
 | 
			
		||||
    while(true){
 | 
			
		||||
        this->executeOnce();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ XFTimeoutManager::~XFTimeoutManager() {
 | 
			
		||||
 | 
			
		||||
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
 | 
			
		||||
    this->pMutex_->lock();
 | 
			
		||||
    this->timeouts_.push_front(pNewTimeout);
 | 
			
		||||
    this->timeouts_.push_back(pNewTimeout);
 | 
			
		||||
    this->pMutex_->unlock();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -89,6 +89,7 @@ void XFTimeoutManager::tick() {
 | 
			
		||||
                XFEvent* ev = *(it);
 | 
			
		||||
                XFDispatcher::getInstance()->pushEvent(ev);
 | 
			
		||||
                it = this->timeouts_.erase(it);
 | 
			
		||||
                it--;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        this->pMutex_->unlock();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user