IVGCVSW-4073 Send stream info in the ConnectionAcknowledgedCommandHandler
[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         // Send all the packet required for the handshake with the external profiling service
42         m_SendCounterPacket.SendStreamMetaDataPacket();
43         m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
44         m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
45
46         // Notify the Send Thread that new data is available in the Counter Stream Buffer
47         m_SendCounterPacket.SetReadyToRead();
48
49         break;
50     case ProfilingState::Active:
51         return; // NOP
52     default:
53         throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
54                                           % static_cast<int>(currentState)));
55     }
56 }
57
58 } // namespace profiling
59
60 } // namespace armnn
61