71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
#include <cassert>
|
|
#include <config/xf-config.h>
|
|
|
|
#if (USE_XF_COMMON_DISPATCHER_CLASS != 0)
|
|
#if defined(XF_TRACE_EVENT_PUSH_POP) && (XF_TRACE_EVENT_PUSH_POP != 0)
|
|
#include "trace/trace.h"
|
|
#endif // XF_TRACE_EVENT_PUSH_POP
|
|
#include "xf/interface/timeoutmanager.h"
|
|
#include "xf/interface/behavior.h"
|
|
#include "xf/interface/mutex.h"
|
|
#include "dispatcher.h"
|
|
|
|
using interface::XFTimeoutManager; // Allows to use expression 'XFTimeoutManager' instead of 'interface::XFTimeoutManager'.
|
|
using interface::XFBehavior; // Expression XFBehavior used in code below is in fact the XFBehavior interface class.
|
|
using Mutex = interface::XFMutex; // Rename XFMutex interface class to Mutex for easier use.
|
|
|
|
// Implementation of the getInstance() method of the 'interface::XFDispatcher' class.
|
|
//
|
|
// Note: The implementation is done here because only in this file the real XFDispatcher
|
|
// class is known (port specific class). An instance of the XFDispatcher class is
|
|
// returned by the 'interface::XFDispatcher' class.
|
|
interface::XFDispatcher * interface::XFDispatcher::getInstance() {
|
|
static ::XFDispatcher dispatcher;
|
|
return &dispatcher;
|
|
}
|
|
|
|
// TODO: Implement code for XFDispatcher class
|
|
|
|
XFDispatcher::XFDispatcher() {
|
|
|
|
}
|
|
|
|
XFDispatcher::~XFDispatcher() {
|
|
|
|
}
|
|
|
|
void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const {
|
|
if(pEvent->getBehavior()->process(pEvent)) { // TODO look weird
|
|
//events_.pop();
|
|
delete pEvent;
|
|
}
|
|
}
|
|
|
|
void XFDispatcher::pushEvent(XFEvent *pEvent) {
|
|
events_.push(pEvent);
|
|
}
|
|
|
|
void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) {
|
|
XFTimeoutManager::getInstance()->scheduleTimeout(timeoutId, interval, pBehavior);
|
|
}
|
|
|
|
void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior) {
|
|
XFTimeoutManager::getInstance()->unscheduleTimeout(timeoutId, pBehavior);
|
|
}
|
|
|
|
void XFDispatcher::executeOnce() {
|
|
//XFEvent* event;
|
|
dispatchEvent(events_.front());
|
|
events_.pop();
|
|
|
|
}
|
|
|
|
int XFDispatcher::execute(const void *param) {
|
|
while(true){
|
|
executeOnce();
|
|
}
|
|
}
|
|
|
|
|
|
#endif // USE_XF_COMMON_DISPATCHER_CLASS
|