blob: e85acb4215f4bfa63c76c8f7afdf36b32acc9506 [file] [log] [blame]
Narumol Prangnawarat48033692019-09-20 12:04:55 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RequestCounterDirectoryCommandHandler.hpp"
7
Matteo Martincigh8efc5002019-10-10 14:30:29 +01008#include <boost/format.hpp>
Matteo Martincighd0613b52019-10-09 16:47:04 +01009
Narumol Prangnawarat48033692019-09-20 12:04:55 +010010namespace armnn
11{
12
13namespace profiling
14{
15
16void RequestCounterDirectoryCommandHandler::operator()(const Packet& packet)
17{
Matteo Martincigh8efc5002019-10-10 14:30:29 +010018 ProfilingState currentState = m_StateMachine.GetCurrentState();
19 switch (currentState)
20 {
21 case ProfilingState::Uninitialised:
22 case ProfilingState::NotConnected:
23 case ProfilingState::WaitingForAck:
24 throw RuntimeException(boost::str(boost::format("Request Counter Directory Handler invoked while in an "
25 "wrong state: %1%")
26 % GetProfilingStateName(currentState)));
27 case ProfilingState::Active:
28 // Process the packet
29 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u))
30 {
31 throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 3 but "
32 "received family = %1%, id = %2%")
33 % packet.GetPacketFamily()
34 % packet.GetPacketId()));
35 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010036
Matteo Martincigh8efc5002019-10-10 14:30:29 +010037 // Write a Counter Directory packet to the Counter Stream Buffer
38 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
39
40 // Notify the Send Thread that new data is available in the Counter Stream Buffer
41 m_SendCounterPacket.SetReadyToRead();
42
43 break;
44 default:
45 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
46 % static_cast<int>(currentState)));
47 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010048}
49
50} // namespace profiling
51
Matteo Martincighd0613b52019-10-09 16:47:04 +010052} // namespace armnn