blob: 324737eda5cfb596beed5bec1e7e12d34a9f6b16 [file] [log] [blame]
Jim Flynnbbfe6032020-07-20 16:57:44 +01001//
2// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6
7#include <common/include/Assert.hpp>
8#include <common/include/CommandHandlerRegistry.hpp>
9
10#include <sstream>
11
12namespace arm
13{
14
15namespace pipe
16{
17
18void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor,
19 uint32_t familyId,
20 uint32_t packetId,
21 uint32_t version)
22{
23 ARM_PIPE_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
24
25 CommandHandlerKey key(familyId, packetId, version);
26 registry[key] = functor;
27}
28
29void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor)
30{
31 ARM_PIPE_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
32
33 RegisterFunctor(functor, functor->GetFamilyId(), functor->GetPacketId(), functor->GetVersion());
34}
35
36CommandHandlerFunctor* CommandHandlerRegistry::GetFunctor(uint32_t familyId,uint32_t packetId, uint32_t version) const
37{
38 CommandHandlerKey key(familyId, packetId, version);
39
40 // Check that the requested key exists
41 if (registry.find(key) == registry.end())
42 {
43 std::stringstream ss;
44 ss << "Functor with requested PacketId=" << packetId << " and Version=" << version << " does not exist";
45 throw ProfilingException(ss.str());
46 }
47
48 CommandHandlerFunctor* commandHandlerFunctor = registry.at(key);
49 if (commandHandlerFunctor == nullptr)
50 {
51 std::stringstream ss;
52 ss << "Invalid functor registered for PacketId=" << packetId << " and Version=" << version;
53 throw ProfilingException(ss.str());
54 }
55
56 return commandHandlerFunctor;
57}
58
59} // namespace pipe
60
61} // namespace arm