|
1 /** |
|
2 * Copyright (c) 2009 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: CUpnpCdsReaderAO class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include <upnpfilesharing.h> |
|
20 #include <upnpobject.h> |
|
21 |
|
22 #include "upnpcdsreaderao.h" |
|
23 #include "upnpsharingalgorithmconstants.h" |
|
24 #include "upnplog.h" |
|
25 #include "upnpcommonutils.h" |
|
26 #include "upnpcdsliteobjectarray.h" |
|
27 #include "upnpbrowsecriteria.h" |
|
28 #include "upnpcontainerlist.h" |
|
29 #include "upnpitemlist.h" |
|
30 |
|
31 const TInt KDefaultBrowseReqCount( 50 ); |
|
32 const TInt KLoopLimit( 3 ); |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CUpnpSecAccessController::NewL |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 CUpnpCdsReaderAO* CUpnpCdsReaderAO::NewL( |
|
39 CUpnpCdsLiteObjectArray& aUpnpCdsLiteObjects ) |
|
40 { |
|
41 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::NewL" ); |
|
42 |
|
43 CUpnpCdsReaderAO* self = new ( ELeave ) CUpnpCdsReaderAO( |
|
44 aUpnpCdsLiteObjects ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // CUpnpCdsReaderAO::ConstructL |
|
53 // -------------------------------------------------------------------------- |
|
54 // |
|
55 void CUpnpCdsReaderAO::ConstructL() |
|
56 { |
|
57 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::ConstructL" ); |
|
58 |
|
59 if ( !CActiveScheduler::Current() ) |
|
60 { |
|
61 iScheduler = new ( ELeave ) CActiveScheduler; |
|
62 CActiveScheduler::Install( iScheduler ); |
|
63 } |
|
64 // Add this active object to the active scheduler. |
|
65 CActiveScheduler::Add( this ); |
|
66 |
|
67 iFileSharing = CUpnpFileSharing::NewL(); |
|
68 iWaitRequest = new ( ELeave ) CActiveSchedulerWait(); |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CUpnpCdsReaderAO::~CUpnpCdsReaderAO |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CUpnpCdsReaderAO::~CUpnpCdsReaderAO() |
|
76 { |
|
77 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::~CUpnpCdsReaderAO" ); |
|
78 |
|
79 delete iFileSharing; |
|
80 delete iWaitRequest; |
|
81 |
|
82 if ( CActiveScheduler::Current() == iScheduler ) |
|
83 { |
|
84 CActiveScheduler::Install( NULL ); |
|
85 } |
|
86 delete iScheduler; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CUpnpCdsReaderAO::ReadCdsStructureL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 void CUpnpCdsReaderAO::ReadCdsStructureL() |
|
94 { |
|
95 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::ReadCdsStructureL" ); |
|
96 |
|
97 // Start reading from root container |
|
98 GetContainersL( KRootContainer ); |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // CUpnpCdsReaderAO::GetContainersL |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 void CUpnpCdsReaderAO::GetContainersL( const TDesC8& aContainerId ) |
|
106 { |
|
107 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::GetContainersL" ); |
|
108 |
|
109 // Get all items of container with id aContainerId |
|
110 GetItemsL( aContainerId ); |
|
111 |
|
112 // Number of found items. Count is initialized as KDefaultBrowseReqCount |
|
113 // to get into the while loop. Loop ends, when GetSharedItemListL |
|
114 // request does not get new objects |
|
115 TInt count( KDefaultBrowseReqCount ); |
|
116 TInt startingIndex( 0 ); |
|
117 TInt loopCounter( 0 ); |
|
118 |
|
119 while ( startingIndex < count ) |
|
120 { |
|
121 count = 0; |
|
122 |
|
123 CUpnpContainerList* containerList = CUpnpContainerList::NewL(); |
|
124 CleanupStack::PushL( containerList ); |
|
125 |
|
126 CUpnpBrowseCriteria* browseCriteria = CUpnpBrowseCriteria::NewLC(); |
|
127 browseCriteria->SetRequestedCount( KDefaultBrowseReqCount ); |
|
128 browseCriteria->SetStartingIndex( startingIndex ); |
|
129 browseCriteria->SetFilterL( KBrowseCriteriaFilter ); |
|
130 |
|
131 // Query all items and containers with container id aContainerId |
|
132 iFileSharing->GetSharedContainerListL( |
|
133 UPnPCommonUtils::DesC8ToInt( aContainerId ), |
|
134 *browseCriteria, |
|
135 *containerList, |
|
136 count, |
|
137 iStatus ); |
|
138 |
|
139 CleanupStack::PopAndDestroy( browseCriteria ); |
|
140 |
|
141 // Wait for the request to complete |
|
142 CompleteRequestL(); |
|
143 |
|
144 // Leave, if GetSharedContainerListL gives continuously zero items |
|
145 if ( !containerList->ObjectCount() ) |
|
146 { |
|
147 loopCounter += 1; |
|
148 if ( loopCounter >= KLoopLimit ) |
|
149 { |
|
150 User::Leave( KErrGeneral ); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 loopCounter = 0; |
|
156 } |
|
157 |
|
158 for ( TInt index( 0 ); index < containerList->ObjectCount(); index++ ) |
|
159 { |
|
160 // Append container to the objects array |
|
161 iUpnpCdsLiteObjects.AppendL( ( *containerList )[ index ] ); |
|
162 // Call object search recursively for each found container |
|
163 GetContainersL( ( *containerList )[ index ]->Id() ); |
|
164 } |
|
165 |
|
166 startingIndex += containerList->ObjectCount(); |
|
167 |
|
168 CleanupStack::PopAndDestroy( containerList ); |
|
169 } |
|
170 } |
|
171 |
|
172 // -------------------------------------------------------------------------- |
|
173 // CUpnpCdsReaderAO::GetItemsL |
|
174 // -------------------------------------------------------------------------- |
|
175 // |
|
176 void CUpnpCdsReaderAO::GetItemsL( const TDesC8& aContainerId ) |
|
177 { |
|
178 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::GetItemsL" ); |
|
179 |
|
180 // Number of found items. Count is initialized as KDefaultBrowseReqCount |
|
181 // to get into the while loop. Loop ends, when GetSharedItemListL |
|
182 // request does not get new objects |
|
183 TInt count( KDefaultBrowseReqCount ); |
|
184 TInt startingIndex( 0 ); |
|
185 TInt loopCounter( 0 ); |
|
186 |
|
187 while ( startingIndex < count ) |
|
188 { |
|
189 count = 0; |
|
190 |
|
191 CUpnpItemList* itemList = CUpnpItemList::NewL(); |
|
192 CleanupStack::PushL( itemList ); |
|
193 |
|
194 CUpnpBrowseCriteria* browseCriteria = CUpnpBrowseCriteria::NewLC(); |
|
195 browseCriteria->SetRequestedCount( KDefaultBrowseReqCount ); |
|
196 browseCriteria->SetStartingIndex( startingIndex ); |
|
197 browseCriteria->SetFilterL( KBrowseCriteriaFilter ); |
|
198 |
|
199 // Query all items of container with container id aContainerId |
|
200 iFileSharing->GetSharedItemListL( |
|
201 UPnPCommonUtils::DesC8ToInt( aContainerId ), |
|
202 *browseCriteria, |
|
203 *itemList, |
|
204 count, |
|
205 iStatus ); |
|
206 |
|
207 CleanupStack::PopAndDestroy( browseCriteria ); |
|
208 |
|
209 // Wait for the request to complete |
|
210 CompleteRequestL(); |
|
211 |
|
212 // Leave, if GetSharedContainerListL gives continuously zero items |
|
213 if ( !itemList->ObjectCount() ) |
|
214 { |
|
215 loopCounter += 1; |
|
216 if ( loopCounter >= KLoopLimit ) |
|
217 { |
|
218 User::Leave( KErrGeneral ); |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 loopCounter = 0; |
|
224 } |
|
225 |
|
226 // Append files to the objects array |
|
227 for ( TInt index( 0 ); index < itemList->ObjectCount(); index++ ) |
|
228 { |
|
229 // Local media applications store temporary items under |
|
230 // root container. Therefore items whose parent container |
|
231 // is root, are not appended to the objects array. |
|
232 if ( ( *itemList )[ index ]->ParentId().Match( KRootContainer ) |
|
233 == KErrNotFound ) |
|
234 { |
|
235 iUpnpCdsLiteObjects.AppendL( ( *itemList )[ index ] ); |
|
236 } |
|
237 } |
|
238 |
|
239 startingIndex += itemList->ObjectCount(); |
|
240 |
|
241 CleanupStack::PopAndDestroy( itemList ); |
|
242 } |
|
243 } |
|
244 |
|
245 // -------------------------------------------------------------------------- |
|
246 // CUpnpCdsReaderAO::RunL |
|
247 // -------------------------------------------------------------------------- |
|
248 // |
|
249 void CUpnpCdsReaderAO::RunL() |
|
250 { |
|
251 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::RunL" ); |
|
252 |
|
253 // Request completed - no need to wait anymore |
|
254 // Let ao caller to continue |
|
255 StopWaitingRequestComplete(); |
|
256 } |
|
257 |
|
258 // -------------------------------------------------------------------------- |
|
259 // CUpnpCdsReaderAO::DoCancel |
|
260 // -------------------------------------------------------------------------- |
|
261 // |
|
262 void CUpnpCdsReaderAO::DoCancel() |
|
263 { |
|
264 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::DoCancel" ); |
|
265 |
|
266 Cancel(); |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CUpnpCdsReaderAO::WaitRequestToComplete |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 void CUpnpCdsReaderAO::WaitRequestToComplete() |
|
274 { |
|
275 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::\ |
|
276 WaitRequestToComplete" ); |
|
277 |
|
278 // Wait for a request to complete |
|
279 if ( iWaitRequest && !iWaitRequest->IsStarted() ) |
|
280 { |
|
281 iWaitRequest->Start(); |
|
282 } |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CUpnpCdsReaderAO::StopWaitingRequestComplete |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 void CUpnpCdsReaderAO::StopWaitingRequestComplete() |
|
290 { |
|
291 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::\ |
|
292 StopWaitingRequestComplete" ); |
|
293 |
|
294 // Stop waiting process after query has been completed |
|
295 if ( iWaitRequest && iWaitRequest->IsStarted() ) |
|
296 { |
|
297 iWaitRequest->AsyncStop(); |
|
298 } |
|
299 } |
|
300 |
|
301 // -------------------------------------------------------------------------- |
|
302 // CUpnpCdsReaderAO::CompleteRequestL |
|
303 // -------------------------------------------------------------------------- |
|
304 // |
|
305 void CUpnpCdsReaderAO::CompleteRequestL() |
|
306 { |
|
307 __LOG( "[CUpnpSharingAlgorithm]\t CUpnpCdsReaderAO::\ |
|
308 CompleteRequestL" ); |
|
309 |
|
310 if ( !IsActive() ) |
|
311 { |
|
312 SetActive(); |
|
313 } |
|
314 else |
|
315 { |
|
316 User::Leave( KErrInUse ); |
|
317 } |
|
318 |
|
319 // Wait for request to complete |
|
320 WaitRequestToComplete(); |
|
321 |
|
322 // Leave if error happens |
|
323 if ( iStatus.Int() != KErrNone && |
|
324 iStatus.Int() != KErrNotFound ) |
|
325 { |
|
326 User::Leave( iStatus.Int() ); |
|
327 } |
|
328 } |
|
329 |
|
330 // End of File |