xref: /aosp_15_r20/external/armnn/profiling/client/src/RequestCounterDirectoryCommandHandler.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "RequestCounterDirectoryCommandHandler.hpp"
7 
8 #include <fmt/format.h>
9 
10 namespace arm
11 {
12 
13 namespace pipe
14 {
15 
operator ()(const arm::pipe::Packet & packet)16 void RequestCounterDirectoryCommandHandler::operator()(const arm::pipe::Packet& packet)
17 {
18     ProfilingState currentState = m_StateMachine.GetCurrentState();
19     switch (currentState)
20     {
21     case ProfilingState::Uninitialised:
22     case ProfilingState::NotConnected:
23     case ProfilingState::WaitingForAck:
24         throw arm::pipe::ProfilingException(fmt::format("Request Counter Directory Comand Handler invoked while in an "
25                                             "wrong state: {}",
26                                             GetProfilingStateName(currentState)));
27     case ProfilingState::Active:
28         // Process the packet
29         if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u))
30         {
31             throw arm::pipe::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 3 but "
32                                                                   "received family = {}, id = {}",
33                                                                   packet.GetPacketFamily(),
34                                                                   packet.GetPacketId()));
35         }
36 
37         // Send all the packet required for the handshake with the external profiling service
38         m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
39         m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
40 
41         break;
42     default:
43         throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
44                                             static_cast<int>(currentState)));
45     }
46 }
47 
48 } // namespace pipe
49 
50 } // namespace arm
51