blob: 9d2d1a2bd2c8d2ae4bfa0af62427456181185adf [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:
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 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
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 Armaganb5f01b22019-09-18 17:29:00 +010048}
49
50} // namespace profiling
51
52} // namespace armnn
53