[Orxonox-commit 2785] r7488 - in code/trunk: doc/api src/modules/notifications src/modules/notifications/dispatchers

dafrick at orxonox.net dafrick at orxonox.net
Fri Sep 24 12:01:57 CEST 2010


Author: dafrick
Date: 2010-09-24 12:01:57 +0200 (Fri, 24 Sep 2010)
New Revision: 7488

Modified:
   code/trunk/doc/api/Groups.dox
   code/trunk/src/modules/notifications/Notification.cc
   code/trunk/src/modules/notifications/Notification.h
   code/trunk/src/modules/notifications/NotificationDispatcher.cc
   code/trunk/src/modules/notifications/NotificationDispatcher.h
   code/trunk/src/modules/notifications/NotificationManager.cc
   code/trunk/src/modules/notifications/NotificationQueue.cc
   code/trunk/src/modules/notifications/NotificationQueue.h
   code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
   code/trunk/src/modules/notifications/dispatchers/SimpleNotification.h
Log:
Some more documentation.
Making NotificationManager Root scope, cleaning up, especially in Notification (now it's just a data structure anymore).


Modified: code/trunk/doc/api/Groups.dox
===================================================================
--- code/trunk/doc/api/Groups.dox	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/doc/api/Groups.dox	2010-09-24 10:01:57 UTC (rev 7488)
@@ -152,14 +152,17 @@
     @section NotificationsTechincalDetails Technical details
     The Notifications module has three major parts that interact with each other. First there is the @ref orxonox::NotificationQueue "NotificationQueue", this is the entity that (logically, not effectively) displays @ref orxonox::Notification "Notifications" according to some rules, then there is the NotificationLayer, which is the GUI which (actually) displays @ref orxonox::Notification "Notifications" by visualizing the @ref orxonox::NotificationQueue "NotificationQueues" and as a result also the @ref orxonox::Notification "Notifications", that are displayed by the respective @ref orxonox::NotificationQueue "NotificationQueues" and lastly there is the @ref orxonox::NotificationManager "NotificationManager", which connects these two.
 
+    @subsection NotificationQueue NotificationQueue
+    The @ref orxonox::NotificationQueue "NotificationQueue" is the entity, that (as said earlier) logically displays @ref orxonox::Notification "Notifications". Furthermore a @ref orxonox::NotificationQueue "NotificationQueue" displays only a subset of all the @ref orxonox::Notification "Notifications". The parameters that reduce the range of @ref orxonox::Notification "Notifications" are:
+    - @b senders The senders, set of targets of a @ref orxonox::NotificationQueue "NotificationQueue" is the set of senders a @ref orxonox::NotificationQueue "NotificationQueue" displays  @ref orxonox::Notification "Notifications" from. E.g. If one would set the senders to "questsystem" then only  @ref orxonox::Notification "Notifications" from the Questsystem wouuld be displayed in that particular queue. If you set senders to "all" then all Notifications will be displayed. Different senders can be concatinated with commas.
+    - @b size The size specifies how many @ref orxonox::Notification "Notifications" are displayed at the most, if there are more @ref orxonox::Notification "Notifications" that could be displayed but the size is smaller than the number of @ref orxonox::Notification "Notifications", then only the most recent are displayed.
+    - @b displayTime The display time specifies how long a @ref orxonox::Notification "Notification" is displayed at the most.
+
     @subsection NotificationLayer NotificationLayer
     The NotificationLayer is a GUI sheet, that displays all the @ref orxonox::NotificationQueue "NotificationQueues" and their @ref orxonox::Notification "Notifications". In its normal mode of operation it is transparent to input, meaning that it only functions as a means of displaying, however if switched to edit mode the NotificationLayer no longer is transparent to input and allows for the adding, removal and modification of @ref orxonox::NotificationQueue "NotificationQueues".
 
-    @subsection NotificationQueue NotificationQueue
-    ...
-
     @subsection NotificationManager NotificationManager
-    ...
+    The @ref orxonox::NotificationManager "NotificationManager" is (hence the name) the managing entity in this setting. It is responsible for the registering and unregistering of @ref orxonox::NotificationListener "NotificationListeners" (which the @ref orxonox::NotificationQueue "NotificationQueue" is) and also informs them about changes related to @ref orxonox::Notification "Notifications". It is also responsible for the creation and destruction of @ref orxonox::NotificationQueue "NotificationQueues" through the NotificationLayer and is also the point of approach for the NotificationLayer to get information it needs. Finally the @ref orxonox::NotificationManager "NotificationManager" is responsible for sending (and in the process creating) @ref orxonox::Notification "Notifications" and is a means for the @ref orxonox::NotificationQueue "NotificationQueues" to get the information they need about @ref orxonox::Notification "Notifications".
 
     @subsection Notification Notification
     The @ref orxonox::Notification "Notification" class is more or less a data structure that groups the notification message and the sender, and possibly other future parameters together to form a comprehensive structure that we call Notification.
@@ -171,6 +174,10 @@
 
     @defgroup NotificationDispatchers Dispatchers
     @ingroup Notifications
+
+    @ref orxonox::NotificationDispatcher "NotificationDispatchers" are entities that are instantiated in a level file (through XML) and that dispatch (or send) a specific @ref orxonox::Notification "Notification" upon having received a triggering event.
+
+    At this point there are two @ref orxonox::NotificationDispatcher "NotificationDispatchers", the @ref orxonox::SimpleNotification "SimpleNotification", which just displays a specified message, and the @ref orxonox::CommandNotification "CommandNotification" which displays a message with a binding for a specified command in it.
 */
 
 /**

Modified: code/trunk/src/modules/notifications/Notification.cc
===================================================================
--- code/trunk/src/modules/notifications/Notification.cc	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/Notification.cc	2010-09-24 10:01:57 UTC (rev 7488)
@@ -59,11 +59,12 @@
     @param message
         The message of the Notification.
     */
-    Notification::Notification(const std::string & message)
+    Notification::Notification(const std::string& message, const std::string& sender)
     {
         RegisterRootObject(Notification);
         this->initialize();
         this->message_ = message;
+        this->sender_ = sender;
     }
 
     /**
@@ -83,47 +84,6 @@
     {
         this->message_.clear();
         this->sender_ = NotificationManager::NONE;
-        this->sent_ = false;
     }
 
-    /**
-    @brief
-        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
-    @param sender
-        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
-    @return
-        Returns true if successful.
-    */
-    bool Notification::send(const std::string & sender)
-    {
-        if(this->isSent()) //TODO: Needed?
-            return false;
-
-        this->sender_ = sender;
-        bool successful = NotificationManager::getInstance().registerNotification(this);
-        if(!successful)
-            return false;
-        this->sent_ = true;
-
-        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
-
-        return true;
-    }
-
-    /**
-    @brief
-        Sets the message of the notification.
-    @param message
-        The message to be set.
-    @return
-        Returns true if successful.
-    */
-    bool Notification::setMessage(const std::string & message)
-    {
-        if(this->isSent()) // The message cannot be changed if the message has already been sent.
-            return false;
-        this->message_ = message;
-        return true;
-    }
-
 }

Modified: code/trunk/src/modules/notifications/Notification.h
===================================================================
--- code/trunk/src/modules/notifications/Notification.h	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/Notification.h	2010-09-24 10:01:57 UTC (rev 7488)
@@ -53,18 +53,10 @@
     {
         public:
             Notification();
-            Notification(const std::string & message);
+            Notification(const std::string& message, const std::string& sender);
             virtual ~Notification();
 
-            bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
-
             /**
-            @brief Checks whether the Notification was sent.
-            @return Returns true if the Notification was sent already.
-            */
-            inline bool isSent(void) const
-                { return this->sent_; }
-            /**
             @brief Returns the message of the Notification.
             @return Returns the message of the Notification.
             */
@@ -74,12 +66,9 @@
             inline const std::string & getSender(void) const
                 { return this->sender_; }
 
-            bool setMessage(const std::string & message); //!< Sets the message of the notification.
-
         private:
             std::string message_; //!< The Notification message.
             std::string sender_; //!< The sender of the notification.
-            bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
 
             void initialize(void); //!< Registers the object and sets some default values.
 

Modified: code/trunk/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.cc	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.cc	2010-09-24 10:01:57 UTC (rev 7488)
@@ -82,6 +82,8 @@
     {
         SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
 
+        XMLPortParam(NotificationDispatcher, "sender", getSender, setSender, xmlelement, mode);
+        
         XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
     }
 

Modified: code/trunk/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.h	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.h	2010-09-24 10:01:57 UTC (rev 7488)
@@ -48,9 +48,11 @@
     @brief
         A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified @ref orxonox::Notification "Notification".
 
+        There is one parameter to be set, the @b sender . The sender specifies the part of Orxonox the sent @ref orxonox::Notification "Notification" comes from. The default value is set by the classes implementing NotificationDispatcher.
+
         Its standard usage is:
         @code
-        <NotificationDispatcher>
+        <NotificationDispatcher sender="me">
             <events>
                 <trigger>
                     <PlayerTrigger />
@@ -75,8 +77,14 @@
             @brief Get the sender of the Notification dispatched by this NotificationDispatcher.
             @return Returns the name of the sender.
             */
-            const std::string& getSender(void)
+            const std::string& getSender(void) const
                 { return this->sender_; }
+                        /**
+            @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
+            @param sender The name of the sender.
+            */
+            void setSender(const std::string& sender)
+                { this->sender_ = sender; }
 
             void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
             bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
@@ -87,13 +95,6 @@
             void registerVariables(void); //!< Register some variables for synchronisation.
 
             /**
-            @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
-            @param sender The name of the sender.
-            */
-            void setSender(const std::string& sender)
-                { this->sender_ = sender; }
-
-            /**
             @brief Creates the notification message that should be sent upon the NotificationDispatcher triggering.
                    This method can be overloaded to customize the NotificationDispatcher.
             @return Returns the notification message.

Modified: code/trunk/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-24 10:01:57 UTC (rev 7488)
@@ -57,7 +57,7 @@
     // Register tolua_open function when loading the library.
     DeclareToluaInterface(Notifications);
 
-    ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
+    ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
 
     // Setting console command to enter the edit mode.
     SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
@@ -87,6 +87,11 @@
     {
         ModifyConsoleCommand("enterEditMode").setObject(NULL);
 
+        // Destroys all Notifications.
+        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it!= this->allNotificationsList_.end(); it++)
+            it->second->destroy();
+        this->allNotificationsList_.clear();
+
         COUT(3) << "NotificationManager destroyed." << std::endl;
     }
 
@@ -97,11 +102,9 @@
     void NotificationManager::preDestroy(void)
     {
         // Destroys all NotificationQueues that have been registered with the NotificationManager.
-        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
+        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++)
         {
-            NotificationQueue* queue = (*it).second;
-            it++;
-            queue->destroy();
+            it->second->destroy(true);
         }
         this->queues_.clear();
     }
@@ -123,8 +126,9 @@
         // 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);
-            notification->send(sender);
+            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())

Modified: code/trunk/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationQueue.cc	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/NotificationQueue.cc	2010-09-24 10:01:57 UTC (rev 7488)
@@ -37,6 +37,7 @@
 #include <sstream>
 
 #include "core/CoreIncludes.h"
+#include "core/GameMode.h"
 #include "core/GUIManager.h"
 #include "core/LuaState.h"
 #include "util/Convert.h"
@@ -111,17 +112,30 @@
     {
         this->targets_.clear();
 
-        if(this->registered_) // If the 
+        if(this->registered_) // If the NotificationQueue is registered.
         {
-            this->clear();
+            this->clear(true);
 
             // Unregister with the NotificationManager.
             NotificationManager::getInstance().unregisterListener(this);
             NotificationManager::getInstance().unregisterQueue(this);
+        }
+    }
 
-            // Remove the NotificationQueue in lua.
+    /**
+    @brief
+        Destroys the NotificationQueue.
+        Used in lua and NotificationManager.
+    @param noGraphics
+        If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed.
+    */
+    void NotificationQueue::destroy(bool noGraphics)
+    {
+        // Remove the NotificationQueue in lua.
+        if(GameMode::showsGraphics() && !noGraphics)
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
-        }
+
+        this->OrxonoxClass::destroy();
     }
 
     /**
@@ -130,7 +144,8 @@
     */
     void NotificationQueue::create(void)
     {
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
+        if(GameMode::showsGraphics())
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
     }
 
     /**
@@ -225,7 +240,8 @@
         this->notifications_.insert(this->notifications_.begin(), container);
 
         // Push the Notification to the GUI.
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
+        if(GameMode::showsGraphics())
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     }
 
     /**
@@ -253,7 +269,8 @@
         delete container;
 
         // Pops the Notification from the GUI.
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
+        if(GameMode::showsGraphics())
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     }
 
     /**
@@ -275,14 +292,17 @@
         delete *containerIterator;
 
         // Removes the Notification from the GUI.
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
+        if(GameMode::showsGraphics())
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     }
 
     /**
     @brief
         Clears the NotificationQueue by removing all NotificationContainers.
+    @param noGraphics
+        If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
     */
-    void NotificationQueue::clear(void)
+    void NotificationQueue::clear(bool noGraphics)
     {
         this->ordering_.clear();
         // Delete all NotificationContainers in the list.
@@ -294,7 +314,8 @@
         this->size_ = 0;
 
         // Clear the NotificationQueue in the GUI.
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
+        if(GameMode::showsGraphics() && !noGraphics)
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
     }
 
     /**

Modified: code/trunk/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-24 10:01:57 UTC (rev 7488)
@@ -68,10 +68,10 @@
         Displays @ref orxonox::Notification "Notifications" from specific senders.
 
         There are quite some parameters that influence the behaviour of the NotificationQueue:
-        - 'name': The name of the NotificationQueue. It needs to be unique.
-        - 'senders': The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
-        - 'size': The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
-        - 'displayTime': The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
+        - @b name The name of the NotificationQueue. It needs to be unique.
+        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
+        - @b size The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
+        - @b displayTime The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
 
     @author
         Damian 'Mozork' Frick
@@ -84,11 +84,8 @@
             NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
             virtual ~NotificationQueue();
 
-            /**
-            @brief Destroys the NotificationQueue.
-                   Used in lua.
-            */
-            void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
+            //! Destroys the NotificationQueue.
+            void destroy(bool noGraphics = false); // tolua_export
 
             virtual void tick(float dt); //!< To update from time to time.
 
@@ -167,7 +164,7 @@
             void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
             void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer.
 
-            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
+            void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.
 
     }; // tolua_export
 

Modified: code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CommandNotification.h	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/dispatchers/CommandNotification.h	2010-09-24 10:01:57 UTC (rev 7488)
@@ -49,7 +49,7 @@
 
         In use it would like this:
         @code
-        <CommandNotification preMessage="Please press " command="someCommand" postMessage=" to do something." >
+        <CommandNotification preMessage="Please press " command="someCommand" postMessage=" to do something." sender="me">
             <events>
                 <trigger>
                     <PlayerTrigger />

Modified: code/trunk/src/modules/notifications/dispatchers/SimpleNotification.h
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/SimpleNotification.h	2010-09-23 21:57:08 UTC (rev 7487)
+++ code/trunk/src/modules/notifications/dispatchers/SimpleNotification.h	2010-09-24 10:01:57 UTC (rev 7488)
@@ -48,7 +48,7 @@
 
         In use it would like this:
         @code
-        <SimpleNotification message="some message..." >
+        <SimpleNotification message="some message..." sender="me">
             <events>
                 <trigger>
                     <PlayerTrigger />




More information about the Orxonox-commit mailing list