From 67ef2a52c3cdcc37538d77711bbcea2f0e5655e5 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 10 Oct 2019 13:29:02 +0100 Subject: IVGCVSW-3964 Change the type held by the Packet class to unsigned char * Updated the Packet class * Updated the pertinent code accordingly Signed-off-by: Matteo Martincigh Change-Id: I73eab5b1ead67a610cd17fd33f8a74f764ad8cc4 --- src/profiling/Packet.hpp | 18 +++++++-------- .../ProfilingConnectionDumpToFileDecorator.cpp | 10 +++++---- .../ProfilingConnectionDumpToFileDecorator.hpp | 2 +- src/profiling/SocketProfilingConnection.cpp | 4 ++-- ...ProfilingConnectionDumpToFileDecoratorTests.cpp | 8 +++---- src/profiling/test/ProfilingTests.cpp | 26 +++++++++++----------- src/profiling/test/ProfilingTests.hpp | 6 ++--- 7 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/profiling') diff --git a/src/profiling/Packet.hpp b/src/profiling/Packet.hpp index fae368b64e..ff6de69f53 100644 --- a/src/profiling/Packet.hpp +++ b/src/profiling/Packet.hpp @@ -33,7 +33,7 @@ public: m_PacketFamily = (header >> 26); } - Packet(uint32_t header, uint32_t length, std::unique_ptr& data) + Packet(uint32_t header, uint32_t length, std::unique_ptr& data) : m_Header(header) , m_Length(length) , m_Data(std::move(data)) @@ -66,13 +66,13 @@ public: Packet& operator=(const Packet&) = delete; Packet& operator=(Packet&&) = default; - uint32_t GetHeader() const { return m_Header; } - uint32_t GetPacketFamily() const { return m_PacketFamily; } - uint32_t GetPacketId() const { return m_PacketId; } - uint32_t GetPacketClass() const { return m_PacketId >> 3; } - uint32_t GetPacketType() const { return m_PacketId & 7; } - uint32_t GetLength() const { return m_Length; } - const char* const GetData() const { return m_Data.get(); } + uint32_t GetHeader() const { return m_Header; } + uint32_t GetPacketFamily() const { return m_PacketFamily; } + uint32_t GetPacketId() const { return m_PacketId; } + uint32_t GetPacketClass() const { return m_PacketId >> 3; } + uint32_t GetPacketType() const { return m_PacketId & 7; } + uint32_t GetLength() const { return m_Length; } + const unsigned char* const GetData() const { return m_Data.get(); } bool IsEmpty() { return m_Header == 0 && m_Length == 0; } @@ -81,7 +81,7 @@ private: uint32_t m_PacketFamily; uint32_t m_PacketId; uint32_t m_Length; - std::unique_ptr m_Data; + std::unique_ptr m_Data; }; } // namespace profiling diff --git a/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp b/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp index 3d4b6bf927..d7915624f6 100644 --- a/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp +++ b/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp @@ -51,7 +51,7 @@ bool ProfilingConnectionDumpToFileDecorator::WritePacket(const unsigned char* bu bool success = true; if (m_Settings.m_DumpOutgoing) { - success &= DumpOutgoingToFile(reinterpret_cast(buffer), length); + success &= DumpOutgoingToFile(buffer, length); } success &= m_Connection->WritePacket(buffer, length); return success; @@ -105,7 +105,8 @@ void ProfilingConnectionDumpToFileDecorator::DumpIncomingToFile(const Packet& pa m_IncomingDumpFileStream.write(reinterpret_cast(&header), sizeof header); m_IncomingDumpFileStream.write(reinterpret_cast(&packetLength), sizeof packetLength); - m_IncomingDumpFileStream.write(packet.GetData(), boost::numeric_cast(packetLength)); + m_IncomingDumpFileStream.write(reinterpret_cast(packet.GetData()), + boost::numeric_cast(packetLength)); success &= m_IncomingDumpFileStream.good(); if (!(success || m_Settings.m_IgnoreFileErrors)) @@ -122,7 +123,7 @@ void ProfilingConnectionDumpToFileDecorator::DumpIncomingToFile(const Packet& pa /// @param buffer pointer to data to write /// @param length number of bytes to write /// @return true if write successful, false otherwise -bool ProfilingConnectionDumpToFileDecorator::DumpOutgoingToFile(const char* buffer, uint32_t length) +bool ProfilingConnectionDumpToFileDecorator::DumpOutgoingToFile(const unsigned char* buffer, uint32_t length) { bool success = true; if (!m_OutgoingDumpFileStream.is_open()) @@ -136,7 +137,8 @@ bool ProfilingConnectionDumpToFileDecorator::DumpOutgoingToFile(const char* buff } // attempt to write binary data - m_OutgoingDumpFileStream.write(buffer, boost::numeric_cast(length)); + m_OutgoingDumpFileStream.write(reinterpret_cast(buffer), + boost::numeric_cast(length)); success &= m_OutgoingDumpFileStream.good(); if (!(success || m_Settings.m_IgnoreFileErrors)) { diff --git a/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp b/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp index c2ae538138..cc79d954d9 100644 --- a/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp +++ b/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp @@ -64,7 +64,7 @@ private: void DumpIncomingToFile(const Packet& packet); - bool DumpOutgoingToFile(const char* buffer, uint32_t length); + bool DumpOutgoingToFile(const unsigned char* buffer, uint32_t length); void Fail(const std::string& errorMessage); diff --git a/src/profiling/SocketProfilingConnection.cpp b/src/profiling/SocketProfilingConnection.cpp index 0ae7b0e1fe..ad629928f9 100644 --- a/src/profiling/SocketProfilingConnection.cpp +++ b/src/profiling/SocketProfilingConnection.cpp @@ -119,10 +119,10 @@ Packet SocketProfilingConnection::ReadPacket(uint32_t timeout) uint32_t dataLength = 0; std::memcpy(&dataLength, header + 4u, sizeof(dataLength)); - std::unique_ptr packetData; + std::unique_ptr packetData; if (dataLength > 0) { - packetData = std::make_unique(dataLength); + packetData = std::make_unique(dataLength); } ssize_t receivedLength = recv(m_Socket[0].fd, packetData.get(), dataLength, 0); diff --git a/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp b/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp index fac93c5ddf..a7acdd63cc 100644 --- a/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp +++ b/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp @@ -32,7 +32,7 @@ class DummyProfilingConnection : public IProfilingConnection public: DummyProfilingConnection() : m_Open(true) - , m_PacketData(std::make_unique(g_DataLength)) + , m_PacketData(std::make_unique(g_DataLength)) { // populate packet data and construct packet std::memcpy(m_PacketData.get(), g_DataPtr, g_DataLength); @@ -65,8 +65,8 @@ public: } private: - bool m_Open; - std::unique_ptr m_PacketData; + bool m_Open; + std::unique_ptr m_PacketData; std::unique_ptr m_Packet; }; @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(DumpIncomingValidFile) decorator.Close(); std::vector data = ReadDumpFile(settings.m_IncomingDumpFileName); - const char* packetData = packet->GetData(); + const char* packetData = reinterpret_cast(packet->GetData()); // check if the data read back from the dump file matches the original constexpr unsigned int bytesToSkip = 2u * sizeof(uint32_t); // skip header and packet length diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 57a11d0503..27bacf7145 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -198,9 +198,9 @@ BOOST_AUTO_TEST_CASE(CheckEncodeVersion) BOOST_AUTO_TEST_CASE(CheckPacketClass) { uint32_t length = 4; - std::unique_ptr packetData0 = std::make_unique(length); - std::unique_ptr packetData1 = std::make_unique(0); - std::unique_ptr nullPacketData; + std::unique_ptr packetData0 = std::make_unique(length); + std::unique_ptr packetData1 = std::make_unique(0); + std::unique_ptr nullPacketData; Packet packetTest0(472580096, length, packetData0); @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(CheckPacketClass) BOOST_CHECK(packetTest3.GetLength() == 0); BOOST_CHECK(packetTest3.GetData() == nullptr); - const char* packetTest0Data = packetTest0.GetData(); + const unsigned char* packetTest0Data = packetTest0.GetData(); Packet packetTest4(std::move(packetTest0)); BOOST_CHECK(packetTest0.GetData() == nullptr); @@ -260,9 +260,9 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor) it++; BOOST_CHECK(it->first==keyC); - std::unique_ptr packetDataA; - std::unique_ptr packetDataB; - std::unique_ptr packetDataC; + std::unique_ptr packetDataA; + std::unique_ptr packetDataB; + std::unique_ptr packetDataC; Packet packetA(500000000, 0, packetDataA); Packet packetB(600000000, 0, packetDataB); @@ -302,9 +302,9 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry) registry.RegisterFunctor(&testFunctorB); registry.RegisterFunctor(&testFunctorC); - std::unique_ptr packetDataA; - std::unique_ptr packetDataB; - std::unique_ptr packetDataC; + std::unique_ptr packetDataA; + std::unique_ptr packetDataB; + std::unique_ptr packetDataC; Packet packetA(500000000, 0, packetDataA); Packet packetB(600000000, 0, packetDataB); @@ -1707,7 +1707,7 @@ BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData) uint32_t dataLength1 = 8; uint32_t offset = 0; - std::unique_ptr uniqueData1 = std::make_unique(dataLength1); + std::unique_ptr uniqueData1 = std::make_unique(dataLength1); unsigned char* data1 = reinterpret_cast(uniqueData1.get()); WriteUint32(data1, offset, period1); @@ -1758,7 +1758,7 @@ BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData) uint32_t period2 = 11; uint32_t dataLength2 = 4; - std::unique_ptr uniqueData2 = std::make_unique(dataLength2); + std::unique_ptr uniqueData2 = std::make_unique(dataLength2); WriteUint32(reinterpret_cast(uniqueData2.get()), 0, period2); @@ -1802,7 +1802,7 @@ BOOST_AUTO_TEST_CASE(CheckConnectionAcknowledged) uint32_t dataLength1 = 8; uint32_t offset = 0; - std::unique_ptr uniqueData1 = std::make_unique(dataLength1); + std::unique_ptr uniqueData1 = std::make_unique(dataLength1); unsigned char* data1 = reinterpret_cast(uniqueData1.get()); WriteUint32(data1, offset, period1); diff --git a/src/profiling/test/ProfilingTests.hpp b/src/profiling/test/ProfilingTests.hpp index e1686162db..4d2f974344 100644 --- a/src/profiling/test/ProfilingTests.hpp +++ b/src/profiling/test/ProfilingTests.hpp @@ -71,8 +71,7 @@ public: std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); // Return connection acknowledged packet - std::unique_ptr packetData; - return Packet(65536, 0, packetData); + return Packet(65536); } }; @@ -94,8 +93,7 @@ public: } // Return connection acknowledged packet after three timeouts - std::unique_ptr packetData; - return Packet(65536, 0, packetData); + return Packet(65536); } private: -- cgit v1.2.1