61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* \file PacketDispatcher.h
|
|
* \brief File containing the td::protocol::PacketDispatcher class
|
|
*/
|
|
|
|
#include <sp/common/NonCopyable.h>
|
|
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
namespace sp {
|
|
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" |