X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fevent.cpp;fp=source%2Fevent.cpp;h=0000000000000000000000000000000000000000;hp=01b8542a6225c2d0fb7cd703e4bb32d93283ce32;hb=e1ea831a640fba534e7e42e399f04cdf681ef8d3;hpb=0bcb8d4d6f33cbdad7b921cac787740bfe8e212e diff --git a/source/event.cpp b/source/event.cpp deleted file mode 100644 index 01b8542..0000000 --- a/source/event.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -This file is part of libmspframework -Copyright © 2006 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ -#ifdef WIN32 -#include -#include -#endif - -#include "application.h" -#include "event.h" - -using namespace std; - -namespace Msp { - -EventManager::EventManager(Application &a): - app(a), - next_id(1) -{ - app.add_pollable(&pipe, POLLIN).signal_event.connect(sigc::mem_fun(this, &EventManager::data_available)); -} - -EventManager::Event &EventManager::create_event() -{ - events.push_back(Event(*this, next_id++)); - return events.back(); -} - -void EventManager::data_available(short) -{ - unsigned buf[1024]; - int len=pipe.read((char *)buf, sizeof(buf)); - for(unsigned i=0; i*sizeof(unsigned)<(unsigned)len; ++i) - { - for(list::iterator j=events.begin(); j!=events.end(); ++j) - if(j->get_id()==buf[i]) - j->signal_triggered.emit(); - } -} - -void EventManager::Event::trigger() -{ - mgr.pipe.write((char *)&id, sizeof(id)); -} - -EventManager::Pipe::Pipe() -{ -#ifdef WIN32 - _pipe(fd, 1024, _O_BINARY); -#else - ::pipe(fd); -#endif -} - -int EventManager::Pipe::write(char *buf, unsigned len) -{ -#ifdef WIN32 - return _write(fd[1], buf, len); -#else - return ::write(fd[1], buf, len); -#endif -} - -int EventManager::Pipe::read(char *buf, unsigned len) -{ -#ifdef WIN32 - return _read(fd[0], buf, len); -#else - return ::read(fd[0], buf, len); -#endif -} - -} // namespace Msp