X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fevent.h;fp=source%2Fevent.h;h=091d637814d57e3999885e29952fcab7d843e9ca;hp=0000000000000000000000000000000000000000;hb=1013e3c216cdf8e0ecc0f3b1e8314989b5333818;hpb=5780f0826f057f99593de46a583be7c098efaf90 diff --git a/source/event.h b/source/event.h new file mode 100644 index 0000000..091d637 --- /dev/null +++ b/source/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