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: |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 25 | throw RuntimeException(boost::str(boost::format("Connection Acknowledged Command Handler invoked while in an " |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 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 | |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 41 | // Send all the packet required for the handshake with the external profiling service |
| 42 | m_SendCounterPacket.SendStreamMetaDataPacket(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 43 | m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory); |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 44 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 45 | |
| 46 | // Notify the Send Thread that new data is available in the Counter Stream Buffer |
| 47 | m_SendCounterPacket.SetReadyToRead(); |
| 48 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 49 | break; |
| 50 | case ProfilingState::Active: |
| 51 | return; // NOP |
| 52 | default: |
| 53 | throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%") |
| 54 | % static_cast<int>(currentState))); |
| 55 | } |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace profiling |
| 59 | |
| 60 | } // namespace armnn |
| 61 | |