Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/Notification.cc @ 7410

Last change on this file since 7410 was 7410, checked in by dafrick, 14 years ago

Removing some warnings (both compiler and doxygen).

  • Property svn:eol-style set to native
File size: 4.3 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 thes
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
31    @brief Implementation of the Notification class.
32*/
33
34#include "Notification.h"
35
36#include "core/CoreIncludes.h"
37#include "network/NetworkFunction.h"
38#include "NotificationManager.h"
39
40namespace orxonox
41{
42
43    CreateUnloadableFactory(Notification);
44
45    registerMemberNetworkFunction(Notification, sendHelper);
46
47    /**
48    @brief
49        Default constructor. Initializes the object.
50    @param creator
51        The object that created this Notification
52    */
53    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
54    {
55        RegisterObject(Notification);
56        this->initialize();
57        this->registerVariables();
58    }
59
60    /**
61    @brief
62        Constructor. Creates a Notification with the input message.
63    @param creator
64        The creator.
65    @param message
66        The message of the Notification.
67    */
68    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
69    {
70        RegisterObject(Notification);
71        this->initialize();
72        this->message_ = message;
73        this->registerVariables();
74    }
75
76    /**
77    @brief
78        Destructor.
79    */
80    Notification::~Notification()
81    {
82
83    }
84
85    /**
86    @brief
87        Registers the object and sets some default values.
88    */
89    void Notification::initialize(void)
90    {
91        this->message_.clear();
92        this->sender_ = NotificationManager::NONE;
93        this->sent_ = false;
94    }
95
96    void Notification::registerVariables(void)
97    {
98        registerVariable(this->message_);
99        registerVariable(this->sender_);
100        registerVariable(this->sent_);
101    }
102
103    /**
104    @brief
105        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
106    @param clientID
107        The id of the client that this Notification is sent to.
108    @param sender
109        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
110    @return
111        Returns true if successful.
112    */
113    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
114    {
115
116        if(GameMode::isStandalone())
117        {
118            this->sendHelper(sender);
119        }
120        else
121        {
122            callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender);
123        }
124
125        return true;
126    }
127
128    bool Notification::sendHelper(const std::string& sender)
129    {
130        if(this->isSent()) //TODO: Needed?
131            return false;
132
133        this->sender_ = sender;
134        bool successful = NotificationManager::getInstance().registerNotification(this);
135        if(!successful)
136            return false;
137        this->sent_ = true;
138
139        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
140
141        return true;
142    }
143
144    /**
145    @brief
146        Sets the message of the notification.
147    @param message
148        The message to be set.
149    @return
150        Returns true if successful.
151    */
152    bool Notification::setMessage(const std::string & message)
153    {
154        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
155            return false;
156        this->message_ = message;
157        return true;
158    }
159
160}
Note: See TracBrowser for help on using the repository browser.