X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Feventobject.h;fp=source%2Fio%2Feventobject.h;h=b8423c927f1daa95dd517c961e83c3477cf42731;hb=c21ab7e49852585df01b4cc19599e25a918b581b;hp=0000000000000000000000000000000000000000;hpb=31e72f50fbb34d86877e5110401c49ce3fefd4bb;p=libs%2Fcore.git diff --git a/source/io/eventobject.h b/source/io/eventobject.h new file mode 100644 index 0000000..b8423c9 --- /dev/null +++ b/source/io/eventobject.h @@ -0,0 +1,54 @@ +#ifndef MSP_IO_EVENTOBJECT_H_ +#define MSP_IO_EVENTOBJECT_H_ + +#include "base.h" + +namespace Msp { +namespace IO { + +struct Handle; + +/** +Interface class for objects that can provide event-based I/O. These objects +can be fed to the various poll functions in poll.h, or added to an +EventDispatcher to generate event signals. +*/ +class EventObject: public Base +{ +public: + /** Emitted when there is data available for reading. If all data is not + read, the signal is emitted again immediately. */ + sigc::signal signal_data_available; + + /** Emitted when the mask of interesting events changes. Mainly for use by + EventDispatcher. */ + sigc::signal signal_events_changed; + +private: + PollEvent events; + +protected: + EventObject(); + + void set_events(PollEvent); +public: + /** Returns a mask of the currently interesting events. Used by + EventDispatcher. */ + PollEvent get_events() const { return events; } + + /** Returns a handle for polling. */ + virtual const Handle &get_event_handle() = 0; + + /** Notifies the object of an event. Used by EventDispatcher. */ + void event(PollEvent); + +protected: + /** Called when an event occurs. Derived classes can implement this to + process events. */ + virtual void on_event(PollEvent) { } +}; + +} // namespace IO +} // namespace Msp + +#endif