Created
March 2, 2012 16:48
-
-
Save mkroman/1959586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "visichat/controller.hpp" | |
using namespace VisiChat; | |
Controller::Controller() | |
{ | |
m_eventBase = event_base_new(); | |
} | |
void Controller::run() | |
{ | |
EVCallback<Controller> wrapper(this, &Controller::callback); | |
event* timerEvent = event_new(m_eventBase, -1, EV_TIMEOUT | EV_PERSIST, static_cast<event_callback_fn>(&wrapper), this); | |
timeval timeInterval = { 2, 0 }; | |
event_add(timerEvent, &timeInterval); | |
event_base_dispatch(m_eventBase); | |
} | |
void Controller::callback(int fd, short flags, void *data) | |
{ | |
std::cout << __PRETTY_FUNCTION__ << std::endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <event.h> | |
#include <time.h> | |
namespace VisiChat | |
{ | |
template<class T> | |
class EVCallback | |
{ | |
typedef void (T::*callbackFunctor)(int, short, void*); | |
public: | |
EVCallback(T* pInstance, callbackFunctor pFunctor) | |
: m_pInstance(pInstance), m_pFunctor(pFunctor) | |
{ | |
} | |
void operator()(int fileDescriptor, short flags, void* data) | |
{ | |
(m_pInstance->*m_pFunctor)(fileDescriptor, flags, data); | |
} | |
private: | |
T* m_pInstance; | |
callbackFunctor m_pFunctor; | |
}; | |
class Controller | |
{ | |
public: | |
Controller(); | |
void run(); | |
void close(); | |
void callback(int fd, short flags, void *data); | |
private: | |
event_base* m_eventBase; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment