|
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 * testagentconsumer.cpp |
|
16 * implements some of OMA DRM for testing purposes |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include <caf/caf.h> |
|
23 #include "testagentdata.h" |
|
24 #include "testagentattributes.h" |
|
25 #include "TestAgentFile.h" |
|
26 #include "TestAgentDrmContent.h" |
|
27 |
|
28 using namespace ContentAccess; |
|
29 |
|
30 CTestAgentData* CTestAgentData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) |
|
31 { |
|
32 CTestAgentData* self = NewLC(aVirtualPath, aShareMode); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CTestAgentData* CTestAgentData::NewLC(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) |
|
38 { |
|
39 CTestAgentData* self=new(ELeave) CTestAgentData(); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(aVirtualPath, aShareMode); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CTestAgentData* CTestAgentData::NewL(RFile& aFile, const TDesC& aUniqueId) |
|
46 { |
|
47 CTestAgentData* self = NewLC(aFile, aUniqueId); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CTestAgentData* CTestAgentData::NewLC(RFile& aFile, const TDesC& aUniqueId) |
|
53 { |
|
54 CTestAgentData* self=new(ELeave) CTestAgentData(); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(aFile, aUniqueId); |
|
57 return self; |
|
58 } |
|
59 |
|
60 CTestAgentData::CTestAgentData() |
|
61 { |
|
62 } |
|
63 |
|
64 CTestAgentData::~CTestAgentData() |
|
65 { |
|
66 delete iVirtualPath; |
|
67 delete iTestFileObject; |
|
68 |
|
69 iFile.Close(); |
|
70 iFs.Close(); |
|
71 } |
|
72 |
|
73 void CTestAgentData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode) |
|
74 { |
|
75 // It is at this point that the agent can open the target content |
|
76 // and cache the size. Evaluation of intent will be left until the |
|
77 // CData object is created. |
|
78 |
|
79 // default share mode of EFileShareReadersOnly |
|
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 TFileName dummyFileName; |
|
96 TTestAgentAttributes::GetDummyFileName(aVirtualPath.URI(), dummyFileName); |
|
97 |
|
98 // open the file with the correct mode |
|
99 User::LeaveIfError(iFs.Connect()); |
|
100 User::LeaveIfError(iFs.ShareAuto()); |
|
101 User::LeaveIfError(iFile.Open(iFs, dummyFileName, mode)); |
|
102 |
|
103 // remember the location of the file |
|
104 iVirtualPath = CVirtualPath::NewL(dummyFileName, aVirtualPath.UniqueId()); |
|
105 |
|
106 // Parse the structure of the DCF file if asked to open default content |
|
107 if(aVirtualPath.UniqueId().Length() == 0) |
|
108 { |
|
109 iTestFileObject = CTestAgentFile::NewL(iFile); |
|
110 } |
|
111 else |
|
112 { |
|
113 iTestFileObject = CTestAgentDrmContent::NewL(iFile); |
|
114 } |
|
115 |
|
116 // seek to start of data in the file, ready to "read" |
|
117 TInt Pos = 0; |
|
118 Seek(ESeekStart, Pos); |
|
119 } |
|
120 |
|
121 |
|
122 void CTestAgentData::ConstructL(RFile& aFile, const TDesC& aUniqueId) |
|
123 { |
|
124 User::LeaveIfError(iFile.Duplicate(aFile)); |
|
125 |
|
126 User::LeaveIfError(iFs.Connect()); |
|
127 User::LeaveIfError(iFs.ShareAuto()); |
|
128 |
|
129 // only parse the drm content if requested to open it |
|
130 if(aUniqueId.Length() == 0) |
|
131 { |
|
132 iTestFileObject = CTestAgentFile::NewL(iFile); |
|
133 } |
|
134 else |
|
135 { |
|
136 iTestFileObject = CTestAgentDrmContent::NewL(iFile); |
|
137 } |
|
138 |
|
139 |
|
140 // seek to start of data in the file, ready to "read" |
|
141 TInt Pos = 0; |
|
142 Seek(ESeekStart, Pos); |
|
143 } |
|
144 |
|
145 void CTestAgentData::DataSizeL(TInt &aSize) |
|
146 { |
|
147 iTestFileObject->DataSizeL(aSize); |
|
148 } |
|
149 |
|
150 TInt CTestAgentData::EvaluateIntent(TIntent /*aIntent*/) |
|
151 { |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 TInt CTestAgentData::ExecuteIntent(TIntent /*aIntent*/) |
|
156 { |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 TInt CTestAgentData::Read(TDes8& aDes) |
|
161 { |
|
162 return iTestFileObject->Read(aDes,aDes.MaxLength()); |
|
163 } |
|
164 |
|
165 TInt CTestAgentData::Read(TDes8& aDes,TInt aLength) |
|
166 { |
|
167 return iTestFileObject->Read(aDes,aLength); |
|
168 } |
|
169 |
|
170 void CTestAgentData::Read(TDes8& aDes,TRequestStatus& aStatus) |
|
171 { |
|
172 iTestFileObject->Read(aDes, aDes.MaxLength(), aStatus); |
|
173 } |
|
174 |
|
175 void CTestAgentData::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
176 { |
|
177 iTestFileObject->Read(aDes, aLength, aStatus); |
|
178 } |
|
179 |
|
180 TInt CTestAgentData::Read(TInt aPos, TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
181 { |
|
182 iTestFileObject->Read(aPos, aDes, aLength, aStatus); |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 void CTestAgentData::ReadCancel(TRequestStatus& aStatus) |
|
187 { |
|
188 iTestFileObject->ReadCancel(aStatus); |
|
189 } |
|
190 |
|
191 TInt CTestAgentData::Seek(TSeek aMode, TInt& aPos) |
|
192 { |
|
193 return iTestFileObject->Seek(aMode, aPos); |
|
194 } |
|
195 |
|
196 TInt CTestAgentData::SetProperty(TAgentProperty /*aProperty*/, TInt /*aValue*/) |
|
197 { |
|
198 return KErrCANotSupported; |
|
199 } |
|
200 |
|
201 TInt CTestAgentData::GetAttribute(TInt aAttribute, TInt& aValue) |
|
202 { |
|
203 return iTestFileObject->GetAttribute(aAttribute, aValue); |
|
204 } |
|
205 |
|
206 TInt CTestAgentData::GetAttributeSet(RAttributeSet& aAttributeSet) |
|
207 { |
|
208 return TTestAgentAttributes::GetAttributeSet(*iTestFileObject, aAttributeSet); |
|
209 } |
|
210 |
|
211 TInt CTestAgentData::GetStringAttribute(TInt aAttribute, TDes& aValue) |
|
212 { |
|
213 return iTestFileObject->GetStringAttribute(aAttribute, aValue); |
|
214 } |
|
215 |
|
216 TInt CTestAgentData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) |
|
217 { |
|
218 return TTestAgentAttributes::GetStringAttributeSet(*iTestFileObject, aStringAttributeSet); |
|
219 } |
|
220 |
|
221 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
222 TInt CTestAgentData::Read64(TInt64 /* aPos */, TDes8& /* aDes */, TInt /* aLength */, TRequestStatus& /* aStatus */) |
|
223 { |
|
224 return KErrCANotSupported; |
|
225 } |
|
226 |
|
227 void CTestAgentData::DataSize64L(TInt64& /*aSize*/) |
|
228 { |
|
229 User::Leave(KErrCANotSupported); |
|
230 } |
|
231 |
|
232 TInt CTestAgentData::Seek64(TSeek /*aMode*/, TInt64& /*aPos*/) |
|
233 { |
|
234 return KErrCANotSupported; |
|
235 } |
|
236 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
237 |