2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
11 #include "application.h"
18 EventManager::EventManager(Application &a):
22 app.add_pollable(&pipe, POLLIN).signal_event.connect(sigc::mem_fun(this, &EventManager::data_available));
25 EventManager::Event &EventManager::create_event()
27 events.push_back(Event(*this, next_id++));
31 void EventManager::data_available(short)
34 int len=pipe.read((char *)buf, sizeof(buf));
35 for(unsigned i=0; i*sizeof(unsigned)<(unsigned)len; ++i)
37 for(list<Event>::iterator j=events.begin(); j!=events.end(); ++j)
38 if(j->get_id()==buf[i])
39 j->signal_triggered.emit();
43 void EventManager::Event::trigger()
45 mgr.pipe.write((char *)&id, sizeof(id));
48 EventManager::Pipe::Pipe()
51 _pipe(fd, 1024, _O_BINARY);
57 int EventManager::Pipe::write(char *buf, unsigned len)
60 return _write(fd[1], buf, len);
62 return ::write(fd[1], buf, len);
66 int EventManager::Pipe::read(char *buf, unsigned len)
69 return _read(fd[0], buf, len);
71 return ::read(fd[0], buf, len);