blob: 5a5d87999687fdae26c8372f38d8af6e960af55d [file] [log] [blame]
Francis Murtagh94d79152019-08-16 17:45:07 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Francis Murtagh94d79152019-08-16 17:45:07 +01003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "CommandHandlerFunctor.hpp"
9#include "CommandHandlerKey.hpp"
10
Jim Flynnbbfe6032020-07-20 16:57:44 +010011#include <functional>
Francis Murtagh94d79152019-08-16 17:45:07 +010012#include <unordered_map>
13
Jim Flynnbbfe6032020-07-20 16:57:44 +010014namespace arm
Aron Virginas-Tare898db92019-08-22 12:56:34 +010015{
16
Jim Flynnbbfe6032020-07-20 16:57:44 +010017namespace pipe
Aron Virginas-Tare898db92019-08-22 12:56:34 +010018{
19
Francis Murtagh94d79152019-08-16 17:45:07 +010020struct CommandHandlerHash
21{
22 std::size_t operator() (const CommandHandlerKey& commandHandlerKey) const
23 {
24 std::size_t seed = 0;
Jim Flynnbbfe6032020-07-20 16:57:44 +010025 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);
Francis Murtagh94d79152019-08-16 17:45:07 +010028 return seed;
29 }
30};
31
32class CommandHandlerRegistry
33{
34public:
35 CommandHandlerRegistry() = default;
36
Jim Flynn397043f2019-10-17 17:37:10 +010037 void RegisterFunctor(CommandHandlerFunctor* functor, uint32_t familyId, uint32_t packetId, uint32_t version);
Francis Murtagh94d79152019-08-16 17:45:07 +010038
Matteo Martincighc2728f92019-10-07 12:35:21 +010039 void RegisterFunctor(CommandHandlerFunctor* functor);
40
Jim Flynn397043f2019-10-17 17:37:10 +010041 CommandHandlerFunctor* GetFunctor(uint32_t familyId, uint32_t packetId, uint32_t version) const;
Francis Murtagh94d79152019-08-16 17:45:07 +010042
43private:
44 std::unordered_map<CommandHandlerKey, CommandHandlerFunctor*, CommandHandlerHash> registry;
Aron Virginas-Tare898db92019-08-22 12:56:34 +010045};
46
Jim Flynnbbfe6032020-07-20 16:57:44 +010047} // namespace pipe
Aron Virginas-Tare898db92019-08-22 12:56:34 +010048
Jim Flynnbbfe6032020-07-20 16:57:44 +010049} // namespace arm