handle and destroy those frigging event loops, all, god, 4 hours....

This commit is contained in:
Jan Kaluza 2011-08-17 18:50:59 +02:00
parent 9fdc06d793
commit a1d9abd984
2 changed files with 12 additions and 3 deletions

View file

@ -30,16 +30,18 @@
using namespace Swift;
static SpectrumEventLoop *loop;
// Fires the event's callback and frees the event
static gboolean processEvent(void *data) {
Event *ev = (Event *) data;
ev->callback();
delete ev;
loop->handle(ev);
return FALSE;
}
SpectrumEventLoop::SpectrumEventLoop() : m_isRunning(false) {
m_loop = NULL;
loop = this;
if (true) {
m_loop = g_main_loop_new(NULL, FALSE);
}
@ -67,6 +69,11 @@ void SpectrumEventLoop::run() {
#endif
}
void SpectrumEventLoop::handle(Swift::Event *event) {
handleEvent(*event);
delete event;
}
void SpectrumEventLoop::stop() {
std::cout << "stopped loop\n";
if (!m_isRunning)
@ -85,6 +92,6 @@ void SpectrumEventLoop::stop() {
void SpectrumEventLoop::post(const Event& event) {
// pass copy of event to main thread
Event *ev = new Event(event.owner, event.callback);
Event *ev = new Event(event);
purple_timeout_add(0, processEvent, ev);
}

View file

@ -38,6 +38,8 @@ class SpectrumEventLoop : public Swift::EventLoop {
// Stops tht eventloop.
void stop();
void handle(Swift::Event *event);
// Posts new Swift::Event to main thread.
virtual void post(const Swift::Event& event);