1 // 2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "ProfilingException.hpp" 9 10 #include <memory> 11 12 namespace arm 13 { 14 15 namespace pipe 16 { 17 18 class Packet 19 { 20 public: Packet()21 Packet() 22 : m_Header(0) 23 , m_PacketFamily(0) 24 , m_PacketId(0) 25 , m_Length(0) 26 , m_Data(nullptr) 27 {} 28 Packet(uint32_t header)29 Packet(uint32_t header) 30 : m_Header(header) 31 , m_Length(0) 32 , m_Data(nullptr) 33 { 34 m_PacketId = ((header >> 16) & 1023); 35 m_PacketFamily = (header >> 26); 36 } 37 Packet(uint32_t header,uint32_t length,std::unique_ptr<unsigned char[]> & data)38 Packet(uint32_t header, uint32_t length, std::unique_ptr<unsigned char[]>& data) 39 : m_Header(header) 40 , m_Length(length) 41 , m_Data(std::move(data)) 42 { 43 m_PacketId = ((header >> 16) & 1023); 44 m_PacketFamily = (header >> 26); 45 46 if (length == 0 && m_Data != nullptr) 47 { 48 throw arm::pipe::InvalidArgumentException("Data should be null when length is zero"); 49 } 50 } 51 Packet(Packet && other)52 Packet(Packet&& other) 53 : m_Header(other.m_Header) 54 , m_PacketFamily(other.m_PacketFamily) 55 , m_PacketId(other.m_PacketId) 56 , m_Length(other.m_Length) 57 , m_Data(std::move(other.m_Data)) 58 { 59 other.m_Header = 0; 60 other.m_PacketFamily = 0; 61 other.m_PacketId = 0; 62 other.m_Length = 0; 63 } 64 65 ~Packet() = default; 66 67 Packet(const Packet& other) = delete; 68 Packet& operator=(const Packet&) = delete; 69 Packet& operator=(Packet&&) = default; 70 GetHeader() const71 uint32_t GetHeader() const { return m_Header; } GetPacketFamily() const72 uint32_t GetPacketFamily() const { return m_PacketFamily; } GetPacketId() const73 uint32_t GetPacketId() const { return m_PacketId; } GetPacketClass() const74 uint32_t GetPacketClass() const { return m_PacketId >> 3; } GetPacketType() const75 uint32_t GetPacketType() const { return m_PacketId & 7; } GetLength() const76 uint32_t GetLength() const { return m_Length; } GetData() const77 const unsigned char* GetData() const { return m_Data.get(); } 78 IsEmpty()79 bool IsEmpty() { return m_Header == 0 && m_Length == 0; } 80 81 private: 82 uint32_t m_Header; 83 uint32_t m_PacketFamily; 84 uint32_t m_PacketId; 85 uint32_t m_Length; 86 std::unique_ptr<unsigned char[]> m_Data; 87 }; 88 89 } // namespace pipe 90 91 } // namespace arm 92