- Timestamp:
- Sep 9, 2010, 10:59:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/src/modules/notifications/NotificationManager.cc
r7362 r7395 28 28 29 29 /** 30 @file 30 @file NotificationManager.cc 31 31 @brief Implementation of the NotificationManager class. 32 32 */ … … 43 43 #include "NotificationQueue.h" 44 44 45 #include "ToluaBindNotifications.h" 46 45 47 namespace orxonox 46 48 { … … 49 51 const std::string NotificationManager::NONE("none"); 50 52 53 // Register tolua_open function when loading the library. 54 DeclareToluaInterface(Notifications); 55 51 56 ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false); 52 57 … … 65 70 66 71 ModifyConsoleCommand("enterEditMode").setObject(this); 67 68 if(GameMode::showsGraphics()) 69 { 70 GUIManager::getInstance().loadGUI("NotificationLayer"); 71 72 // Create first queue: 73 this->queues_.push_back(new NotificationQueue("all")); 74 } 72 73 COUT(3) << "NotificatioManager created." << std::endl; 75 74 } 76 75 … … 82 81 { 83 82 ModifyConsoleCommand("enterEditMode").setObject(NULL); 83 84 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 85 it->second->destroy(); 86 87 COUT(3) << "NotificationManager destroyed." << std::endl; 84 88 } 85 89 86 90 void NotificationManager::preDestroy(void) 87 91 { 88 for(std::vector<NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) 89 (*it)->destroy(); 92 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); ) 93 { 94 NotificationQueue* queue = (*it).second; 95 it++; 96 queue->destroy(); 97 } 90 98 this->queues_.clear(); 91 99 } … … 101 109 bool NotificationManager::registerNotification(Notification* notification) 102 110 { 103 104 if(notification == NULL) //!< A NULL-Notification cannot be registered. 111 if(notification == NULL) // A NULL-Notification cannot be registered. 105 112 return false; 106 113 107 114 std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time. 108 115 109 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time,notification));110 111 if(notification->getSender() == N ONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.116 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification)); 117 118 if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications. 112 119 return true; 113 120 114 121 bool all = false; 115 if(notification->getSender() == ALL) // If all are the sender, then the Notifications is added to every NotificationListener.122 if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener. 116 123 all = true; 117 124 … … 119 126 for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners. 120 127 { 121 std::set<std::string> set = it->first->getTargetsSet(); 122 if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works. 128 std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet(); 129 bool bAll = set.find(NotificationManager::ALL) != set.end(); 130 if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works. 123 131 { 124 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); // Insert the Notification in the Notifications list of the current NotificationListener. 132 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 } 125 136 it->first->update(notification, time); // Update the listener. 126 137 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification); … … 132 143 } 133 144 134 COUT(4) << "Notification registered with the NotificationManager." << std::endl;145 COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl; 135 146 136 147 return true; … … 154 165 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 155 166 156 // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed. 157 if(this->listenerCounter_[notification] == (unsigned int) 0) 158 { 159 this->removeNotification(notification, this->allNotificationsList_); 160 this->listenerCounter_.erase(notification); 161 notification->destroy(); 162 } 163 164 COUT(4) << "Notification unregistered with the NotificationManager." << std::endl; 167 COUT(4) << "Notification (&" << notification << ")unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl; 165 168 } 166 169 … … 175 178 Returns true if successful. 176 179 */ 177 //TODO: Needed?178 180 bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map) 179 181 { … … 206 208 this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners. 207 209 208 std::set<std::string > set = listener->getTargetsSet(); //TODO: Does this work?210 std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet(); 209 211 210 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. 211 if(set.find(ALL) != set.end()) 212 { 213 bool bAll = set.find(NotificationManager::ALL) != set.end(); 214 std::multimap<std::time_t, Notification*> map; 215 if(bAll) 213 216 this->notificationLists_[index] = &this->allNotificationsList_; 214 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 215 return true; 216 } 217 218 this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>; 219 std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index]; 217 else 218 { 219 this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>; 220 map = *this->notificationLists_[index]; 221 } 220 222 221 223 // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 222 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)223 { 224 if( set.find(it->second->getSender()) != set.end()) // Checks whether the overlayhas the sender of the current notification as target.224 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 225 { 226 if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target. 225 227 { 226 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 228 if(!bAll) 229 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 227 230 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 228 231 if(counterIt == this->listenerCounter_.end()) … … 288 291 return false; 289 292 290 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.291 292 if(notifications == NULL) // Returns NULL, if there are no Notifications.293 return true;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; 294 297 295 298 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; 296 299 itLowest = notifications->lower_bound(timeFrameStart); 297 itHighest = notifications->upper_bound(timeFrame Start);300 itHighest = notifications->upper_bound(timeFrameEnd); 298 301 299 302 for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it. 300 { 301 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); // Add the found Notifications to the map. 302 } 303 map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map. 303 304 304 305 return true; 305 306 } 306 307 307 void NotificationManager::createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime) 308 { 309 this->queues_.push_back(new NotificationQueue(name, targets, size, displayTime)); 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()); 310 335 } 311 336
Note: See TracChangeset
for help on using the changeset viewer.