blob: a0825c7ba7f6ff9ca62121773708bf503ace4cf5 [file] [log] [blame]
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001//
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 Martincighd0613b52019-10-09 16:47:04 +010010#include <boost/format.hpp>
11
Sadik Armaganb5f01b22019-09-18 17:29:00 +010012namespace armnn
13{
14
15namespace profiling
16{
17
18void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet)
19{
Matteo Martincighd0613b52019-10-09 16:47:04 +010020 ProfilingState currentState = m_StateMachine.GetCurrentState();
21 switch (currentState)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010022 {
Matteo Martincighd0613b52019-10-09 16:47:04 +010023 case ProfilingState::Uninitialised:
24 case ProfilingState::NotConnected:
Matteo Martincighe8485382019-10-10 14:08:21 +010025 throw RuntimeException(boost::str(boost::format("Connection Acknowledged Command Handler invoked while in an "
Matteo Martincighd0613b52019-10-09 16:47:04 +010026 "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 Martincighc2728f92019-10-07 12:35:21 +010037
Matteo Martincighd0613b52019-10-09 16:47:04 +010038 // Once a Connection Acknowledged packet has been received, move to the Active state immediately
39 m_StateMachine.TransitionToState(ProfilingState::Active);
40
Keith Davis3201eea2019-10-24 17:30:41 +010041 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
42
43 // Notify the Send Thread that new data is available in the Counter Stream Buffer
44 m_SendCounterPacket.SetReadyToRead();
45
Matteo Martincighd0613b52019-10-09 16:47:04 +010046 break;
47 case ProfilingState::Active:
48 return; // NOP
49 default:
50 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
51 % static_cast<int>(currentState)));
52 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010053}
54
55} // namespace profiling
56
57} // namespace armnn
58