Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Finished EditMode, needs some polish (no not the language…) though.
Took better advantage of lua tables in NotificationLayer.lua
Fixed a lot of bugs, it really is a miracle that the Notifications worked as well as they did.

  • Property svn:eol-style set to native
File size: 5.4 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*/
33
34#ifndef _NotificationManager_H__
35#define _NotificationManager_H__
36
37#include "notifications/NotificationsPrereqs.h"
38
39#include <ctime>
40#include <map>
41#include <string>
42
43#include "util/Singleton.h"
44#include "core/OrxonoxClass.h"
45
46namespace orxonox // tolua_export
47{ // tolua_export
48
49    /**
50    @brief
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.
53    @author
54        Damian 'Mozork' Frick
55    */
56    class _NotificationsExport NotificationManager // tolua_export
57        : public Singleton<NotificationManager>, public OrxonoxClass
58    { // tolua_export
59            friend class Singleton<NotificationManager>;
60        public:
61            NotificationManager();
62            virtual ~NotificationManager();
63
64            virtual void preDestroy(void);
65
66            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
67
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.
70
71            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
72            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
73            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
74            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
75
76            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.
77
78            /**
79            @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
80            @param listener The NotificationListener the Notifications are fetched for.
81            @param map A multimap, in which the notifications are stored.
82            @param timeDelay The timespan.
83            @return Returns true if successful.
84            */
85            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
86                { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
87
88            void enterEditMode(void);
89
90            // tolua_begin
91            void loadQueues(void);
92           
93            void createQueue(const std::string& name);
94            orxonox::NotificationQueue* getQueue(const std::string & name);
95            // tolua_end
96
97            bool registerQueue(NotificationQueue* queue);
98            void unregisterQueue(NotificationQueue* queue);
99
100        private:
101            static NotificationManager* singletonPtr_s;
102
103            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
104
105            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*, 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            std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
111
112            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
113
114    }; // tolua_export
115
116} // tolua_export
117
118#endif /* _NotificationManager_H__ */
Note: See TracBrowser for help on using the repository browser.