blob: c2fef7a5974aac8b46e13bc2ba93116fc19a3884 [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#include "CommandHandlerRegistry.hpp"
7
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01008#include <armnn/utility/Assert.hpp>
9
Matteo Martincighc2728f92019-10-07 12:35:21 +010010#include <boost/format.hpp>
Francis Murtagh94d79152019-08-16 17:45:07 +010011
Aron Virginas-Tare898db92019-08-22 12:56:34 +010012namespace armnn
13{
14
15namespace profiling
16{
17
Jim Flynn397043f2019-10-17 17:37:10 +010018void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor,
19 uint32_t familyId,
20 uint32_t packetId,
21 uint32_t version)
Francis Murtagh94d79152019-08-16 17:45:07 +010022{
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010023 ARMNN_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
Matteo Martincighc2728f92019-10-07 12:35:21 +010024
Jim Flynn397043f2019-10-17 17:37:10 +010025 CommandHandlerKey key(familyId, packetId, version);
Francis Murtagh94d79152019-08-16 17:45:07 +010026 registry[key] = functor;
27}
28
Matteo Martincighc2728f92019-10-07 12:35:21 +010029void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor)
30{
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010031 ARMNN_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
Matteo Martincighc2728f92019-10-07 12:35:21 +010032
Jim Flynn397043f2019-10-17 17:37:10 +010033 RegisterFunctor(functor, functor->GetFamilyId(), functor->GetPacketId(), functor->GetVersion());
Matteo Martincighc2728f92019-10-07 12:35:21 +010034}
35
Jim Flynn397043f2019-10-17 17:37:10 +010036CommandHandlerFunctor* CommandHandlerRegistry::GetFunctor(uint32_t familyId,uint32_t packetId, uint32_t version) const
Francis Murtagh94d79152019-08-16 17:45:07 +010037{
Jim Flynn397043f2019-10-17 17:37:10 +010038 CommandHandlerKey key(familyId, packetId, version);
Francis Murtagh94d79152019-08-16 17:45:07 +010039
40 // Check that the requested key exists
41 if (registry.find(key) == registry.end())
42 {
Matteo Martincighc2728f92019-10-07 12:35:21 +010043 throw armnn::InvalidArgumentException(
44 boost::str(boost::format("Functor with requested PacketId=%1% and Version=%2% does not exist")
45 % packetId
46 % version));
Francis Murtagh94d79152019-08-16 17:45:07 +010047 }
48
Matteo Martincighc2728f92019-10-07 12:35:21 +010049 CommandHandlerFunctor* commandHandlerFunctor = registry.at(key);
50 if (commandHandlerFunctor == nullptr)
51 {
52 throw RuntimeException(
53 boost::str(boost::format("Invalid functor registered for PacketId=%1% and Version=%2%")
54 % packetId
55 % version));
56 }
57
58 return commandHandlerFunctor;
Francis Murtagh94d79152019-08-16 17:45:07 +010059}
Aron Virginas-Tare898db92019-08-22 12:56:34 +010060
61} // namespace profiling
62
63} // namespace armnn