Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2011, 4:21:14 PM (13 years ago)
Author:
dafrick
Message:

Making NotificationQueue XML-loadable. Adding notifications to all levels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc

    r8453 r8636  
    3838
    3939#include "core/CoreIncludes.h"
     40#include "core/XMLPort.h"
    4041#include "util/SubString.h"
    4142
     
    4344{
    4445
    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
    4867    @param name
    4968        The name of the new NotificationQueue. It needs to be unique
    5069    @param senders
    5170        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 separated by commas.
     71        The senders need to be seperated by commas.
    5372    @param size
    5473        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     
    5675        The time during which a Notification is (at most) displayed.
    5776    */
    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    {
    65101        this->size_ = 0;
    66102        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    {
    74115        // Register the NotificationQueue with the NotificationManager.
    75116        bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
     
    87128    /**
    88129    @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     @brief
    108130        Updates the queue from time to time.
    109131    @param dt
     
    115137        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.
    116138        {
    117             this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     139            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containing the current time.
    118140
    119141            std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
     
    129151    }
    130152
     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
    131164    /**
    132165    @brief
     
    148181        if(!notifications->empty())
    149182        {
    150             // Add all Notifications.
     183            // Add all Notifications that have been created after this NotificationQueue was created.
    151184            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            }
    153189        }
    154190
     
    305341            return;
    306342
     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       
    307349        this->maxSize_ = size;
    308350
    309         if(this->registered_)
     351        if(this->isRegistered())
    310352            this->update();
    311353    }
     
    322364            return;
    323365
     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           
    324371        this->displayTime_ = time;
    325372
    326         if(this->registered_)
     373        if(this->isRegistered())
    327374            this->update();
    328375    }
     
    367414
    368415        // TODO: Why?
    369         if(this->registered_)
     416        if(this->isRegistered())
    370417        {
    371418            NotificationManager::getInstance().unregisterQueue(this);
Note: See TracChangeset for help on using the changeset viewer.