blob: 8070afe623d7446f9e44c75f751dc0632b1c28c8 [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
8#include <boost/assert.hpp>
Matteo Martincighc2728f92019-10-07 12:35:21 +01009#include <boost/format.hpp>
Francis Murtagh94d79152019-08-16 17:45:07 +010010
Aron Virginas-Tare898db92019-08-22 12:56:34 +010011namespace armnn
12{
13
14namespace profiling
15{
16
Jim Flynn397043f2019-10-17 17:37:10 +010017void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor,
18 uint32_t familyId,
19 uint32_t packetId,
20 uint32_t version)
Francis Murtagh94d79152019-08-16 17:45:07 +010021{
Matteo Martincighc2728f92019-10-07 12:35:21 +010022 BOOST_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
23
Jim Flynn397043f2019-10-17 17:37:10 +010024 CommandHandlerKey key(familyId, packetId, version);
Francis Murtagh94d79152019-08-16 17:45:07 +010025 registry[key] = functor;
26}
27
Matteo Martincighc2728f92019-10-07 12:35:21 +010028void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor)
29{
30 BOOST_ASSERT_MSG(functor, "Provided functor should not be a nullptr");
31
Jim Flynn397043f2019-10-17 17:37:10 +010032 RegisterFunctor(functor, functor->GetFamilyId(), functor->GetPacketId(), functor->GetVersion());
Matteo Martincighc2728f92019-10-07 12:35:21 +010033}
34
Jim Flynn397043f2019-10-17 17:37:10 +010035CommandHandlerFunctor* CommandHandlerRegistry::GetFunctor(uint32_t familyId,uint32_t packetId, uint32_t version) const
Francis Murtagh94d79152019-08-16 17:45:07 +010036{
Jim Flynn397043f2019-10-17 17:37:10 +010037 CommandHandlerKey key(familyId, packetId, version);
Francis Murtagh94d79152019-08-16 17:45:07 +010038
39 // Check that the requested key exists
40 if (registry.find(key) == registry.end())
41 {
Matteo Martincighc2728f92019-10-07 12:35:21 +010042 throw armnn::InvalidArgumentException(
43 boost::str(boost::format("Functor with requested PacketId=%1% and Version=%2% does not exist")
44 % packetId
45 % version));
Francis Murtagh94d79152019-08-16 17:45:07 +010046 }
47
Matteo Martincighc2728f92019-10-07 12:35:21 +010048 CommandHandlerFunctor* commandHandlerFunctor = registry.at(key);
49 if (commandHandlerFunctor == nullptr)
50 {
51 throw RuntimeException(
52 boost::str(boost::format("Invalid functor registered for PacketId=%1% and Version=%2%")
53 % packetId
54 % version));
55 }
56
57 return commandHandlerFunctor;
Francis Murtagh94d79152019-08-16 17:45:07 +010058}
Aron Virginas-Tare898db92019-08-22 12:56:34 +010059
60} // namespace profiling
61
62} // namespace armnn