Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2009, 12:33:16 AM (15 years ago)
Author:
landauf
Message:

Moved Notification and NotificationManger from overlays to the quest objects (NotificationOverlay and NotificationQueue remain with the other overlays).

Added a new interface NotificationListener. The NotificationManager sends notifications to all listeners. NotificationQueue is such a listener (through inheritance). This removes another dependency between orxonox and overlays.

Location:
code/branches/libraries/src/orxonox/objects/quest/notifications
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/libraries/src/orxonox/objects/quest/notifications/NotificationManager.cc

    r5616 r5619  
    3838#include "core/CoreIncludes.h"
    3939#include "Notification.h"
    40 #include "NotificationQueue.h"
     40#include "interfaces/NotificationListener.h"
    4141
    4242namespace orxonox
     
    6969    /**
    7070    @brief
    71         Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.
     71        Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender.
    7272    @param notification
    7373        The Notification to be registered.
     
    7777    bool NotificationManager::registerNotification(Notification* notification)
    7878    {
    79    
     79
    8080        if(notification == NULL) //!< A NULL-Notification cannot be registered.
    8181            return false;
    82        
     82
    8383        std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
    84        
     84
    8585        this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
    86        
     86
    8787        if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
    8888            return true;
    89        
     89
    9090        bool all = false;
    91         if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationQueue.
     91        if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationListener.
    9292            all = true;
    93        
    94         //!< Insert the notification in all queues that have its sender as target.
    95         for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.
     93
     94        //!< Insert the notification in all listeners that have its sender as target.
     95        for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) //!< Iterate through all listeners.
    9696        {
    9797            std::set<std::string> set = it->first->getTargetsSet();
    9898            if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
    9999            {
    100                 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
    101                 it->first->update(notification, time); //!< Update the queue.
     100                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
     101                it->first->update(notification, time); //!< Update the listener.
    102102            }
    103103        }
    104        
     104
    105105        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
    106        
     106
    107107        return true;
    108108    }
    109    
     109
    110110    /**
    111111    @brief
    112         Registers a NotificationQueue within the NotificationManager.
    113     @param queue
    114         The NotificationQueue to be registered.
     112        Registers a NotificationListener within the NotificationManager.
     113    @param listener
     114        The NotificationListener to be registered.
    115115    @return
    116116        Returns true if successful.
    117117    */
    118     bool NotificationManager::registerQueue(NotificationQueue* queue)
     118    bool NotificationManager::registerListener(NotificationListener* listener)
    119119    {
    120120        this->highestIndex_ += 1;
    121121        int index = this->highestIndex_;
    122        
    123         this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.
    124        
    125         std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
    126        
    127         //! If all senders are the target of the queue, then the list of notification for that specific queue is te same as the list of all Notifications.
     122
     123        this->listenerList_[listener] = index; //!< Add the NotificationListener to the list of listeners.
     124
     125        std::set<std::string> set = listener->getTargetsSet(); //TDO: Works this?
     126
     127        //! If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications.
    128128        if(set.find(ALL) != set.end())
    129129        {
    130130            this->notificationLists_[index] = &this->allNotificationsList_;
    131             COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
     131            COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
    132132            return true;
    133133        }
    134        
     134
    135135        this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
    136136        std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
    137        
    138         //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
     137
     138        //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
    139139        for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    140140        {
     
    144144            }
    145145        }
    146        
    147         queue->update(); //!< Update the queue.
    148146
    149         COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
    150        
     147        listener->update(); //!< Update the listener.
     148
     149        COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     150
    151151        return true;
    152152    }
    153    
     153
    154154    /**
    155155    @brief
    156         Fetches the Notifications for a specific NotificationQueue in a specified timeframe.
    157     @param queue
    158         The NotificationQueue the Notifications are fetched for.
     156        Fetches the Notifications for a specific NotificationListener in a specified timeframe.
     157    @param listener
     158        The NotificationListener the Notifications are fetched for.
    159159    @param map
    160160        A multimap, in which the notifications are stored.
     
    166166        Returns true if successful.
    167167    */
    168     bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     168    bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    169169    {
    170         if(queue == NULL || map == NULL)
     170        if(listener == NULL || map == NULL)
    171171            return false;
    172172
    173         std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue.
    174        
     173        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; //!< The Notifications for the input NotificationListener.
     174
    175175        if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
    176176            return true;
    177    
     177
    178178        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
    179179        itLowest = notifications->lower_bound(timeFrameStart);
    180180        itHighest = notifications->upper_bound(timeFrameStart);
    181        
     181
    182182        for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
    183183        {
    184184            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
    185185        }
    186        
     186
    187187        return true;
    188188    }
Note: See TracChangeset for help on using the changeset viewer.