[Orxonox-commit 3765] r8445 - in code/branches/tutoriallevel2/src: modules/notifications modules/questsystem orxonox/interfaces
dafrick at orxonox.net
dafrick at orxonox.net
Tue May 10 23:37:22 CEST 2011
Author: dafrick
Date: 2011-05-10 23:37:22 +0200 (Tue, 10 May 2011)
New Revision: 8445
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/NotificationListener.cc
code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
Log:
NotificationListener is new an entity which is informed of new notifications. The NotificationManager is, so far, the only NotificationListener. This means that Notifications can now be sent from within orxonox (though not libraries or external).
Also introduced notification commands to affect the NotificationQueues in more ways than just have them display messages (e.g. clearing them).
Added a message type which allows to send Notifications of different importance, allowing the NotificationQueus to display them differently.
Modified: code/branches/tutoriallevel2/src/modules/notifications/Notification.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/Notification.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/Notification.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -47,12 +47,13 @@
@param sender
The sender of the Notification.
*/
- Notification::Notification(const std::string& message, const std::string& sender)
+ Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
{
RegisterRootObject(Notification);
this->initialize();
this->message_ = message;
this->sender_ = sender;
+ this->type_ = type;
}
/**
Modified: code/branches/tutoriallevel2/src/modules/notifications/Notification.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/Notification.h 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/Notification.h 2011-05-10 21:37:22 UTC (rev 8445)
@@ -39,6 +39,7 @@
#include <string>
#include "core/OrxonoxClass.h"
+#include "interfaces/NotificationListener.h"
namespace orxonox
{
@@ -47,7 +48,7 @@
@brief
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).
- A Notification is just a datastructure that is used internally by the Notifications module.
+ A Notification is just a data structure that is used internally by the Notifications module.
@author
Damian 'Mozork' Frick
@@ -57,7 +58,7 @@
class _NotificationsExport Notification : public OrxonoxClass
{
public:
- Notification(const std::string& message, const std::string& sender);
+ Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
virtual ~Notification();
/**
@@ -74,9 +75,17 @@
inline const std::string & getSender(void) const
{ return this->sender_; }
+ /**
+ @brief Get the type of the Notification.
+ @return Returns an enum with the type of the Notification.
+ */
+ inline notificationMessageType::Value getType(void) const
+ { return this->type_; }
+
private:
std::string message_; //!< The Notification message.
std::string sender_; //!< The sender of the notification.
+ notificationMessageType::Value type_; //!< The type of the notification.
void initialize(void); //!< Registers the object and sets some default values.
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -112,7 +112,8 @@
if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
{
const std::string message = this->createNotificationMessage();
- NotificationListener::sendNotification(message, this->getSender(), notificationMessageMode::message, notificationSendMode::network, clientId);
+ // TODO: Make the type configurable.
+ NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);
}
else if(GameMode::isServer())
{
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -104,15 +104,66 @@
this->queues_.clear();
}
-
- bool NotificationManager::registerNotification(const std::string& message, const std::string& sender)
+
+ /**
+ @brief
+ Creates and registers a Notification with the input message from the input sender.
+ This is called by the NotificationListener, whenever a new notification arrives.
+ @param message
+ The message of the new Notification.
+ @param sender
+ The name of the entity (of the collective) that sent the new Notification.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
{
- Notification* notification = new Notification(message, sender);
+ // TODO: Do something with the type.
+ Notification* notification = new Notification(message, sender, type);
return this->registerNotification(notification);
}
/**
@brief
+ Executes the input command from the input sender.
+ This is called by the NotificationListener, whenever a new command arrives.
+ @param command
+ The command to be executed,
+ @param sender
+ The The name of the entity (of the collective) that sent the command.
+ */
+ bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
+ {
+ if(command == notificationCommand::clear)
+ {
+ this->commandClear(sender);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ @brief
+ The clear command. Clears all NotificationQueues that have its sender as a target.
+ @param sender
+ The sender of the clear command.
+ */
+ void NotificationManager::commandClear(const std::string& sender)
+ {
+ bool all = (sender == NotificationListener::ALL);
+ // Clear all NotificationQueues that have the input 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->second->getTargetsSet();
+ // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target.
+ if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end())
+ it->second->tidy();
+ }
+ }
+
+ /**
+ @brief
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.
@@ -131,9 +182,8 @@
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() == NotificationListener::ALL) // If all are the sender, then the Notifications is added to every NotificationQueue.
- all = true;
+ // If all are the sender, then the Notifications is added to every NotificationQueue.
+ bool all = (notification->getSender() == NotificationListener::ALL);
// 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.
@@ -363,7 +413,7 @@
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
NotificationQueue* infoQueue = new NotificationQueue("info", NotificationListener::ALL, 1, -1);
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"CCFFFF00\")");
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)");
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueAlignment(\"info\", \"HorzCentred\")");
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h 2011-05-10 21:37:22 UTC (rev 8445)
@@ -66,7 +66,7 @@
NotificationManager();
virtual ~NotificationManager();
- virtual void preDestroy(void); //!< Is called before the object is destroyed.
+ virtual void preDestroy(void); // Is called before the object is destroyed.
/**
@brief Get the instance of the NotificationManager Singleton.
@@ -74,16 +74,17 @@
*/
static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
- virtual bool registerNotification(const std::string& message, const std::string& sender);
+ virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
+ virtual bool executeCommand(notificationCommand::Value command, const std::string& sender);
- bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
- void unregisterNotification(Notification* notification, NotificationQueue* queue); //!< Unregisters a Notification within the NotificationManager for a given NotificationQueue.
+ bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
+ void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
- 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.
+ 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 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.
+ @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now 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 timeDelay The timespan.
@return Returns true if successful.
@@ -91,17 +92,17 @@
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(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 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.
+ void enterEditMode(void); // Enters the edit mode of the NotificationLayer.
- bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
- void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
+ bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
+ void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
// tolua_begin
- void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
- void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
- orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
+ void loadQueues(void); // Loads all the NotificationQueues that should exist.
+ void createQueue(const std::string& name); // Creates a new NotificationQueue.
+ orxonox::NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
// tolua_end
private:
@@ -112,7 +113,10 @@
std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
- bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
+ bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
+
+ // Commands
+ void commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
}; // tolua_export
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -55,7 +55,7 @@
The name of the new NotificationQueue. It needs to be unique
@param senders
The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
- The senders need to be seperated by commas.
+ The senders need to be separated by commas.
@param size
The size (the maximum number of displayed Notifications) of this NotificationQueue.
@param displayTime
@@ -303,7 +303,7 @@
@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.
+ If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
*/
void NotificationQueue::clear(bool noGraphics)
{
@@ -368,7 +368,7 @@
/**
@brief
- Produces all targets of the NotificationQueue concatinated as string, with commas (',') as seperators.
+ Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators.
@return
Returns the targets as a string.
*/
@@ -394,7 +394,7 @@
Sets the targets of the NotificationQueue.
The targets are the senders whose Notifications are displayed in this queue.
@param targets
- Accepts a string of targets, each seperated by commas (','), spaces are ignored.
+ Accepts a string of targets, each separated by commas (','), spaces are ignored.
*/
void NotificationQueue::setTargets(const std::string & targets)
{
@@ -411,6 +411,12 @@
NotificationManager::getInstance().registerQueue(this);
}
}
+
+ void NotificationQueue::tidy(void)
+ {
+ while(this->size_ > 0)
+ this->pop();
+ }
}
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h 2011-05-10 21:37:22 UTC (rev 8445)
@@ -76,7 +76,7 @@
@brief
Displays @ref orxonox::Notification "Notifications" from specific senders.
- There are quite some parameters that influence the behaviour of the NotificationQueue:
+ There are quite some parameters that influence the behavior of the 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.
@@ -144,9 +144,11 @@
// tolua_begin
void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
- const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
+ const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets.
// tolua_end
+ void tidy(void);
+
private:
static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
Modified: code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -118,7 +118,7 @@
return false;
}
- NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageMode::message, notificationSendMode::network, player->getClientID());
+ NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
return true;
}
Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc 2011-05-10 21:37:22 UTC (rev 8445)
@@ -34,17 +34,20 @@
#include "core/CoreIncludes.h"
#include "network/Host.h"
#include "network/NetworkFunction.h"
+#include "util/SubString.h"
#include "interfaces/NotificationListener.h"
namespace orxonox
{
- const std::string NotificationListener::ALL("all");
- const std::string NotificationListener::NONE("none");
+ /*static*/ const std::string NotificationListener::ALL("all");
+ /*static*/ const std::string NotificationListener::NONE("none");
- registerStaticNetworkFunction(NotificationListener::sendNotificationHelper);
+ // Commands
+ /*static*/ const std::string NotificationListener::COMMAND_CLEAR("clear");
+ registerStaticNetworkFunction(NotificationListener::sendHelper);
NotificationListener::NotificationListener()
{
@@ -53,48 +56,86 @@
/**
@brief
- Sends a Notification with the specified message to the specified client from the specified sender.
+ Helper method to send both notifications and commands over the network.
@param message
- The message that should be sent.
+ The message/command that should be sent.
@param sender
- The sender that sent the notification.
- @param messageMode
- The mode of the message, can be either 'message' or 'command'.
+ The sender that sent the notification/command.
@param sendMode
- The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts.
+ The mode in which the notification/command is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts.
@param clientId
- The id of the client the notification should be sent to.
+ The id of the client the notification/command should be sent to.
+ @param isCommand
+ Whether the message is a notification or a command.
+ @param messageType
+ The type of the notification, can be either 'info' or 'important'.
*/
- /*static*/ void NotificationListener::sendNotification(const std::string& message, const std::string& sender, notificationMessageMode::Value messageMode, notificationSendMode::Value sendMode, unsigned int clientId)
+ /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand, notificationMessageType::Value messageType)
{
- // If we're in standalone mode or we're already no the right client we create and send the Notification.
+ // If we're in standalone mode or we're already no the right client we create and send the notification/command.
if(GameMode::isStandalone() || sendMode == notificationSendMode::local || (sendMode == notificationSendMode::network && Host::getPlayerID() == clientId))
{
- sendNotificationHelper(message, sender, messageMode);
+ sendHelper(message, sender, isCommand, messageType);
}
- // If we're on the server (and the server is not the intended recipient of the Notification) we send it over the network.
+ // If we're on the server (and the server is not the intended recipient of the notification/command) we send it over the network.
else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)
{
- callStaticNetworkFunction(NotificationListener::sendNotificationHelper, clientId, message, sender, (unsigned int)messageMode);
+ callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, (unsigned int)messageType);
}
else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)
{
// TODO: Works as intended?
- callStaticNetworkFunction(NotificationListener::sendNotificationHelper, NETWORK_PEER_ID_BROADCAST, message, sender, (unsigned int)messageMode);
+ callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, (unsigned int)messageType);
}
}
-
- /*static*/ void NotificationListener::sendNotificationHelper(const std::string& message, const std::string& sender, unsigned int messageMode)
+
+ /**
+ @brief
+ Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
+ @param message
+ The notification/command to be sent/executed.
+ @param sender
+ The sender that sent the notification/command.
+ @param isCommand
+ Whether the message is a command or a notification.
+ @param messageType
+ The type of the notification.
+ */
+ /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, unsigned int messageType)
{
// Iterate through all NotificationListeners and notify them by calling the method they overloaded.
for(ObjectList<NotificationListener>::iterator it = ObjectList<NotificationListener>::begin(); it != ObjectList<NotificationListener>::end(); ++it)
{
- if(messageMode == 0 && it->registerNotification(message, sender))
+ // If the notification is a message.
+ if(!isCommand && it->registerNotification(message, sender, notificationMessageType::Value(messageType)))
COUT(3) << "Notification \"" << message << "\" sent." << std::endl;
-
- if(messageMode == 1)
- it->executeCommand(message, sender);
+
+ // If the notification is a command.
+ if(isCommand)
+ {
+ notificationCommand::Value command = str2Command(message);
+ if(command != notificationCommand::none && it->executeCommand(command, sender))
+ COUT(3) << "Command \"" << message << "\" executed." << std::endl;
+ }
}
}
+
+ /**
+ @brief
+ Helper method. Converts a string into the enum for a command.
+ @param string
+ The string to be converted.
+ @return
+ Returns the corresponding enum, notificationCommand::none if the command doesn't exist.
+ */
+ /*static*/ notificationCommand::Value NotificationListener::str2Command(const std::string& string)
+ {
+ notificationCommand::Value command = notificationCommand::none;
+
+ if(string == NotificationListener::COMMAND_CLEAR)
+ command = notificationCommand::clear;
+
+ return command;
+ }
}
\ No newline at end of file
Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h 2011-05-10 19:27:03 UTC (rev 8444)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h 2011-05-10 21:37:22 UTC (rev 8445)
@@ -47,12 +47,12 @@
namespace orxonox
{
-
- namespace notificationMessageMode
+ // TODO: Document.
+ namespace notificationMessageType
{
enum Value {
- message,
- command
+ info,
+ important
};
}
@@ -64,34 +64,90 @@
broadcast
};
}
+
+ namespace notificationCommand
+ {
+ enum Value {
+ none,
+ clear
+ };
+ }
// TODO: Update doc.
/**
@brief
NotificationListener interface.
- The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed)
- When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager".
+ The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
+ The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton.
+ When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
+
@author
Damian 'Mozork' Frick
@ingroup Notifications
+ @todo Consistent terminology between message, notification and command.
*/
class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
{
public:
NotificationListener();
virtual ~NotificationListener() {}
+
+ /**
+ @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 sender The sender that sent the notification. Default is 'none'.
+ @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
+ @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.
+ @param clientId The id of the client the notification should be sent to. Default is 0.
+ */
+ static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
+ { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
+ /**
+ @brief Sends a specified command to the specified client from the specified sender.
+ @param message The command that should be sent (and later executed).
+ @param sender The sender that sent the notification. Default is 'none'.
+ @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
+ @param clientId The id of the client the command should be sent to. Default is 0.
+ */
+ static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
+ { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
+
+ static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
+
+ //TODO: Make protected?
- 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.
+ /**
+ @brief Registers a notification with the NotificationListener.
+ This needs to be overloaded by each class inheriting from NotificationListener.
+ @param message The notification's message.
+ @param sender The sender of the notification.
+ @param type The type of the notification.
+ @return Returns true if the notification was successfully registered, false if not.
+ */
+ virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
+ { return false; }
+ /**
+ @brief Executes a command with the NotificationListener
+ This needs to be overloaded by each class inheriting from NotificationListener.
+ @param command The command to be executed.
+ @param sender The sender of the command.
+ @return Returns true if the command was successfully executed, false if not.
+ */
+ virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
- static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageMode::Value messageMode = notificationMessageMode::message, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0);
- static void sendNotificationHelper(const std::string& message, const std::string& sender, unsigned int messageMode);
+ static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
+ static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
- virtual bool registerNotification(const std::string& message, const std::string& sender) { return false; }
- virtual void executeCommand(const std::string& command, const std::string& sender) {}
+ //! Commands
+ static const std::string COMMAND_CLEAR;
+
+ protected:
+ static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
+
+ static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
};
}
More information about the Orxonox-commit
mailing list