blob: a2a045d1e03c8d4013025ace3badbf7c46a25872 [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);
Colm Donelan2ba48d22019-11-29 09:10:59 +000040 // Send the counter directory packet.
Keith Davis3201eea2019-10-24 17:30:41 +010041 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000042 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Keith Davis3201eea2019-10-24 17:30:41 +010043
44 // Notify the Send Thread that new data is available in the Counter Stream Buffer
45 m_SendCounterPacket.SetReadyToRead();
46
Matteo Martincighd0613b52019-10-09 16:47:04 +010047 break;
48 case ProfilingState::Active:
49 return; // NOP
50 default:
51 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
52 % static_cast<int>(currentState)));
53 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010054}
55
56} // namespace profiling
57
58} // namespace armnn
59