Adonthell  0.4
event_handler.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000/2001/2002/2003 Kai Sterker <kai.sterker@gmail.com>
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 /**
21  * @file event_handler.h
22  * @author Kai Sterker <kai.sterker@gmail.com>
23  *
24  * @brief Declares the event_handler class
25  *
26  */
27 
28 #ifndef EVENT_HANDLER_H__
29 #define EVENT_HANDLER_H__
30 
31 #include "event_handler_base.h"
32 #include "event_list.h"
33 
34 /**
35  * It ensures global access to the individual %event handlers.
36  */
38 {
39 public:
40  /**
41  * Instanciate the actual event handlers. Event handlers
42  * can be specific to a certain event, or take care of
43  * different events.
44  */
45  static void init ();
46 
47  /**
48  * Delete the %event handlers.
49  */
50  static void cleanup ();
51 
52  /**
53  * Unregister an %event.
54  *
55  * @param ev pointer to the %event to unregister.
56  */
57  static void remove_event (event* ev)
58  {
59  ev->set_registered (false);
60  Handler[ev->type ()]->remove_event (ev);
61  }
62 
63  /**
64  * Check if an %event corresponding to ev exists, and execute it.
65  *
66  * @param ev %event to raise.
67  */
68  static void raise_event (const event* ev)
69  {
70  Handler[ev->type ()]->raise_event (ev);
71  }
72 
73 protected:
74  /**
75  * Registers an %event.
76  *
77  * @param ev pointer to the %event to register.
78  */
79  static void register_event (event* ev)
80  {
81  ev->set_registered (true);
82  Handler[ev->type ()]->register_event (ev);
83  }
84 
85  /**
86  * Only %event_list is allowed to register events with the
87  * %event_handler.
88  */
89  friend void event_list::add_event (event* ev);
90 
91  /**
92  * As is event::resume.
93  */
94  friend void event::resume ();
95 
96 private:
97  /**
98  * A list of the actual %event handlers
99  */
100  static event_handler_base* Handler[MAX_EVENTS];
101 };
102 
103 #endif // EVENT_HANDLER_H__
static void raise_event(const event *ev)
Check if an event corresponding to ev exists, and execute it.
Definition: event_handler.h:68
This is the base class for actual event handlers.
virtual void remove_event(event *ev)=0
Unregister an event.
static void init()
Instanciate the actual event handlers.
Base class for events.
Definition: event.h:75
void add_event(event *ev)
Adds an event to this list.
Definition: event_list.cc:62
Declares the base class for event handlers.
void set_registered(bool reg)
Set whether the event is registered with the event handler.
Definition: event.h:143
virtual void resume()
Re-enable an event that has been paused.
Definition: event.cc:234
static void remove_event(event *ev)
Unregister an event.
Definition: event_handler.h:57
virtual void raise_event(const event *ev)=0
Check if an event corresponding to ev exists, and execute it.
static void cleanup()
Delete the event handlers.
static void register_event(event *ev)
Registers an event.
Definition: event_handler.h:79
virtual void register_event(event *ev)=0
Registers an event.
u_int8 type() const
Get the event&#39;s type.
Definition: event.h:102
It ensures global access to the individual event handlers.
Definition: event_handler.h:37
Declares the event_list class.