]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/poller.h
Rename to libmspcore
[libs/core.git] / source / core / poller.h
diff --git a/source/core/poller.h b/source/core/poller.h
new file mode 100644 (file)
index 0000000..dcd3658
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+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_
+
+#ifdef WIN32
+#include "win32poll.h"
+#else
+#include <sys/poll.h>
+#endif
+#include <vector>
+#include <sigc++/sigc++.h>
+#include "mutex.h"
+
+namespace Msp {
+
+class Pollable;
+
+class Poller
+{
+public:
+       class Slot
+       {
+       public:
+               sigc::signal<void, short> 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<Slot *>   slots;
+       std::vector<pollfd> pfd;
+       Mutex               slots_mutex;
+       Mutex               pfd_mutex;
+       bool                dirty;
+
+       void remove_stale_slots();
+       void rebuild_pfd();
+       void pollable_deleted(Pollable *);
+};
+
+};
+
+#endif