Orxonox  0.0.5 Codename: Arcturus
NotificationListener.h
Go to the documentation of this file.
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 
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 
47 
48 namespace orxonox
49 {
50  // TODO: Document.
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.
84  {
85  public:
87  virtual ~NotificationListener() {}
88 
98  { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
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 
121  virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
122  { return false; }
130  virtual bool executeCommand(NotificationCommand command, const std::string& sender) { return false; }
131 
132  public:
133 
134  static const std::string ALL;
135  static const std::string NONE;
136 
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__ */
static const std::string COMMAND_CLEAR
Commands.
Definition: NotificationListener.h:138
::std::string string
Definition: gtest-port.h:756
NotificationCommand
Definition: NotificationListener.h:62
NotificationListener interface.
Definition: NotificationListener.h:83
virtual bool executeCommand(NotificationCommand command, const std::string &sender)
Executes a command with the NotificationListener This needs to be overloaded by each class inheriting...
Definition: NotificationListener.h:130
Output level, used for messages directed to the user (e.g. "Press any key to continue") ...
Definition: OutputDefinitions.h:89
This is the class from which all interfaces of the game-logic (not the engine) are derived from...
Definition: OrxonoxInterface.h:50
static void sendCommand(const std::string &command, const std::string &sender=NotificationListener::NONE, NotificationSendMode sendMode=NotificationSendMode::local, unsigned int clientId=0)
Sends a specified command to the specified client from the specified sender.
Definition: NotificationListener.h:106
virtual ~NotificationListener()
Definition: NotificationListener.h:87
static const std::string COMMAND_NONE
Definition: NotificationListener.h:139
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.
Definition: NotificationListener.cc:76
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI() command(const std::string &fragment)
Returns a list of commands and groups and also supports auto-completion of the arguments of these com...
Definition: ArgumentCompletionFunctions.cc:178
Declaration of OrxonoxInterface, the base class of all interfaces in Orxonox.
NotificationSendMode
Definition: NotificationListener.h:56
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Declaration of several string manipulation functions, used in many parts of the game.
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
virtual bool registerNotification(const std::string &message, const std::string &sender, NotificationMessageType type)
Registers a notification with the NotificationListener.
Definition: NotificationListener.h:121
static const std::string ALL
Static string to indicate a sender that sends to all NotificationQueues.
Definition: NotificationListener.h:134
NotificationMessageType
Definition: NotificationListener.h:51
static const std::string NONE
Static string to indicate a sender that sends to no specific NotificationQueues.
Definition: NotificationListener.h:135
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)
Sends a Notification with the specified message to the specified client from the specified sender...
Definition: NotificationListener.h:97