Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/NotificationManager.h @ 9691

Last change on this file since 9691 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 7.9 KB
RevLine 
[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"
[8706]45#include "interfaces/NotificationListener.h"
[2280]46
[7403]47namespace orxonox // tolua_export
48{ // tolua_export
49
[2280]50    /**
51    @brief
[8706]52        A Notification represents a short message used to inform the player about something that just happened. With the @ref orxonox::NotificationManager "NotificationManager" a Notification can be sent from any part of orxonox and is then displayed by the proper @ref orxonox::NotificationQueue "NotificationQueue(s)" (depending on which senders the specific @ref orxonox::NotificationQueue "NotificationQueues" accepts).
[7552]53
[8706]54        A Notification is just a data structure that is used internally by the Notifications module.
55
[2280]56    @author
57        Damian 'Mozork' Frick
[7552]58
59    @ingroup Notifications
[2280]60    */
[8706]61    class _NotificationsExport Notification
62    {
63        public:
64            Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
65            virtual ~Notification();
66
67            /**
68            @brief Destroys the Notification.
69            */
70            void destroy(void)
71                { delete this; }
72
73            /**
74            @brief Get the message of the Notification.
75            @return Returns the message of the Notification.
76            */
77            inline const std::string & getMessage(void) const
78                { return this->message_; }
79
80            /**
81            @brief Get the sender of the Notification.
82            @return Returns the sender of the Notification.
83            */
84            inline const std::string & getSender(void) const
85                { return this->sender_; }
86
87            /**
88            @brief Get the type of the Notification.
89            @return Returns an enum with the type of the Notification.
90            */
91            inline notificationMessageType::Value getType(void) const
92                { return this->type_; }
93
94        private:
95            std::string message_; //!< The Notification message.
96            std::string sender_; //!< The sender of the notification.
97            notificationMessageType::Value type_; //!< The type of the notification.
98
99            void initialize(void); //!< Registers the object and sets some default values.
100
101    };
102
103    /**
104    @brief
105        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues".
106        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues".
107        It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
108
109    @author
110        Damian 'Mozork' Frick
111
112    @ingroup Notifications
113    */
[7403]114    class _NotificationsExport NotificationManager // tolua_export
[8706]115        : public Singleton<NotificationManager>, public NotificationListener
[7403]116    { // tolua_export
[5929]117            friend class Singleton<NotificationManager>;
[2911]118        public:
119            NotificationManager();
120            virtual ~NotificationManager();
[3034]121
[8706]122            virtual void preDestroy(void); // Is called before the object is destroyed.
[7403]123
[7484]124            /**
125            @brief Get the instance of the NotificationManager Singleton.
126            @return Returns a reference to the NotificationManager.
127            */
[7403]128            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
129
[8706]130            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
131            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender);
[3034]132
[8706]133            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
134            void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
[7474]135
[8706]136            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); // Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map.
[3034]137
[2911]138            /**
[8706]139            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map.
140            @param queue The NotificationQueue the Notifications are fetched for.
[7403]141            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
[2911]142            @param timeDelay The timespan.
143            @return Returns true if successful.
144            */
[8706]145            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
146                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
[3034]147
[8706]148            void getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); // Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map.
[7403]149
[8706]150            bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
151            void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
[7403]152
[8706]153            void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
[7403]154
[8706]155            NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
156
[2911]157        private:
[3370]158            static NotificationManager* singletonPtr_s;
[2911]159
[7403]160            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
[8706]161            std::map<const std::string, std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
[2280]162
[7403]163            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
[3034]164
[8706]165            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
166           
167            // Commands
168            bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
[2280]169
[7403]170    }; // tolua_export
[2280]171
[7403]172} // tolua_export
173
[2280]174#endif /* _NotificationManager_H__ */
Note: See TracBrowser for help on using the repository browser.