Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lastmanstanding/src/modules/notifications/NotificationManager.h @ 7554

Last change on this file since 7554 was 7474, checked in by dafrick, 14 years ago

Synchronizing Notifications.
In the course of that, notifications are not longer sent by creating a Notification and the calling notification.send() bur by letting the NotificationManager handle all this: NotificationManager::getInstance().sendNotification(message)
This made QuestNotification obsolete, thus it was removde.

Also did some work on synchronizing the Script class. It should work properly most of the time, but the current solution is unreliable and unsatisfactory. So this will change as soon as I know how.

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