[2280] | 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 | |
---|
[2911] | 29 | /** |
---|
[7403] | 30 | @file NotificationManager.h |
---|
[2911] | 31 | @brief Definition of the NotificationManager class. |
---|
[7456] | 32 | @ingroup Notifications |
---|
[2911] | 33 | */ |
---|
| 34 | |
---|
[2280] | 35 | #ifndef _NotificationManager_H__ |
---|
| 36 | #define _NotificationManager_H__ |
---|
| 37 | |
---|
[7164] | 38 | #include "notifications/NotificationsPrereqs.h" |
---|
[2280] | 39 | |
---|
[3196] | 40 | #include <ctime> |
---|
[2911] | 41 | #include <map> |
---|
[2280] | 42 | #include <string> |
---|
[3370] | 43 | |
---|
[8453] | 44 | #include "core/OrxonoxClass.h" |
---|
[5929] | 45 | #include "util/Singleton.h" |
---|
[8453] | 46 | #include "interfaces/NotificationListener.h" |
---|
[2280] | 47 | |
---|
[7403] | 48 | namespace orxonox // tolua_export |
---|
| 49 | { // tolua_export |
---|
| 50 | |
---|
[2280] | 51 | /** |
---|
| 52 | @brief |
---|
[8453] | 53 | 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). |
---|
[7552] | 54 | |
---|
[8453] | 55 | A Notification is just a data structure that is used internally by the Notifications module. |
---|
| 56 | |
---|
[2280] | 57 | @author |
---|
| 58 | Damian 'Mozork' Frick |
---|
[7552] | 59 | |
---|
| 60 | @ingroup Notifications |
---|
[2280] | 61 | */ |
---|
[8453] | 62 | class _NotificationsExport Notification |
---|
| 63 | { |
---|
| 64 | public: |
---|
| 65 | Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type); |
---|
| 66 | virtual ~Notification(); |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | @brief Destroys the Notification. |
---|
| 70 | */ |
---|
| 71 | void destroy(void) |
---|
| 72 | { delete this; } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief Get the message of the Notification. |
---|
| 76 | @return Returns the message of the Notification. |
---|
| 77 | */ |
---|
| 78 | inline const std::string & getMessage(void) const |
---|
| 79 | { return this->message_; } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | @brief Get the sender of the Notification. |
---|
| 83 | @return Returns the sender of the Notification. |
---|
| 84 | */ |
---|
| 85 | inline const std::string & getSender(void) const |
---|
| 86 | { return this->sender_; } |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | @brief Get the type of the Notification. |
---|
| 90 | @return Returns an enum with the type of the Notification. |
---|
| 91 | */ |
---|
| 92 | inline notificationMessageType::Value getType(void) const |
---|
| 93 | { return this->type_; } |
---|
| 94 | |
---|
| 95 | private: |
---|
| 96 | std::string message_; //!< The Notification message. |
---|
| 97 | std::string sender_; //!< The sender of the notification. |
---|
| 98 | notificationMessageType::Value type_; //!< The type of the notification. |
---|
| 99 | |
---|
| 100 | void initialize(void); //!< Registers the object and sets some default values. |
---|
| 101 | |
---|
| 102 | }; |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | @brief |
---|
| 106 | The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues". |
---|
| 107 | It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues". |
---|
| 108 | It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer. |
---|
| 109 | |
---|
| 110 | @author |
---|
| 111 | Damian 'Mozork' Frick |
---|
| 112 | |
---|
| 113 | @ingroup Notifications |
---|
| 114 | */ |
---|
[7403] | 115 | class _NotificationsExport NotificationManager // tolua_export |
---|
[8453] | 116 | : public Singleton<NotificationManager>, public NotificationListener |
---|
[7403] | 117 | { // tolua_export |
---|
[5929] | 118 | friend class Singleton<NotificationManager>; |
---|
[2911] | 119 | public: |
---|
| 120 | NotificationManager(); |
---|
| 121 | virtual ~NotificationManager(); |
---|
[3034] | 122 | |
---|
[8453] | 123 | virtual void preDestroy(void); // Is called before the object is destroyed. |
---|
[7403] | 124 | |
---|
[7484] | 125 | /** |
---|
| 126 | @brief Get the instance of the NotificationManager Singleton. |
---|
| 127 | @return Returns a reference to the NotificationManager. |
---|
| 128 | */ |
---|
[7403] | 129 | static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export |
---|
| 130 | |
---|
[8453] | 131 | virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type); |
---|
| 132 | virtual bool executeCommand(notificationCommand::Value command, const std::string& sender); |
---|
[3034] | 133 | |
---|
[8453] | 134 | bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager. |
---|
| 135 | void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue. |
---|
[7474] | 136 | |
---|
[8453] | 137 | 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. |
---|
[3034] | 138 | |
---|
[2911] | 139 | /** |
---|
[8453] | 140 | @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map. |
---|
| 141 | @param queue The NotificationQueue the Notifications are fetched for. |
---|
[7403] | 142 | @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. |
---|
[2911] | 143 | @param timeDelay The timespan. |
---|
| 144 | @return Returns true if successful. |
---|
| 145 | */ |
---|
[8453] | 146 | void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay) |
---|
| 147 | { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); } |
---|
[3034] | 148 | |
---|
[8453] | 149 | 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. |
---|
[7403] | 150 | |
---|
[8453] | 151 | bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue. |
---|
| 152 | void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue. |
---|
[7403] | 153 | |
---|
[8453] | 154 | void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist. |
---|
[7403] | 155 | |
---|
[8453] | 156 | NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name. |
---|
| 157 | |
---|
[2911] | 158 | private: |
---|
[3370] | 159 | static NotificationManager* singletonPtr_s; |
---|
[2911] | 160 | |
---|
[7403] | 161 | std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. |
---|
[8453] | 162 | 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. |
---|
[2280] | 163 | |
---|
[7403] | 164 | std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. |
---|
[3034] | 165 | |
---|
[8453] | 166 | bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map. |
---|
| 167 | |
---|
| 168 | // Commands |
---|
| 169 | bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target. |
---|
[2280] | 170 | |
---|
[7403] | 171 | }; // tolua_export |
---|
[2280] | 172 | |
---|
[7403] | 173 | } // tolua_export |
---|
| 174 | |
---|
[2280] | 175 | #endif /* _NotificationManager_H__ */ |
---|