IVGCVSW-3902 Create IReadOnlyPacketBuffer, IPacketBuffer and IBufferManager interfaces

 * Create IReadOnlyPacketBuffer, IPacketBuffer and IBufferManager interfaces
 * Add Read and Write util functions that use IPacketBuffer
 * Add MockBufferManager using IBufferManager for testing
 * Modify SendCounterPacket to use IBufferManager
 * Modify MockStreamCounterBuffer to use IBufferManager
 * Remove IBufferWrapper and MockBuffer
 * Add MockPacketBuffer for testing
 * Modify unit tests to use the new interfaces

Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com>
Change-Id: Ib86768187e032f07169aa39367a418b7665c9f03
diff --git a/src/profiling/SendCounterPacket.hpp b/src/profiling/SendCounterPacket.hpp
index 8dd44ec..c57546d 100644
--- a/src/profiling/SendCounterPacket.hpp
+++ b/src/profiling/SendCounterPacket.hpp
@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "IBufferWrapper.hpp"
+#include "IBufferManager.hpp"
 #include "ISendCounterPacket.hpp"
 #include "ICounterDirectory.hpp"
 #include "IProfilingConnection.hpp"
@@ -31,9 +31,9 @@
 
     using IndexValuePairsVector = std::vector<std::pair<uint16_t, uint32_t>>;
 
-    SendCounterPacket(IProfilingConnection& profilingConnection, IBufferWrapper& buffer)
+    SendCounterPacket(IProfilingConnection& profilingConnection, IBufferManager& buffer)
         : m_ProfilingConnection(profilingConnection)
-        , m_Buffer(buffer)
+        , m_BufferManager(buffer)
         , m_IsRunning(false)
         , m_KeepRunning(false)
     {}
@@ -63,15 +63,25 @@
     template <typename ExceptionType>
     void CancelOperationAndThrow(const std::string& errorMessage)
     {
-        // Cancel the operation
-        m_Buffer.Commit(0);
+        // Throw a runtime exception with the given error message
+        throw ExceptionType(errorMessage);
+    }
+
+    template <typename ExceptionType>
+    void CancelOperationAndThrow(std::unique_ptr<IPacketBuffer>& writerBuffer, const std::string& errorMessage)
+    {
+        if (writerBuffer != nullptr)
+        {
+            // Cancel the operation
+            m_BufferManager.Release(writerBuffer);
+        }
 
         // Throw a runtime exception with the given error message
         throw ExceptionType(errorMessage);
     }
 
     IProfilingConnection& m_ProfilingConnection;
-    IBufferWrapper& m_Buffer;
+    IBufferManager& m_BufferManager;
     std::mutex m_WaitMutex;
     std::condition_variable m_WaitCondition;
     std::thread m_SendThread;