summaryrefslogtreecommitdiffstats
blob: fbb70790ac1a033d6f9206c681306c3d9d27e1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef SWIFTEN_MainEventLoop_H
#define SWIFTEN_MainEventLoop_H

#include <boost/function.hpp>

#include "Swiften/EventLoop/Deleter.h"
#include "Swiften/EventLoop/EventLoop.h"

namespace Swift {
	class EventLoop;
	class EventOwner;

	class MainEventLoop {
			friend class EventLoop;

		public:
			/**
			 * Post an event from the given owner to the event loop.
			 * If the owner is destroyed, all events should be removed from the
			 * loop using removeEventsFromOwner().
			 */
			static void postEvent(boost::function<void ()> event, boost::shared_ptr<EventOwner> owner = boost::shared_ptr<EventOwner>());

			static void removeEventsFromOwner(boost::shared_ptr<EventOwner> owner);

			template<typename T>
			static void deleteLater(T* t) {
				getInstance()->postEvent(Deleter<T>(t), 0);
			}

		private:
			static void setInstance(EventLoop*);
			static void resetInstance();
			static EventLoop* getInstance();
		
		private:
			static EventLoop* instance_;
	};
}

#endif