Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Merged notifications branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.2 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 sender
107        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
108    @return
109        Returns true if successful.
110    */
111    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
112    {
113
114        if(GameMode::isStandalone())
115        {
116            this->sendHelper(sender);
117        }
118        else
119        {
120            callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender);
121        }
122
123        return true;
124    }
125
126    bool Notification::sendHelper(const std::string& sender)
127    {
128        if(this->isSent()) //TODO: Needed?
129            return false;
130
131        this->sender_ = sender;
132        bool successful = NotificationManager::getInstance().registerNotification(this);
133        if(!successful)
134            return false;
135        this->sent_ = true;
136
137        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
138
139        return true;
140    }
141
142    /**
143    @brief
144        Sets the message of the notification.
145    @param message
146        The message to be set.
147    @return
148        Returns true if successful.
149    */
150    bool Notification::setMessage(const std::string & message)
151    {
152        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
153            return false;
154        this->message_ = message;
155        return true;
156    }
157
158}
Note: See TracBrowser for help on using the repository browser.