Changeset 7399 for code/branches/notifications/src/modules
- Timestamp:
- Sep 10, 2010, 11:17:02 PM (14 years ago)
- Location:
- code/branches/notifications/src/modules/notifications
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/src/modules/notifications/NotificationManager.cc
r7398 r7399 39 39 #include "core/LuaState.h" 40 40 #include "util/ScopedSingletonManager.h" 41 41 42 #include "interfaces/NotificationListener.h" 43 42 44 #include "Notification.h" 43 45 #include "NotificationQueue.h" … … 56 58 ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false); 57 59 58 //TODO: Make work.59 60 SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode); 60 61 … … 70 71 71 72 ModifyConsoleCommand("enterEditMode").setObject(this); 72 73 73 74 COUT(3) << "NotificatioManager created." << std::endl; 74 75 } … … 82 83 ModifyConsoleCommand("enterEditMode").setObject(NULL); 83 84 85 // Destroys all Notifications that have been registered with the NotificationManager. 84 86 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 85 87 it->second->destroy(); 86 88 87 89 COUT(3) << "NotificationManager destroyed." << std::endl; 88 90 } 89 91 92 /** 93 @brief 94 Is called before the object is destroyed. 95 */ 90 96 void NotificationManager::preDestroy(void) 91 97 { 98 // Destroys all NotificationQueues that have been registered with the NotificationManager. 92 99 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); ) 93 100 { … … 109 116 bool NotificationManager::registerNotification(Notification* notification) 110 117 { 111 if(notification == NULL) // A NULL-Notification cannot be registered. 112 return false; 118 assert(notification); 113 119 114 120 std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time. 115 121 122 // Add the Notification to the list that holds all Notifications. 116 123 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification)); 117 124 … … 123 130 all = true; 124 131 125 // Insert the notification in all listeners that have its sender as target.126 for(std::map<NotificationListener*, int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners.132 // Insert the Notification in all NotificationListeners that have its sender as target. 133 for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners. 127 134 { 128 135 std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet(); 129 136 bool bAll = set.find(NotificationManager::ALL) != set.end(); 130 if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works. 137 // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target. 138 if(all || bAll || set.find(notification->getSender()) != set.end()) 131 139 { 132 140 if(!bAll) 133 { 134 this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the Notifications list of the current NotificationListener. 135 } 136 it->first->update(notification, time); // Update the listener. 137 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification); 138 if(counterIt == this->listenerCounter_.end()) 139 this->listenerCounter_[notification] = 1; 140 else 141 this->listenerCounter_[notification] = counterIt->second + 1; 141 this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener. 142 it->first->update(notification, time); // Update the NotificationListener. 142 143 } 143 144 } … … 150 151 /** 151 152 @brief 152 Unregisters a Notification within the NotificationManager .153 Unregisters a Notification within the NotificationManager for a given NotificationListener. 153 154 @param notification 154 155 A pointer to the Notification to be unregistered. … … 161 162 assert(listener); 162 163 163 // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented. 164 if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second))) 165 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 164 // Remove the Notification from the list of Notifications of the input NotificationListener. 165 this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)); 166 166 167 167 COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl; … … 170 170 /** 171 171 @brief 172 Helper method that removes an input notification form an input map.172 Helper method that removes an input Notification form an input map. 173 173 @param notification 174 A pointer to the notification to be removed.174 A pointer to the Notification to be removed. 175 175 @param map 176 The map the notification should be removed from.176 The map the Notification should be removed from. 177 177 @return 178 178 Returns true if successful. … … 199 199 The NotificationListener to be registered. 200 200 @return 201 Returns true if successful. 201 Returns true if successful. Fales if the NotificationListener is already registered. 202 202 */ 203 203 bool NotificationManager::registerListener(NotificationListener* listener) 204 204 { 205 assert(listener); 206 207 // If the NotificationListener is already registered. 208 if(this->listenerList_.find(listener) != this->listenerList_.end()) 209 return false; 210 205 211 this->highestIndex_ += 1; 206 int index = this->highestIndex_;207 208 this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners.212 unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely. 213 214 this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners. 209 215 210 216 std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet(); 211 217 212 // If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications.218 // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications. 213 219 bool bAll = set.find(NotificationManager::ALL) != set.end(); 214 220 std::multimap<std::time_t, Notification*>* map; 215 221 if(bAll) 216 222 this->notificationLists_[index] = &this->allNotificationsList_; 223 // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners. 217 224 else 218 225 { … … 224 231 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 225 232 { 226 if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target. 227 { 228 if(!bAll) 229 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 230 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 231 if(counterIt == this->listenerCounter_.end()) 232 this->listenerCounter_[it->second] = 1; 233 else 234 this->listenerCounter_[it->second] = counterIt->second + 1; 235 } 233 if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target. 234 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 236 235 } 237 236 … … 245 244 /** 246 245 @brief 247 Unregisters a NotificationListener withing the NotificationManager. 246 Unregisters a NotificationListener within the NotificationManager. 247 @param listener 248 The NotificationListener to be unregistered. 248 249 */ 249 250 void NotificationManager::unregisterListener(NotificationListener* listener) … … 251 252 assert(listener); 252 253 253 int identifier = this->listenerList_.find(listener)->second; 254 //TODO: Make unsigned int. 255 unsigned int identifier = this->listenerList_.find(listener)->second; 254 256 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 255 257 256 // If the map is not the map of all notifications, make sure all Notifications are removed and delete it.258 // If the map is not the map of all Notifications, make sure all Notifications are unregistered. 257 259 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 258 260 if(map != &this->allNotificationsList_) … … 266 268 } 267 269 270 // Remove the NotificationListener from the list of NotificationListeners. 268 271 this->listenerList_.erase(listener); 272 // Remove the Notifications list that was associated with the input NotificationListener. 269 273 this->notificationLists_.erase(identifier); 270 274 … … 274 278 /** 275 279 @brief 276 Fetches the Notifications for a specific NotificationListener in a specified timeframe .280 Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 277 281 @param listener 278 282 The NotificationListener the Notifications are fetched for. 279 283 @param map 280 A multimap, in which the notifications are stored.284 A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 281 285 @param timeFrameStart 282 286 The start time of the timeframe. … … 286 290 Returns true if successful. 287 291 */ 288 bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 289 { 290 if(listener == NULL || map == NULL) 291 return false; 292 293 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener. 294 295 if(notifications == NULL) // Returns false, if there are no Notifications. 296 return false; 292 void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 293 { 294 assert(listener); 295 assert(map); 296 297 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener. 297 298 298 299 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; 300 // Iterators pointing to the bounds specified by the specified start and end times of the time frame. 299 301 itLowest = notifications->lower_bound(timeFrameStart); 300 302 itHighest = notifications->upper_bound(timeFrameEnd); 301 303 302 for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it. 303 map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map. 304 305 return true; 306 } 307 308 void NotificationManager::loadQueues(void) 309 { 310 new NotificationQueue("all"); 311 } 312 313 void NotificationManager::createQueue(const std::string& name) 314 { 315 new NotificationQueue(name); 316 } 317 318 NotificationQueue* NotificationManager::getQueue(const std::string & name) 319 { 320 std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name); 321 if(it == this->queues_.end()) 322 return NULL; 323 324 return (*it).second; 325 } 326 327 bool NotificationManager::registerQueue(NotificationQueue* queue) 328 { 329 return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second; 330 } 331 332 void NotificationManager::unregisterQueue(NotificationQueue* queue) 333 { 334 this->queues_.erase(queue->getName()); 335 } 336 304 for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time frame to the end of it. 305 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map. 306 } 307 308 /** 309 @brief 310 Enters the edit mode of the NotificationLayer. 311 */ 337 312 void NotificationManager::enterEditMode(void) 338 313 { … … 342 317 } 343 318 319 /** 320 @brief 321 Registers a NotificationQueue. 322 This makes sure that the NotificationQueue can be attained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager. 323 @param queue 324 A pointer to the NotificationQueue to be registered. 325 @return 326 Returns true if successful. If e.g. the a NotificationQueue with that name already exists this returns false. 327 */ 328 bool NotificationManager::registerQueue(NotificationQueue* queue) 329 { 330 return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second; 331 } 332 333 /** 334 @brief 335 Unregisters a NotificationQueue. 336 @param queue 337 A pointer to the NotificationQueue to be unregistered. 338 */ 339 void NotificationManager::unregisterQueue(NotificationQueue* queue) 340 { 341 this->queues_.erase(queue->getName()); 342 } 343 344 /** 345 @brief 346 Loads all the NotificationQueues that should exist. 347 */ 348 void NotificationManager::loadQueues(void) 349 { 350 new NotificationQueue("all"); 351 } 352 353 /** 354 @brief 355 Creates a new NotificationQueue. 356 This is used in lua. 357 @param name 358 The name of the new NotificationQueue. 359 */ 360 void NotificationManager::createQueue(const std::string& name) 361 { 362 new NotificationQueue(name); 363 } 364 365 /** 366 @brief 367 Get the NotificationQueue with the input name. 368 @param name 369 The name of the NotificationQueue. 370 @return 371 Returns a pointer to the NotificationQueue with the input name. Returns NULL if no NotificationQueue with such a name exists. 372 */ 373 NotificationQueue* NotificationManager::getQueue(const std::string & name) 374 { 375 std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name); 376 // Returns NULL if no such NotificationQueue exists. 377 if(it == this->queues_.end()) 378 return NULL; 379 380 return (*it).second; 381 } 382 344 383 } -
code/branches/notifications/src/modules/notifications/NotificationManager.h
r7395 r7399 62 62 virtual ~NotificationManager(); 63 63 64 virtual void preDestroy(void); 64 virtual void preDestroy(void); //!< Is called before the object is destroyed. 65 65 66 66 static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export … … 70 70 71 71 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 72 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager .72 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener. 73 73 bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. 74 74 void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. 75 75 76 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.76 void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 77 77 78 78 /** 79 @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.79 @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map. 80 80 @param listener The NotificationListener the Notifications are fetched for. 81 @param map A multimap, in which the notifications are stored.81 @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 82 82 @param timeDelay The timespan. 83 83 @return Returns true if successful. 84 84 */ 85 boolgetNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)86 { returnthis->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }85 void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay) 86 { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } 87 87 88 void enterEditMode(void); 88 void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer. 89 90 bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue. 91 void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue. 89 92 90 93 // tolua_begin 91 void loadQueues(void); 92 93 void createQueue(const std::string& name); 94 orxonox::NotificationQueue* getQueue(const std::string & name); 94 void loadQueues(void); //!< Loads all the NotificationQueues that should exist. 95 void createQueue(const std::string& name); //!< Creates a new NotificationQueue. 96 orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name. 95 97 // tolua_end 96 97 bool registerQueue(NotificationQueue* queue);98 void unregisterQueue(NotificationQueue* queue);99 98 100 99 private: 101 100 static NotificationManager* singletonPtr_s; 102 101 102 unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 103 104 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. 105 std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 106 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 107 103 108 std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. 104 109 105 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 106 107 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored. 108 std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 109 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 110 std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with. 111 112 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map. 110 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map. 113 111 114 112 }; // tolua_export -
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
r7398 r7399 41 41 #include "core/LuaState.h" 42 42 #include "util/Convert.h" 43 #include "util/SubString.h" 44 43 45 #include "Notification.h" 44 46 … … 49 51 @brief 50 52 Constructor. Creates and initializes the object. 53 @param name 54 The name of the new NotificationQueue. 55 @param senders 56 The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. 57 The senders need to be seperated by commas. 58 @param size 59 The size (the maximum number of displayed Notifications) of this NotificationQueue. 60 @param displayTime 61 The time during which a Notification is (at most) displayed. 51 62 */ 52 63 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) … … 56 67 RegisterRootObject(NotificationQueue); 57 68 58 this->initialize(); 59 69 // Initialize. 70 this->size_ = 0; 71 this->tickTime_ = 0.0; 72 73 // Sets the input values. 60 74 this->setTargets(senders); 61 75 this->name_ = name; … … 63 77 this->setDisplayTime(displayTime); 64 78 79 //TODO: Destroy if registration fails? 80 81 // Register the NotificationQueue with the NotificationManager. 65 82 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); 66 83 this->registered_ = true; 67 if(!queueRegistered) 84 if(!queueRegistered) // If the registration has failed. 68 85 { 69 86 this->registered_ = false; … … 72 89 } 73 90 74 this->create(); 75 91 this->create(); // Creates the NotificationQueue in lua. 92 93 // register the NotificationQueue as NotificationListener with the NotificationManager. 76 94 bool listenerRegistered = NotificationManager::getInstance().registerListener(this); 77 if(!listenerRegistered) 95 if(!listenerRegistered) // If the registration has failed. 78 96 { 79 97 this->registered_ = false; 98 // Remove the NotificationQueue in lua. 99 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 80 100 NotificationManager::getInstance().unregisterQueue(this); 81 101 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; … … 94 114 this->targets_.clear(); 95 115 96 if(this->registered_) 116 if(this->registered_) // If the 97 117 { 98 118 this->clear(); 99 119 120 // Unregister with the NotificationManager. 100 121 NotificationManager::getInstance().unregisterListener(this); 101 122 NotificationManager::getInstance().unregisterQueue(this); 102 123 124 // Remove the NotificationQueue in lua. 103 125 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 104 126 } 105 }106 107 /**108 @brief109 Initializes the object.110 Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.111 */112 void NotificationQueue::initialize(void)113 {114 this->size_ = 0;115 this->tickTime_ = 0.0;116 127 } 117 128 … … 139 150 140 151 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); 141 while(it != this->ordering_.upper_bound(&this->timeLimit_)) // Iterate through all elements whose creation time is smaller than the current time minus the display time. 152 // Iterate through all elements whose creation time is smaller than the current time minus the display time. 153 while(it != this->ordering_.upper_bound(&this->timeLimit_)) 142 154 { 143 155 NotificationContainer* temp = *it; 144 156 it++; 145 this->remove(temp); 157 this->remove(temp); // Remove the Notifications that have expired. 146 158 } 147 159 … … 160 172 161 173 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 162 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time. 163 { 164 COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl; 165 return; 166 } 174 // Get the Notifications sent in the interval from now to now minus the display time. 175 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 167 176 168 177 if(!notifications->empty()) 169 178 { 170 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)// Add all Notifications.171 {179 // Add all Notifications. 180 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 172 181 this->push(it->second, it->first); 173 }174 182 } 175 183 176 184 delete notifications; 177 185 178 COUT( 3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4.186 COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; 179 187 } 180 188 … … 191 199 this->push(notification, time); 192 200 193 COUT( 3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4.194 } 195 196 /** 197 @brief 198 Adds a Notification to the NotificationQueue.201 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; 202 } 203 204 /** 205 @brief 206 Adds (pushes) a Notification to the NotificationQueue. 199 207 It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI. 200 208 @param notification 201 The Notification .209 The Notification to be pushed. 202 210 @param time 203 The time .211 The time when the Notification has been sent. 204 212 */ 205 213 void NotificationQueue::push(Notification* notification, const std::time_t & time) … … 216 224 217 225 this->ordering_.insert(container); 226 // Insert the Notification at the begin of the list (vector, actually). 218 227 this->notifications_.insert(this->notifications_.begin(), container); 219 228 229 // Push the Notification to the GUI. 220 230 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 221 231 } … … 223 233 /** 224 234 @brief 225 Removes the least recently added Notification form the NotificationQueue.235 Removes (pops) the least recently added Notification form the NotificationQueue. 226 236 */ 227 237 void NotificationQueue::pop(void) … … 230 240 this->ordering_.erase(container); 231 241 this->notifications_.pop_back(); 242 232 243 this->size_--; 244 233 245 delete container; 246 247 // Pops the Notification from the GUI. 234 248 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 235 249 } … … 237 251 /** 238 252 @brief 239 Removes the Notification that is stored in the input container.253 Removes the Notification that is stored in the input NotificationContainer. 240 254 @param container 241 255 The NotificationContainer with the Notification to be removed. … … 244 258 { 245 259 std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container); 260 // Get the index at which the Notification is. 246 261 std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin (); 247 262 this->ordering_.erase(container); 248 263 this->notifications_.erase(it); 264 249 265 this->size_--; 266 250 267 delete container; 268 269 // Removes the Notification from the GUI. 251 270 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); 252 271 } … … 254 273 /** 255 274 @brief 256 Clears the queue by removing all Notifications.275 Clears the NotificationQueue by removing all NotificationContainers. 257 276 */ 258 277 void NotificationQueue::clear(void) 259 278 { 260 279 this->ordering_.clear(); 280 // Delete all NotificationContainers in the list. 261 281 for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++) 262 282 delete *it; 263 283 264 284 this->notifications_.clear(); 285 265 286 this->size_ = 0; 287 288 // Clear the NotificationQueue in the GUI. 266 289 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")"); 267 290 } … … 272 295 @param name 273 296 The name to be set. 274 @return 275 returns true if successful. 276 */ 277 bool NotificationQueue::setName(const std::string& name) 297 */ 298 void NotificationQueue::setName(const std::string& name) 278 299 { 279 300 this->name_ = name; 280 return true;281 301 } 282 302 … … 286 306 @param size 287 307 The size to be set. 288 @return289 Returns true if successful.290 308 */ 291 309 void NotificationQueue::setMaxSize(unsigned int size) … … 293 311 if(this->maxSize_ == size) 294 312 return; 295 313 296 314 this->maxSize_ = size; 297 this->sizeChanged(); 298 } 299 300 /** 301 @brief 302 Adjusts the NotificationQueue, when the maximum size has changed. 303 */ 304 void NotificationQueue::sizeChanged(void) 305 { 306 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getSize()) + ")"); 307 this->update(); 315 316 if(this->registered_) 317 this->update(); 308 318 } 309 319 … … 329 339 /** 330 340 @brief 331 Produces all targets concatinated as string, with kommas (',') as seperators.341 Produces all targets of the NotificationQueue concatinated as string, with kommas (',') as seperators. 332 342 @return 333 343 Returns the targets as a string. … … 337 347 std::stringstream stream; 338 348 bool first = true; 339 for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets. 349 // Iterate through the set of targets. 350 for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) 340 351 { 341 352 if(!first) 342 stream << ',';353 stream << ", "; 343 354 else 344 355 first = false; … … 351 362 /** 352 363 @brief 353 Sets the targets of the queue.364 Sets the targets of the NotificationQueue. 354 365 The targets are the senders whose Notifications are displayed in this queue. 355 366 @param targets 356 367 Accepts a string of targets, each seperated by commas (','), spaces are ignored. 357 @return 358 Returns true if successful. 359 */ 360 bool NotificationQueue::setTargets(const std::string & targets) 368 */ 369 void NotificationQueue::setTargets(const std::string & targets) 361 370 { 362 371 this->targets_.clear(); 363 372 364 //TODO: Do with SubString. 365 std::string* pTemp; 366 unsigned int index = 0; 367 while(index < targets.size()) // Go through the string, character by character until the end is reached. 368 { 369 pTemp = new std::string(); 370 while(index < targets.size() && targets[index] != ',' && targets[index] != ' ') 371 { 372 *pTemp += targets[index]; 373 index++; 374 } 375 index++; 376 this->targets_.insert(*pTemp); 377 } 373 SubString string = SubString(targets, ",", " ", false); 374 for(unsigned int i = 0; i < string.size(); i++) 375 this->targets_.insert(string[i]); 378 376 379 377 if(this->registered_) … … 382 380 NotificationManager::getInstance().registerListener(this); 383 381 } 384 385 return true;386 382 } 387 383 -
code/branches/notifications/src/modules/notifications/NotificationQueue.h
r7398 r7399 43 43 44 44 #include "tools/interfaces/Tickable.h" 45 45 46 #include "interfaces/NotificationListener.h" 46 47 #include "NotificationManager.h" … … 76 77 virtual ~NotificationQueue(); 77 78 79 /** 80 @brief Destroys the NotificationQueue. 81 Used in lua. 82 */ 78 83 void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export 79 84 80 85 virtual void tick(float dt); //!< To update from time to time. 81 86 82 void update(void); //!< Updates the queue.83 void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.87 void update(void); //!< Updates the NotificationQueue. 88 void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification. 84 89 85 90 // tolua_begin … … 110 115 /** 111 116 @brief Returns the current number of Notifications displayed. 112 @return Returns the size of the queue.117 @return Returns the size of the NotificationQueue. 113 118 */ 114 119 inline unsigned int getSize() const … … 116 121 117 122 /** 118 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.119 @return Retu ns a set of stringholding the different targets.123 @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue. 124 @return Returns a set of strings holding the different targets. 120 125 */ 121 126 inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() … … 123 128 124 129 // tolua_begin 125 boolsetTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.130 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 126 131 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets. 127 132 // tolua_end … … 137 142 unsigned int displayTime_; //!< The time a Notification is displayed. 138 143 139 std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of.144 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 140 145 141 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well? 146 std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of. 147 148 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. 142 149 std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue. 143 150 … … 145 152 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 146 153 147 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.148 149 void initialize(void); //!< Initializes the object.150 154 void create(void); //!< Creates the NotificationQueue in lua. 151 155 152 boolsetName(const std::string& name); //!< Sets the name of the NotificationQueue.156 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 153 157 154 void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed. 158 void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue. 159 void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue. 160 void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer. 155 161 156 void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue. 157 void pop(void); //!< Removes the least recently added Notification form the NotificationQueue. 158 void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container. 159 160 void clear(void); //!< Clears the queue by removing all Notifications. 162 void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers. 161 163 162 164 }; // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.