Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2011, 11:37:22 PM (14 years ago)
Author:
dafrick
Message:

NotificationListener is new an entity which is informed of new notifications. The NotificationManager is, so far, the only NotificationListener. This means that Notifications can now be sent from within orxonox (though not libraries or external).
Also introduced notification commands to affect the NotificationQueues in more ways than just have them display messages (e.g. clearing them).
Added a message type which allows to send Notifications of different importance, allowing the NotificationQueus to display them differently.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc

    r8378 r8445  
    105105        this->queues_.clear();
    106106    }
     107
     108    /**
     109    @brief
     110        Creates and registers a Notification with the input message from the input sender.
     111        This is called by the NotificationListener, whenever a new notification arrives.
     112    @param message
     113        The message of the new Notification.
     114    @param sender
     115        The name of the entity (of the collective) that sent the new Notification.
     116    @return
     117        Returns true if successful.
     118    */
     119    bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     120    {
     121        // TODO: Do something with the type.
     122        Notification* notification = new Notification(message, sender, type);
     123        return this->registerNotification(notification);
     124    }
     125
     126    /**
     127    @brief
     128        Executes the input command from the input sender.
     129        This is called by the NotificationListener, whenever a new command arrives.
     130    @param command
     131        The command to be executed,
     132    @param sender
     133        The The name of the entity (of the collective) that sent the command.
     134    */
     135    bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
     136    {
     137        if(command == notificationCommand::clear)
     138        {
     139            this->commandClear(sender);
     140            return true;
     141        }
     142
     143        return false;
     144    }
     145
     146    /**
     147    @brief
     148        The clear command. Clears all NotificationQueues that have its sender as a target.
     149    @param sender
     150        The sender of the clear command.
     151    */
     152    void NotificationManager::commandClear(const std::string& sender)
     153    {
     154        bool all = (sender == NotificationListener::ALL);
     155        // Clear all NotificationQueues that have the input sender as target.
     156        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
     157        {
     158            const std::set<std::string>& set = it->second->getTargetsSet();
     159            // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target.
     160            if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end())
     161                it->second->tidy();
     162        }
     163    }
    107164   
    108     bool NotificationManager::registerNotification(const std::string& message, const std::string& sender)
    109     {
    110         Notification* notification = new Notification(message, sender);
    111         return this->registerNotification(notification);
    112     }
    113 
    114165    /**
    115166    @brief
     
    132183            return true;
    133184
    134         bool all = false;
    135         if(notification->getSender() == NotificationListener::ALL) // If all are the sender, then the Notifications is added to every NotificationQueue.
    136             all = true;
     185        // If all are the sender, then the Notifications is added to every NotificationQueue.
     186        bool all = (notification->getSender() == NotificationListener::ALL);
    137187
    138188        // Insert the Notification in all NotificationQueues that have its sender as target.
     
    364414
    365415        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationListener::ALL, 1, -1);
    366         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
     416        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"CCFFFF00\")");
    367417        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
    368418        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
Note: See TracChangeset for help on using the changeset viewer.