[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 | /** |
---|
[3196] | 30 | @file |
---|
[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> |
---|
[7354] | 42 | #include <vector> |
---|
[3370] | 43 | |
---|
[5929] | 44 | #include "util/Singleton.h" |
---|
[3196] | 45 | #include "core/OrxonoxClass.h" |
---|
[2280] | 46 | |
---|
[7354] | 47 | namespace orxonox // tolua_export |
---|
| 48 | { // tolua_export |
---|
| 49 | |
---|
[2280] | 50 | /** |
---|
| 51 | @brief |
---|
[5619] | 52 | The Singleton NotificationManager functions as a gateway between Notifications and NotificationListeners. |
---|
| 53 | It receives, organizes Notifications and the redistributes them to the specific NotificationListeners. |
---|
[2280] | 54 | @author |
---|
| 55 | Damian 'Mozork' Frick |
---|
| 56 | */ |
---|
[7354] | 57 | class _NotificationsExport NotificationManager // tolua_export |
---|
| 58 | : public Singleton<NotificationManager>, public OrxonoxClass |
---|
| 59 | { // tolua_export |
---|
[5929] | 60 | friend class Singleton<NotificationManager>; |
---|
[2911] | 61 | public: |
---|
| 62 | NotificationManager(); |
---|
| 63 | virtual ~NotificationManager(); |
---|
[3034] | 64 | |
---|
[7354] | 65 | virtual void preDestroy(void); |
---|
| 66 | |
---|
| 67 | static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export |
---|
| 68 | |
---|
[7163] | 69 | static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners. |
---|
| 70 | static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener. |
---|
[3034] | 71 | |
---|
[2911] | 72 | bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. |
---|
[7163] | 73 | void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager. |
---|
[5619] | 74 | bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. |
---|
[7163] | 75 | void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. |
---|
[3034] | 76 | |
---|
[5619] | 77 | bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe. |
---|
[3034] | 78 | |
---|
[2911] | 79 | /** |
---|
[5619] | 80 | @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now. |
---|
| 81 | @param listener The NotificationListener the Notifications are fetched for. |
---|
[2911] | 82 | @param map A multimap, in which the notifications are stored. |
---|
| 83 | @param timeDelay The timespan. |
---|
| 84 | @return Returns true if successful. |
---|
| 85 | */ |
---|
[5619] | 86 | bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay) |
---|
| 87 | { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } |
---|
[3034] | 88 | |
---|
[7354] | 89 | void enterEditMode(void); |
---|
| 90 | |
---|
| 91 | void createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime); // tolua_export |
---|
| 92 | |
---|
[2911] | 93 | private: |
---|
[3370] | 94 | static NotificationManager* singletonPtr_s; |
---|
[2911] | 95 | |
---|
[7354] | 96 | std::vector<NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. |
---|
[7349] | 97 | |
---|
[7163] | 98 | int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. |
---|
[3034] | 99 | |
---|
[7163] | 100 | std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored. |
---|
[5619] | 101 | std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. |
---|
| 102 | std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. |
---|
[7163] | 103 | std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with. |
---|
[2280] | 104 | |
---|
[7163] | 105 | bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map. |
---|
[3034] | 106 | |
---|
[7354] | 107 | }; // tolua_export |
---|
[2280] | 108 | |
---|
[7354] | 109 | } // tolua_export |
---|
[2280] | 110 | |
---|
| 111 | #endif /* _NotificationManager_H__ */ |
---|