|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <caf/caf.h> |
|
20 #include "testagentcontent.h" |
|
21 #include "testagentattributes.h" |
|
22 |
|
23 using namespace ContentAccess; |
|
24 |
|
25 _LIT(KDummyContainer,"DummyContainer"); |
|
26 |
|
27 CTestAgentContent* CTestAgentContent::NewL(const TDesC& aURI, TContentShareMode aShareMode) |
|
28 { |
|
29 CTestAgentContent* self = NewLC(aURI, aShareMode); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CTestAgentContent* CTestAgentContent::NewLC(const TDesC& aURI, TContentShareMode aShareMode) |
|
35 { |
|
36 CTestAgentContent* self=new(ELeave) CTestAgentContent(); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(aURI, aShareMode); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTestAgentContent* CTestAgentContent::NewL(RFile& aFile) |
|
43 { |
|
44 CTestAgentContent* self = NewLC(aFile); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CTestAgentContent* CTestAgentContent::NewLC(RFile& aFile) |
|
50 { |
|
51 CTestAgentContent* self=new(ELeave) CTestAgentContent(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aFile); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CTestAgentContent::CTestAgentContent() |
|
59 { |
|
60 iDummyContainerOpen=EFalse; |
|
61 } |
|
62 |
|
63 CTestAgentContent::~CTestAgentContent() |
|
64 { |
|
65 delete iTestFile; |
|
66 delete iTestDrmContent; |
|
67 delete iURI; |
|
68 |
|
69 iFile.Close(); |
|
70 iFs.Close(); |
|
71 } |
|
72 |
|
73 void CTestAgentContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode) |
|
74 { |
|
75 TFileName dummyFileName; |
|
76 TTestAgentAttributes::GetDummyFileName(aURI, dummyFileName); |
|
77 |
|
78 iURI = dummyFileName.AllocL(); |
|
79 |
|
80 TUint mode = EFileStream | EFileRead; |
|
81 |
|
82 if(aShareMode == EContentShareReadWrite) |
|
83 { |
|
84 mode |= EFileShareReadersOrWriters; |
|
85 } |
|
86 else if (aShareMode == EContentShareExclusive) |
|
87 { |
|
88 mode |= EFileShareExclusive; |
|
89 } |
|
90 else |
|
91 { |
|
92 mode |= EFileShareReadersOnly; |
|
93 } |
|
94 |
|
95 // open underlying file handle |
|
96 User::LeaveIfError(iFs.Connect()); |
|
97 User::LeaveIfError(iFile.Open(iFs, *iURI, mode)); |
|
98 |
|
99 // Create DRM file objects |
|
100 iTestFile = CTestAgentFile::NewL(iFile); |
|
101 iTestDrmContent = CTestAgentDrmContent::NewL(iFile); |
|
102 |
|
103 // reset file pointer back to the beginning of the file |
|
104 TInt pos = 0; |
|
105 iFile.Seek(ESeekStart,pos); |
|
106 iShareMode = aShareMode; |
|
107 } |
|
108 |
|
109 void CTestAgentContent::ConstructL(RFile& aFile) |
|
110 { |
|
111 User::LeaveIfError(iFile.Duplicate(aFile)); |
|
112 |
|
113 // Create file objects |
|
114 iTestFile = CTestAgentFile::NewL(iFile); |
|
115 iTestDrmContent = CTestAgentDrmContent::NewL(iFile); |
|
116 |
|
117 // reset file pointer back to the beginning of the file |
|
118 TInt pos = 0; |
|
119 iFile.Seek(ESeekStart, pos); |
|
120 } |
|
121 |
|
122 TInt CTestAgentContent::OpenContainer(const TDesC& aUniqueId) |
|
123 { |
|
124 if(!iDummyContainerOpen && aUniqueId == KDummyContainer()) |
|
125 { |
|
126 iDummyContainerOpen = ETrue; |
|
127 return KErrNone; |
|
128 } |
|
129 return KErrNotFound; |
|
130 } |
|
131 |
|
132 TInt CTestAgentContent::CloseContainer() |
|
133 { |
|
134 if(iDummyContainerOpen) |
|
135 { |
|
136 iDummyContainerOpen = EFalse; |
|
137 return KErrNone; |
|
138 } |
|
139 return KErrNotFound; |
|
140 } |
|
141 |
|
142 void CTestAgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray) |
|
143 { |
|
144 if(!iDummyContainerOpen) |
|
145 { |
|
146 // The content object |
|
147 CEmbeddedObject *embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), *iURI, iTestDrmContent->ContentMimeType(), EContentObject); |
|
148 CleanupStack::PushL(embeddedObject); |
|
149 aArray.AppendL(embeddedObject); |
|
150 // Now owned by the array so do not destroy |
|
151 CleanupStack::Pop(embeddedObject); |
|
152 embeddedObject = NULL; |
|
153 |
|
154 // the file itself |
|
155 embeddedObject = CEmbeddedObject::NewL(KNullDesC(), *iURI, iTestFile->ContentMimeType(), EContentObject); |
|
156 CleanupStack::PushL(embeddedObject); |
|
157 aArray.AppendL(embeddedObject); |
|
158 // Now owned by the array so do not destroy |
|
159 CleanupStack::Pop(embeddedObject); |
|
160 embeddedObject = NULL; |
|
161 |
|
162 // The dummy container |
|
163 embeddedObject = CEmbeddedObject::NewL(KDummyContainer(), KDummyContainer(), KNullDesC8(), EContainerObject); |
|
164 CleanupStack::PushL(embeddedObject); |
|
165 aArray.AppendL(embeddedObject); |
|
166 // Now owned by the array so do not destroy |
|
167 CleanupStack::Pop(embeddedObject); |
|
168 embeddedObject = NULL; |
|
169 } |
|
170 } |
|
171 |
|
172 void CTestAgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType) |
|
173 { |
|
174 CEmbeddedObject *embeddedObject = NULL; |
|
175 if(!iDummyContainerOpen) |
|
176 { |
|
177 // the only embedded object is the file itself |
|
178 if(aType == EContentObject) |
|
179 { |
|
180 // The content object |
|
181 embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), *iURI, iTestDrmContent->ContentMimeType(), EContentObject); |
|
182 CleanupStack::PushL(embeddedObject); |
|
183 aArray.AppendL(embeddedObject); |
|
184 // Now owned by the array so do not destroy |
|
185 CleanupStack::Pop(embeddedObject); |
|
186 embeddedObject = NULL; |
|
187 |
|
188 // the file itself |
|
189 embeddedObject = CEmbeddedObject::NewL(KNullDesC(), *iURI, iTestFile->ContentMimeType(), EContentObject); |
|
190 CleanupStack::PushL(embeddedObject); |
|
191 aArray.AppendL(embeddedObject); |
|
192 // Now owned by the array so do not destroy |
|
193 CleanupStack::Pop(embeddedObject); |
|
194 embeddedObject = NULL; |
|
195 } |
|
196 else |
|
197 { |
|
198 // The dummy container |
|
199 embeddedObject = CEmbeddedObject::NewL(KDummyContainer(), KDummyContainer(), KNullDesC8(), EContainerObject); |
|
200 CleanupStack::PushL(embeddedObject); |
|
201 aArray.AppendL(embeddedObject); |
|
202 // Now owned by the array so do not destroy |
|
203 CleanupStack::Pop(embeddedObject); |
|
204 embeddedObject = NULL; |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 TInt CTestAgentContent::Search(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool aRecursive) |
|
210 { |
|
211 TRAPD(err, SearchL(aArray, aMimeType, aRecursive)); |
|
212 return err; |
|
213 } |
|
214 |
|
215 void CTestAgentContent::SearchL(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool ) |
|
216 { |
|
217 CEmbeddedObject *embeddedObject = NULL; |
|
218 if(iTestDrmContent->ContentMimeType() == aMimeType) |
|
219 { |
|
220 // content object matches required mime type |
|
221 embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), *iURI, iTestDrmContent->ContentMimeType(), EContentObject); |
|
222 } |
|
223 else if(aMimeType == iTestFile->ContentMimeType()) |
|
224 { |
|
225 // matches the file itself |
|
226 embeddedObject = CEmbeddedObject::NewL(KNullDesC(), *iURI, iTestFile->ContentMimeType(), EContentObject); |
|
227 } |
|
228 else |
|
229 { |
|
230 User::Leave(KErrNotFound); |
|
231 } |
|
232 |
|
233 CleanupStack::PushL(embeddedObject); |
|
234 aArray.AppendL(embeddedObject); |
|
235 // Now owned by the array so do not destroy |
|
236 CleanupStack::Pop(embeddedObject); |
|
237 } |
|
238 |
|
239 TInt CTestAgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId) |
|
240 { |
|
241 // check that the unique Id exists |
|
242 if(TTestAgentAttributes::CheckUniqueId(aUniqueId) != KErrNone) |
|
243 { |
|
244 return KErrNotFound; |
|
245 } |
|
246 |
|
247 if(aUniqueId.Length() == 0) |
|
248 { |
|
249 // If it's the entire file |
|
250 return iTestFile->GetAttribute(aAttribute, aValue); |
|
251 } |
|
252 else if(aUniqueId == KDefaultContentObject()) |
|
253 { |
|
254 // If it's the embedded content |
|
255 return iTestDrmContent->GetAttribute(aAttribute, aValue); |
|
256 } |
|
257 return KErrNotFound; |
|
258 } |
|
259 |
|
260 TInt CTestAgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId) |
|
261 { |
|
262 // check that the unique Id exists |
|
263 if(TTestAgentAttributes::CheckUniqueId(aUniqueId) != KErrNone) |
|
264 { |
|
265 return KErrNotFound; |
|
266 } |
|
267 |
|
268 if(aUniqueId.Length() == 0) |
|
269 { |
|
270 // The entire file |
|
271 return TTestAgentAttributes::GetAttributeSet(*iTestFile, aAttributeSet); |
|
272 } |
|
273 else if(aUniqueId == KDefaultContentObject()) |
|
274 { |
|
275 // the embedded content |
|
276 return TTestAgentAttributes::GetAttributeSet(*iTestDrmContent, aAttributeSet); |
|
277 } |
|
278 return KErrNotFound; |
|
279 } |
|
280 |
|
281 TInt CTestAgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId) |
|
282 { |
|
283 // check that the unique Id exists |
|
284 if(TTestAgentAttributes::CheckUniqueId(aUniqueId) != KErrNone) |
|
285 { |
|
286 return KErrNotFound; |
|
287 } |
|
288 |
|
289 if(aUniqueId.Length() == 0) |
|
290 { |
|
291 // If it's the entire file |
|
292 return iTestFile->GetStringAttribute(aAttribute, aValue); |
|
293 } |
|
294 else |
|
295 { |
|
296 // If it's the embedded content |
|
297 return iTestDrmContent->GetStringAttribute(aAttribute, aValue); |
|
298 } |
|
299 } |
|
300 |
|
301 TInt CTestAgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId) |
|
302 { |
|
303 // check that the unique Id exists |
|
304 if(TTestAgentAttributes::CheckUniqueId(aUniqueId) != KErrNone) |
|
305 { |
|
306 return KErrNotFound; |
|
307 } |
|
308 |
|
309 if(aUniqueId.Length() == 0) |
|
310 { |
|
311 // The entire file |
|
312 return TTestAgentAttributes::GetStringAttributeSet(*iTestFile, aStringAttributeSet); |
|
313 } |
|
314 else |
|
315 { |
|
316 // the embedded content |
|
317 return TTestAgentAttributes::GetStringAttributeSet(*iTestDrmContent, aStringAttributeSet); |
|
318 } |
|
319 } |
|
320 |
|
321 _LIT(KAgentSpecificCommandResponse, "output"); |
|
322 |
|
323 TInt CTestAgentContent::AgentSpecificCommand(TInt aCommand, const TDesC8&, TDes8& aOutputBuffer) |
|
324 { |
|
325 if(aCommand == 1) |
|
326 { |
|
327 aOutputBuffer.Copy(KAgentSpecificCommandResponse()); |
|
328 return KErrNone; |
|
329 } |
|
330 return KErrCANotSupported; |
|
331 } |
|
332 |
|
333 void CTestAgentContent::AgentSpecificCommand(TInt aCommand, const TDesC8& aInputBuffer, TDes8& aOutputBuffer, TRequestStatus& aStatus) |
|
334 { |
|
335 TRequestStatus *ptr = &aStatus; |
|
336 User::RequestComplete(ptr, AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer)); |
|
337 } |
|
338 |
|
339 void CTestAgentContent::NotifyStatusChange(TEventMask , TRequestStatus& aStatus, const TDesC& ) |
|
340 { |
|
341 TRequestStatus *ptr = &aStatus; |
|
342 User::RequestComplete(ptr, KErrCANotSupported); |
|
343 } |
|
344 |
|
345 TInt CTestAgentContent::CancelNotifyStatusChange(TRequestStatus& , const TDesC& ) |
|
346 { |
|
347 return KErrCANotSupported; |
|
348 } |
|
349 |
|
350 void CTestAgentContent::RequestRights(TRequestStatus& aStatus , const TDesC& ) |
|
351 { |
|
352 TRequestStatus *ptr = &aStatus; |
|
353 User::RequestComplete(ptr, KErrCANotSupported); |
|
354 } |
|
355 |
|
356 TInt CTestAgentContent::CancelRequestRights(TRequestStatus& , const TDesC& ) |
|
357 { |
|
358 return KErrCANotSupported; |
|
359 } |
|
360 |
|
361 void CTestAgentContent::DisplayInfoL(TDisplayInfo , const TDesC& ) |
|
362 { |
|
363 User::Leave(KErrCANotSupported); |
|
364 } |
|
365 |
|
366 TInt CTestAgentContent::SetProperty(TAgentProperty /*aProperty*/, TInt /*aValue*/) |
|
367 { |
|
368 return KErrNone; |
|
369 } |
|
370 |
|
371 |