[Orxonox-commit 3693] r8374 - in code/branches/tutoriallevel2/src: modules/notifications modules/questsystem orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Mon May 2 10:20:45 CEST 2011


Author: dafrick
Date: 2011-05-02 10:20:45 +0200 (Mon, 02 May 2011)
New Revision: 8374

Modified:
   code/branches/tutoriallevel2/src/modules/notifications/Notification.cc
   code/branches/tutoriallevel2/src/modules/notifications/Notification.h
   code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
   code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc
   code/branches/tutoriallevel2/src/orxonox/interfaces/CMakeLists.txt
   code/branches/tutoriallevel2/src/orxonox/interfaces/InterfaceCompilation.cc
   code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
Log:
Changes in notifications module structure. Notifications can now be sent through the NotificationListener, meaning, they can be sent from anywhere within orxonox (and the modules of course).


Modified: code/branches/tutoriallevel2/src/modules/notifications/Notification.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/Notification.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/Notification.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -34,7 +34,7 @@
 #include "Notification.h"
 
 #include "core/CoreIncludes.h"
-#include "NotificationManager.h"
+#include "interfaces/NotificationListener.h"
 
 namespace orxonox
 {
@@ -71,7 +71,7 @@
     void Notification::initialize(void)
     {
         this->message_.clear();
-        this->sender_ = NotificationManager::NONE;
+        this->sender_ = NotificationListener::NONE;
     }
 
 }

Modified: code/branches/tutoriallevel2/src/modules/notifications/Notification.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/Notification.h	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/Notification.h	2011-05-02 08:20:45 UTC (rev 8374)
@@ -79,7 +79,6 @@
             std::string sender_; //!< The sender of the notification.
 
             void initialize(void); //!< Registers the object and sets some default values.
-            void registerVariables(void) {}
 
     };
 

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -40,11 +40,10 @@
 #include "network/Host.h"
 
 #include "infos/PlayerInfo.h"
+#include "interfaces/NotificationListener.h"
 #include "interfaces/PlayerTrigger.h"
 #include "worldentities/pawns/Pawn.h"
 
-#include "NotificationManager.h"
-
 namespace orxonox
 {
 
@@ -60,7 +59,7 @@
     {
         RegisterObject(NotificationDispatcher);
 
-        this->sender_ = NotificationManager::NONE;
+        this->sender_ = NotificationListener::NONE;
         this->registerVariables();
     }
 
@@ -113,7 +112,7 @@
         if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
         {
             const std::string message = this->createNotificationMessage();
-            NotificationManager::sendNotification(message, clientId, this->getSender());
+            NotificationListener::sendNotification(message, clientId, this->getSender());
         }
         else if(GameMode::isServer())
         {

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -35,10 +35,9 @@
 
 #include "core/command/ConsoleCommand.h"
 #include "core/CoreIncludes.h"
+#include "core/GameMode.h"
 #include "core/GUIManager.h"
 #include "core/LuaState.h"
-#include "network/Host.h"
-#include "network/NetworkFunction.h"
 #include "util/Convert.h"
 #include "util/ScopedSingletonManager.h"
 
@@ -52,9 +51,6 @@
 namespace orxonox
 {
 
-    const std::string NotificationManager::ALL("all");
-    const std::string NotificationManager::NONE("none");
-
     // Register tolua_open function when loading the library.
     DeclareToluaInterface(Notifications);
 
@@ -63,8 +59,6 @@
     // Setting console command to enter the edit mode.
     SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
 
-    registerStaticNetworkFunction(NotificationManager::sendNotification);
-
     /**
     @brief
         Constructor. Registers the Object.
@@ -73,8 +67,6 @@
     {
         RegisterRootObject(NotificationManager);
 
-        this->highestIndex_ = 0;
-
         ModifyConsoleCommand("enterEditMode").setObject(this);
 
         COUT(3) << "NotificatioManager created." << std::endl;
@@ -112,38 +104,16 @@
 
         this->queues_.clear();
     }
-
-    /**
-    @brief
-        Sends a Notification with the specified message to the specified client from the specified sender.
-    @param message
-        The message that should be sent.
-    @param clientId
-        The id of the client the notification should be sent to.
-    @param sender
-        The sender that sent the notification.
-    @param isLocal
-        If this is set to true (false is default), then the Notification is sent to the client where this function is executed, meaning the Notification is sent locally.
-    */
-    /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender, bool isLocal)
+    
+    bool NotificationManager::registerNotification(const std::string& message, const std::string& sender)
     {
-        // If we're in standalone mode or we're already no the right client we create and send the Notification.
-        if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId)
-        {
-            Notification* notification = new Notification(message, sender);
-            if(NotificationManager::getInstance().registerNotification(notification))
-                COUT(3) << "Notification \"" << notification->getMessage() << "\" sent." << std::endl;
-        }
-        // If we're on the server (and the server is not the intended recipient of the Notification) we send it over the network.
-        else if(GameMode::isServer())
-        {
-            callStaticNetworkFunction(NotificationManager::sendNotification, clientId, message, clientId, sender);
-        }
+        Notification* notification = new Notification(message, sender);
+        return this->registerNotification(notification);
     }
 
     /**
     @brief
-        Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender.
+        Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationQueues associated with its sender.
     @param notification
         The Notification to be registered.
     @return
@@ -158,24 +128,24 @@
         // Add the Notification to the list that holds all Notifications.
         this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
 
-        if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
+        if(notification->getSender() == NotificationListener::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
             return true;
 
         bool all = false;
-        if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
+        if(notification->getSender() == NotificationListener::ALL) // If all are the sender, then the Notifications is added to every NotificationQueue.
             all = true;
 
-        // Insert the Notification in all NotificationListeners that have its sender as target.
-        for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
+        // Insert the Notification in all NotificationQueues that have its sender as target.
+        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
         {
-            const std::set<std::string>& set = it->first->getTargetsSet();
-            bool bAll = set.find(NotificationManager::ALL) != set.end();
-            // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
+            const std::set<std::string>& set = it->second->getTargetsSet();
+            bool bAll = set.find(NotificationListener::ALL) != set.end();
+            // If either the Notification has as sender 'all', the NotificationQueue displays all Notifications or the NotificationQueue has the sender of the Notification as target.
             if(all || bAll || set.find(notification->getSender()) != set.end())
             {
                 if(!bAll)
-                    this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.
-                it->first->update(notification, time); // Update the NotificationListener.
+                    this->notificationLists_[it->second->getName()]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationQueue.
+                it->second->update(notification, time); // Update the NotificationQueue.
             }
         }
 
@@ -186,21 +156,21 @@
 
     /**
     @brief
-        Unregisters a Notification within the NotificationManager for a given NotificationListener.
+        Unregisters a Notification within the NotificationManager for a given NotificationQueue.
     @param notification
         A pointer to the Notification to be unregistered.
-    @param listener
-        A pointer to the NotificationListener the Notification is unregistered for.
+    @param queue
+        A pointer to the NotificationQueue the Notification is unregistered for.
     */
-    void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener)
+    void NotificationManager::unregisterNotification(Notification* notification, NotificationQueue* queue)
     {
         assert(notification);
-        assert(listener);
+        assert(queue);
 
-        // Remove the Notification from the list of Notifications of the input NotificationListener.
-        this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second));
+        // Remove the Notification from the list of Notifications of the input NotificationQueue.
+        this->removeNotification(notification, *(this->notificationLists_.find(queue->getName())->second));
 
-        COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
+        COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from NotificationQueue " << queue->getName() << "." << std::endl;
     }
 
     /**
@@ -230,91 +200,9 @@
 
     /**
     @brief
-        Registers a NotificationListener within the NotificationManager.
-    @param listener
-        The NotificationListener to be registered.
-    @return
-        Returns true if successful.  Fales if the NotificationListener is already registered.
-    */
-    bool NotificationManager::registerListener(NotificationListener* listener)
-    {
-        assert(listener);
-
-        // If the NotificationListener is already registered.
-        if(this->listenerList_.find(listener) != this->listenerList_.end())
-            return false;
-
-        this->highestIndex_ += 1;
-        unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely.
-
-        this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
-
-        const std::set<std::string>& set = listener->getTargetsSet();
-
-        // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications.
-        bool bAll = set.find(NotificationManager::ALL) != set.end();
-        std::multimap<std::time_t, Notification*>* map = NULL;
-        if(bAll)
-            this->notificationLists_[index] = &this->allNotificationsList_;
-        // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners.
-        else
-        {
-            this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
-            map = this->notificationLists_[index];
-        }
-
-        // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
-        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
-        {
-            if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
-                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
-        }
-
-        listener->update(); // Update the listener.
-
-        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
-
-        return true;
-    }
-
-    /**
-    @brief
-        Unregisters a NotificationListener within the NotificationManager.
-    @param listener
-        The NotificationListener to be unregistered.
-    */
-    void NotificationManager::unregisterListener(NotificationListener* listener)
-    {
-        assert(listener);
-
-        unsigned int identifier = this->listenerList_.find(listener)->second;
-        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
-
-        // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
-        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
-        if(map != &this->allNotificationsList_)
-        {
-            while(it != map->end())
-            {
-                this->unregisterNotification(it->second, listener);
-                it = map->begin();
-            }
-            delete map;
-        }
-
-        COUT(4) << "NotificationListener '" << identifier << "' unregistered with the NotificationManager." << std::endl;
-
-        // Remove the NotificationListener from the list of NotificationListeners.
-        this->listenerList_.erase(listener);
-        // Remove the Notifications list that was associated with the input NotificationListener.
-        this->notificationLists_.erase(identifier);
-    }
-
-    /**
-    @brief
-        Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
-    @param listener
-        The NotificationListener the Notifications are fetched for.
+        Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map.
+    @param queue
+        The NotificationQueue the Notifications are fetched for.
     @param map
         A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     @param timeFrameStart
@@ -324,12 +212,12 @@
     @return
         Returns true if successful.
     */
-    void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
+    void NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     {
-        assert(listener);
+        assert(queue);
         assert(map);
 
-        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
+        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue.
 
         std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
         // Iterators pointing to the bounds specified by the specified start and end times of the time frame.
@@ -342,9 +230,9 @@
 
     /**
     @brief
-        Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
-    @param listener
-        The NotificationListener the Notifications are fetched for.
+        Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map.
+    @param queue
+        The NotificationQueue the Notifications are fetched for.
     @param map
         A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     @param numberOfNotifications
@@ -352,12 +240,12 @@
     @return
         Returns true if successful.
     */
-    void NotificationManager::getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
+    void NotificationManager::getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
     {
-        assert(listener);
+        assert(queue);
         assert(map);
 
-        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
+        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue.
 
         if(!notifications->empty()) // If the list of Notifications is not empty.
         {
@@ -389,7 +277,7 @@
     /**
     @brief
         Registers a NotificationQueue.
-        This makes sure that the NotificationQueue can be attained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.
+        This makes sure that the NotificationQueue can be accessed through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.
     @param queue
         A pointer to the NotificationQueue to be registered.
     @return
@@ -397,8 +285,39 @@
     */
     bool NotificationManager::registerQueue(NotificationQueue* queue)
     {
+        assert(queue);
+
+        // If the NotificationQueue is already registered.
+        if(this->queues_.find(queue->getName()) != this->queues_.end())
+            return false;
+
+        this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)); // Add the NotificationQueue to the list of NotificationQueues.
+
+        const std::set<std::string>& set = queue->getTargetsSet();
+
+        // If all senders are the target of the NotificationQueue, then the list of Notifications for that specific NotificationQueue is the same as the list of all Notifications.
+        bool bAll = set.find(NotificationListener::ALL) != set.end();
+        std::multimap<std::time_t, Notification*>* map = NULL;
+        if(bAll)
+            this->notificationLists_[queue->getName()] = &this->allNotificationsList_;
+        // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationQueues.
+        else
+        {
+            this->notificationLists_[queue->getName()] = new std::multimap<std::time_t, Notification*>;
+            map = this->notificationLists_[queue->getName()];
+        }
+
+        // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
+        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
+        {
+            if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
+                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
+        }
+
+        queue->update(); // Update the queue.
+        
         COUT(4) << "NotificationQueue '" << queue->getName() << "' registered with the NotificationManager." << std::endl;
-        return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
+        return true;
     }
 
     /**
@@ -409,8 +328,28 @@
     */
     void NotificationManager::unregisterQueue(NotificationQueue* queue)
     {
-        COUT(4) << "NotificationQueue '" << queue->getName() << "' unregistered with the NotificationManager." << std::endl;
+        assert(queue);
+
+        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(queue->getName())->second;
+
+        // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
+        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
+        if(map != &this->allNotificationsList_)
+        {
+            while(it != map->end())
+            {
+                this->unregisterNotification(it->second, queue);
+                it = map->begin();
+            }
+            delete map;
+        }
+
+        // Remove the NotificationQueue from the list of NotificationQueues.
         this->queues_.erase(queue->getName());
+        // Remove the Notifications list that was associated with the input NotificationQueue.
+        this->notificationLists_.erase(queue->getName());
+        
+        COUT(4) << "NotificationQueue '" << queue->getName() << "' unregistered with the NotificationManager." << std::endl;
     }
 
     /**
@@ -423,7 +362,7 @@
         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
 
-        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
+        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationListener::ALL, 1, -1);
         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h	2011-05-02 08:20:45 UTC (rev 8374)
@@ -42,7 +42,7 @@
 #include <string>
 
 #include "util/Singleton.h"
-#include "core/OrxonoxClass.h"
+#include "interfaces/NotificationListener.h"
 
 namespace orxonox // tolua_export
 { // tolua_export
@@ -59,7 +59,7 @@
     @ingroup Notifications
     */
     class _NotificationsExport NotificationManager // tolua_export
-        : public Singleton<NotificationManager>, public OrxonoxClass
+        : public Singleton<NotificationManager>, public NotificationListener
     { // tolua_export
             friend class Singleton<NotificationManager>;
         public:
@@ -74,30 +74,24 @@
             */
             static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
 
-            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
-            static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
+            virtual bool registerNotification(const std::string& message, const std::string& sender);
 
-            //! Sends a Notification with the specified message to the specified client from the specified sender.
-            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);
-
             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
-            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
-            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
-            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
+            void unregisterNotification(Notification* notification, NotificationQueue* queue); //!< Unregisters a Notification within the NotificationManager for a given NotificationQueue.
 
-            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.
+            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.
 
             /**
-            @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
-            @param listener The NotificationListener the Notifications are fetched for.
+            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from now-timeDelay to now and stores them in the input map.
+            @param listener The NotificationQueue the Notifications are fetched for.
             @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
             @param timeDelay The timespan.
             @return Returns true if successful.
             */
-            void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
-                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
+            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
+                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
 
-            void getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); //!< Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
+            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.
 
             void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
 
@@ -113,11 +107,8 @@
         private:
             static NotificationManager* singletonPtr_s;
 
-            unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
-
             std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
-            std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
-            std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
+            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.
 
             std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
 

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -89,19 +89,6 @@
 
         this->create(); // Creates the NotificationQueue in lua.
 
-        // Register the NotificationQueue as NotificationListener with the NotificationManager.
-        bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
-        if(!listenerRegistered) // If the registration has failed.
-        {
-            this->registered_ = false;
-            // Remove the NotificationQueue in lua.
-            if(GameMode::showsGraphics())
-                GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
-            NotificationManager::getInstance().unregisterQueue(this);
-            COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;
-            return;
-        }
-
         COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
     }
 
@@ -118,7 +105,6 @@
             this->clear(true);
 
             // Unregister with the NotificationManager.
-            NotificationManager::getInstance().unregisterListener(this);
             NotificationManager::getInstance().unregisterQueue(this);
         }
     }
@@ -180,6 +166,7 @@
     @brief
         Updates the NotificationQueue.
         Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
+        This is called by the NotificationManager when the Notifications have changed so much, that the NotificationQueue may have to re-initialize his operations.
     */
     void NotificationQueue::update(void)
     {
@@ -417,10 +404,11 @@
         for(unsigned int i = 0; i < string.size(); i++)
             this->targets_.insert(string[i]);
 
+        // TODO: Why?
         if(this->registered_)
         {
-            NotificationManager::getInstance().unregisterListener(this);
-            NotificationManager::getInstance().registerListener(this);
+            NotificationManager::getInstance().unregisterQueue(this);
+            NotificationManager::getInstance().registerQueue(this);
         }
     }
 

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h	2011-05-02 08:20:45 UTC (rev 8374)
@@ -45,7 +45,6 @@
 #include "NotificationManager.h"
 
 #include "tools/interfaces/Tickable.h"
-#include "interfaces/NotificationListener.h"
 
 namespace orxonox // tolua_export
 { // tolua_export
@@ -89,7 +88,7 @@
     @ingroup Notifications
     */
     class _NotificationsExport NotificationQueue // tolua_export
-        : public Tickable, public NotificationListener
+        : public Tickable
     { // tolua_export
 
         public:

Modified: code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -39,7 +39,7 @@
 
 #include "infos/PlayerInfo.h"
 
-#include "notifications/NotificationManager.h"
+#include "interfaces/NotificationListener.h"
 
 namespace orxonox
 {
@@ -118,7 +118,7 @@
             return false;
         }
 
-        NotificationManager::sendNotification(message, player->getClientID(), QuestDescription::SENDER);
+        NotificationListener::sendNotification(message, player->getClientID(), QuestDescription::SENDER);
         return true;
     }
 

Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/CMakeLists.txt
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/CMakeLists.txt	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/CMakeLists.txt	2011-05-02 08:20:45 UTC (rev 8374)
@@ -1,5 +1,6 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   InterfaceCompilation.cc
+  NotificationListener.cc
   Pickupable.cc
   PickupCarrier.cc
   PickupListener.cc

Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/InterfaceCompilation.cc	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/InterfaceCompilation.cc	2011-05-02 08:20:45 UTC (rev 8374)
@@ -85,12 +85,4 @@
     {
         RegisterRootObject(Rewardable);
     }
-
-    //----------------------------
-    // NotificationListener
-    //----------------------------
-    NotificationListener::NotificationListener()
-    {
-        RegisterRootObject(NotificationListener);
-    }
 }

Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h	2011-05-02 03:00:20 UTC (rev 8373)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h	2011-05-02 08:20:45 UTC (rev 8374)
@@ -66,24 +66,14 @@
         public:
             NotificationListener();
             virtual ~NotificationListener() {}
-
-            /**
-            @brief Get the senders that are targets of this NotificationListener.
-            @return Returns the set of senders that are targets of this NotificationListener.
-            */
-            virtual const std::set<std::string> & getTargetsSet(void) = 0;
-
-            /**
-            @brief Updates the whole NotificationListener.
-                   This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations.
-            */
-            virtual void update(void) = 0;
-            /**
-            @brief Updates the NotificationListener, when a new Notification has come in at the specified time.
-            @param notification A pointer to the @ref orxonox::Notification "Notification".
-            @param time The time the @ref orxonox::Notification "Notification" has come in.
-            */
-            virtual void update(Notification* notification, const std::time_t & time) = 0;
+            
+            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
+            static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
+            
+            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationListener::NONE, bool isLocal = false);
+            
+            virtual bool registerNotification(const std::string& message, const std::string& sender)
+                { return false; }
     };
 }
 




More information about the Orxonox-commit mailing list