nuke dispatch
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* \file PacketDispatcher.h
|
||||
* \brief File containing the td::protocol::PacketDispatcher class
|
||||
*/
|
||||
|
||||
#include <td/common/NonCopyable.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
/**
|
||||
* \class Dispatcher
|
||||
* \brief Class used to dispatch things
|
||||
*/
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
class Dispatcher : private NonCopyable {
|
||||
private:
|
||||
std::map<T_Enum, std::vector<T_Handler*>> m_Handlers;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Constructor
|
||||
*/
|
||||
Dispatcher() {}
|
||||
|
||||
/**
|
||||
* \brief Dispatch a packet
|
||||
* \param packet The packet to dispatch
|
||||
*/
|
||||
void Dispatch(const T& packet);
|
||||
|
||||
/**
|
||||
* \brief Register a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void RegisterHandler(T_Enum type, T_Handler& handler);
|
||||
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param type The packet type
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(T_Enum type, T_Handler& handler);
|
||||
|
||||
/**
|
||||
* \brief Unregister a packet handler
|
||||
* \param handler The packet handler
|
||||
*/
|
||||
void UnregisterHandler(T_Handler& handler);
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
|
||||
#include "Dispatcher.inl"
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
void Dispatcher<T_Enum, T_Handler, T>::Dispatch(const T& packet) {
|
||||
T_Enum type = packet.GetType();
|
||||
for (auto* handler : m_Handlers[type])
|
||||
handler->Check(packet);
|
||||
}
|
||||
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
void Dispatcher<T_Enum, T_Handler, T>::RegisterHandler(T_Enum type, T_Handler& handler) {
|
||||
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), &handler);
|
||||
if (found == m_Handlers[type].end())
|
||||
m_Handlers[type].push_back(&handler);
|
||||
}
|
||||
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
void Dispatcher<T_Enum, T_Handler, T>::UnregisterHandler(T_Enum type, T_Handler& handler) {
|
||||
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end());
|
||||
}
|
||||
|
||||
template <typename T_Enum, typename T_Handler, typename T>
|
||||
void Dispatcher<T_Enum, T_Handler, T>::UnregisterHandler(T_Handler& handler) {
|
||||
for (auto& pair : m_Handlers) {
|
||||
if (pair.second.empty())
|
||||
continue;
|
||||
|
||||
PacketType type = pair.first;
|
||||
|
||||
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user