Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ConnectionAcknowledgedCommandHandler.hpp" |
| 7 | |
| 8 | #include <armnn/Exceptions.hpp> |
| 9 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame^] | 10 | #include <boost/format.hpp> |
| 11 | |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | namespace profiling |
| 16 | { |
| 17 | |
| 18 | void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet) |
| 19 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame^] | 20 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 21 | switch (currentState) |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 22 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame^] | 23 | case ProfilingState::Uninitialised: |
| 24 | case ProfilingState::NotConnected: |
| 25 | throw RuntimeException(boost::str(boost::format("Connection Acknowledged Handler invoked while in an " |
| 26 | "wrong state: %1%") |
| 27 | % GetProfilingStateName(currentState))); |
| 28 | case ProfilingState::WaitingForAck: |
| 29 | // Process the packet |
| 30 | if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u)) |
| 31 | { |
| 32 | throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 1 but " |
| 33 | "received family = %1%, id = %2%") |
| 34 | % packet.GetPacketFamily() |
| 35 | % packet.GetPacketId())); |
| 36 | } |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 37 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame^] | 38 | // Once a Connection Acknowledged packet has been received, move to the Active state immediately |
| 39 | m_StateMachine.TransitionToState(ProfilingState::Active); |
| 40 | |
| 41 | break; |
| 42 | case ProfilingState::Active: |
| 43 | return; // NOP |
| 44 | default: |
| 45 | throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%") |
| 46 | % static_cast<int>(currentState))); |
| 47 | } |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // namespace profiling |
| 51 | |
| 52 | } // namespace armnn |
| 53 | |