|
1 /* |
|
2 * Copyright (c) 2006 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: EXPORT_C implementation of drm media utility |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bautils.h> |
|
20 #include <mpxmedia.h> |
|
21 #include "mpxdrmmediautility.h" |
|
22 #include "mpxdrmmediaomaagent.h" |
|
23 #include "mpxdrmmediawmaagent.h" |
|
24 #include "mpxmediadrmdefs.h" |
|
25 #include "mpxlog.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // Two-phased constructor. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 EXPORT_C CMPXDrmMediaUtility* CMPXDrmMediaUtility::NewL() |
|
32 { |
|
33 MPX_FUNC("CMPXDrmMediaUtility::NewL()"); |
|
34 CMPXDrmMediaUtility* p = new (ELeave) CMPXDrmMediaUtility(); |
|
35 CleanupStack::PushL(p); |
|
36 p->ConstructL(); |
|
37 CleanupStack::Pop(p); |
|
38 return p; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // Two-phased constructor. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CMPXDrmMediaUtility* CMPXDrmMediaUtility::NewLC() |
|
46 { |
|
47 MPX_FUNC("CMPXDrmMediaUtility::NewLC()"); |
|
48 CMPXDrmMediaUtility* p = new (ELeave) CMPXDrmMediaUtility(); |
|
49 CleanupStack::PushL(p); |
|
50 p->ConstructL(); |
|
51 return p; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // Destructor |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CMPXDrmMediaUtility::~CMPXDrmMediaUtility() |
|
59 { |
|
60 MPX_FUNC("CMPXDrmMediaUtility::~CMPXDrmMediaUtility()"); |
|
61 iAgents.ResetAndDestroy(); |
|
62 iAgents.Close(); |
|
63 delete iDefaultMedia; |
|
64 iFs.Close(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // Default constructor |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CMPXDrmMediaUtility::CMPXDrmMediaUtility() |
|
72 { |
|
73 MPX_FUNC("CMPXDrmMediaUtility::CMPXDrmMediaUtility()"); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // 2nd phase constructor. |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 void CMPXDrmMediaUtility::ConstructL() |
|
81 { |
|
82 MPX_FUNC("CMPXDrmMediaUtility::ConstructL()"); |
|
83 |
|
84 // Create the OMA Agent |
|
85 CMPXDrmMediaOmaAgent* omaAgent = CMPXDrmMediaOmaAgent::NewLC(); |
|
86 iAgents.Insert( omaAgent, EOmaDrmAgent ); |
|
87 CleanupStack::Pop( omaAgent ); |
|
88 |
|
89 // Create the WMA Agent |
|
90 CMPXDrmMediaWmaAgent* wmaAgent = CMPXDrmMediaWmaAgent::NewLC(); |
|
91 iAgents.Insert( wmaAgent, EWmaDrmAgent ); |
|
92 CleanupStack::Pop( wmaAgent ); |
|
93 |
|
94 // Create a default media |
|
95 RArray<TInt> supportedIds; |
|
96 CleanupClosePushL( supportedIds ); |
|
97 supportedIds.AppendL(KMPXMediaIdDrm); |
|
98 iDefaultMedia = CMPXMedia::NewL( supportedIds.Array() ); |
|
99 CleanupStack::PopAndDestroy( &supportedIds ); |
|
100 iDefaultMedia->SetTObjectValueL( KMPXMediaDrmProtected, |
|
101 EFalse ); |
|
102 |
|
103 // Create file system session |
|
104 User::LeaveIfError( iFs.Connect() ); |
|
105 } |
|
106 |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // Initialize utility using a filename |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C void CMPXDrmMediaUtility::InitL( const TDesC& aFileName ) |
|
113 { |
|
114 MPX_DEBUG2("CMPXDrmMediaUtility::InitL(%S) entering", &aFileName ); |
|
115 |
|
116 Close(); |
|
117 |
|
118 if ( BaflUtils::FileExists( iFs, aFileName )) |
|
119 { |
|
120 CContent* content( CContent::NewLC( aFileName, EContentShareReadWrite )); |
|
121 FindAgent( *content ); |
|
122 if ( iCurrentAgent ) |
|
123 { |
|
124 iCurrentAgent->InitL( aFileName ); |
|
125 } |
|
126 CleanupStack::PopAndDestroy( content ); |
|
127 } |
|
128 iConsumeStarted = EFalse; |
|
129 |
|
130 MPX_DEBUG1("CMPXDrmMediaUtility::InitL() exiting" ); |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // Initialize utility using a file handle |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C void CMPXDrmMediaUtility::InitL( RFile& aFile ) |
|
138 { |
|
139 MPX_DEBUG1("CMPXDrmMediaUtility::InitL(RFile) entering" ); |
|
140 |
|
141 Close(); |
|
142 CContent* content = CContent::NewLC( aFile ); |
|
143 FindAgent( *content ); |
|
144 if ( iCurrentAgent ) |
|
145 { |
|
146 iCurrentAgent->InitL( aFile ); |
|
147 } |
|
148 CleanupStack::PopAndDestroy( content ); |
|
149 iConsumeStarted = EFalse; |
|
150 |
|
151 MPX_DEBUG1("CMPXDrmMediaUtility::InitL(RFile) exiting" ); |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // Gets media object with the given attributes |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C const CMPXMedia* CMPXDrmMediaUtility::GetMediaL( TUint aAttributes ) |
|
159 { |
|
160 MPX_DEBUG2("CMPXDrmMediaUtility::GetMediaL(%d) entering", aAttributes ); |
|
161 |
|
162 const CMPXMedia* media( NULL ); |
|
163 if ( iCurrentAgent ) |
|
164 { |
|
165 media = &( iCurrentAgent->GetMediaL( aAttributes )); |
|
166 } |
|
167 else |
|
168 { |
|
169 MPX_DEBUG1("CMPXDrmMediaUtility::GetMediaL(): Returning default media"); |
|
170 media = iDefaultMedia; |
|
171 } |
|
172 |
|
173 MPX_DEBUG1("CMPXDrmMediaUtility::GetMediaL() exiting" ); |
|
174 return media; |
|
175 } |
|
176 |
|
177 |
|
178 // ---------------------------------------------------------------------------- |
|
179 // Consumes the rights for the current media according |
|
180 // to the specified consume type |
|
181 // ---------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C void CMPXDrmMediaUtility::ConsumeL( TDrmConsumeType aType ) |
|
184 { |
|
185 MPX_DEBUG1("CMPXDrmMediaUtility::ConsumeL() entering"); |
|
186 |
|
187 if ( iCurrentAgent ) |
|
188 { |
|
189 TDrmConsumeType type( EMPXDrmConsumeNone ); |
|
190 const CMPXMedia& media( iCurrentAgent->GetMediaL( EMPXMediaDrmProtected )); |
|
191 if ( media.ValueTObjectL<TBool>( KMPXMediaDrmProtected )) |
|
192 { |
|
193 switch ( aType ) |
|
194 { |
|
195 case EMPXDrmConsumeStart: |
|
196 { |
|
197 type = aType; |
|
198 iConsumeStarted = ETrue; |
|
199 break; |
|
200 } |
|
201 case EMPXDrmConsumePause: |
|
202 case EMPXDrmConsumeContinue: |
|
203 case EMPXDrmConsumeFinish: |
|
204 { |
|
205 if ( iConsumeStarted ) |
|
206 { |
|
207 type = aType; |
|
208 if ( EMPXDrmConsumeFinish == aType ) |
|
209 { |
|
210 iConsumeStarted = EFalse; |
|
211 } |
|
212 } |
|
213 break; |
|
214 } |
|
215 case EMPXDrmConsumeStartOrContinue: |
|
216 { |
|
217 if ( iConsumeStarted ) |
|
218 { |
|
219 type = EMPXDrmConsumeContinue; |
|
220 } |
|
221 else |
|
222 { |
|
223 type = EMPXDrmConsumeStart; |
|
224 iConsumeStarted = ETrue; |
|
225 } |
|
226 break; |
|
227 } |
|
228 default: |
|
229 { |
|
230 type = EMPXDrmConsumeNone; |
|
231 iConsumeStarted = EFalse; |
|
232 break; |
|
233 } |
|
234 } |
|
235 |
|
236 if ( EMPXDrmConsumeNone != type ) |
|
237 { |
|
238 iCurrentAgent->ConsumeL( type ); |
|
239 } |
|
240 } |
|
241 else |
|
242 { |
|
243 iConsumeStarted = EFalse; |
|
244 } |
|
245 } |
|
246 |
|
247 MPX_DEBUG1("CMPXDrmMediaUtility::ConsumeL() exiting" ); |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------------------------- |
|
251 // Closes and unitializes the utility |
|
252 // ---------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C void CMPXDrmMediaUtility::Close() |
|
255 { |
|
256 MPX_DEBUG1("CMPXDrmMediaUtility::Close() entering" ); |
|
257 |
|
258 if ( iCurrentAgent ) |
|
259 { |
|
260 iCurrentAgent->Close(); |
|
261 iCurrentAgent = NULL; |
|
262 } |
|
263 |
|
264 MPX_DEBUG1("CMPXDrmMediaUtility::Close() exiting" ); |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // Finds an agent to handle the content |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 void CMPXDrmMediaUtility::FindAgent( CContent& aContent ) |
|
272 { |
|
273 MPX_DEBUG1("CMPXDrmMediaUtility::FindAgent() entering" ); |
|
274 |
|
275 TAgent agent( aContent.Agent() ); |
|
276 if ( agent.Name() == KMPXWDRMCafAgentName || |
|
277 agent.Name() == KMPXS60WMDRMCafAgent ) |
|
278 { |
|
279 iCurrentAgent = iAgents[EWmaDrmAgent]; |
|
280 } |
|
281 else if ( agent.Name() == KMPXOMACafAgentName ) |
|
282 { |
|
283 iCurrentAgent = iAgents[EOmaDrmAgent]; |
|
284 } |
|
285 else |
|
286 { |
|
287 iCurrentAgent = NULL; |
|
288 } |
|
289 MPX_DEBUG1("CMPXDrmMediaUtility::FindAgent() exiting" ); |
|
290 } |