IVGCVSW-3963 Implement the Request Counter Directory Handler

 * Integrated the RequestCounterDirectoryCommandHandler in the
   ProfilingService class
 * Code refactoring
 * Added/Updated unit tests

Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: I60d9f8acf166e29b3dabc921dbdb8149461bd85f
diff --git a/src/profiling/RequestCounterDirectoryCommandHandler.cpp b/src/profiling/RequestCounterDirectoryCommandHandler.cpp
index 0fdcf10..e85acb4 100644
--- a/src/profiling/RequestCounterDirectoryCommandHandler.cpp
+++ b/src/profiling/RequestCounterDirectoryCommandHandler.cpp
@@ -5,7 +5,7 @@
 
 #include "RequestCounterDirectoryCommandHandler.hpp"
 
-#include <boost/assert.hpp>
+#include <boost/format.hpp>
 
 namespace armnn
 {
@@ -15,10 +15,36 @@
 
 void RequestCounterDirectoryCommandHandler::operator()(const Packet& packet)
 {
-    BOOST_ASSERT(packet.GetLength() == 0);
+    ProfilingState currentState = m_StateMachine.GetCurrentState();
+    switch (currentState)
+    {
+    case ProfilingState::Uninitialised:
+    case ProfilingState::NotConnected:
+    case ProfilingState::WaitingForAck:
+        throw RuntimeException(boost::str(boost::format("Request Counter Directory Handler invoked while in an "
+                                                        "wrong state: %1%")
+                                          % GetProfilingStateName(currentState)));
+    case ProfilingState::Active:
+        // Process the packet
+        if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u))
+        {
+            throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 3 but "
+                                                                           "received family = %1%, id = %2%")
+                                                  % packet.GetPacketFamily()
+                                                  % packet.GetPacketId()));
+        }
 
-    // Write packet to Counter Stream Buffer
-    m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
+        // Write a Counter Directory packet to the Counter Stream Buffer
+        m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
+
+        // Notify the Send Thread that new data is available in the Counter Stream Buffer
+        m_SendCounterPacket.SetReadyToRead();
+
+        break;
+    default:
+        throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
+                                          % static_cast<int>(currentState)));
+    }
 }
 
 } // namespace profiling