- Timestamp:
- May 28, 2011, 4:21:14 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc
r8453 r8636 38 38 39 39 #include "core/CoreIncludes.h" 40 #include "core/XMLPort.h" 40 41 #include "util/SubString.h" 41 42 … … 43 44 { 44 45 45 /** 46 @brief 47 Constructor. Creates and initializes the object. 46 CreateFactory(NotificationQueue); 47 48 /** 49 @brief 50 Default constructor. Registers and initializes the object. 51 @param creator 52 The creator of the NotificationQueue. 53 */ 54 NotificationQueue::NotificationQueue(BaseObject* creator) : BaseObject(creator), registered_(false) 55 { 56 RegisterObject(NotificationQueue); 57 58 this->initialize(); 59 } 60 61 // TODO move to docu. 62 /** 63 @brief 64 Constructor. Registers and initializes the object. 65 @param creator 66 The creator of the NotificationQueue 48 67 @param name 49 68 The name of the new NotificationQueue. It needs to be unique 50 69 @param senders 51 70 The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. 52 The senders need to be sep arated by commas.71 The senders need to be seperated by commas. 53 72 @param size 54 73 The size (the maximum number of displayed Notifications) of this NotificationQueue. … … 56 75 The time during which a Notification is (at most) displayed. 57 76 */ 58 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) 59 { 60 this->registered_ = false; 61 62 RegisterRootObject(NotificationQueue); 63 64 // Initialize. 77 78 /** 79 @brief 80 Destructor. 81 */ 82 NotificationQueue::~NotificationQueue() 83 { 84 this->targets_.clear(); 85 86 if(this->isRegistered()) // If the NotificationQueue is registered. 87 { 88 this->clear(true); 89 90 // Unregister with the NotificationManager. 91 NotificationManager::getInstance().unregisterQueue(this); 92 } 93 } 94 95 /** 96 @brief 97 Initializes the NotificationQueue. 98 */ 99 void NotificationQueue::initialize(void) 100 { 65 101 this->size_ = 0; 66 102 this->tickTime_ = 0.0f; 67 68 // Sets the input values. 69 this->setTargets(senders); 70 this->name_ = name; 71 this->maxSize_ = size; 72 this->setDisplayTime(displayTime); 73 103 this->maxSize_ = NotificationQueue::DEFAULT_SIZE; 104 this->displayTime_ = NotificationQueue::DEFAULT_DISPLAY_TIME; 105 106 this->creationTime_ = std::time(0); 107 } 108 109 /** 110 @brief 111 Creates the NotificationQueue. 112 */ 113 void NotificationQueue::create(void) 114 { 74 115 // Register the NotificationQueue with the NotificationManager. 75 116 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); … … 87 128 /** 88 129 @brief 89 Destructor.90 */91 NotificationQueue::~NotificationQueue()92 {93 this->targets_.clear();94 95 if(this->registered_) // If the NotificationQueue is registered.96 {97 this->clear(true);98 99 // Unregister with the NotificationManager.100 NotificationManager::getInstance().unregisterQueue(this);101 }102 103 COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl;104 }105 106 /**107 @brief108 130 Updates the queue from time to time. 109 131 @param dt … … 115 137 if(this->displayTime_ != INF && this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick. 116 138 { 117 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containi g the current time.139 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containing the current time. 118 140 119 141 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); … … 129 151 } 130 152 153 void NotificationQueue::XMLPort(Element& xmlelement, XMLPort::Mode mode) 154 { 155 SUPER(NotificationQueue, XMLPort, xmlelement, mode); 156 157 XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode).defaultValues(NotificationListener::ALL); 158 XMLPortParam(NotificationQueue, "size", setMaxSize, getMaxSize, xmlelement, mode); 159 XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode); 160 161 this->create(); 162 } 163 131 164 /** 132 165 @brief … … 148 181 if(!notifications->empty()) 149 182 { 150 // Add all Notifications .183 // Add all Notifications that have been created after this NotificationQueue was created. 151 184 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 152 this->push(it->second, it->first); 185 { 186 if(it->first >= this->creationTime_) 187 this->push(it->second, it->first); 188 } 153 189 } 154 190 … … 305 341 return; 306 342 343 if(size == 0) 344 { 345 COUT(2) << "Trying to set maximal size of NotificationQueue '" << this->getName() << "' to 0. Ignoring..." << endl; 346 return; 347 } 348 307 349 this->maxSize_ = size; 308 350 309 if(this-> registered_)351 if(this->isRegistered()) 310 352 this->update(); 311 353 } … … 322 364 return; 323 365 366 if(time != NotificationQueue::INF && time <= 0) 367 { 368 COUT(2) << "Trying to set display time of NotificationQueue '" << this->getName() << "' to non-positive value. Ignoring..." << endl; 369 } 370 324 371 this->displayTime_ = time; 325 372 326 if(this-> registered_)373 if(this->isRegistered()) 327 374 this->update(); 328 375 } … … 367 414 368 415 // TODO: Why? 369 if(this-> registered_)416 if(this->isRegistered()) 370 417 { 371 418 NotificationManager::getInstance().unregisterQueue(this);
Note: See TracChangeset
for help on using the changeset viewer.