Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "CommandHandlerFunctor.hpp" |
| 9 | #include "CommandHandlerKey.hpp" |
| 10 | |
| 11 | #include <boost/functional/hash.hpp> |
| 12 | #include <unordered_map> |
| 13 | |
| 14 | struct CommandHandlerHash |
| 15 | { |
| 16 | std::size_t operator() (const CommandHandlerKey& commandHandlerKey) const |
| 17 | { |
| 18 | std::size_t seed = 0; |
| 19 | boost::hash_combine(seed, commandHandlerKey.GetPacketId()); |
| 20 | boost::hash_combine(seed, commandHandlerKey.GetVersion()); |
| 21 | return seed; |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | class CommandHandlerRegistry |
| 26 | { |
| 27 | public: |
| 28 | CommandHandlerRegistry() = default; |
| 29 | |
| 30 | void RegisterFunctor(CommandHandlerFunctor* functor, uint32_t packetId, uint32_t version); |
| 31 | |
| 32 | CommandHandlerFunctor* GetFunctor(uint32_t packetId, uint32_t version) const; |
| 33 | |
| 34 | private: |
| 35 | std::unordered_map<CommandHandlerKey, CommandHandlerFunctor*, CommandHandlerHash> registry; |
| 36 | }; |