Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.h @ 8453

Last change on this file since 8453 was 8453, checked in by dafrick, 13 years ago

Merging tutoriallevel2 branch into tutoriallevel3 branch.

  • Property svn:eol-style set to native
File size: 7.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file NotificationListener.h
31    @brief Definition of the NotificationListener class.
32    @ingroup Notifications
33*/
34
35#ifndef _NotificationListener_H__
36#define _NotificationListener_H__
37
38#include "OrxonoxPrereqs.h"
39
40#include <ctime>
41#include <set>
42#include <string>
43
44#include "util/StringUtils.h"
45
46#include "core/OrxonoxClass.h"
47
48namespace orxonox
49{
50    // TODO: Document.
51    namespace notificationMessageType
52    {
53        enum Value {
54            info,
55            important
56        };
57    }
58   
59    namespace notificationSendMode
60    {
61        enum Value {
62            local,
63            network,
64            broadcast
65        };
66    }
67   
68    namespace notificationCommand
69    {
70        enum Value {
71            none,
72            clear
73        };
74    }
75
76    // TODO: Update doc.
77    /**
78    @brief
79        NotificationListener interface.
80
81        The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
82        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.
83
84        When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
85
86    @author
87        Damian 'Mozork' Frick
88       
89    @ingroup Notifications
90    @todo Consistent terminology between message, notification and command.
91    */
92    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
93    {
94        public:
95            NotificationListener();
96            virtual ~NotificationListener() {}
97
98            /**
99            @brief Sends a Notification with the specified message to the specified client from the specified sender.
100            @param message The message that should be sent.
101            @param sender The sender that sent the notification. Default is 'none'.
102            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
103            @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.
104            @param clientId The id of the client the notification should be sent to. Default is 0.
105            */
106            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)
107                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
108            /**
109            @brief Sends a specified command to the specified client from the specified sender.
110            @param command The command that should be sent (and later executed).
111            @param sender The sender that sent the notification. Default is 'none'.
112            @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.
113            @param clientId The id of the client the command should be sent to. Default is 0.
114            */
115            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
116                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
117
118            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.
119
120            //TODO: Make protected?
121           
122            /**
123            @brief Registers a notification with the NotificationListener.
124                   This needs to be overloaded by each class inheriting from NotificationListener.
125            @param message The notification's message.
126            @param sender The sender of the notification.
127            @param type The type of the notification.
128            @return Returns true if the notification was successfully registered, false if not.
129            */
130            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
131                { return false; }
132            /**
133            @brief Executes a command with the NotificationListener
134                   This needs to be overloaded by each class inheriting from NotificationListener.
135            @param command The command to be executed.
136            @param sender The sender of the command.
137            @return Returns true if the command was successfully executed, false if not.
138            */
139            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
140
141        public:
142           
143            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
144            static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
145           
146            //! Commands
147            static const std::string COMMAND_CLEAR;
148            static const std::string COMMAND_NONE;
149           
150        protected:
151            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.
152
153            static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
154            static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
155    };
156}
157
158#endif /* _NotificationListener_H__ */
Note: See TracBrowser for help on using the repository browser.