blob: ba81f1790f15a969be4c7c6420ee66a9d56ce9db [file] [log] [blame]
Francis Murtagh94d79152019-08-16 17:45:07 +01001//
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
14struct 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
25class CommandHandlerRegistry
26{
27public:
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
34private:
35 std::unordered_map<CommandHandlerKey, CommandHandlerFunctor*, CommandHandlerHash> registry;
36};