a0825c7ba7f6ff9ca62121773708bf503ace4cf5
[platform/upstream/armnn.git] / src / profiling / ConnectionAcknowledgedCommandHandler.cpp
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
10 #include <boost/format.hpp>
11
12 namespace armnn
13 {
14
15 namespace profiling
16 {
17
18 void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet)
19 {
20     ProfilingState currentState = m_StateMachine.GetCurrentState();
21     switch (currentState)
22     {
23     case ProfilingState::Uninitialised:
24     case ProfilingState::NotConnected:
25         throw RuntimeException(boost::str(boost::format("Connection Acknowledged Command 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         }
37
38         // Once a Connection Acknowledged packet has been received, move to the Active state immediately
39         m_StateMachine.TransitionToState(ProfilingState::Active);
40
41         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
46         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     }
53 }
54
55 } // namespace profiling
56
57 } // namespace armnn
58