Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/orxonox/interfaces/NotificationListener.h @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 7.5 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/class/OrxonoxInterface.h"
47
48namespace orxonox
49{
50    // TODO: Document.
51    enum class NotificationMessageType {
52        info,
53        important
54    };
55   
56    enum class NotificationSendMode {
57        local,
58        network,
59        broadcast
60    };
61   
62    enum class NotificationCommand {
63        none,
64        clear
65    };
66
67    // TODO: Update doc.
68    /**
69    @brief
70        NotificationListener interface.
71
72        The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
73        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.
74
75        When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
76
77    @author
78        Damian 'Mozork' Frick
79       
80    @ingroup Notifications
81    @todo Consistent terminology between message, notification and command.
82    */
83    class _OrxonoxExport NotificationListener : virtual public OrxonoxInterface
84    {
85        public:
86            NotificationListener();
87            virtual ~NotificationListener() {}
88
89            /**
90            @brief Sends a Notification with the specified message to the specified client from the specified sender.
91            @param message The message that should be sent.
92            @param sender The sender that sent the notification. Default is 'none'.
93            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
94            @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.
95            @param clientId The id of the client the notification should be sent to. Default is 0.
96            */
97            static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, NotificationMessageType messageType = NotificationMessageType::info, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0)
98                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
99            /**
100            @brief Sends a specified command to the specified client from the specified sender.
101            @param command The command that should be sent (and later executed).
102            @param sender The sender that sent the notification. Default is 'none'.
103            @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.
104            @param clientId The id of the client the command should be sent to. Default is 0.
105            */
106            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0)
107                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
108
109            static void sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
110
111            //TODO: Make protected?
112           
113            /**
114            @brief Registers a notification with the NotificationListener.
115                   This needs to be overloaded by each class inheriting from NotificationListener.
116            @param message The notification's message.
117            @param sender The sender of the notification.
118            @param type The type of the notification.
119            @return Returns true if the notification was successfully registered, false if not.
120            */
121            virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
122                { return false; }
123            /**
124            @brief Executes a command with the NotificationListener
125                   This needs to be overloaded by each class inheriting from NotificationListener.
126            @param command The command to be executed.
127            @param sender The sender of the command.
128            @return Returns true if the command was successfully executed, false if not.
129            */
130            virtual bool executeCommand(NotificationCommand command, const std::string& sender) { return false; }
131
132        public:
133           
134            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
135            static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
136           
137            //! Commands
138            static const std::string COMMAND_CLEAR;
139            static const std::string COMMAND_NONE;
140           
141        protected:
142            static void sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand = false, NotificationMessageType messageType = NotificationMessageType::info); // Helper method to send both notifications and commands over the network.
143
144            static NotificationCommand str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
145            static const std::string& command2Str(NotificationCommand command); // Helper method. Converts a command enum into its corresponding string.
146    };
147}
148
149#endif /* _NotificationListener_H__ */
Note: See TracBrowser for help on using the repository browser.