From d0613b56cea7eba0604e0548bddffd773a4eb554 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Wed, 9 Oct 2019 16:47:04 +0100 Subject: IVGCVSW-3937 Improve the Connection Acknowledged Handler * The Connection Acknowledged Handler should report an error is it's called while in a wrong state * Stopping the threads in the ProfilingService before having to start them again * Updated the unit tests to check the changes * Removed unnecessary Packet.cpp file * Fixed memory leak Signed-off-by: Matteo Martincigh Change-Id: I8c4d33b4d97994df86fe6c9f8c659f880ec64c16 --- .../ConnectionAcknowledgedCommandHandler.cpp | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/profiling/ConnectionAcknowledgedCommandHandler.cpp') diff --git a/src/profiling/ConnectionAcknowledgedCommandHandler.cpp b/src/profiling/ConnectionAcknowledgedCommandHandler.cpp index f90b601b7e..9d2d1a2bd2 100644 --- a/src/profiling/ConnectionAcknowledgedCommandHandler.cpp +++ b/src/profiling/ConnectionAcknowledgedCommandHandler.cpp @@ -7,6 +7,8 @@ #include +#include + namespace armnn { @@ -15,15 +17,34 @@ namespace profiling void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet) { - if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u)) + ProfilingState currentState = m_StateMachine.GetCurrentState(); + switch (currentState) { - throw armnn::InvalidArgumentException(std::string("Expected Packet family = 0, id = 1 but received family = ") - + std::to_string(packet.GetPacketFamily()) - + " id = " + std::to_string(packet.GetPacketId())); + case ProfilingState::Uninitialised: + case ProfilingState::NotConnected: + throw RuntimeException(boost::str(boost::format("Connection Acknowledged Handler invoked while in an " + "wrong state: %1%") + % GetProfilingStateName(currentState))); + case ProfilingState::WaitingForAck: + // Process the packet + if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u)) + { + throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 1 but " + "received family = %1%, id = %2%") + % packet.GetPacketFamily() + % packet.GetPacketId())); + } + + // Once a Connection Acknowledged packet has been received, move to the Active state immediately + m_StateMachine.TransitionToState(ProfilingState::Active); + + break; + case ProfilingState::Active: + return; // NOP + default: + throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%") + % static_cast(currentState))); } - - // Once a Connection Acknowledged packet has been received, move to the Active state immediately - m_StateMachine.TransitionToState(ProfilingState::Active); } } // namespace profiling -- cgit v1.2.1