Add i8042 back
[qemupp.git] / include / notify.hpp
bloba24557d202fc2cd25cee76f5a0428fa264034804
1 #ifndef NOTIFY_HPP
2 #define NOTIFY_HPP
4 #include <functional>
5 #include <list>
6 #include <utility>
8 typedef std::function<void (void)> Notifier;
9 typedef std::list<std::pair<int, Notifier> > NotifierList;
10 typedef NotifierList::iterator NotifierHandle;
12 class Notifiable
14 public:
15 void disconnect(NotifierHandle handle) {
16 this->notifier_list.erase(handle);
19 protected:
20 NotifierHandle connect(int type, Notifier notifier) {
21 NotifierList &nl = this->notifier_list;
22 std::pair<int, Notifier> item(type, notifier);
23 return nl.insert(nl.end(), item);
26 void notify(int event) {
27 NotifierList &nl = this->notifier_list;
28 NotifierList::iterator i;
30 for (i = nl.begin(); i != nl.end(); ++i) {
31 if (i->first == event) {
32 i->second();
37 private:
38 NotifierList notifier_list;
41 #endif