Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 1 | // |
| 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 Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 9 | #include <boost/format.hpp> |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 10 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 11 | namespace armnn |
| 12 | { |
| 13 | |
| 14 | namespace profiling |
| 15 | { |
| 16 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 17 | void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor, |
| 18 | uint32_t familyId, |
| 19 | uint32_t packetId, |
| 20 | uint32_t version) |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 21 | { |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 22 | BOOST_ASSERT_MSG(functor, "Provided functor should not be a nullptr"); |
| 23 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 24 | CommandHandlerKey key(familyId, packetId, version); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 25 | registry[key] = functor; |
| 26 | } |
| 27 | |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 28 | void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor) |
| 29 | { |
| 30 | BOOST_ASSERT_MSG(functor, "Provided functor should not be a nullptr"); |
| 31 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 32 | RegisterFunctor(functor, functor->GetFamilyId(), functor->GetPacketId(), functor->GetVersion()); |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 35 | CommandHandlerFunctor* CommandHandlerRegistry::GetFunctor(uint32_t familyId,uint32_t packetId, uint32_t version) const |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 36 | { |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 37 | CommandHandlerKey key(familyId, packetId, version); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 38 | |
| 39 | // Check that the requested key exists |
| 40 | if (registry.find(key) == registry.end()) |
| 41 | { |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 42 | throw armnn::InvalidArgumentException( |
| 43 | boost::str(boost::format("Functor with requested PacketId=%1% and Version=%2% does not exist") |
| 44 | % packetId |
| 45 | % version)); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 48 | 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 Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 58 | } |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 59 | |
| 60 | } // namespace profiling |
| 61 | |
| 62 | } // namespace armnn |