[Orxonox-commit 2694] r7399 - in code/branches/notifications: data/gui/scripts src/modules/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Fri Sep 10 23:17:03 CEST 2010
Author: dafrick
Date: 2010-09-10 23:17:02 +0200 (Fri, 10 Sep 2010)
New Revision: 7399
Modified:
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
code/branches/notifications/src/modules/notifications/NotificationManager.cc
code/branches/notifications/src/modules/notifications/NotificationManager.h
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
code/branches/notifications/src/modules/notifications/NotificationQueue.h
Log:
Some cleanup and documenting.
After some more extensive testing it seems to work, the code looks ok as well...
Modified: code/branches/notifications/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-10 17:50:06 UTC (rev 7398)
+++ code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-10 21:17:02 UTC (rev 7399)
@@ -7,15 +7,17 @@
P.sampleWindow = nil
+-- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need.
function P.onLoad()
orxonox.NotificationManager:getInstance():loadQueues()
P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/SampleWindow")
end
+-- Creates a queue in the GUI.
function P.createQueue(name, size)
local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
- queue:setProperty("BackgroundColor", "00FFFFFF")
+ queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
root:addChildWindow(queue)
queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
@@ -30,95 +32,95 @@
}
P.queueList[name] = queueTuple -- name access
- P.setVisible(queueTuple, false)
+ P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it.
end
-function P.removeQueue(name)
- local queue = P.queueList[name]
+-- Removes a queue from the GUI.
+function P.removeQueue(queueName)
+ local queue = P.queueList[queueName]
if queue ~= nil then
winMgr:destroyWindow(queue.window)
end
- P.queueList[name] = nil
+ P.queueList[queueName] = nil
end
+-- Pushes an input notification to the input queue.
function P.pushNotification(queueName, notification)
local queue = P.queueList[queueName]
if queue == nil then
- cout(0, "0Queue is nil! " .. queueName)
return
end
item = CEGUI.createListboxTextItem(notification)
local listbox = CEGUI.toListbox(queue.window)
+ -- Add the item to the top of the listbox.
if listbox:getItemCount() == 0 then
listbox:addItem(item)
else
listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
end
+ -- If the queue has been invisible, set it to visible.
if queue.visible == false then
P.setVisible(queue, true)
end
end
+-- Pops the least recently added notification from the queue.
function P.popNotification(queueName)
local queue = P.queueList[queueName]
if queue == nil then
- cout(0, "1Queue is nil! " .. queueName)
return
end
local listbox = CEGUI.toListbox(queue.window)
+ -- Removes the item from the bottom of the listbox.
listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
+ -- Sets the queue to invisible if there are no more notifications in it.
if listbox:getItemCount() == 0 then
P.setVisible(queue, false)
end
end
+-- Removes a notification at a given index from the queue.
function P.removeNotification(queueName, index)
local queue = P.queueList[queueName]
if queue == nil then
- cout(0, "2Queue is nil! " .. queueName)
return
end
local listbox = CEGUI.toListbox(queue.window)
+ -- Removes the item.
listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
+ -- Sets the queue to invisible if there are no more notifications in it.
if listbox:getItemCount() == 0 then
P.setVisible(queue, false)
end
end
-function P.clearQueue(name)
- local queue = P.queueList[name]
+-- Clears the queue. Removes all notifications from it.
+function P.clearQueue(queueName)
+ local queue = P.queueList[queueName]
if queue == nil then
- cout(0, "3Queue is nil! " .. name)
return
end
local listbox = CEGUI.toListbox(queue.window)
CEGUI.toListbox(queue.window):resetList()
+ -- Sets the queue to invisible.
P.setVisible(queue, false)
end
-function P.changeSize(name, size)
- local queue = P.queueList[name]
- if queue == nil then
- cout(0, "5Queue is nil! " .. name)
- return
- end
- queue.window:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue.window, size)))
-end
-
+-- Sets the visibility of the queue.
function P.setVisible(queue, visible)
if queue == nil then
- cout(0, "6Queue is nil! " .. queue.name)
return
end
queue.window:setVisible(visible)
queue.visible = visible
end
+-- Enter the edit mode of the notification layer.
function P.enterEditMode()
P.editMode = true
@@ -138,6 +140,7 @@
vertOffset = 0
horzOffset = 0
+ -- Line to be able to create a new queue.
local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle")
newQueueTitle:setText("Create a new NotificationQueue:")
local size = getMinTextSize(newQueueTitle)
@@ -164,6 +167,7 @@
vertOffset = vertOffset + textHeight + 5
horzOffset = 0
+ -- Button to leave the edit mode.
local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton")
leave:setText("leave Edit Mode")
P.sampleWindow:setText("leave Edit Mode")
@@ -179,25 +183,29 @@
for k,v in pairs(P.queueList) do
if v ~= nil then
local queue = P.queueList[k]
- root:removeChildWindow(queue.window)
-
- local window = P.createQueueEditFrame(queue.name)
- window:setArea(queue.window:getArea())
-
- queue.edit = window
+ -- Remove the window that displays the queue from the root window such that it is no longer displayed.
+ root:removeChildWindow(v.window)
+
+ -- Create the frame window, with options to edit the queue, that is displayed instead of the queue.
+ local window = P.createQueueEditFrame(v.name)
+ window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue.
+
+ v.edit = window
end
end
end
-function P.createQueueEditFrame(name)
+-- Helper function. Creates a frame for the input queue.
+function P.createQueueEditFrame(queueName)
local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
- window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. name)
+
+ window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName)
local frame = tolua.cast(window, "CEGUI::FrameWindow")
frame:setCloseButtonEnabled(true)
orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked")
- frame:setText("NotificationQueue \"" .. name .. "\"")
+ frame:setText("NotificationQueue \"" .. queueName .. "\"")
root:addChildWindow(window)
- local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/ScrollingPane")
+ local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane")
pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
window:addChildWindow(pane)
@@ -205,7 +213,8 @@
local horzOffset = 0
local vertOffset = 0
- local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/TargetsTitle")
+ -- The line that lets you edit the targets of the queue.
+ local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle")
targetsTitle:setText("Targets:")
local size = getMinTextSize(targetsTitle)
local textHeight = size[1]
@@ -213,9 +222,9 @@
targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
pane:addChildWindow(targetsTitle)
horzOffset = horzOffset + size[2] + 5
- local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets")
+ local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
targets:setProperty("ReadOnly", "set:False")
- local targetsText = orxonox.NotificationManager:getInstance():getQueue(name):getTargets()
+ local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets()
targets:setText(targetsText)
P.sampleWindow:setText(targetsText)
size = getMinTextSize(P.sampleWindow)
@@ -223,7 +232,7 @@
targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
horzOffset = horzOffset + size[2]*2+20 + 5
pane:addChildWindow(targets)
- local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets/Save")
+ local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
save:setText("save")
P.sampleWindow:setText("save")
size = getMinTextSize(P.sampleWindow)
@@ -236,16 +245,17 @@
vertOffset = vertOffset + textHeight + 5
horzOffset = 0
- local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/SizeTitle")
+ -- The line that lets you edit the size of the queue.
+ local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle")
sizeTitle:setText("Size:")
size = getMinTextSize(sizeTitle)
sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
pane:addChildWindow(sizeTitle)
horzOffset = horzOffset + size[2] + 5
- local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size")
+ local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
queueSize:setProperty("ReadOnly", "set:False")
- local maxSize = orxonox.NotificationManager:getInstance():getQueue(name):getMaxSize()
+ local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize()
queueSize:setText(maxSize)
P.sampleWindow:setText(maxSize)
size = getMinTextSize(P.sampleWindow)
@@ -253,7 +263,7 @@
queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
horzOffset = horzOffset + size[2]*2+20 + 5
pane:addChildWindow(queueSize)
- save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size/Save")
+ save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
save:setText("save")
P.sampleWindow:setText("save")
size = getMinTextSize(P.sampleWindow)
@@ -266,16 +276,17 @@
vertOffset = vertOffset + textHeight + 5
horzOffset = 0
- local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTimeTitle")
+ -- The line that lets you edit the display time of the queue.
+ local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle")
displayTimeTitle:setText("Display time:")
size = getMinTextSize(displayTimeTitle)
displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
pane:addChildWindow(displayTimeTitle)
horzOffset = horzOffset + size[2] + 5
- local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime")
+ local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
displayTime:setProperty("ReadOnly", "set:False")
- local time = orxonox.NotificationManager:getInstance():getQueue(name):getDisplayTime()
+ local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime()
displayTime:setText(time)
P.sampleWindow:setText(time)
size = getMinTextSize(P.sampleWindow)
@@ -283,7 +294,7 @@
displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
horzOffset = horzOffset + size[2]*2+20 + 5
pane:addChildWindow(displayTime)
- save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime/Save")
+ save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
save:setText("save")
P.sampleWindow:setText("save")
size = getMinTextSize(P.sampleWindow)
@@ -298,6 +309,7 @@
return window
end
+-- Leave the edit mode.
function P.leaveEditMode()
P.editMode = false
@@ -305,8 +317,11 @@
--Replace all queues with FrameWindows
for k,v in pairs(P.queueList) do
if v ~= nil then
+ -- Add the queue window to the root window to have it displayed again.
root:addChildWindow(v.window)
+ -- Set the size and position of the queue window to the size and position of the queue edit frame.
v.window:setArea(v.edit:getArea())
+ -- Destroy the edit frame.
winMgr:destroyWindow(v.edit)
v.edit = nil
end
@@ -316,13 +331,16 @@
winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow"))
end
+-- Is called after the sheet has been hidden.
function P.afterHide()
+ -- If we leave the edit mode we show the sheet again.
if P.editMode then
P.leaveEditMode()
showMenuSheet(P.name, false, true)
end
end
+-- If the button to save the targets of a queue has been clicked.
function P. saveTargets_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -336,16 +354,20 @@
local width = window:getWidth():asAbsolute(1)
local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
+ -- Set the new targets.
queue:setTargets(window:getText())
local targets = queue:getTargets()
window:setText(targets)
P.sampleWindow:setText(targets)
local size = getMinTextSize(P.sampleWindow)
+ -- Adjust the width of the targets field.
window:setWidth(CEGUI.UDim(0, size[2]*2+20))
+ -- Adjust the position of the save button after the targets field.
save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
end
+-- If the button to save the size if a queue has been clicked.
function P. saveSize_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -359,16 +381,20 @@
local width = window:getWidth():asAbsolute(1)
local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
+ -- Set the new size.
queue:setMaxSize(tonumber(window:getText()))
local maxSize = queue:getMaxSize()
window:setText(maxSize)
P.sampleWindow:setText(maxSize)
local size = getMinTextSize(P.sampleWindow)
+ -- Adjust the width of the size field.
window:setWidth(CEGUI.UDim(0, size[2]*2+20))
+ -- Adjust the position of the save button after the size field.
save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
end
+-- If the button to save the display time if a queue has been clicked.
function P. saveDisplayTime_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -382,40 +408,50 @@
local width = window:getWidth():asAbsolute(1)
local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
+ -- Set the new display time.
queue:setDisplayTime(tonumber(window:getText()))
local time = queue:getDisplayTime()
window:setText(time)
P.sampleWindow:setText(time)
local size = getMinTextSize(P.sampleWindow)
+ -- Adjust the width of the display time field.
window:setWidth(CEGUI.UDim(0, size[2]*2+20))
+ -- Adjust the position of the save button after the display time field.
save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
end
+-- if the button to create a new queue has been clicked.
function P.createNewQueue_clicked(e)
local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
local name = window:getText()
+ -- Creates the new queue.
orxonox.NotificationManager:getInstance():createQueue(name)
local queue = P.queueList[name]
if queue == nil then
- cout(0, "7Queue is nil! " .. name)
return
end
-
+
+ -- Create the frame that represents the queue in edit mode, since that's what we're in.
local frame = P.createQueueEditFrame(name)
local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
+ -- Remove the queue window from the root window, since we're in edit mode.
root:removeChildWindow(queue.window)
+ -- Set the frame window size and position to that of the queue window.
frame:setArea(queue.window:getArea())
queue.edit = frame
-
+
+ -- Reset the text to create a new queue.
window:setText("")
end
+-- If the button to leave the edit mode has been clicked.
function P.leaveEditMode_clicked(e)
hideMenuSheet(P.name)
end
+-- If the button to close the queue has been clicked.
function P.closeQueue_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -424,11 +460,14 @@
local nameStr = match()
local queueName = string.sub(nameStr, 10, string.len(nameStr))
+ -- Destroy the frame window,
winMgr:destroyWindow(P.queueList[queueName].edit)
P.queueList[queueName].edit = nil
+ -- Destroy the queue.
orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()
end
+-- Helper function. Returns height a queue needs to have to display 'size' items.
function P.queueHeightHelper(queue, size)
local listbox = CEGUI.toListbox(queue)
local item = CEGUI.createListboxTextItem("Text")
Modified: code/branches/notifications/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.cc 2010-09-10 17:50:06 UTC (rev 7398)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.cc 2010-09-10 21:17:02 UTC (rev 7399)
@@ -38,7 +38,9 @@
#include "core/GUIManager.h"
#include "core/LuaState.h"
#include "util/ScopedSingletonManager.h"
+
#include "interfaces/NotificationListener.h"
+
#include "Notification.h"
#include "NotificationQueue.h"
@@ -55,7 +57,6 @@
ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
- //TODO: Make work.
SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
/**
@@ -69,7 +70,7 @@
this->highestIndex_ = 0;
ModifyConsoleCommand("enterEditMode").setObject(this);
-
+
COUT(3) << "NotificatioManager created." << std::endl;
}
@@ -81,14 +82,20 @@
{
ModifyConsoleCommand("enterEditMode").setObject(NULL);
+ // Destroys all Notifications that have been registered with the NotificationManager.
for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
it->second->destroy();
-
+
COUT(3) << "NotificationManager destroyed." << std::endl;
}
+ /**
+ @brief
+ Is called before the object is destroyed.
+ */
void NotificationManager::preDestroy(void)
{
+ // Destroys all NotificationQueues that have been registered with the NotificationManager.
for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
{
NotificationQueue* queue = (*it).second;
@@ -108,11 +115,11 @@
*/
bool NotificationManager::registerNotification(Notification* notification)
{
- if(notification == NULL) // A NULL-Notification cannot be registered.
- return false;
+ assert(notification);
std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time.
+ // Add the Notification to the list that holds all Notifications.
this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
@@ -122,23 +129,17 @@
if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
all = true;
- // Insert the notification in all listeners that have its sender as target.
- for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners.
+ // Insert the Notification in all NotificationListeners that have its sender as target.
+ for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
{
std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
bool bAll = set.find(NotificationManager::ALL) != set.end();
- if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works.
+ // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
+ if(all || bAll || set.find(notification->getSender()) != set.end())
{
if(!bAll)
- {
- this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the Notifications list of the current NotificationListener.
- }
- it->first->update(notification, time); // Update the listener.
- std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
- if(counterIt == this->listenerCounter_.end())
- this->listenerCounter_[notification] = 1;
- else
- this->listenerCounter_[notification] = counterIt->second + 1;
+ this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.
+ it->first->update(notification, time); // Update the NotificationListener.
}
}
@@ -149,7 +150,7 @@
/**
@brief
- Unregisters a Notification within the NotificationManager.
+ Unregisters a Notification within the NotificationManager for a given NotificationListener.
@param notification
A pointer to the Notification to be unregistered.
@param listener
@@ -160,20 +161,19 @@
assert(notification);
assert(listener);
- // 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.
- if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
- this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
+ // Remove the Notification from the list of Notifications of the input NotificationListener.
+ this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second));
COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
}
/**
@brief
- Helper method that removes an input notification form an input map.
+ Helper method that removes an input Notification form an input map.
@param notification
- A pointer to the notification to be removed.
+ A pointer to the Notification to be removed.
@param map
- The map the notification should be removed from.
+ The map the Notification should be removed from.
@return
Returns true if successful.
*/
@@ -198,22 +198,29 @@
@param listener
The NotificationListener to be registered.
@return
- Returns true if successful.
+ Returns true if successful. Fales if the NotificationListener is already registered.
*/
bool NotificationManager::registerListener(NotificationListener* listener)
{
+ assert(listener);
+
+ // If the NotificationListener is already registered.
+ if(this->listenerList_.find(listener) != this->listenerList_.end())
+ return false;
+
this->highestIndex_ += 1;
- int index = this->highestIndex_;
+ unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely.
- this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners.
+ this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
- // 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.
+ // 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.
bool bAll = set.find(NotificationManager::ALL) != set.end();
std::multimap<std::time_t, Notification*>* map;
if(bAll)
this->notificationLists_[index] = &this->allNotificationsList_;
+ // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners.
else
{
this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
@@ -223,16 +230,8 @@
// Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
{
- if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target.
- {
- if(!bAll)
- map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
- std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
- if(counterIt == this->listenerCounter_.end())
- this->listenerCounter_[it->second] = 1;
- else
- this->listenerCounter_[it->second] = counterIt->second + 1;
- }
+ if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
+ map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
}
listener->update(); // Update the listener.
@@ -244,16 +243,19 @@
/**
@brief
- Unregisters a NotificationListener withing the NotificationManager.
+ Unregisters a NotificationListener within the NotificationManager.
+ @param listener
+ The NotificationListener to be unregistered.
*/
void NotificationManager::unregisterListener(NotificationListener* listener)
{
assert(listener);
- int identifier = this->listenerList_.find(listener)->second;
+ //TODO: Make unsigned int.
+ unsigned int identifier = this->listenerList_.find(listener)->second;
std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
- // If the map is not the map of all notifications, make sure all Notifications are removed and delete it.
+ // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
std::multimap<std::time_t, Notification*>::iterator it = map->begin();
if(map != &this->allNotificationsList_)
{
@@ -265,7 +267,9 @@
delete map;
}
+ // Remove the NotificationListener from the list of NotificationListeners.
this->listenerList_.erase(listener);
+ // Remove the Notifications list that was associated with the input NotificationListener.
this->notificationLists_.erase(identifier);
COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl;
@@ -273,11 +277,11 @@
/**
@brief
- Fetches the Notifications for a specific NotificationListener in a specified timeframe.
+ Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
@param listener
The NotificationListener the Notifications are fetched for.
@param map
- A multimap, in which the notifications are stored.
+ A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
@param timeFrameStart
The start time of the timeframe.
@param timeFrameEnd
@@ -285,60 +289,95 @@
@return
Returns true if successful.
*/
- bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
+ void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
{
- if(listener == NULL || map == NULL)
- return false;
+ assert(listener);
+ assert(map);
- std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
+ std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
- if(notifications == NULL) // Returns false, if there are no Notifications.
- return false;
-
std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
+ // Iterators pointing to the bounds specified by the specified start and end times of the time frame.
itLowest = notifications->lower_bound(timeFrameStart);
itHighest = notifications->upper_bound(timeFrameEnd);
- for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it.
- map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map.
+ for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time frame to the end of it.
+ map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
+ }
- return true;
+ /**
+ @brief
+ Enters the edit mode of the NotificationLayer.
+ */
+ void NotificationManager::enterEditMode(void)
+ {
+ GUIManager::getInstance().hideGUI("NotificationLayer");
+ GUIManager::getInstance().showGUI("NotificationLayer", false, false);
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()");
}
+ /**
+ @brief
+ Registers a NotificationQueue.
+ 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.
+ @param queue
+ A pointer to the NotificationQueue to be registered.
+ @return
+ Returns true if successful. If e.g. the a NotificationQueue with that name already exists this returns false.
+ */
+ bool NotificationManager::registerQueue(NotificationQueue* queue)
+ {
+ return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
+ }
+
+ /**
+ @brief
+ Unregisters a NotificationQueue.
+ @param queue
+ A pointer to the NotificationQueue to be unregistered.
+ */
+ void NotificationManager::unregisterQueue(NotificationQueue* queue)
+ {
+ this->queues_.erase(queue->getName());
+ }
+
+ /**
+ @brief
+ Loads all the NotificationQueues that should exist.
+ */
void NotificationManager::loadQueues(void)
{
new NotificationQueue("all");
}
+ /**
+ @brief
+ Creates a new NotificationQueue.
+ This is used in lua.
+ @param name
+ The name of the new NotificationQueue.
+ */
void NotificationManager::createQueue(const std::string& name)
{
new NotificationQueue(name);
}
+ /**
+ @brief
+ Get the NotificationQueue with the input name.
+ @param name
+ The name of the NotificationQueue.
+ @return
+ Returns a pointer to the NotificationQueue with the input name. Returns NULL if no NotificationQueue with such a name exists.
+ */
NotificationQueue* NotificationManager::getQueue(const std::string & name)
{
std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
+ // Returns NULL if no such NotificationQueue exists.
if(it == this->queues_.end())
return NULL;
return (*it).second;
}
- bool NotificationManager::registerQueue(NotificationQueue* queue)
- {
- return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
- }
-
- void NotificationManager::unregisterQueue(NotificationQueue* queue)
- {
- this->queues_.erase(queue->getName());
- }
-
- void NotificationManager::enterEditMode(void)
- {
- GUIManager::getInstance().hideGUI("NotificationLayer");
- GUIManager::getInstance().showGUI("NotificationLayer", false, false);
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()");
- }
-
}
Modified: code/branches/notifications/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.h 2010-09-10 17:50:06 UTC (rev 7398)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.h 2010-09-10 21:17:02 UTC (rev 7399)
@@ -61,7 +61,7 @@
NotificationManager();
virtual ~NotificationManager();
- virtual void preDestroy(void);
+ virtual void preDestroy(void); //!< Is called before the object is destroyed.
static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
@@ -69,48 +69,46 @@
static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
- void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
+ void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
- 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.
+ 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.
/**
- @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
+ @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
@param listener The NotificationListener the Notifications are fetched for.
- @param map A multimap, in which the notifications are stored.
+ @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
@param timeDelay The timespan.
@return Returns true if successful.
*/
- bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
- { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
+ void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
+ { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
- void enterEditMode(void);
+ void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
+ bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
+ void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
+
// tolua_begin
- void loadQueues(void);
-
- void createQueue(const std::string& name);
- orxonox::NotificationQueue* getQueue(const std::string & name);
+ void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
+ void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
+ orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
// tolua_end
- bool registerQueue(NotificationQueue* queue);
- void unregisterQueue(NotificationQueue* queue);
-
private:
static NotificationManager* singletonPtr_s;
- std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
+ unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
- int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
-
- std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored.
- std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
+ std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
+ std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
- std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
- bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
+ std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
+ bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
+
}; // tolua_export
} // tolua_export
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-10 17:50:06 UTC (rev 7398)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-10 21:17:02 UTC (rev 7399)
@@ -40,6 +40,8 @@
#include "core/GUIManager.h"
#include "core/LuaState.h"
#include "util/Convert.h"
+#include "util/SubString.h"
+
#include "Notification.h"
namespace orxonox
@@ -48,6 +50,15 @@
/**
@brief
Constructor. Creates and initializes the object.
+ @param name
+ The name of the new NotificationQueue.
+ @param senders
+ The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
+ The senders need to be seperated by commas.
+ @param size
+ The size (the maximum number of displayed Notifications) of this NotificationQueue.
+ @param displayTime
+ The time during which a Notification is (at most) displayed.
*/
NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime)
{
@@ -55,28 +66,37 @@
RegisterRootObject(NotificationQueue);
- this->initialize();
+ // Initialize.
+ this->size_ = 0;
+ this->tickTime_ = 0.0;
+ // Sets the input values.
this->setTargets(senders);
this->name_ = name;
this->maxSize_ = size;
this->setDisplayTime(displayTime);
+ //TODO: Destroy if registration fails?
+
+ // Register the NotificationQueue with the NotificationManager.
bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
this->registered_ = true;
- if(!queueRegistered)
+ if(!queueRegistered) // If the registration has failed.
{
this->registered_ = false;
COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
return;
}
- this->create();
-
+ this->create(); // Creates the NotificationQueue in lua.
+
+ // register the NotificationQueue as NotificationListener with the NotificationManager.
bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
- if(!listenerRegistered)
+ if(!listenerRegistered) // If the registration has failed.
{
this->registered_ = false;
+ // Remove the NotificationQueue in lua.
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")");
NotificationManager::getInstance().unregisterQueue(this);
COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
return;
@@ -93,30 +113,21 @@
{
this->targets_.clear();
- if(this->registered_)
+ if(this->registered_) // If the
{
this->clear();
-
+
+ // Unregister with the NotificationManager.
NotificationManager::getInstance().unregisterListener(this);
NotificationManager::getInstance().unregisterQueue(this);
+ // Remove the NotificationQueue in lua.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")");
}
}
/**
@brief
- Initializes the object.
- Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.
- */
- void NotificationQueue::initialize(void)
- {
- this->size_ = 0;
- this->tickTime_ = 0.0;
- }
-
- /**
- @brief
Creates the NotificationQueue in lua.
*/
void NotificationQueue::create(void)
@@ -138,11 +149,12 @@
this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
- 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.
+ // Iterate through all elements whose creation time is smaller than the current time minus the display time.
+ while(it != this->ordering_.upper_bound(&this->timeLimit_))
{
NotificationContainer* temp = *it;
it++;
- this->remove(temp);
+ this->remove(temp); // Remove the Notifications that have expired.
}
this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter.
@@ -159,23 +171,19 @@
this->clear();
std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
- if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time.
- {
- COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
- return;
- }
+ // Get the Notifications sent in the interval from now to now minus the display time.
+ NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
if(!notifications->empty())
{
- for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
- {
+ // Add all Notifications.
+ for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
this->push(it->second, it->first);
- }
}
delete notifications;
- COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4.
+ COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
}
/**
@@ -190,17 +198,17 @@
{
this->push(notification, time);
- COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4.
+ COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
}
/**
@brief
- Adds a Notification to the NotificationQueue.
+ Adds (pushes) a Notification to the NotificationQueue.
It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
@param notification
- The Notification.
+ The Notification to be pushed.
@param time
- The time.
+ The time when the Notification has been sent.
*/
void NotificationQueue::push(Notification* notification, const std::time_t & time)
{
@@ -215,54 +223,69 @@
this->size_++;
this->ordering_.insert(container);
+ // Insert the Notification at the begin of the list (vector, actually).
this->notifications_.insert(this->notifications_.begin(), container);
+ // Push the Notification to the GUI.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
}
/**
@brief
- Removes the least recently added Notification form the NotificationQueue.
+ Removes (pops) the least recently added Notification form the NotificationQueue.
*/
void NotificationQueue::pop(void)
{
NotificationContainer* container = this->notifications_.back();
this->ordering_.erase(container);
this->notifications_.pop_back();
+
this->size_--;
+
delete container;
+
+ // Pops the Notification from the GUI.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
}
/**
@brief
- Removes the Notification that is stored in the input container.
+ Removes the Notification that is stored in the input NotificationContainer.
@param container
The NotificationContainer with the Notification to be removed.
*/
void NotificationQueue::remove(NotificationContainer* container)
{
std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
+ // Get the index at which the Notification is.
std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
this->ordering_.erase(container);
this->notifications_.erase(it);
+
this->size_--;
+
delete container;
+
+ // Removes the Notification from the GUI.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
}
/**
@brief
- Clears the queue by removing all Notifications.
+ Clears the NotificationQueue by removing all NotificationContainers.
*/
void NotificationQueue::clear(void)
{
this->ordering_.clear();
+ // Delete all NotificationContainers in the list.
for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
delete *it;
this->notifications_.clear();
+
this->size_ = 0;
+
+ // Clear the NotificationQueue in the GUI.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
}
@@ -271,13 +294,10 @@
Sets the name of the NotificationQueue.
@param name
The name to be set.
- @return
- returns true if successful.
*/
- bool NotificationQueue::setName(const std::string& name)
+ void NotificationQueue::setName(const std::string& name)
{
this->name_ = name;
- return true;
}
/**
@@ -285,26 +305,16 @@
Sets the maximum number of displayed Notifications.
@param size
The size to be set.
- @return
- Returns true if successful.
*/
void NotificationQueue::setMaxSize(unsigned int size)
{
if(this->maxSize_ == size)
return;
-
+
this->maxSize_ = size;
- this->sizeChanged();
- }
- /**
- @brief
- Adjusts the NotificationQueue, when the maximum size has changed.
- */
- void NotificationQueue::sizeChanged(void)
- {
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getSize()) + ")");
- this->update();
+ if(this->registered_)
+ this->update();
}
/**
@@ -328,7 +338,7 @@
/**
@brief
- Produces all targets concatinated as string, with kommas (',') as seperators.
+ Produces all targets of the NotificationQueue concatinated as string, with kommas (',') as seperators.
@return
Returns the targets as a string.
*/
@@ -336,10 +346,11 @@
{
std::stringstream stream;
bool first = true;
- for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
+ // Iterate through the set of targets.
+ for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
{
if(!first)
- stream << ',';
+ stream << ", ";
else
first = false;
stream << *it;
@@ -350,39 +361,24 @@
/**
@brief
- Sets the targets of the queue.
+ Sets the targets of the NotificationQueue.
The targets are the senders whose Notifications are displayed in this queue.
@param targets
Accepts a string of targets, each seperated by commas (','), spaces are ignored.
- @return
- Returns true if successful.
*/
- bool NotificationQueue::setTargets(const std::string & targets)
+ void NotificationQueue::setTargets(const std::string & targets)
{
this->targets_.clear();
- //TODO: Do with SubString.
- std::string* pTemp;
- unsigned int index = 0;
- while(index < targets.size()) // Go through the string, character by character until the end is reached.
- {
- pTemp = new std::string();
- while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
- {
- *pTemp += targets[index];
- index++;
- }
- index++;
- this->targets_.insert(*pTemp);
- }
+ SubString string = SubString(targets, ",", " ", false);
+ for(unsigned int i = 0; i < string.size(); i++)
+ this->targets_.insert(string[i]);
if(this->registered_)
{
NotificationManager::getInstance().unregisterListener(this);
NotificationManager::getInstance().registerListener(this);
}
-
- return true;
}
}
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-10 17:50:06 UTC (rev 7398)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-10 21:17:02 UTC (rev 7399)
@@ -42,6 +42,7 @@
#include <vector>
#include "tools/interfaces/Tickable.h"
+
#include "interfaces/NotificationListener.h"
#include "NotificationManager.h"
@@ -75,12 +76,16 @@
NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
virtual ~NotificationQueue();
+ /**
+ @brief Destroys the NotificationQueue.
+ Used in lua.
+ */
void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
virtual void tick(float dt); //!< To update from time to time.
- void update(void); //!< Updates the queue.
- void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
+ void update(void); //!< Updates the NotificationQueue.
+ void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification.
// tolua_begin
/**
@@ -109,20 +114,20 @@
/**
@brief Returns the current number of Notifications displayed.
- @return Returns the size of the queue.
+ @return Returns the size of the NotificationQueue.
*/
inline unsigned int getSize() const
{ return this->size_; }
/**
- @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
- @return Retuns a set of string holding the different targets.
+ @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
+ @return Returns a set of strings holding the different targets.
*/
inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
{ return this->targets_; }
// tolua_begin
- bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
+ void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
// tolua_end
@@ -136,29 +141,26 @@
unsigned int size_; //!< The number of Notifications displayed.
unsigned int displayTime_; //!< The time a Notification is displayed.
- std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of.
+ bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
- std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well?
+ std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
+
+ std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
- bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
-
- void initialize(void); //!< Initializes the object.
void create(void); //!< Creates the NotificationQueue in lua.
- bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
+ void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
- void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed.
+ void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
+ void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
+ void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer.
- void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue.
- void pop(void); //!< Removes the least recently added Notification form the NotificationQueue.
- void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container.
+ void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
- void clear(void); //!< Clears the queue by removing all Notifications.
-
}; // tolua_export
} // tolua_export
More information about the Orxonox-commit
mailing list