- Timestamp:
- Sep 9, 2010, 10:59:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
r7354 r7395 35 35 36 36 #include <map> 37 #include <sstream> 37 38 38 39 #include "core/CoreIncludes.h" … … 62 63 this->setDisplayTime(displayTime); 63 64 65 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); 66 this->registered_ = true; 67 if(!queueRegistered) 68 { 69 this->registered_ = false; 70 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 71 return; 72 } 73 64 74 this->create(); 65 66 NotificationManager::getInstance().registerListener(this); 67 this->registered_ = true; 75 76 bool listenerRegistered = NotificationManager::getInstance().registerListener(this); 77 if(!listenerRegistered) 78 { 79 this->registered_ = false; 80 NotificationManager::getInstance().unregisterQueue(this); 81 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 82 return; 83 } 68 84 69 85 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; … … 77 93 { 78 94 this->targets_.clear(); 79 this->clear();80 95 81 96 if(this->registered_) 97 { 98 this->clear(); 99 82 100 NotificationManager::getInstance().unregisterListener(this); 101 NotificationManager::getInstance().unregisterQueue(this); 102 } 83 103 } 84 104 … … 100 120 void NotificationQueue::create(void) 101 121 { 102 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");122 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 103 123 } 104 124 … … 144 164 } 145 165 146 if(notifications->empty()) 147 return; 148 149 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications. 150 this->push(it->second, it->first); 166 if(!notifications->empty()) 167 { 168 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications. 169 { 170 this->push(it->second, it->first); 171 } 172 } 151 173 152 174 delete notifications; 153 175 154 COUT( 4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;176 COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4. 155 177 } 156 178 … … 167 189 this->push(notification, time); 168 190 169 COUT( 4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;191 COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4. 170 192 } 171 193 … … 253 275 bool NotificationQueue::setName(const std::string& name) 254 276 { 255 //TODO: Test uniqueness of name.256 277 this->name_ = name; 257 278 return true; … … 268 289 void NotificationQueue::setMaxSize(unsigned int size) 269 290 { 291 if(this->maxSize_ == size) 292 return; 293 270 294 this->maxSize_ = size; 271 295 this->sizeChanged(); … … 292 316 void NotificationQueue::setDisplayTime(unsigned int time) 293 317 { 318 if(this->displayTime_ == time) 319 return; 320 294 321 this->displayTime_ = time; 295 this->update(); 322 323 if(this->registered_) 324 this->update(); 296 325 } 297 326 … … 299 328 @brief 300 329 Produces all targets concatinated as string, with kommas (',') as seperators. 301 @param string 302 Pointer to a string which will be used by the method to fill with the concatination of the targets. 303 @return 304 Returns true if successful. 305 */ 306 bool NotificationQueue::getTargets(std::string* string) const 307 { 308 if(string == NULL) 309 { 310 COUT(4) << "Input string must have memory allocated." << std::endl; 311 return false; 312 } 313 string->clear(); 330 @return 331 Returns the targets as a string. 332 */ 333 const std::string& NotificationQueue::getTargets(void) const 334 { 335 std::stringstream stream; 314 336 bool first = true; 315 for(std::set<std::string >::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.337 for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets. 316 338 { 317 339 if(!first) 318 *string +=',';340 stream << ','; 319 341 else 320 342 first = false; 321 *string +=*it;322 } 323 324 return true;343 stream << *it; 344 } 345 346 return *(new std::string(stream.str())); 325 347 } 326 348 … … 352 374 } 353 375 376 if(this->registered_) 377 { 378 NotificationManager::getInstance().unregisterListener(this); 379 NotificationManager::getInstance().registerListener(this); 380 } 381 354 382 return true; 355 383 }
Note: See TracChangeset
for help on using the changeset viewer.