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