[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 | |
---|
[5929] | 44 | #include "util/Singleton.h" |
---|
[3196] | 45 | #include "core/OrxonoxClass.h" |
---|
[2280] | 46 | |
---|
[7403] | 47 | namespace orxonox // tolua_export |
---|
| 48 | { // tolua_export |
---|
| 49 | |
---|
[2280] | 50 | /** |
---|
| 51 | @brief |
---|
[7484] | 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". |
---|
[7489] | 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. |
---|
[2280] | 55 | @author |
---|
| 56 | Damian 'Mozork' Frick |
---|
| 57 | */ |
---|
[7403] | 58 | class _NotificationsExport NotificationManager // tolua_export |
---|
| 59 | : public Singleton<NotificationManager>, public OrxonoxClass |
---|
| 60 | { // tolua_export |
---|
[5929] | 61 | friend class Singleton<NotificationManager>; |
---|
[2911] | 62 | public: |
---|
| 63 | NotificationManager(); |
---|
| 64 | virtual ~NotificationManager(); |
---|
[3034] | 65 | |
---|
[7403] | 66 | virtual void preDestroy(void); //!< Is called before the object is destroyed. |
---|
| 67 | |
---|
[7484] | 68 | /** |
---|
| 69 | @brief Get the instance of the NotificationManager Singleton. |
---|
| 70 | @return Returns a reference to the NotificationManager. |
---|
| 71 | */ |
---|
[7403] | 72 | static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export |
---|
| 73 | |
---|
[7163] | 74 | static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners. |
---|
| 75 | static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener. |
---|
[3034] | 76 | |
---|
[7484] | 77 | //! Sends a Notification with the specified message to the specified client from the specified sender. |
---|
[7486] | 78 | static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false); |
---|
[7474] | 79 | |
---|
[2911] | 80 | bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. |
---|
[7403] | 81 | void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener. |
---|
[5619] | 82 | bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. |
---|
[7163] | 83 | void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. |
---|
[3034] | 84 | |
---|
[7403] | 85 | void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. |
---|
[3034] | 86 | |
---|
[2911] | 87 | /** |
---|
[7403] | 88 | @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map. |
---|
[5619] | 89 | @param listener The NotificationListener the Notifications are fetched for. |
---|
[7403] | 90 | @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. |
---|
[2911] | 91 | @param timeDelay The timespan. |
---|
| 92 | @return Returns true if successful. |
---|
| 93 | */ |
---|
[7403] | 94 | void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay) |
---|
| 95 | { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } |
---|
[3034] | 96 | |
---|
[7403] | 97 | void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer. |
---|
| 98 | |
---|
| 99 | bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue. |
---|
| 100 | void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue. |
---|
| 101 | |
---|
| 102 | // tolua_begin |
---|
| 103 | void loadQueues(void); //!< Loads all the NotificationQueues that should exist. |
---|
| 104 | void createQueue(const std::string& name); //!< Creates a new NotificationQueue. |
---|
| 105 | orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name. |
---|
| 106 | // tolua_end |
---|
| 107 | |
---|
[2911] | 108 | private: |
---|
[3370] | 109 | static NotificationManager* singletonPtr_s; |
---|
[2911] | 110 | |
---|
[7403] | 111 | unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. |
---|
[3034] | 112 | |
---|
[7403] | 113 | std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. |
---|
| 114 | std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. |
---|
| 115 | std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. |
---|
[2280] | 116 | |
---|
[7403] | 117 | std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. |
---|
[3034] | 118 | |
---|
[7403] | 119 | bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map. |
---|
[2280] | 120 | |
---|
[7403] | 121 | }; // tolua_export |
---|
[2280] | 122 | |
---|
[7403] | 123 | } // tolua_export |
---|
| 124 | |
---|
[2280] | 125 | #endif /* _NotificationManager_H__ */ |
---|