1 // 2 // Copyright © 2017 Arm Ltd and Contributors. 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 <functional> 12 #include <unordered_map> 13 14 namespace arm 15 { 16 17 namespace pipe 18 { 19 20 struct CommandHandlerHash 21 { operator ()arm::pipe::CommandHandlerHash22 std::size_t operator() (const CommandHandlerKey& commandHandlerKey) const 23 { 24 std::size_t seed = 0; 25 std::hash<uint32_t> hasher; 26 seed ^= hasher(commandHandlerKey.GetPacketId()) + 0x9e3779b9 + (seed<<6) + (seed>>2); 27 seed ^= hasher(commandHandlerKey.GetVersion()) + 0x9e3779b9 + (seed<<6) + (seed>>2); 28 return seed; 29 } 30 }; 31 32 class CommandHandlerRegistry 33 { 34 public: 35 CommandHandlerRegistry() = default; 36 37 void RegisterFunctor(CommandHandlerFunctor* functor, uint32_t familyId, uint32_t packetId, uint32_t version); 38 39 void RegisterFunctor(CommandHandlerFunctor* functor); 40 41 CommandHandlerFunctor* GetFunctor(uint32_t familyId, uint32_t packetId, uint32_t version) const; 42 43 private: 44 std::unordered_map<CommandHandlerKey, CommandHandlerFunctor*, CommandHandlerHash> registry; 45 }; 46 47 } // namespace pipe 48 49 } // namespace arm 50