|
1 /* |
|
2 * Copyright (c) 2005 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: Interface for the consume operations. This class handles all |
|
15 * operations regarding rights consumption in DRM5. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef DRMCONSUME_H |
|
20 #define DRMCONSUME_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <caf/caftypes.h> |
|
25 |
|
26 // CONSTANTS |
|
27 // MACROS |
|
28 // DATA TYPES |
|
29 // FORWARD DECLARATIONS |
|
30 class CDRMDbSession; |
|
31 class RMessage2; |
|
32 class CDRMPermission; |
|
33 class CDRMConstraint; |
|
34 |
|
35 // TYPE DEFINITIONS |
|
36 // FUNCTION PROTOTYPES |
|
37 |
|
38 // CLASS DECLARATION |
|
39 /** |
|
40 * CDRMConsume acts as content consumer in DRM5 Rights Server. It is accessed |
|
41 * by CDRMDbSession. Content consumption is initiated via HandleL() method |
|
42 * in the beginning of the consumption, and later on the class can be |
|
43 * controlled through Pause(), Continue() and Stop(). Destructor calls |
|
44 * the Cancel() method. |
|
45 * |
|
46 * @lib RightsServer.exe |
|
47 * @since 3.0 |
|
48 */ |
|
49 NONSHARABLE_CLASS( CDRMConsume ) : public CTimer |
|
50 { |
|
51 |
|
52 public: // Constructors and destructor. |
|
53 /** |
|
54 * NewLC |
|
55 * |
|
56 * Two-phase constructor. |
|
57 * |
|
58 * @since 3.0 |
|
59 * @param aParent Callback handle to the session |
|
60 * owning this instance. |
|
61 * @param aURI Content-ID. |
|
62 * @return A pointer to newly created object. |
|
63 */ |
|
64 static CDRMConsume* NewLC( CDRMDbSession& aParent, |
|
65 const TDesC8& aURI, |
|
66 const TDesC8* aParentId ); |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 virtual ~CDRMConsume(); |
|
71 |
|
72 public: // New functions. |
|
73 /** |
|
74 * HandleL |
|
75 * |
|
76 * Starts the content consumption. |
|
77 * |
|
78 * Whenever this method is called, rights database also gets |
|
79 * updated if related permissions are stateful. When calling HandleL |
|
80 * several times for the same class instance instance, the permissions |
|
81 * are consumed only once if the related permissions returned by |
|
82 * CDRMDbSession::FindRightsObjectL() are the same returned earlier. |
|
83 * |
|
84 * @since 3.0 |
|
85 * @param aIntent Usage intent. |
|
86 */ |
|
87 void HandleL( ContentAccess::TIntent aIntent ); |
|
88 |
|
89 /** |
|
90 * Pause |
|
91 * |
|
92 * Pauses the content consumption. |
|
93 * |
|
94 * Content consuption can be resumed via ContinueL() and HandleL(). |
|
95 * See comments in HandleL() method for information about permission |
|
96 * consumption. |
|
97 * |
|
98 * @since 3.0 |
|
99 */ |
|
100 void Pause(); |
|
101 |
|
102 /** |
|
103 * ContinueL |
|
104 * |
|
105 * Continues the content consumption. |
|
106 * |
|
107 * This method works similarily to HandleL. |
|
108 * |
|
109 * @since 3.0 |
|
110 */ |
|
111 void ContinueL(); |
|
112 |
|
113 /** |
|
114 * Stop |
|
115 * |
|
116 * Stops the content consumption. |
|
117 * |
|
118 * This method works similarily to Pause() |
|
119 * |
|
120 * @since 3.0 |
|
121 */ |
|
122 void Stop(); |
|
123 |
|
124 /** |
|
125 * CountConstraintActive |
|
126 * |
|
127 * Checks whether a count constraint was used earlier |
|
128 * |
|
129 * @since 3.0 |
|
130 * @return ETrue if a count constraint was used earlier, |
|
131 * EFalse otherwise |
|
132 */ |
|
133 TBool CountConstraintActive(); |
|
134 |
|
135 /** |
|
136 * IsExpired |
|
137 * |
|
138 * Returns ETrue if the last consumption lead to expired rights |
|
139 * |
|
140 * @since 3.0 |
|
141 * @return ETrue if the rights are expired, |
|
142 * EFalse otherwise |
|
143 */ |
|
144 TBool IsExpired(); |
|
145 |
|
146 /** |
|
147 * Returns the current child permission |
|
148 * |
|
149 * @since 3.0 |
|
150 * @return the permission |
|
151 */ |
|
152 CDRMPermission& GetChild(); |
|
153 |
|
154 protected: // from base class CActive |
|
155 /** |
|
156 * RunL |
|
157 * |
|
158 * Handles the completed asynchronous request. |
|
159 */ |
|
160 void RunL(); |
|
161 |
|
162 /** |
|
163 * RunError |
|
164 * |
|
165 * Handles errors happened during RunL(). |
|
166 * |
|
167 * At the moment this method does nothing. |
|
168 * |
|
169 * @since 3.0 |
|
170 * @param Error code |
|
171 * @return KErrNone if the error could be handled. Otherwise an |
|
172 * error code is returned. |
|
173 */ |
|
174 TInt RunError( TInt aError ); |
|
175 |
|
176 protected: // New Functions |
|
177 /** |
|
178 * Constructor |
|
179 * |
|
180 * Constructs the class instance. |
|
181 * |
|
182 * @since 3.0 |
|
183 * @param aSession Callback session to the CDRMDbSession owning |
|
184 * this instance. |
|
185 */ |
|
186 CDRMConsume( CDRMDbSession& aSession ); |
|
187 |
|
188 /** |
|
189 * Second phase constructor |
|
190 * |
|
191 * Finalizes the construction of the class instance. |
|
192 * |
|
193 * @since 3.0 |
|
194 * @param aURI Content-ID |
|
195 */ |
|
196 void ConstructL( const TDesC8& aURI, |
|
197 const TDesC8* aParentId ); |
|
198 |
|
199 private: // From base class CActive |
|
200 /** |
|
201 * DoCancel |
|
202 * |
|
203 * Handles the cancelling operations. |
|
204 * This method updates timed constraints of the permission found |
|
205 * earlier (if such constraints exist). Calls DoCancelL() in trap |
|
206 * harness. |
|
207 * |
|
208 * @since 3.0 |
|
209 */ |
|
210 void DoCancel(); |
|
211 |
|
212 private: // New functions |
|
213 /** |
|
214 * InitializeL |
|
215 * |
|
216 * This method finds the proper permissions (child & parent) for the |
|
217 * given intent and previously set content-ID. |
|
218 * |
|
219 * @since 3.0 |
|
220 * @param aIntent Consumption intent |
|
221 * @param aSecureTime Whether the given time is secure or not |
|
222 * @param aTrustedTime Current time. |
|
223 */ |
|
224 void InitializeL( ContentAccess::TIntent aIntent, |
|
225 TBool aSecureTime, |
|
226 const TTime& aTrustedTime ); |
|
227 |
|
228 /** |
|
229 * ActivateL |
|
230 * |
|
231 * In case of time based or interval based constraints, this method |
|
232 * activates the internal timer to monitor delay. |
|
233 * |
|
234 * @since 3.0 |
|
235 * @aParam aSecureTime Whether the given time is secure or not. |
|
236 * @aParam aTrustedTime Current time. |
|
237 */ |
|
238 void ActivateL( TBool aSecureTime, |
|
239 const TTime& aTrustedTime ); |
|
240 |
|
241 /** |
|
242 * Consume |
|
243 * |
|
244 * This method consumes the internally stored permissions according to |
|
245 * the given parameters. If a(ny) internally stored permission is |
|
246 * changed, the internal status masks iTimedCounts and iTimedCounts. |
|
247 * |
|
248 * @since 3.0 |
|
249 * @param aUpdateCounter Whether to consume counter constraint. |
|
250 * @param aInitInterval Whether to initialize (possibly) |
|
251 * uninialized interval. |
|
252 * @param aUpdateTimedCount Whether to update timed counter. |
|
253 * @param aElapsedTime How much time has elapsed since initialization |
|
254 * @param aSecureTime Whether the given time is secure or not. |
|
255 * @param aTrustedTime Current time. |
|
256 */ |
|
257 void Consume( TBool aUpdateCounter, |
|
258 TBool aInitInterval, |
|
259 TBool aUpdateTimedCount, |
|
260 const TTimeIntervalSeconds& aElapsedTime, |
|
261 TBool aSecureTime, |
|
262 const TTime& aTrustedTime ); |
|
263 |
|
264 /** |
|
265 * CombinePermissionsL |
|
266 * |
|
267 * Combines internal iParent and iChild into iCombined. |
|
268 * |
|
269 * @since 3.0 |
|
270 */ |
|
271 void CombinePermissionsL(); |
|
272 |
|
273 /** |
|
274 * UpdateDBL |
|
275 * |
|
276 * Commits the internal iChild & iParent to the database in case |
|
277 * they have changed. |
|
278 */ |
|
279 void UpdateDBL(); |
|
280 |
|
281 /** |
|
282 * ConsumeConstraint |
|
283 * |
|
284 * Consumes the given constraint by the given parameters. |
|
285 * |
|
286 * @since 3.0 |
|
287 @ @param aConstraint Constraint to be consumed. |
|
288 * @param aUpdateCounter Whether to decrease the counter constraint. |
|
289 * @param aInitInterval Whether to initialize (possibly) |
|
290 * uninitialized interval. |
|
291 * @param aUpdateTimedCount Whether to decrease timed counter. |
|
292 * @param aElapsedTime How much time has elapsed since initialization |
|
293 * @param aSecureTime Whether the given time is secure or not. |
|
294 * @param aCumulativeTime The time that has elapsed cumulatively |
|
295 * from the start of a timed counter |
|
296 * @param aTrustedTime Current time. |
|
297 */ |
|
298 TBool ConsumeConstraint( CDRMConstraint& aConstraint, |
|
299 TBool aUpdateCounter, |
|
300 TBool aInitInterval, |
|
301 TBool aUpdateTimedCount, |
|
302 const TTimeIntervalSeconds& aElapsedTime, |
|
303 TBool aSecureTime, |
|
304 const TTime& aTrustedTime, |
|
305 TTimeIntervalSeconds& aCumulativeTime ); |
|
306 |
|
307 /** |
|
308 * ConsumeTimedItemsL |
|
309 * |
|
310 * Consumes timed items. |
|
311 * |
|
312 * @since 3.0 |
|
313 * @param aDelay The delay between timer initialization and this |
|
314 * moment. |
|
315 * @param aSecureTime Whether the given time is secure or not. |
|
316 * @param aTrustedTime Current time. |
|
317 */ |
|
318 void ConsumeTimedItemsL( TTimeIntervalSeconds aDelay, |
|
319 TBool aSecureTime, |
|
320 const TTime& aTrustedTime ); |
|
321 |
|
322 /** |
|
323 * DoContinueL |
|
324 * |
|
325 * Handles the operations of RunL() method when timer goes off. |
|
326 * |
|
327 * @since 3.0 |
|
328 */ |
|
329 void DoContinueL(); |
|
330 |
|
331 /** |
|
332 * SecurityLevelChanged |
|
333 * |
|
334 * Checks whether the secure time is now insecure or vice versa, |
|
335 * compared to the situation when ActivateL() was called. |
|
336 * |
|
337 * @since 3.0 |
|
338 * @param aSecureTime Current time security level. |
|
339 * @return Whether the security level of the time is different. |
|
340 */ |
|
341 TBool SecurityLevelChanged( TBool aSecureTime ) const; |
|
342 |
|
343 /** |
|
344 * DoCancelL |
|
345 * |
|
346 * Updates time based constraints of internally stored permissions |
|
347 * in case of cancel operation. |
|
348 * |
|
349 * @since 3.0 |
|
350 */ |
|
351 void DoCancelL(); |
|
352 |
|
353 /** |
|
354 * |
|
355 * Updates the metering count, defines the metering accumulated time |
|
356 * and updates the metering database if there was metered content. |
|
357 * |
|
358 * @since S60 3.2 |
|
359 */ |
|
360 void UpdateMeteringDbL(); |
|
361 |
|
362 /** |
|
363 * |
|
364 * Creates a Rights Issuer Context to Roap storage and checks the rights |
|
365 * of the Rights Issuer to use metering. |
|
366 * |
|
367 * @since S60 3.2 |
|
368 * @param aRiId |
|
369 * @return Whether metering can be allowed base on the Rights Issuer Id or not |
|
370 */ |
|
371 TBool CheckRiContextRightsL( const TDesC8& aRiId ); |
|
372 |
|
373 |
|
374 private: // New functions. |
|
375 /** |
|
376 * Default constructor. |
|
377 * |
|
378 * Prohibited. |
|
379 */ |
|
380 CDRMConsume(); |
|
381 |
|
382 public: // Data |
|
383 protected: // Data |
|
384 private: // Data |
|
385 // Callback handle. |
|
386 CDRMDbSession& iSession; |
|
387 |
|
388 // Usage intent when the consumption was initialized. |
|
389 ContentAccess::TIntent iIntent; |
|
390 |
|
391 // Content-id |
|
392 HBufC8* iURI; |
|
393 |
|
394 // id of the parent, if this exists we are using a parent RO |
|
395 HBufC8* iParentId; |
|
396 |
|
397 // The child permission used in the consumption operation. |
|
398 CDRMPermission* iChild; |
|
399 |
|
400 // A constraint combined from iChild & iParent. |
|
401 CDRMConstraint* iCombined; |
|
402 |
|
403 // The time when CTimer went active. |
|
404 TTime iTime; |
|
405 |
|
406 // Tells how much the waiting time was when initialized. |
|
407 TInt16 iCurrentDelay; |
|
408 |
|
409 // Internal state. |
|
410 TUint8 iMask; |
|
411 |
|
412 // Internal state to check whether timed counters have been modified. |
|
413 TUint8 iTimedCounts; |
|
414 |
|
415 // Internal state to check whether counters have been modified. |
|
416 TUint8 iCounters; |
|
417 |
|
418 // Set to ETrue if a count constraint was used |
|
419 TBool iCountConstraintActive; |
|
420 |
|
421 // Set to ETrue if the last consumption lead to expired rights |
|
422 TBool iExpired; |
|
423 |
|
424 // Tells how much time has been actually spent rendering |
|
425 TTimeIntervalSeconds iCumulativeDelayTop; |
|
426 TTimeIntervalSeconds iCumulativeDelayChild; |
|
427 |
|
428 // Tells the total cumulative time. It is needed when calculating |
|
429 // accumulated time for metering purposes. |
|
430 TTimeIntervalSeconds iTotalCumulativeTime; |
|
431 |
|
432 // Bit to tell if we use timed count |
|
433 TBool iUsingTimedCount; |
|
434 }; |
|
435 |
|
436 #endif // DRMCONSUME_H |
|
437 |
|
438 // EOF |