Changeset 5619 for code/branches/libraries/src/orxonox/objects/quest
- Timestamp:
- Aug 11, 2009, 12:33:16 AM (15 years ago)
- Location:
- code/branches/libraries/src/orxonox/objects/quest
- Files:
-
- 2 added
- 2 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/libraries/src/orxonox/objects/quest/CMakeLists.txt
r3196 r5619 18 18 QuestNotification.cc 19 19 ) 20 21 ADD_SUBDIRECTORY(notifications) -
code/branches/libraries/src/orxonox/objects/quest/QuestNotification.h
r3196 r5619 26 26 * 27 27 */ 28 28 29 29 #ifndef _QuestNotification_H__ 30 30 #define _QuestNotification_H__ … … 33 33 34 34 #include <string> 35 #include " overlays/notifications/Notification.h"35 #include "notifications/Notification.h" 36 36 37 37 namespace orxonox { … … 39 39 /** 40 40 @brief 41 41 42 42 @author 43 43 Damian 'Mozork' Frick … … 49 49 QuestNotification(const std::string & message); 50 50 virtual ~QuestNotification(); 51 51 52 52 bool send(void); 53 53 54 54 private: 55 55 static const std::string SENDER; 56 56 57 57 void initialize(void); 58 58 59 59 }; 60 60 -
code/branches/libraries/src/orxonox/objects/quest/notifications/NotificationManager.cc
r5616 r5619 38 38 #include "core/CoreIncludes.h" 39 39 #include "Notification.h" 40 #include " NotificationQueue.h"40 #include "interfaces/NotificationListener.h" 41 41 42 42 namespace orxonox … … 69 69 /** 70 70 @brief 71 Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.71 Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender. 72 72 @param notification 73 73 The Notification to be registered. … … 77 77 bool NotificationManager::registerNotification(Notification* notification) 78 78 { 79 79 80 80 if(notification == NULL) //!< A NULL-Notification cannot be registered. 81 81 return false; 82 82 83 83 std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time. 84 84 85 85 this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification)); 86 86 87 87 if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications. 88 88 return true; 89 89 90 90 bool all = false; 91 if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every Notification Queue.91 if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationListener. 92 92 all = true; 93 94 //!< Insert the notification in all queues that have its sender as target.95 for(std::map<Notification Queue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.93 94 //!< Insert the notification in all listeners that have its sender as target. 95 for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) //!< Iterate through all listeners. 96 96 { 97 97 std::set<std::string> set = it->first->getTargetsSet(); 98 98 if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works. 99 99 { 100 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current Notification Queue.101 it->first->update(notification, time); //!< Update the queue.100 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener. 101 it->first->update(notification, time); //!< Update the listener. 102 102 } 103 103 } 104 104 105 105 COUT(3) << "Notification registered with the NotificationManager." << std::endl; 106 106 107 107 return true; 108 108 } 109 109 110 110 /** 111 111 @brief 112 Registers a Notification Queuewithin the NotificationManager.113 @param queue114 The Notification Queueto be registered.112 Registers a NotificationListener within the NotificationManager. 113 @param listener 114 The NotificationListener to be registered. 115 115 @return 116 116 Returns true if successful. 117 117 */ 118 bool NotificationManager::register Queue(NotificationQueue* queue)118 bool NotificationManager::registerListener(NotificationListener* listener) 119 119 { 120 120 this->highestIndex_ += 1; 121 121 int index = this->highestIndex_; 122 123 this-> queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.124 125 std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?126 127 //! If all senders are the target of the queue, then the list of notification for that specific queueis te same as the list of all Notifications.122 123 this->listenerList_[listener] = index; //!< Add the NotificationListener to the list of listeners. 124 125 std::set<std::string> set = listener->getTargetsSet(); //TDO: Works this? 126 127 //! 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. 128 128 if(set.find(ALL) != set.end()) 129 129 { 130 130 this->notificationLists_[index] = &this->allNotificationsList_; 131 COUT(3) << "Notification Queueregistered with the NotificationManager." << std::endl;131 COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl; 132 132 return true; 133 133 } 134 134 135 135 this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>; 136 136 std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index]; 137 138 //! Iterate through all Notifications to determine whether any of them should belong to the newly registered Notification Queue.137 138 //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 139 139 for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 140 140 { … … 144 144 } 145 145 } 146 147 queue->update(); //!< Update the queue.148 146 149 COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl; 150 147 listener->update(); //!< Update the listener. 148 149 COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl; 150 151 151 return true; 152 152 } 153 153 154 154 /** 155 155 @brief 156 Fetches the Notifications for a specific Notification Queuein a specified timeframe.157 @param queue158 The Notification Queuethe Notifications are fetched for.156 Fetches the Notifications for a specific NotificationListener in a specified timeframe. 157 @param listener 158 The NotificationListener the Notifications are fetched for. 159 159 @param map 160 160 A multimap, in which the notifications are stored. … … 166 166 Returns true if successful. 167 167 */ 168 bool NotificationManager::getNotifications(Notification Queue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)168 bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 169 169 { 170 if( queue== NULL || map == NULL)170 if(listener == NULL || map == NULL) 171 171 return false; 172 172 173 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this-> queueList_[queue]]; //!< The Notifications for the input NotificationQueue.174 173 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; //!< The Notifications for the input NotificationListener. 174 175 175 if(notifications == NULL) //!< Returns NULL, if there are no Notifications. 176 176 return true; 177 177 178 178 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; 179 179 itLowest = notifications->lower_bound(timeFrameStart); 180 180 itHighest = notifications->upper_bound(timeFrameStart); 181 181 182 182 for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it. 183 183 { 184 184 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map. 185 185 } 186 186 187 187 return true; 188 188 } -
code/branches/libraries/src/orxonox/objects/quest/notifications/NotificationManager.h
r5616 r5619 49 49 /** 50 50 @brief 51 The Singleton NotificationManager functions as a gateway between Notifications and Notification Queues.52 It receives, organizes Notifications and the redistributes them to the specific Notification Queues.51 The Singleton NotificationManager functions as a gateway between Notifications and NotificationListeners. 52 It receives, organizes Notifications and the redistributes them to the specific NotificationListeners. 53 53 @author 54 54 Damian 'Mozork' Frick … … 65 65 66 66 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 67 bool register Queue(NotificationQueue* queue); //!< Registers a NotificationQueuewithin the NotificationManager.67 bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. 68 68 69 bool getNotifications(Notification Queue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueuein a specified timeframe.69 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. 70 70 71 71 /** 72 @brief Fetches the Notifications for a specific Notification Queuestarting at a specified time.73 @param queue The NotificationQueuethe Notifications are fetched for.72 @brief Fetches the Notifications for a specific NotificationListener starting at a specified time. 73 @param listener The NotificationListener the Notifications are fetched for. 74 74 @param map A multimap, in which the notifications are stored. 75 75 @param timeFrameStart The start time the Notifications are fetched from. 76 76 @return Returns true if successful. 77 77 */ 78 bool getNotifications(Notification Queue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)79 { return this->getNotifications( queue, map, timeFrameStart, std::time(0)); }78 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart) 79 { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); } 80 80 /** 81 @brief Fetches the Notifications for a specific Notification Queuestarting at a specified timespan before now.82 @param queue The NotificationQueuethe Notifications are fetched for.81 @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now. 82 @param listener The NotificationListener the Notifications are fetched for. 83 83 @param map A multimap, in which the notifications are stored. 84 84 @param timeDelay The timespan. 85 85 @return Returns true if successful. 86 86 */ 87 bool getNotifications(Notification Queue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay)88 { return this->getNotifications( queue, map, std::time(0)-timeDelay, std::time(0)); }87 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay) 88 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } 89 89 90 90 private: … … 94 94 95 95 std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps). 96 std::map<Notification Queue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier.97 std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a Notification Queue), are stored.96 std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 97 std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 98 98 99 99
Note: See TracChangeset
for help on using the changeset viewer.