ScummVM API documentation
notification.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1995-1997 Presto Studios, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef PEGASUS_NOTIFICATION_H
26 #define PEGASUS_NOTIFICATION_H
27 
28 #include "common/array.h"
29 #include "common/list.h"
30 
31 #include "pegasus/types.h"
32 #include "pegasus/util.h"
33 
34 namespace Pegasus {
35 
36 class NotificationManager;
37 class NotificationReceiver;
38 
39 struct ReceiverEntry {
40  NotificationReceiver *receiver;
41  NotificationFlags mask;
42 };
43 
44 int operator==(const ReceiverEntry &entry1, const ReceiverEntry &entry2);
45 int operator!=(const ReceiverEntry &entry1, const ReceiverEntry &entry2);
46 
48 
49 /*
50  A notification can have 32 flags associated with it, which can be user-defined.
51 */
52 
53 class Notification : public IDObject {
54 friend class NotificationManager;
55 
56 public:
57  Notification(const NotificationID id, NotificationManager *owner);
58  virtual ~Notification();
59 
60  // notifyMe will have this receiver notified when any of the specified notification
61  // flags are set.
62  // If there is already a notification set for this receiver, notifyMe does a bitwise
63  // OR with the receiver's current notification flags.
64 
65  // Can selectively set or clear notification bits by using the flags and mask argument.
66 
67  void notifyMe(NotificationReceiver*, NotificationFlags flags, NotificationFlags mask);
68  void cancelNotification(NotificationReceiver *receiver);
69 
70  void setNotificationFlags(NotificationFlags flags, NotificationFlags mask);
71  NotificationFlags getNotificationFlags() { return _currentFlags; }
72 
73  void clearNotificationFlags() { setNotificationFlags(0, ~(NotificationFlags)0); }
74 
75 protected:
76  void checkReceivers();
77 
78  NotificationManager *_owner;
79  ReceiverList _receivers;
80  NotificationFlags _currentFlags;
81 };
82 
84 friend class Notification;
85 
86 public:
88  virtual ~NotificationReceiver();
89 
90 protected:
91  // receiveNotification is called automatically whenever a notification that this
92  // receiver depends on has its flags set
93 
94  virtual void receiveNotification(Notification *, const NotificationFlags);
95  virtual void newNotification(Notification *notification);
96 
97 private:
98  Notification *_notification;
99 };
100 
102 
104 friend class Notification;
105 
106 public:
108  ~NotificationManager() override;
109 
110  void checkNotifications();
111 
112 protected:
113  void addNotification(Notification *notification);
114  void removeNotification(Notification *notification);
115  void detachNotifications();
116 
117  NotificationList _notifications;
118 };
119 
120 } // End of namespace Pegasus
121 
122 #endif
Definition: util.h:38
Definition: notification.h:53
Definition: notification.h:39
Definition: notification.h:103
Definition: notification.h:83
Definition: ai_action.h:33