File indexing completed on 2024-05-05 04:44:41
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License version 2 as published by the Free Software Foundation. 0007 0008 This library is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 Library General Public License for more details. 0012 0013 You should have received a copy of the GNU Library General Public License 0014 along with this library; see the file COPYING.LIB. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 0018 */ 0019 0020 #ifndef PHONON_PACKET_H 0021 #define PHONON_PACKET_H 0022 0023 #include "export.h" 0024 0025 namespace Phonon 0026 { 0027 0028 class PacketPool; 0029 0030 class PacketPrivate; 0031 /** \class Packet packetpool.h phonon/Packet 0032 * \brief Class to access memory preallocated by PacketPool 0033 * 0034 * \note PacketPool and Packet are threadsafe. 0035 * 0036 * \author Matthias Kretz <kretz@kde.org> 0037 */ 0038 class PHONONEXPERIMENTAL_EXPORT Packet 0039 { 0040 friend class PacketPoolPrivate; 0041 Q_DECLARE_PRIVATE(Packet) 0042 public: 0043 /** 0044 * Constructs a null packet. 0045 * 0046 * \see isNull 0047 */ 0048 Packet(); 0049 /** 0050 * Returns a packet with a capacity of pool.packetSize if there is still free data in the 0051 * PacketPool. Returns a null packet otherwise. The size will initially be set to 0. 0052 */ 0053 explicit Packet(PacketPool &pool); 0054 /** 0055 * Returns a shared copy of the object. Note that Packet will not detach (and it can not 0056 * detach as there's a fixed amount of memory preallocated. If you want to copy the actual 0057 * memory data you have to request another packet from the pool and copy the memory 0058 * yourself.) 0059 */ 0060 Packet(const Packet &rhs); 0061 /** 0062 * Assigns a shared copy of the object. Note that Packet will not detach (and it can not 0063 * detach as there's a fixed amount of memory preallocated. If you want to copy the actual 0064 * memory data you have to request another packet from the pool and copy the memory 0065 * yourself.) 0066 */ 0067 Packet &operator=(const Packet &rhs); 0068 0069 /** 0070 * Dereferences the packet data. If this is the last reference that gets released the packet 0071 * becomes available in the PacketPool again automatically. 0072 */ 0073 ~Packet(); 0074 0075 /** 0076 * Returns whether the packets reference the same data. 0077 */ 0078 bool operator==(const Packet &rhs) const; 0079 0080 /** 0081 * Returns whether the packets reference different data. 0082 */ 0083 bool operator!=(const Packet &rhs) const; 0084 0085 /** 0086 * Returns whether this object is a null packet. 0087 * 0088 * \see Packet() 0089 */ 0090 bool isNull() const; 0091 0092 /** 0093 * Returns a pointer to read the data this packet references. 0094 * 0095 * You may read size() bytes. 0096 */ 0097 const char *data() const; 0098 0099 /** 0100 * Returns a pointer to read and write the data this packet references. 0101 * 0102 * You may read size() bytes. 0103 * You may write capacity() bytes. 0104 * If you write to this pointer do not forget to adjust the size by calling setSize(). 0105 */ 0106 char *data(); 0107 0108 /** 0109 * Returns the number of bytes that have a defined value. 0110 */ 0111 int size() const; 0112 0113 /** 0114 * Sets how many bytes in the data pointer have a defined value. 0115 */ 0116 void setSize(int size); 0117 0118 /** 0119 * Returns the number of bytes that may be accessed. 0120 */ 0121 int capacity() const; 0122 0123 protected: 0124 explicit Packet(PacketPrivate &dd); 0125 PacketPrivate *d_ptr; 0126 }; 0127 0128 } // namespace Phonon 0129 #endif // PHONON_PACKET_H