|
1 /* |
|
2 * Copyright (c) 2007-2008 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: WMDRM Client implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "wmdrmclient.h" |
|
20 #include "wmdrmclientserver.h" |
|
21 |
|
22 #define _LOGGING_FILE L"wmdrmserver.txt" |
|
23 |
|
24 #ifdef _DEBUG |
|
25 #define DEBUGATTR( a ) a |
|
26 #else |
|
27 #define DEBUGATTR( a ) |
|
28 #endif |
|
29 |
|
30 #include "logfn.h" |
|
31 |
|
32 // Constants |
|
33 |
|
34 const TInt KServerDefaultMessageSlots = -1; |
|
35 const TInt KServerRetryCount = 3; |
|
36 |
|
37 // ======== LOCAL FUNCTIONS ======== |
|
38 |
|
39 |
|
40 //--------------------------------------------------------------------------- |
|
41 // SetupSlotSpecL |
|
42 //--------------------------------------------------------------------------- |
|
43 // |
|
44 LOCAL_C void SetupSlotSpecL( |
|
45 RBuf8& aSlotSpec, |
|
46 const TDesC8& aStoreName, |
|
47 const TDesC8& aNamespace, |
|
48 const TDesC8& aHashKey, |
|
49 const TDesC8& aUniqueKey ) |
|
50 { |
|
51 aSlotSpec.CreateL( aStoreName.Length() + aNamespace.Length() + aHashKey.Length() + aUniqueKey.Length() + 4 ); |
|
52 aSlotSpec.Append( aStoreName.Length() ); |
|
53 aSlotSpec.Append( aStoreName ); |
|
54 aSlotSpec.Append( aNamespace.Length() ) ; |
|
55 aSlotSpec.Append( aNamespace ); |
|
56 aSlotSpec.Append( aHashKey.Length() ); |
|
57 aSlotSpec.Append( aHashKey ); |
|
58 aSlotSpec.Append( aUniqueKey.Length() ); |
|
59 aSlotSpec.Append( aUniqueKey ); |
|
60 } |
|
61 |
|
62 //--------------------------------------------------------------------------- |
|
63 // SetupSlotEnumSpecL |
|
64 //--------------------------------------------------------------------------- |
|
65 // |
|
66 LOCAL_C void SetupSlotEnumSpecL( |
|
67 RBuf8& aSlotSpec, |
|
68 const TDesC8& aStoreName, |
|
69 const TDesC8& aNamespace, |
|
70 const TDesC8& aHashKey ) |
|
71 { |
|
72 aSlotSpec.CreateL( aStoreName.Length() + aNamespace.Length() + aHashKey.Length() + 3 ); |
|
73 aSlotSpec.Append( aStoreName.Length() ); |
|
74 aSlotSpec.Append( aStoreName ); |
|
75 aSlotSpec.Append( aNamespace.Length() ) ; |
|
76 aSlotSpec.Append( aNamespace ); |
|
77 aSlotSpec.Append( aHashKey.Length() ); |
|
78 aSlotSpec.Append( aHashKey ); |
|
79 } |
|
80 |
|
81 //--------------------------------------------------------------------------- |
|
82 // StartServer |
|
83 //--------------------------------------------------------------------------- |
|
84 // |
|
85 static TInt StartServer() |
|
86 { |
|
87 RProcess server; |
|
88 TInt r = server.Create( KWmDrmServerImg, KNullDesC ); |
|
89 if ( r != KErrNone ) |
|
90 return r; |
|
91 TRequestStatus stat; |
|
92 server.Rendezvous( stat ); |
|
93 if ( stat != KRequestPending ) |
|
94 { |
|
95 server.Kill( 0 ); |
|
96 } |
|
97 else |
|
98 { |
|
99 server.Resume(); |
|
100 } |
|
101 User::WaitForRequest( stat ); |
|
102 r = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int(); |
|
103 server.Close(); |
|
104 return r; |
|
105 } |
|
106 |
|
107 // ======== MEMBER FUNCTIONS ======== |
|
108 |
|
109 //--------------------------------------------------------------------------- |
|
110 // RWmDrmClient::Connect |
|
111 //--------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TInt RWmDrmClient::Connect() |
|
114 { |
|
115 TInt r = KErrNone; |
|
116 |
|
117 LOGFNR( "RWmDrmClient::Connect", r ); |
|
118 TInt retry = KServerRetryCount; |
|
119 for ( ;; ) |
|
120 { |
|
121 r = CreateSession( KWmDrmServerName, TVersion( 0, 0, 0 ), KServerDefaultMessageSlots ); |
|
122 if ( r != KErrNotFound && r != KErrServerTerminated ) |
|
123 { |
|
124 return r; |
|
125 } |
|
126 if ( --retry == 0 ) |
|
127 { |
|
128 return r; |
|
129 } |
|
130 r = StartServer(); |
|
131 if ( r != KErrNone && r != KErrAlreadyExists ) |
|
132 { |
|
133 return r; |
|
134 } |
|
135 } |
|
136 } |
|
137 |
|
138 //--------------------------------------------------------------------------- |
|
139 // RWmDrmClient::InitStore |
|
140 //--------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C TInt RWmDrmClient::InitStore( |
|
143 const TDesC8& DEBUGATTR( aStoreName ), |
|
144 TBool /* aCreateIfMissing */ ) |
|
145 { |
|
146 TInt r = KErrNone; |
|
147 |
|
148 LOGFNR( "RWmDrmClient::InitStore", r ); |
|
149 LOG( aStoreName ); |
|
150 |
|
151 return r; |
|
152 } |
|
153 |
|
154 //--------------------------------------------------------------------------- |
|
155 // RWmDrmClient::RemoveStore |
|
156 //--------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C TInt RWmDrmClient::RemoveStore( |
|
159 const TDesC8& aStoreName ) |
|
160 { |
|
161 TInt r = KErrNone; |
|
162 |
|
163 LOGFNR( "RWmDrmClient::RemoveStore", r ); |
|
164 LOG( aStoreName ); |
|
165 r = SendReceive( ERemoveStore, TIpcArgs( &aStoreName ) ); |
|
166 return r; |
|
167 } |
|
168 |
|
169 //--------------------------------------------------------------------------- |
|
170 // RWmDrmClient::InitNamespace |
|
171 //--------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C TInt RWmDrmClient::InitNamespace( |
|
174 const TDesC8& DEBUGATTR( aStoreName ), |
|
175 const TDesC8& DEBUGATTR( aNamespace ), |
|
176 TBool /* aCreateIfMissing */) |
|
177 { |
|
178 TInt r = KErrNone; |
|
179 |
|
180 LOGFNR( "RWmDrmClient::InitNamespace", r ); |
|
181 LOG( aStoreName ); LOG( aNamespace ); |
|
182 |
|
183 return r; |
|
184 } |
|
185 |
|
186 //--------------------------------------------------------------------------- |
|
187 // RWmDrmClient::RemoveNamespace |
|
188 //--------------------------------------------------------------------------- |
|
189 // |
|
190 EXPORT_C TInt RWmDrmClient::RemoveNamespace( |
|
191 const TDesC8& aStoreName, |
|
192 const TDesC8& aNamespace ) |
|
193 { |
|
194 TInt r = KErrNone; |
|
195 |
|
196 LOGFNR( "RWmDrmClient::RemoveNamespace", r ); |
|
197 r = SendReceive( ERemoveNamespace, TIpcArgs( &aStoreName, &aNamespace ) ); |
|
198 return r; |
|
199 } |
|
200 |
|
201 //--------------------------------------------------------------------------- |
|
202 // RWmDrmClient::SlotOpen |
|
203 //--------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C TInt RWmDrmClient::SlotOpen( |
|
206 const TDesC8& aStoreName, |
|
207 const TDesC8& aNamespace, |
|
208 const TDesC8& aHashKey, |
|
209 const TDesC8& aUniqueKey, |
|
210 TInt& aSize ) |
|
211 { |
|
212 TInt r = KErrNone; |
|
213 RBuf8 slotSpec; |
|
214 TPckg<TInt> sizePckg( aSize ); |
|
215 |
|
216 LOGFNR( "RWmDrmClient::SlotOpen", r ); |
|
217 LOG( aStoreName ); LOG( aNamespace ); LOG( aHashKey ); LOG( aUniqueKey ); |
|
218 TRAP(r, SetupSlotSpecL( slotSpec, aStoreName, aNamespace, aHashKey, aUniqueKey )); |
|
219 if( r ) |
|
220 { |
|
221 slotSpec.Close(); |
|
222 return r; |
|
223 } |
|
224 r = SendReceive( ESlotOpen, TIpcArgs( &slotSpec, &sizePckg ) ); |
|
225 slotSpec.Close(); |
|
226 return r; |
|
227 } |
|
228 |
|
229 //--------------------------------------------------------------------------- |
|
230 // RWmDrmClient::SlotCreate |
|
231 //--------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C TInt RWmDrmClient::SlotCreate( |
|
234 const TDesC8& aStoreName, |
|
235 const TDesC8& aNamespace, |
|
236 const TDesC8& aHashKey, |
|
237 const TDesC8& aUniqueKey, |
|
238 TInt& aSize ) |
|
239 { |
|
240 TInt r = KErrNone; |
|
241 RBuf8 slotSpec; |
|
242 |
|
243 LOGFNR( "RWmDrmClient::SlotCreate", r ); |
|
244 LOG( aStoreName ); LOG( aNamespace ); LOG( aHashKey ); LOG( aUniqueKey ); |
|
245 TRAP( r, SetupSlotSpecL( slotSpec, aStoreName, aNamespace, aHashKey, aUniqueKey )); |
|
246 if( r ) |
|
247 { |
|
248 slotSpec.Close(); |
|
249 return r; |
|
250 } |
|
251 r = SendReceive( ESlotCreate, TIpcArgs( &slotSpec, aSize ) ); |
|
252 slotSpec.Close(); |
|
253 return r; |
|
254 } |
|
255 |
|
256 //--------------------------------------------------------------------------- |
|
257 // RWmDrmClient::SlotSeek |
|
258 //--------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C TInt RWmDrmClient::SlotSeek( |
|
261 TInt& aPos, |
|
262 TSeek aOrigin ) |
|
263 { |
|
264 TInt r = KErrNone; |
|
265 TInt newPos; |
|
266 TPckg<TInt> posPckg( newPos ); |
|
267 |
|
268 LOGFNR( "RWmDrmClient::SlotSeek", r ); |
|
269 r = SendReceive( ESlotSeek, TIpcArgs( aPos, aOrigin, &posPckg ) ); |
|
270 aPos = newPos; |
|
271 return r; |
|
272 } |
|
273 |
|
274 //--------------------------------------------------------------------------- |
|
275 // RWmDrmClient::SlotRead |
|
276 //--------------------------------------------------------------------------- |
|
277 // |
|
278 EXPORT_C TInt RWmDrmClient::SlotRead( |
|
279 TDes8& aData ) |
|
280 { |
|
281 TInt r = KErrNone; |
|
282 TInt amountRead; |
|
283 TPckg<TInt> amountPckg( amountRead ); |
|
284 |
|
285 LOGFNR( "RWmDrmClient::SlotRead", r ); |
|
286 r = SendReceive( ESlotRead, TIpcArgs( &aData, &amountPckg ) ); |
|
287 if ( r == KErrNone ) |
|
288 { |
|
289 aData.SetLength( amountRead ); |
|
290 } |
|
291 return r; |
|
292 } |
|
293 |
|
294 //--------------------------------------------------------------------------- |
|
295 // RWmDrmClient::SlotWrite |
|
296 //--------------------------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C TInt RWmDrmClient::SlotWrite( |
|
299 const TDesC8& aData ) |
|
300 { |
|
301 TInt r = KErrNone; |
|
302 |
|
303 LOGFNR( "RWmDrmClient::SlotWrite", r ); |
|
304 r = SendReceive( ESlotWrite, TIpcArgs( &aData ) ); |
|
305 return r; |
|
306 } |
|
307 |
|
308 //--------------------------------------------------------------------------- |
|
309 // RWmDrmClient::SlotDelete |
|
310 //--------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C TInt RWmDrmClient::SlotDelete( |
|
313 const TDesC8& aStoreName, |
|
314 const TDesC8& aNamespace, |
|
315 const TDesC8& aHashKey, |
|
316 const TDesC8& aUniqueKey ) |
|
317 { |
|
318 TInt r = KErrNone; |
|
319 RBuf8 slotSpec; |
|
320 |
|
321 LOGFNR( "RWmDrmClient::SlotDelete", r ); |
|
322 TRAP(r, SetupSlotSpecL( slotSpec, aStoreName, aNamespace, aHashKey, aUniqueKey )); |
|
323 if( r ) |
|
324 { |
|
325 slotSpec.Close(); |
|
326 return r; |
|
327 } |
|
328 r = SendReceive( ESlotDelete, TIpcArgs( &slotSpec ) ); |
|
329 slotSpec.Close(); |
|
330 return r; |
|
331 } |
|
332 |
|
333 //--------------------------------------------------------------------------- |
|
334 // RWmDrmClient::SlotResize |
|
335 //--------------------------------------------------------------------------- |
|
336 // |
|
337 EXPORT_C TInt RWmDrmClient::SlotResize( |
|
338 TInt aSize ) |
|
339 { |
|
340 TInt r = KErrNone; |
|
341 |
|
342 LOGFNR( "RWmDrmClient::SlotResize", r ); |
|
343 r = SendReceive( ESlotResize, TIpcArgs( aSize ) ); |
|
344 return r; |
|
345 } |
|
346 |
|
347 //--------------------------------------------------------------------------- |
|
348 // RWmDrmClient::SlotClose |
|
349 //--------------------------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C TInt RWmDrmClient::SlotClose() |
|
352 { |
|
353 TInt r = KErrNone; |
|
354 |
|
355 LOGFNR( "RWmDrmClient::SlotClose", r ); |
|
356 r = SendReceive( ESlotClose ); |
|
357 return r; |
|
358 } |
|
359 |
|
360 //--------------------------------------------------------------------------- |
|
361 // RWmDrmClient::EnumerateStart |
|
362 //--------------------------------------------------------------------------- |
|
363 // |
|
364 EXPORT_C TInt RWmDrmClient::EnumerateStart( |
|
365 const TDesC8& aStoreName, |
|
366 const TDesC8& aNamespace, |
|
367 const TDesC8& aHashKey ) |
|
368 { |
|
369 TInt r = KErrNone; |
|
370 RBuf8 slotSpec; |
|
371 |
|
372 LOGFNR( "RWmDrmClient::EnumerateStart", r ); |
|
373 TRAP(r, SetupSlotEnumSpecL( slotSpec, aStoreName, aNamespace, aHashKey )); |
|
374 if( r ) |
|
375 { |
|
376 slotSpec.Close(); |
|
377 return r; |
|
378 } |
|
379 r = SendReceive( EEnumerateStart, TIpcArgs( &slotSpec ) ); |
|
380 slotSpec.Close(); |
|
381 return r; |
|
382 } |
|
383 |
|
384 //--------------------------------------------------------------------------- |
|
385 // RWmDrmClient::EnumerateReload |
|
386 //--------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C TInt RWmDrmClient::EnumerateReload( |
|
389 TDes8& aStoreName, |
|
390 TDes8& aNamespace, |
|
391 TDes8& aHashKey, |
|
392 TDes8& aUniqueKey ) |
|
393 { |
|
394 TInt r = KErrNone; |
|
395 |
|
396 LOGFNR( "RWmDrmClient::EnumerateReload", r ); |
|
397 r = SendReceive( EEnumerateReload, TIpcArgs( &aStoreName, &aNamespace, &aHashKey, &aUniqueKey ) ); |
|
398 return r; |
|
399 } |
|
400 |
|
401 //--------------------------------------------------------------------------- |
|
402 // RWmDrmClient::EnumerateNext |
|
403 //--------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C TInt RWmDrmClient::EnumerateNext( |
|
406 TDes8& aStoreName, |
|
407 TDes8& aNamespace, |
|
408 TDes8& aHashKey, |
|
409 TDes8& aUniqueKey ) |
|
410 { |
|
411 TInt r = KErrNone; |
|
412 |
|
413 LOGFNR( "RWmDrmClient::EnumerateNext", r ); |
|
414 r = SendReceive( EEnumerateNext, TIpcArgs( &aStoreName, &aNamespace, &aHashKey, &aUniqueKey ) ); |
|
415 return r; |
|
416 } |
|
417 |
|
418 //--------------------------------------------------------------------------- |
|
419 // RWmDrmClient::EnumerateDeleteCurrent |
|
420 //--------------------------------------------------------------------------- |
|
421 // |
|
422 EXPORT_C TInt RWmDrmClient::EnumerateDeleteCurrent() |
|
423 { |
|
424 TInt r = KErrNone; |
|
425 |
|
426 LOGFNR( "RWmDrmClient::EnumerateDelete", r ); |
|
427 r = SendReceive( EEnumerateDelete ); |
|
428 return r; |
|
429 } |
|
430 |
|
431 //--------------------------------------------------------------------------- |
|
432 // RWmDrmClient::EnumerateEnd |
|
433 //--------------------------------------------------------------------------- |
|
434 // |
|
435 EXPORT_C TInt RWmDrmClient::EnumerateEnd() |
|
436 { |
|
437 TInt r = KErrNone; |
|
438 |
|
439 LOGFNR( "RWmDrmClient::EnumerateEnd", r ); |
|
440 r = SendReceive( EEnumerateEnd ); |
|
441 return r; |
|
442 } |
|
443 |
|
444 //--------------------------------------------------------------------------- |
|
445 // RWmDrmClient::LogStats |
|
446 //--------------------------------------------------------------------------- |
|
447 // |
|
448 EXPORT_C TInt RWmDrmClient::LogStats() |
|
449 { |
|
450 TInt r = KErrNone; |
|
451 |
|
452 LOGFNR( "RWmDrmClient::LogStats", r ); |
|
453 r = SendReceive( ELogStats ); |
|
454 return r; |
|
455 } |
|
456 |
|
457 //--------------------------------------------------------------------------- |
|
458 // RWmDrmClient::EmptyCache |
|
459 //--------------------------------------------------------------------------- |
|
460 // |
|
461 EXPORT_C TInt RWmDrmClient::EmptyCache() |
|
462 { |
|
463 TInt r = KErrNone; |
|
464 |
|
465 LOGFNR( "RWmDrmClient::EmptyCache", r ); |
|
466 r = SendReceive( EEmptyCache ); |
|
467 return r; |
|
468 } |
|
469 |
|
470 //--------------------------------------------------------------------------- |
|
471 // RWmDrmClient::TimeValid |
|
472 //--------------------------------------------------------------------------- |
|
473 // |
|
474 EXPORT_C TBool RWmDrmClient::TimeValid() |
|
475 { |
|
476 TBool r = EFalse; |
|
477 |
|
478 LOGFN( "RWmDrmClient::TimeValid" ); |
|
479 if ( SendReceive( ETimeValid ) == KErrNone ) |
|
480 { |
|
481 LOG1( "Time valid" ); |
|
482 r = ETrue; |
|
483 } |
|
484 return r; |
|
485 } |
|
486 |
|
487 //--------------------------------------------------------------------------- |
|
488 // RWmDrmClient::SetTimeAsValid |
|
489 //--------------------------------------------------------------------------- |
|
490 // |
|
491 EXPORT_C void RWmDrmClient::SetTimeAsValid( TBool aValid ) |
|
492 { |
|
493 TInt v = 0; |
|
494 |
|
495 if ( aValid ) |
|
496 { |
|
497 v = 1; |
|
498 } |
|
499 LOGFN( "RWmDrmClient::SetTimeAsValid" ); |
|
500 SendReceive( ESetTimeAsValid, TIpcArgs( v ) ); |
|
501 } |
|
502 |
|
503 //--------------------------------------------------------------------------- |
|
504 // RWmDrmClient::DeleteRights |
|
505 //--------------------------------------------------------------------------- |
|
506 // |
|
507 EXPORT_C TInt RWmDrmClient::DeleteRights() |
|
508 { |
|
509 TInt r = KErrNone; |
|
510 |
|
511 LOGFNR( "RWmDrmClient::DeleteRights", r ); |
|
512 r = SendReceive( EDeleteRights ); |
|
513 return r; |
|
514 } |
|
515 |
|
516 //--------------------------------------------------------------------------- |
|
517 // RWmDrmClient::StoreState |
|
518 //--------------------------------------------------------------------------- |
|
519 // |
|
520 EXPORT_C TInt RWmDrmClient::StoreState( TWmDrmStoreState& aState ) |
|
521 { |
|
522 TInt r = KErrNone; |
|
523 TPckg<TWmDrmStoreState> statePckg( aState ); |
|
524 |
|
525 LOGFNR( "RWmDrmClient::StoreState", r ); |
|
526 r = SendReceive( EStoreState, TIpcArgs( &statePckg ) ); |
|
527 return r; |
|
528 } |
|
529 |
|
530 //--------------------------------------------------------------------------- |
|
531 // RWmDrmClient::GetTime |
|
532 //--------------------------------------------------------------------------- |
|
533 // |
|
534 EXPORT_C TInt RWmDrmClient::GetTime( TTime& aTime, TBool& aValid ) |
|
535 { |
|
536 TInt r = KErrNone; |
|
537 TPckg<TTime> timePckg( aTime ); |
|
538 TPckg<TBool> validPckg( aValid ); |
|
539 |
|
540 LOGFNR( "RWmDrmClient::GetTime", r ); |
|
541 r = SendReceive( EGetTime, TIpcArgs( &timePckg, &validPckg ) ); |
|
542 return r; |
|
543 }; |
|
544 |
|
545 |