Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 12, 2011, 12:31:23 AM (13 years ago)
Author:
dafrick
Message:

Merging tutoriallevel2 branch into tutoriallevel3 branch.

Location:
code/branches/tutoriallevel3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3

  • code/branches/tutoriallevel3/src/modules/notifications/NotificationManager.h

    r7552 r8453  
    4242#include <string>
    4343
     44#include "core/OrxonoxClass.h"
    4445#include "util/Singleton.h"
    45 #include "core/OrxonoxClass.h"
     46#include "interfaces/NotificationListener.h"
    4647
    4748namespace orxonox // tolua_export
     
    5051    /**
    5152    @brief
    52         The Singleton NotificationManager functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationListener "NotificationListeners".
    53         It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationListener "NotificationListeners".
    54         It also provides a static function to send @ref orxonox::Notification "Notifications" and works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
     53        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).
     54
     55        A Notification is just a data structure that is used internally by the Notifications module.
     56
     57    @author
     58        Damian 'Mozork' Frick
     59
     60    @ingroup Notifications
     61    */
     62    class _NotificationsExport Notification
     63    {
     64        public:
     65            Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     66            virtual ~Notification();
     67
     68            /**
     69            @brief Destroys the Notification.
     70            */
     71            void destroy(void)
     72                { delete this; }
     73
     74            /**
     75            @brief Get the message of the Notification.
     76            @return Returns the message of the Notification.
     77            */
     78            inline const std::string & getMessage(void) const
     79                { return this->message_; }
     80
     81            /**
     82            @brief Get the sender of the Notification.
     83            @return Returns the sender of the Notification.
     84            */
     85            inline const std::string & getSender(void) const
     86                { return this->sender_; }
     87
     88            /**
     89            @brief Get the type of the Notification.
     90            @return Returns an enum with the type of the Notification.
     91            */
     92            inline notificationMessageType::Value getType(void) const
     93                { return this->type_; }
     94
     95        private:
     96            std::string message_; //!< The Notification message.
     97            std::string sender_; //!< The sender of the notification.
     98            notificationMessageType::Value type_; //!< The type of the notification.
     99
     100            void initialize(void); //!< Registers the object and sets some default values.
     101
     102    };
     103
     104    /**
     105    @brief
     106        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues".
     107        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues".
     108        It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
    55109
    56110    @author
     
    60114    */
    61115    class _NotificationsExport NotificationManager // tolua_export
    62         : public Singleton<NotificationManager>, public OrxonoxClass
     116        : public Singleton<NotificationManager>, public NotificationListener
    63117    { // tolua_export
    64118            friend class Singleton<NotificationManager>;
     
    67121            virtual ~NotificationManager();
    68122
    69             virtual void preDestroy(void); //!< Is called before the object is destroyed.
     123            virtual void preDestroy(void); // Is called before the object is destroyed.
    70124
    71125            /**
     
    75129            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
    76130
    77             static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
    78             static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
     131            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     132            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender);
    79133
    80             //! Sends a Notification with the specified message to the specified client from the specified sender.
    81             static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);
     134            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
     135            void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
    82136
    83             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    84             void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
    85             bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
    86             void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    87 
    88             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.
     137            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.
    89138
    90139            /**
    91             @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
    92             @param listener The NotificationListener the Notifications are fetched for.
     140            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map.
     141            @param queue The NotificationQueue the Notifications are fetched for.
    93142            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    94143            @param timeDelay The timespan.
    95144            @return Returns true if successful.
    96145            */
    97             void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
    98                 { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
     146            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
     147                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
    99148
    100             void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
     149            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.
    101150
    102             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
    103             void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
     151            bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
     152            void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
    104153
    105             // tolua_begin
    106             void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
    107             void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
    108             orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
    109             // tolua_end
     154            void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
     155
     156            NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
    110157
    111158        private:
    112159            static NotificationManager* singletonPtr_s;
    113160
    114             unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    115 
    116161            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
    117             std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    118             std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
     162            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.
    119163
    120164            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
    121165
    122             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
     166            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
     167           
     168            // Commands
     169            bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
    123170
    124171    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.