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 | |
---|
29 | /** |
---|
30 | @file NotificationManager.h |
---|
31 | @brief Definition of the NotificationManager class. |
---|
32 | @ingroup Notifications |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _NotificationManager_H__ |
---|
36 | #define _NotificationManager_H__ |
---|
37 | |
---|
38 | #include "notifications/NotificationsPrereqs.h" |
---|
39 | |
---|
40 | #include <ctime> |
---|
41 | #include <map> |
---|
42 | #include <string> |
---|
43 | |
---|
44 | #include "util/Singleton.h" |
---|
45 | #include "interfaces/NotificationListener.h" |
---|
46 | |
---|
47 | namespace orxonox // tolua_export |
---|
48 | { // tolua_export |
---|
49 | |
---|
50 | /** |
---|
51 | @brief |
---|
52 | The Singleton NotificationManager functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationListener "NotificationListeners". |
---|
53 | It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationListener "NotificationListeners". |
---|
54 | It also provides a static function to send @ref orxonox::Notification "Notifications" and works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer. |
---|
55 | |
---|
56 | @author |
---|
57 | Damian 'Mozork' Frick |
---|
58 | |
---|
59 | @ingroup Notifications |
---|
60 | */ |
---|
61 | class _NotificationsExport NotificationManager // tolua_export |
---|
62 | : public Singleton<NotificationManager>, public NotificationListener |
---|
63 | { // tolua_export |
---|
64 | friend class Singleton<NotificationManager>; |
---|
65 | public: |
---|
66 | NotificationManager(); |
---|
67 | virtual ~NotificationManager(); |
---|
68 | |
---|
69 | virtual void preDestroy(void); //!< Is called before the object is destroyed. |
---|
70 | |
---|
71 | /** |
---|
72 | @brief Get the instance of the NotificationManager Singleton. |
---|
73 | @return Returns a reference to the NotificationManager. |
---|
74 | */ |
---|
75 | static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export |
---|
76 | |
---|
77 | virtual bool registerNotification(const std::string& message, const std::string& sender); |
---|
78 | |
---|
79 | bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. |
---|
80 | void unregisterNotification(Notification* notification, NotificationQueue* queue); //!< Unregisters a Notification within the NotificationManager for a given NotificationQueue. |
---|
81 | |
---|
82 | 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. |
---|
83 | |
---|
84 | /** |
---|
85 | @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from now-timeDelay to now and stores them in the input map. |
---|
86 | @param listener The NotificationQueue the Notifications are fetched for. |
---|
87 | @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. |
---|
88 | @param timeDelay The timespan. |
---|
89 | @return Returns true if successful. |
---|
90 | */ |
---|
91 | void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay) |
---|
92 | { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); } |
---|
93 | |
---|
94 | 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. |
---|
95 | |
---|
96 | void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer. |
---|
97 | |
---|
98 | bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue. |
---|
99 | void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue. |
---|
100 | |
---|
101 | // tolua_begin |
---|
102 | void loadQueues(void); //!< Loads all the NotificationQueues that should exist. |
---|
103 | void createQueue(const std::string& name); //!< Creates a new NotificationQueue. |
---|
104 | orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name. |
---|
105 | // tolua_end |
---|
106 | |
---|
107 | private: |
---|
108 | static NotificationManager* singletonPtr_s; |
---|
109 | |
---|
110 | std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. |
---|
111 | 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. |
---|
112 | |
---|
113 | std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. |
---|
114 | |
---|
115 | bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map. |
---|
116 | |
---|
117 | }; // tolua_export |
---|
118 | |
---|
119 | } // tolua_export |
---|
120 | |
---|
121 | #endif /* _NotificationManager_H__ */ |
---|