X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpoller.h;fp=source%2Fpoller.h;h=b299b75334efb64d2661f9fbb286e65ee29a6bf7;hb=1013e3c216cdf8e0ecc0f3b1e8314989b5333818;hp=0000000000000000000000000000000000000000;hpb=5780f0826f057f99593de46a583be7c098efaf90;p=libs%2Fcore.git diff --git a/source/poller.h b/source/poller.h new file mode 100644 index 0000000..b299b75 --- /dev/null +++ b/source/poller.h @@ -0,0 +1,52 @@ +/* +This file is part of libmspframework +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_FRAMEWORK_POLLER_H_ +#define MSP_FRAMEWORK_POLLER_H_ + +#include +#include +#include +#include "mutex.h" + +namespace Msp { + +class Pollable; + +class Poller +{ +public: + class Slot + { + public: + sigc::signal signal_event; + + Slot(Pollable *, short); + Pollable *get_object() const { return obj; } + short get_events() const { return events; } + private: + Pollable *obj; + short events; + + void obj_deleted() { obj=0; } + }; + + Slot &add_pollable(Pollable *, short); + int poll(int =0); +private: + std::list slots; + std::vector pfd; + Mutex slots_mutex; + Mutex pfd_mutex; + bool dirty; + + void remove_stale_slots(); + void rebuild_pfd(); + void pollable_deleted(Pollable *); +}; + +}; + +#endif