Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/src/modules/notifications/Notification.cc @ 7326

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

Some additional changes.

  • Property svn:eol-style set to native
File size: 4.0 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    */
51    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
52    {
53        RegisterObject(Notification);
54        this->initialize();
55        this->registerVariables();
56    }
57
58    /**
59    @brief
60        Constructor. Creates a Notification with the input message.
61    @param message
62        The message of the Notification.
63    */
64    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
65    {
66        RegisterObject(Notification);
67        this->initialize();
68        this->message_ = message;
69        this->registerVariables();
70    }
71
72    /**
73    @brief
74        Destructor.
75    */
76    Notification::~Notification()
77    {
78
79    }
80
81    /**
82    @brief
83        Registers the object and sets some default values.
84    */
85    void Notification::initialize(void)
86    {
87        this->message_.clear();
88        this->sender_ = NotificationManager::NONE;
89        this->sent_ = false;
90    }
91
92    void Notification::registerVariables(void)
93    {
94        registerVariable(this->message_);
95        registerVariable(this->sender_);
96        registerVariable(this->sent_);
97    }
98
99    /**
100    @brief
101        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
102    @param sender
103        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
104    @return
105        Returns true if successful.
106    */
107    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
108    {
109
110        callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, clientId, sender);
111
112        return true;
113    }
114
115    bool Notification::sendHelper(unsigned int clientId, const std::string& sender)
116    {
117        if(this->isSent()) //TODO: Needed?
118            return false;
119
120        this->sender_ = sender;
121        bool successful = NotificationManager::getInstance().registerNotification(this);
122        if(!successful)
123            return false;
124        this->sent_ = true;
125
126        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
127
128        return true;
129    }
130
131    /**
132    @brief
133        Sets the message of the notification.
134    @param message
135        The message to be set.
136    @return
137        Returns true if successful.
138    */
139    bool Notification::setMessage(const std::string & message)
140    {
141        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
142            return false;
143        this->message_ = message;
144        return true;
145    }
146
147}
Note: See TracBrowser for help on using the repository browser.