Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS16/src/modules/notifications/NotificationManager.h @ 11347

Last change on this file since 11347 was 11347, checked in by maxima, 7 years ago

dialog branch merged to presentation

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
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
47namespace orxonox // tolua_export
48{ // tolua_export
49
50    /**
51    @brief
52        A Notification represents a short message used to inform the player about something that just happened. With the @ref orxonox::NotificationManager "NotificationManager" a Notification can be sent from any part of orxonox and is then displayed by the proper @ref orxonox::NotificationQueue "NotificationQueue(s)" (depending on which senders the specific @ref orxonox::NotificationQueue "NotificationQueues" accepts).
53
54        A Notification is just a data structure that is used internally by the Notifications module.
55
56    @author
57        Damian 'Mozork' Frick
58
59    @ingroup Notifications
60    */
61    class _NotificationsExport Notification
62    {
63        public:
64            Notification(const std::string& message, const std::string& sender, NotificationMessageType type);
65            virtual ~Notification();
66
67            /**
68            @brief Destroys the Notification.
69            */
70            void destroy(void)
71                { delete this; }
72
73            /**
74            @brief Get the message of the Notification.
75            @return Returns the message of the Notification.
76            */
77            inline const std::string & getMessage(void) const
78                { return this->message_; }
79            /**
80            @brief Get the sender of the Notification.
81            @return Returns the sender of the Notification.
82            */
83            inline const std::string & getSender(void) const
84                { return this->sender_; }
85
86            /**
87            @brief Get the type of the Notification.
88            @return Returns an enum with the type of the Notification.
89            */
90            inline NotificationMessageType getType(void) const
91                { return this->type_; }
92
93        private:
94            std::string message_; //!< The Notification message.
95            std::string sender_;//!< The sender of the notifications.
96            NotificationMessageType type_; //!< The type of the notification.
97
98            void initialize(void); //!< Registers the object and sets some default values.
99
100    };
101
102    /**
103    @brief
104        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues".
105        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues".
106        It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
107
108    @author
109        Damian 'Mozork' Frick
110
111    @ingroup Notifications
112    */
113    class _NotificationsExport NotificationManager // tolua_export
114        : public Singleton<NotificationManager>, public NotificationListener
115    { // tolua_export
116            friend class Singleton<NotificationManager>;
117        public:
118            NotificationManager();
119            virtual ~NotificationManager();
120
121            virtual void preDestroy(void) override; // Is called before the object is destroyed.
122
123            /**
124            @brief Get the instance of the NotificationManager Singleton.
125            @return Returns a reference to the NotificationManager.
126            */
127            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
128
129            virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) override;
130            virtual bool executeCommand(NotificationCommand command, const std::string& sender) override;
131
132            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
133            void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
134
135            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.
136
137            /**
138            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map.
139            @param queue The NotificationQueue the Notifications are fetched for.
140            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
141            @param timeDelay The timespan.
142            @return Returns true if successful.
143            */
144            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
145                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
146
147            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.
148
149            bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
150            void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
151
152            void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
153
154            NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
155
156        private:
157            static NotificationManager* singletonPtr_s;
158
159            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
160            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.
161
162            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
163
164            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
165           
166            // Commands
167            bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
168
169    }; // tolua_export
170
171} // tolua_export
172
173#endif /* _NotificationManager_H__ */
Note: See TracBrowser for help on using the repository browser.