Orxonox  0.0.5 Codename: Arcturus
NotificationManager.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Damian 'Mozork' Frick
24  * Co-authors:
25  * ...
26  *
27  */
28 
35 #ifndef _NotificationManager_H__
36 #define _NotificationManager_H__
37 
39 
40 #include <ctime>
41 #include <map>
42 #include <string>
43 
44 #include "util/Singleton.h"
46 
47 namespace orxonox // tolua_export
48 { // tolua_export
49 
62  {
63  public:
65  virtual ~Notification();
66 
70  void destroy(void)
71  { delete this; }
72 
77  inline const std::string & getMessage(void) const
78  { return this->message_; }
79 
84  inline const std::string & getSender(void) const
85  { return this->sender_; }
86 
91  inline NotificationMessageType getType(void) const
92  { return this->type_; }
93 
94  private:
98 
99  void initialize(void);
100 
101  };
102 
115  : public Singleton<NotificationManager>, public NotificationListener
116  { // tolua_export
118  public:
120  virtual ~NotificationManager();
121 
122  virtual void preDestroy(void) override; // Is called before the object is destroyed.
123 
129 
130  virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) override;
131  virtual bool executeCommand(NotificationCommand command, const std::string& sender) override;
132 
133  bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
134  void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
135 
136  void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); // Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map.
137 
145  void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
146  { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
147 
148  void getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); // Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map.
149 
150  bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
151  void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
152 
153  void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
154 
155  NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
156 
157  private:
159 
160  std::multimap<std::time_t, Notification*> allNotificationsList_;
161  std::map<const std::string, std::multimap<std::time_t, Notification*>*> notificationLists_;
162 
163  std::map<const std::string, NotificationQueue*> queues_;
164 
165  bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
166 
167  // Commands
168  bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
169 
170  }; // tolua_export
171 
172 } // tolua_export
173 
174 #endif /* _NotificationManager_H__ */
void destroy(void)
Destroys the Notification.
Definition: NotificationManager.h:70
::std::string string
Definition: gtest-port.h:756
NotificationCommand
Definition: NotificationListener.h:62
void getNotifications(NotificationQueue *queue, std::multimap< std::time_t, Notification * > *map, int timeDelay)
Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now...
Definition: NotificationManager.h:145
std::string message_
The Notification message.
Definition: NotificationManager.h:95
NotificationListener interface.
Definition: NotificationListener.h:83
Definition of the NotificationListener class.
static NotificationManager & getInstance()
Get the instance of the NotificationManager Singleton.
Definition: NotificationManager.h:128
The Singleton NotificationManager is a NotificationListener and functions as a gateway between Notifi...
Definition: NotificationManager.h:114
std::string sender_
The sender of the notification.
Definition: NotificationManager.h:96
Output level, used for messages directed to the user (e.g. "Press any key to continue") ...
Definition: OutputDefinitions.h:89
#define _NotificationsExport
Definition: NotificationsPrereqs.h:60
std::multimap< std::time_t, Notification * > allNotificationsList_
Container where all Notifications are stored.
Definition: NotificationManager.h:160
static NotificationManager * singletonPtr_s
Definition: NotificationManager.h:158
Displays Notifications from specific senders.
Definition: NotificationQueue.h:92
const std::string & getMessage(void) const
Get the message of the Notification.
Definition: NotificationManager.h:77
Base for singleton classes.
Definition: Singleton.h:114
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI() command(const std::string &fragment)
Returns a list of commands and groups and also supports auto-completion of the arguments of these com...
Definition: ArgumentCompletionFunctions.cc:178
Shared library macros, enums, constants and forward declarations for the questsystem module ...
const std::string & getSender(void) const
Get the sender of the Notification.
Definition: NotificationManager.h:84
A Notification represents a short message used to inform the player about something that just happene...
Definition: NotificationManager.h:61
Definition of the Singleton template that is used as base class for classes that allow only one insta...
NotificationMessageType getType(void) const
Get the type of the Notification.
Definition: NotificationManager.h:91
NotificationMessageType
Definition: NotificationListener.h:51
static T & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
NotificationMessageType type_
The type of the notification.
Definition: NotificationManager.h:97
std::map< const std::string, NotificationQueue * > queues_
The list of NotificationQueues created by the NotificationManager.
Definition: NotificationManager.h:163
std::map< const std::string, std::multimap< std::time_t, Notification * > * > notificationLists_
Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
Definition: NotificationManager.h:161