// synchronized void InitiationDispatcher::removeHandler(const EventHandler & handler, const EventType & type) { BOOST_LOG_TRIVIAL(trace) << "InitiationDispatcher entering removeHandler."; lock_guard<mutex> grd_lock(m_mutex); string id = handler.getId(); BOOST_LOG_TRIVIAL(trace) << "Searching event handler w/ID [" << id << "]"; auto type_handler = m_handlers.find(id); if(type_handler != m_handlers.end()) { // found handler if (type_handler->second.type == type) { BOOST_LOG_TRIVIAL(info) << "Removing event handler w/ID [" << id + "] and type [" << EventTypeMap[type] << "]"; m_handlers.erase(id); } } }
// synchronized void InitiationDispatcher::registerHandler( const EventHandler & handler, const EventType & type) { BOOST_LOG_TRIVIAL(info) << "InitiationDispatcher entering registerHandler."; lock_guard<mutex> grd_lock(m_mutex); if(m_is_closed) { throw new runtime_error( "The initiation dispatcher is closed."); } string id = handler.getId(); BOOST_LOG_TRIVIAL(info) << "Registering event handler w/ID [" + id + "] and type [" + EventTypeMap[type] + "]"; if (m_handlers.find(id)) { throw invalid_argument ("Event handler with ID [" + id + "] has already been registered."); } EventTypeHandler type_handler; type_handler.type = type; type_handler.handler = handler; m_handlers.insert( pair<string,EventTypeHandler>(id, type_handler)); }