|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Source file for CUpnpFilePipe class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpfilepipe.h" |
|
21 |
|
22 _LIT( KComponentLogfile, "upnpcommand.log"); |
|
23 #include "upnplog.h" |
|
24 |
|
25 // -------------------------------------------------------------------------- |
|
26 // CUpnpFilePipe::NewL |
|
27 // Creates a new file pipe with unlimited length. |
|
28 // -------------------------------------------------------------------------- |
|
29 // |
|
30 CUpnpFilePipe* CUpnpFilePipe::NewL() |
|
31 { |
|
32 __LOG( "[UpnpCommand]\t CUpnpFilePipe::NewL" ); |
|
33 |
|
34 // Create a new file pipe with unlimited length (0). |
|
35 return new (ELeave) CUpnpFilePipe( 0 ); |
|
36 } |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CUpnpFilePipe::NewL |
|
40 // Creates a new file pipe with a set length. |
|
41 // -------------------------------------------------------------------------- |
|
42 // |
|
43 CUpnpFilePipe* CUpnpFilePipe::NewL( TInt aMaxSize ) |
|
44 { |
|
45 __LOG( "[UpnpCommand]\t CUpnpFilePipe::NewL" ); |
|
46 |
|
47 // Check param |
|
48 if( aMaxSize <= 0 ) |
|
49 { |
|
50 User::Leave( KErrArgument ); |
|
51 } |
|
52 |
|
53 // Create a new file pipe with the given length. |
|
54 return new (ELeave) CUpnpFilePipe( aMaxSize ); |
|
55 } |
|
56 |
|
57 // -------------------------------------------------------------------------- |
|
58 // CUpnpFilePipe::CUpnpFilePipe |
|
59 // First phase construction. |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CUpnpFilePipe::CUpnpFilePipe( TInt aMaxSize ) |
|
63 : iMaxSize( aMaxSize ) |
|
64 { |
|
65 // No implementation |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // Destructor. |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 CUpnpFilePipe::~CUpnpFilePipe() |
|
73 { |
|
74 __LOG( "[UpnpCommand]\t CUpnpFilePipe::Destructor" ); |
|
75 |
|
76 // Reset the content of the array |
|
77 Reset(); |
|
78 |
|
79 // Close the array |
|
80 iValues.Close(); |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // CUpnpFilePipe::PushL |
|
85 // Pushes one file into the pipe. |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 void CUpnpFilePipe::PushL( const TDesC& aParam ) |
|
89 { |
|
90 __LOG( "[UpnpCommand]\t CUpnpFilePipe::PushL" ); |
|
91 |
|
92 // Parameter check |
|
93 if( aParam == KNullDesC ) |
|
94 { |
|
95 User::Leave( KErrArgument ); |
|
96 } |
|
97 |
|
98 // If we are using a pipe with a limited size |
|
99 if( iMaxSize > 0 ) |
|
100 { |
|
101 // If the pipe is already full (max size reached) remove the newest |
|
102 // file from the pipe |
|
103 if( iValues.Count() >= iMaxSize ) |
|
104 { |
|
105 RemoveNewestFileFromPipe(); |
|
106 } |
|
107 } |
|
108 |
|
109 // Create a new parameter value |
|
110 HBufC* temp = aParam.AllocL(); |
|
111 CleanupStack::PushL( temp ); |
|
112 |
|
113 // Append the new parameter value to the array |
|
114 iValues.AppendL( temp ); |
|
115 |
|
116 // Just pop, ownership transfered to iValues array |
|
117 CleanupStack::Pop( temp ); |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CUpnpFilePipe::FileAt |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 const TDesC& CUpnpFilePipe::FileAt( TInt aIndex ) |
|
125 { |
|
126 __ASSERTD( aIndex >= 0 && aIndex < iValues.Count(), |
|
127 __FILE__, __LINE__ ); |
|
128 TDesC* file = iValues[aIndex]; |
|
129 return *file; |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // CUpnpFilePipe::Reset |
|
134 // Resets the pipe. |
|
135 // -------------------------------------------------------------------------- |
|
136 // |
|
137 void CUpnpFilePipe::Reset() |
|
138 { |
|
139 __LOG( "[UpnpCommand]\t CUpnpFilePipe::Reset" ); |
|
140 |
|
141 // Simply reset the array |
|
142 iValues.ResetAndDestroy(); |
|
143 } |
|
144 |
|
145 // -------------------------------------------------------------------------- |
|
146 // CUpnpFilePipe::Count |
|
147 // Returns the count of the items in the pipe. |
|
148 // -------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CUpnpFilePipe::Count() |
|
151 { |
|
152 __LOG( "[UpnpCommand]\t CUpnpFilePipe::Count" ); |
|
153 |
|
154 // Simply retun the array's item count |
|
155 return iValues.Count(); |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CUpnpFilePipe::AsArray |
|
160 // returns the entire pipe as an array |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 RPointerArray<TDesC>& CUpnpFilePipe::AsArray() |
|
164 { |
|
165 return iValues; |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 // CUpnpFilePipe::RemoveNewestFileFromPipe |
|
170 // Removes the newest file from the pipe. |
|
171 // -------------------------------------------------------------------------- |
|
172 // |
|
173 void CUpnpFilePipe::RemoveNewestFileFromPipe() |
|
174 { |
|
175 __LOG( "[UpnpCommand]\t CUpnpFilePipe::RemoveNewestFileFromPipe" ); |
|
176 |
|
177 // Remove item only if there are items in the pipe |
|
178 if( iValues.Count() > 0 ) |
|
179 { |
|
180 // Get the index of the newest item (last item in the array) |
|
181 TInt newestIndex = iValues.Count() - 1; // indexing starts from 0 |
|
182 |
|
183 // Get the pointer to the data, and delete it |
|
184 HBufC* temp = static_cast<HBufC*>( iValues[newestIndex] ); |
|
185 delete temp; |
|
186 temp = NULL; |
|
187 |
|
188 // Remove the pointer from the array, this will also compress the |
|
189 // array |
|
190 iValues.Remove( newestIndex ); |
|
191 } |
|
192 } |
|
193 |
|
194 // End of file |