1 | /* This file is part of the KDE project |
2 | Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License version 2 as published by the Free Software Foundation. |
7 | |
8 | This library is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | Library General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU Library General Public License |
14 | along with this library; see the file COPYING.LIB. If not, write to |
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
16 | Boston, MA 02110-1301, USA. |
17 | |
18 | */ |
19 | |
20 | #ifndef PHONON_PACKET_H |
21 | #define PHONON_PACKET_H |
22 | |
23 | #include "export.h" |
24 | |
25 | namespace Phonon |
26 | { |
27 | |
28 | class PacketPool; |
29 | |
30 | class PacketPrivate; |
31 | /** \class Packet packetpool.h phonon/Packet |
32 | * \brief Class to access memory preallocated by PacketPool |
33 | * |
34 | * \note PacketPool and Packet are threadsafe. |
35 | * |
36 | * \author Matthias Kretz <kretz@kde.org> |
37 | */ |
38 | class PHONONEXPERIMENTAL_EXPORT Packet |
39 | { |
40 | friend class PacketPoolPrivate; |
41 | Q_DECLARE_PRIVATE(Packet) |
42 | public: |
43 | /** |
44 | * Constructs a null packet. |
45 | * |
46 | * \see isNull |
47 | */ |
48 | Packet(); |
49 | /** |
50 | * Returns a packet with a capacity of pool.packetSize if there is still free data in the |
51 | * PacketPool. Returns a null packet otherwise. The size will initially be set to 0. |
52 | */ |
53 | explicit Packet(PacketPool &pool); |
54 | /** |
55 | * Returns a shared copy of the object. Note that Packet will not detach (and it can not |
56 | * detach as there's a fixed amount of memory preallocated. If you want to copy the actual |
57 | * memory data you have to request another packet from the pool and copy the memory |
58 | * yourself.) |
59 | */ |
60 | Packet(const Packet &rhs); |
61 | /** |
62 | * Assigns a shared copy of the object. Note that Packet will not detach (and it can not |
63 | * detach as there's a fixed amount of memory preallocated. If you want to copy the actual |
64 | * memory data you have to request another packet from the pool and copy the memory |
65 | * yourself.) |
66 | */ |
67 | Packet &operator=(const Packet &rhs); |
68 | |
69 | /** |
70 | * Dereferences the packet data. If this is the last reference that gets released the packet |
71 | * becomes available in the PacketPool again automatically. |
72 | */ |
73 | ~Packet(); |
74 | |
75 | /** |
76 | * Returns whether the packets reference the same data. |
77 | */ |
78 | bool operator==(const Packet &rhs) const; |
79 | |
80 | /** |
81 | * Returns whether the packets reference different data. |
82 | */ |
83 | bool operator!=(const Packet &rhs) const; |
84 | |
85 | /** |
86 | * Returns whether this object is a null packet. |
87 | * |
88 | * \see Packet() |
89 | */ |
90 | bool isNull() const; |
91 | |
92 | /** |
93 | * Returns a pointer to read the data this packet references. |
94 | * |
95 | * You may read size() bytes. |
96 | */ |
97 | const char *data() const; |
98 | |
99 | /** |
100 | * Returns a pointer to read and write the data this packet references. |
101 | * |
102 | * You may read size() bytes. |
103 | * You may write capacity() bytes. |
104 | * If you write to this pointer do not forget to adjust the size by calling setSize(). |
105 | */ |
106 | char *data(); |
107 | |
108 | /** |
109 | * Returns the number of bytes that have a defined value. |
110 | */ |
111 | int size() const; |
112 | |
113 | /** |
114 | * Sets how many bytes in the data pointer have a defined value. |
115 | */ |
116 | void setSize(int size); |
117 | |
118 | /** |
119 | * Returns the number of bytes that may be accessed. |
120 | */ |
121 | int capacity() const; |
122 | |
123 | protected: |
124 | explicit Packet(PacketPrivate &dd); |
125 | PacketPrivate *d_ptr; |
126 | }; |
127 | |
128 | } // namespace Phonon |
129 | #endif // PHONON_PACKET_H |
130 | |