<commit_before>#include "StableHeaders.h"
#include "Framework.h"
#include "EventDataInterface.h"
#include "EventManager.h"
#include "ModuleManager.h"

#include "Poco/DOM/DOMParser.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/Attr.h"
#include "Poco/DOM/NamedNodeMap.h"
#include "Poco/DOM/AutoPtr.h"
#include "Poco/SAX/InputSource.h"

#include <algorithm>

namespace Foundation
{
    EventManager::EventManager(Framework *framework) : 
        framework_(framework),
        next_category_id_(1),
        next_request_tag_(1),
        event_subscriber_root_(EventSubscriberPtr(new EventSubscriber()))
    {
    }

    EventManager::~EventManager()
    {
        event_subscriber_root_.reset();
    }
    
    Core::event_category_id_t EventManager::RegisterEventCategory(const std::string& name)
    {
        if (event_category_map_.find(name) == event_category_map_.end())
        {
            Foundation::RootLogInfo("Registering event category " + name);
            event_category_map_[name] = next_category_id_;
            next_category_id_++;
        }
        else
        {
            Foundation::RootLogWarning("Event category " + name + " is already registered");
        }
        
        return event_category_map_[name];
    }
    
    Core::event_category_id_t EventManager::QueryEventCategory(const std::string& name) const
    {
        EventCategoryMap::const_iterator i = event_category_map_.find(name);
        if (i != event_category_map_.end())
            return i->second;
        else 
            return Core::IllegalEventCategory;
    }
    
    const std::string& EventManager::QueryEventCategoryName(Core::event_category_id_t category_id) const
    {
        EventCategoryMap::const_iterator i = event_category_map_.begin();
        static std::string empty;
        
        while (i != event_category_map_.end())
        {
            if (i->second == category_id)
                return i->first;
             
            ++i;
        }
        
        return empty;
    }
    
    void EventManager::RegisterEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, const std::string& name)
    {
        if (!QueryEventCategoryName(category_id).length())
        {
            Foundation::RootLogError("Trying to register an event for yet unregistered category");
            return;
        }
        
        if (event_map_[category_id].find(event_id) != event_map_[category_id].end())
            Foundation::RootLogWarning("Overwriting already registered event with " + name);
        else
            Foundation::RootLogInfo("Registering event " + name);

        event_map_[category_id][event_id] = name;
    }
    
    bool EventManager::SendEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataInterface* data) const
    {
        if (category_id == 0)
        {
            Foundation::RootLogWarning("Attempted to send event with unknown category");
            return false;
        }    
            
        return SendEvent(event_subscriber_root_.get(), category_id, event_id, data);
    }
    
    void EventManager::SendDelayedEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataPtr data, Core::f64 delay)
    {
        if (category_id == 0)
        {
            Foundation::RootLogWarning("Attempted to send delayed event with unknown category");
            return;
        }    
           
        DelayedEvent new_delayed_event;
        new_delayed_event.category_id_ = category_id;
        new_delayed_event.event_id_ = event_id;
        new_delayed_event.data_ = data;
        new_delayed_event.delay_ = delay;
        
        new_delayed_events_.push_back(new_delayed_event);
    }  
    
    bool EventManager::SendEvent(EventSubscriber* node, Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataInterface* data) const
    {
        if (ModuleSharedPtr module = node->module_.lock())
        {
            if (module->HandleEvent(category_id, event_id, data))
                return true;<commit_msg>Illegal category check modified in SendEvent() & SendDelayedEvent()<commit_after>#include "StableHeaders.h"
#include "Framework.h"
#include "EventDataInterface.h"
#include "EventManager.h"
#include "ModuleManager.h"

#include "Poco/DOM/DOMParser.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/Attr.h"
#include "Poco/DOM/NamedNodeMap.h"
#include "Poco/DOM/AutoPtr.h"
#include "Poco/SAX/InputSource.h"

#include <algorithm>

namespace Foundation
{
    EventManager::EventManager(Framework *framework) : 
        framework_(framework),
        next_category_id_(1),
        next_request_tag_(1),
        event_subscriber_root_(EventSubscriberPtr(new EventSubscriber()))
    {
    }

    EventManager::~EventManager()
    {
        event_subscriber_root_.reset();
    }
    
    Core::event_category_id_t EventManager::RegisterEventCategory(const std::string& name)
    {
        if (event_category_map_.find(name) == event_category_map_.end())
        {
            Foundation::RootLogInfo("Registering event category " + name);
            event_category_map_[name] = next_category_id_;
            next_category_id_++;
        }
        else
        {
            Foundation::RootLogWarning("Event category " + name + " is already registered");
        }
        
        return event_category_map_[name];
    }
    
    Core::event_category_id_t EventManager::QueryEventCategory(const std::string& name) const
    {
        EventCategoryMap::const_iterator i = event_category_map_.find(name);
        if (i != event_category_map_.end())
            return i->second;
        else 
            return Core::IllegalEventCategory;
    }
    
    const std::string& EventManager::QueryEventCategoryName(Core::event_category_id_t category_id) const
    {
        EventCategoryMap::const_iterator i = event_category_map_.begin();
        static std::string empty;
        
        while (i != event_category_map_.end())
        {
            if (i->second == category_id)
                return i->first;
             
            ++i;
        }
        
        return empty;
    }
    
    void EventManager::RegisterEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, const std::string& name)
    {
        if (!QueryEventCategoryName(category_id).length())
        {
            Foundation::RootLogError("Trying to register an event for yet unregistered category");
            return;
        }
        
        if (event_map_[category_id].find(event_id) != event_map_[category_id].end())
            Foundation::RootLogWarning("Overwriting already registered event with " + name);
        else
            Foundation::RootLogInfo("Registering event " + name);

        event_map_[category_id][event_id] = name;
    }
    
    bool EventManager::SendEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataInterface* data) const
    {
        if (category_id == Core::IllegalEventCategory)
        {
            Foundation::RootLogWarning("Attempted to send event with illegal category");
            return false;
        }    
            
        return SendEvent(event_subscriber_root_.get(), category_id, event_id, data);
    }
    
    void EventManager::SendDelayedEvent(Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataPtr data, Core::f64 delay)
    {
        if (category_id == Core::IllegalEventCategory)
        {
            Foundation::RootLogWarning("Attempted to send delayed event with illegal category");
            return;
        }    
           
        DelayedEvent new_delayed_event;
        new_delayed_event.category_id_ = category_id;
        new_delayed_event.event_id_ = event_id;
        new_delayed_event.data_ = data;
        new_delayed_event.delay_ = delay;
        
        new_delayed_events_.push_back(new_delayed_event);
    }  
    
    bool EventManager::SendEvent(EventSubscriber* node, Core::event_category_id_t category_id, Core::event_id_t event_id, EventDataInterface* data) const
    {
        if (ModuleSharedPtr module = node->module_.lock())
        {
            if (module->HandleEvent(category_id, event_id, data))
                return true;
{'fraction_non_alphanumeric': 0.10016998542982031, 'fraction_numerical': 0.0012141816415735794, 'mean_word_length': 2.657637655417407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4908803', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2367, 'n_words': 421}