X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fevent.h;fp=source%2Fcore%2Fevent.h;h=091d637814d57e3999885e29952fcab7d843e9ca;hb=e1ea831a640fba534e7e42e399f04cdf681ef8d3;hp=0000000000000000000000000000000000000000;hpb=0bcb8d4d6f33cbdad7b921cac787740bfe8e212e;p=libs%2Fcore.git diff --git a/source/core/event.h b/source/core/event.h new file mode 100644 index 0000000..091d637 --- /dev/null +++ b/source/core/event.h @@ -0,0 +1,61 @@ +/* +This file is part of libmspframework +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_FRAMEWORK_EVENT_H_ +#define MSP_FRAMEWORK_EVENT_H_ + +#include +#include "pollable.h" + +namespace Msp { + +class Application; + +/** +Events can be used in multi-threaded applictions to trigger actions in the main +thread. +*/ +class EventManager +{ +public: + class Event + { + public: + sigc::signal signal_triggered; + + Event(EventManager &m, unsigned i): mgr(m), id(i) { } + unsigned get_id() const { return id; } + void trigger(); + private: + EventManager &mgr; + unsigned id; + }; + + EventManager(Application &); + Event &create_event(); +private: + class Pipe: public Pollable + { + public: + Pipe(); + int write(char *, unsigned); + int read(char *, unsigned); + private: + int fd[2]; + + int get_fd() { return fd[0]; } + }; + + Application &app; + Pipe pipe; + unsigned next_id; + std::list events; + + void data_available(short); +}; + +} // namespace Msp + +#endif