|
1 /* |
|
2 * Copyright (c) 2004 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: Implementation of the Helper Server session functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <f32file.h> |
|
22 #include "DRMHelperCommon.h" |
|
23 #include "DRMHelperServer.h" |
|
24 #include "DRMHelperSession.h" |
|
25 |
|
26 |
|
27 |
|
28 // LOCAL CONSTANTS AND MACROS |
|
29 #define SERVER const_cast< CDRMHelperServer* >( \ |
|
30 reinterpret_cast< const CDRMHelperServer* >( Server() ) ) |
|
31 |
|
32 |
|
33 // ============================ LOCAL FUNCTIONS =============================== |
|
34 #ifdef _DRM_TESTING |
|
35 LOCAL_C void WriteDownLogL( const TDesC8& text , RFs &aFs ); |
|
36 LOCAL_C void WriteFileL( const TDesC8& text , RFs &aFs , const TDesC& aName ); |
|
37 LOCAL_C void CreateLogL(); |
|
38 LOCAL_C void WriteDownL( const TDesC& aText ); |
|
39 LOCAL_C void WriteDownL( const TDesC8& aText ); |
|
40 LOCAL_C void WriteCurrentTimeL(); |
|
41 #endif |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CDRMHelperSession::CDRMHelperSession |
|
47 // Default constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CDRMHelperSession::CDRMHelperSession() |
|
51 // Base class' constructor is called first. |
|
52 : CSession2() |
|
53 { |
|
54 // Nothing. |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CDRMHelperSession::NewLC |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CDRMHelperSession* CDRMHelperSession::NewL() |
|
63 { |
|
64 CDRMHelperSession* self = new( ELeave ) CDRMHelperSession(); |
|
65 CleanupStack::PushL( self ); |
|
66 #ifdef _DRM_TESTING |
|
67 CreateLogL(); |
|
68 #endif |
|
69 CleanupStack::Pop(self); // self |
|
70 return self; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CDRMHelperSession::~CDRMHelperSession |
|
75 // Destructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CDRMHelperSession::~CDRMHelperSession() |
|
79 { |
|
80 TInt err = KErrNone; |
|
81 TRAP(err , SERVER->StoreL()); |
|
82 // remove warning, and enable logging in the future |
|
83 if( err ) { |
|
84 err = KErrNone; |
|
85 } |
|
86 #ifdef _DRM_TESTING |
|
87 TRAP( err , WriteDownL(_L("destructor")) ); |
|
88 TRAP( err , WriteCurrentTimeL() ); |
|
89 #endif |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CDRMHelperSession::ServiceL |
|
96 // This method runs DispatchL() under TRAP harness, since every error case |
|
97 // can be handled ==> no need to let this function leave. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CDRMHelperSession::ServiceL( const RMessage2& aMessage ) |
|
101 { |
|
102 |
|
103 #ifdef _DRM_TESTING |
|
104 WriteDownL(_L("ServiceL")); |
|
105 WriteCurrentTimeL(); |
|
106 #endif |
|
107 |
|
108 // Trap possible errors... |
|
109 TRAPD( error, DispatchL( aMessage ) ); |
|
110 |
|
111 if ( error ) |
|
112 { |
|
113 aMessage.Complete( error ); |
|
114 return; |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CDRMHelperSession::DispatchL |
|
122 // Checks which command the user requested, and forwards the request to |
|
123 // appropriate private method. This helps to keep the code more readable. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CDRMHelperSession::DispatchL( const RMessage2& aMessage ) |
|
127 { |
|
128 #ifdef _DRM_TESTING |
|
129 WriteDownL(_L("DispatchL")); |
|
130 WriteCurrentTimeL(); |
|
131 #endif |
|
132 switch ( aMessage.Function() ) |
|
133 { |
|
134 case ERegister: |
|
135 RegisterL( aMessage ); |
|
136 break; |
|
137 case ERemove: |
|
138 RemoveL( aMessage ); |
|
139 break; |
|
140 case EIndicateIdle: |
|
141 IndicateIdleL( aMessage ); |
|
142 break; |
|
143 case EIsRegistered: |
|
144 IsRegisteredL( aMessage ); |
|
145 break; |
|
146 default: |
|
147 User::Leave( KErrNotSupported ); |
|
148 } |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CDRMHelperSession::RegisterL |
|
153 // Register the content URI into helper server |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CDRMHelperSession::RegisterL( const RMessage2& aMessage ) |
|
157 { |
|
158 #ifdef _DRM_TESTING |
|
159 WriteDownL(_L("RegisterL")); |
|
160 WriteCurrentTimeL(); |
|
161 #endif |
|
162 |
|
163 TInt size = 0; |
|
164 TInt permType = aMessage.Int0(); |
|
165 TInt regType = aMessage.Int1(); |
|
166 TInt autoType = aMessage.Int2(); |
|
167 |
|
168 HBufC8* cid = NULL; |
|
169 TPtr8 data( NULL , 0 , 0 ); |
|
170 |
|
171 size = User::LeaveIfError( aMessage.GetDesLength( 3 ) ); |
|
172 if (size==0) |
|
173 { |
|
174 aMessage.Complete( KErrArgument ); |
|
175 return; |
|
176 } |
|
177 |
|
178 #ifdef _DRM_TESTING |
|
179 _LIT( KSize , "size = %d"); |
|
180 TBuf<20> sizeBuf; |
|
181 sizeBuf.Format(KSize , size); |
|
182 WriteDownL(sizeBuf); |
|
183 WriteCurrentTimeL(); |
|
184 #endif |
|
185 |
|
186 cid = HBufC8::NewLC( size ); |
|
187 data.Set( cid->Des() ); |
|
188 aMessage.ReadL( 3, data ); |
|
189 |
|
190 #ifdef _DRM_TESTING |
|
191 WriteDownL(data); |
|
192 WriteCurrentTimeL(); |
|
193 #endif |
|
194 |
|
195 SERVER->RegisterL( data , permType , regType , autoType ); |
|
196 SERVER->StoreL(); |
|
197 |
|
198 CleanupStack::PopAndDestroy( cid ); |
|
199 aMessage.Complete( KErrNone ); |
|
200 } |
|
201 |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CDRMHelperSession::RemoveL |
|
205 // Unregister the content URI into helper server |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CDRMHelperSession::RemoveL( const RMessage2& aMessage ) |
|
209 { |
|
210 #ifdef _DRM_TESTING |
|
211 WriteDownL(_L("RemoveL")); |
|
212 WriteCurrentTimeL(); |
|
213 #endif |
|
214 TInt size = 0; |
|
215 TInt permType = aMessage.Int0(); |
|
216 TInt regType = aMessage.Int1(); |
|
217 TInt autoType = aMessage.Int2(); |
|
218 HBufC8* cid = NULL; |
|
219 TPtr8 data( NULL , 0 , 0 ); |
|
220 size = User::LeaveIfError( aMessage.GetDesLength( 3 ) ); |
|
221 if (size==0) |
|
222 { |
|
223 aMessage.Complete( KErrArgument ); |
|
224 return; |
|
225 } |
|
226 cid = HBufC8::NewLC( size ); |
|
227 data.Set( cid->Des() ); |
|
228 aMessage.ReadL( 3, data ); |
|
229 |
|
230 // If this is execute, means we are using a pip file, unregister all other types as well |
|
231 if( permType == 3 ) |
|
232 { |
|
233 // EPlay |
|
234 SERVER->RemoveL( data , 1 , regType , autoType ); |
|
235 // EDisplay |
|
236 SERVER->RemoveL( data , 2 , regType , autoType ); |
|
237 } |
|
238 |
|
239 |
|
240 SERVER->RemoveL( data , permType , regType , autoType ); |
|
241 SERVER->StoreL(); |
|
242 CleanupStack::PopAndDestroy( cid ); |
|
243 aMessage.Complete( KErrNone ); |
|
244 } |
|
245 |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CDRMHelperSession::IndicateIdleL |
|
249 // Unregister the content URI into helper server |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CDRMHelperSession::IndicateIdleL( const RMessage2& aMessage ) |
|
253 { |
|
254 #ifdef _DRM_TESTING |
|
255 WriteDownL(_L("IndicateIdleL")); |
|
256 WriteCurrentTimeL(); |
|
257 #endif |
|
258 SERVER->HandleIdleL(); |
|
259 aMessage.Complete( KErrNone ); |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CDRMHelperSession::IsRegisteredL |
|
265 // check if content is registered or not |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CDRMHelperSession::IsRegisteredL( const RMessage2& aMessage ) |
|
269 { |
|
270 #ifdef _DRM_TESTING |
|
271 WriteDownL(_L("IsRegisteredL")); |
|
272 WriteCurrentTimeL(); |
|
273 #endif |
|
274 |
|
275 TInt size = 0; |
|
276 TInt permType = aMessage.Int0(); |
|
277 TInt regType = aMessage.Int1(); |
|
278 TInt autoType = aMessage.Int2(); |
|
279 HBufC8* cid = NULL; |
|
280 TPtr8 data( NULL , 0 , 0 ); |
|
281 TBool mark = EFalse; |
|
282 TPtr8 ptr(NULL,0,0); |
|
283 size = User::LeaveIfError( aMessage.GetDesLength( 3 ) ); |
|
284 if (size==0) |
|
285 { |
|
286 aMessage.Complete( KErrArgument ); |
|
287 return; |
|
288 } |
|
289 |
|
290 |
|
291 #ifdef _DRM_TESTING |
|
292 _LIT( KSize , "size = %d"); |
|
293 TBuf<20> sizeBuf; |
|
294 sizeBuf.Format(KSize , size); |
|
295 WriteDownL(sizeBuf); |
|
296 WriteCurrentTimeL(); |
|
297 #endif |
|
298 |
|
299 cid = HBufC8::NewLC( size ); |
|
300 data.Set( cid->Des() ); |
|
301 aMessage.ReadL( 3, data ); |
|
302 |
|
303 #ifdef _DRM_TESTING |
|
304 WriteDownL(data); |
|
305 WriteCurrentTimeL(); |
|
306 #endif |
|
307 mark = SERVER->IsRegistered2( data , regType , autoType ); |
|
308 |
|
309 CleanupStack::PopAndDestroy( cid ); |
|
310 |
|
311 aMessage.Complete( mark ); |
|
312 } |
|
313 |
|
314 |
|
315 |
|
316 #ifdef _DRM_TESTING |
|
317 |
|
318 LOCAL_C void WriteDownLogL( const TDesC8& text , RFs &aFs ) |
|
319 { |
|
320 _LIT( KLogFile , "c:\\HSSessionLog.txt" ); |
|
321 WriteFileL( text , aFs , KLogFile ); |
|
322 } |
|
323 |
|
324 LOCAL_C void WriteFileL( const TDesC8& text , RFs &aFs , const TDesC& aName ) |
|
325 { |
|
326 RFile file; |
|
327 TInt size; |
|
328 User::LeaveIfError( file.Open( aFs, aName , EFileWrite ) ); |
|
329 CleanupClosePushL( file ); |
|
330 User::LeaveIfError( file.Size( size ) ); |
|
331 User::LeaveIfError( file.Write( size, text ) ); |
|
332 CleanupStack::PopAndDestroy(&file); //file |
|
333 } |
|
334 |
|
335 LOCAL_C void CreateLogL() |
|
336 { |
|
337 RFs fs; |
|
338 User::LeaveIfError(fs.Connect()); |
|
339 CleanupClosePushL(fs); |
|
340 RFile file; |
|
341 User::LeaveIfError( file.Replace( fs , _L("c:\\HSSessionLog.txt") , EFileWrite ) ); |
|
342 file.Close(); |
|
343 CleanupStack::PopAndDestroy(&fs); //fs |
|
344 } |
|
345 |
|
346 LOCAL_C void WriteDownL( const TDesC& aText ) |
|
347 { |
|
348 RFs fs; |
|
349 User::LeaveIfError( fs.Connect() ); |
|
350 CleanupClosePushL(fs); |
|
351 HBufC8* text = HBufC8::NewLC(1000); |
|
352 TPtr8 textptr(text->Des() ); |
|
353 textptr.Append( aText ); |
|
354 textptr.Append( _L("\r\n") ); |
|
355 WriteDownLogL(textptr , fs); |
|
356 CleanupStack::PopAndDestroy(text); |
|
357 CleanupStack::PopAndDestroy(&fs); //fs |
|
358 } |
|
359 |
|
360 LOCAL_C void WriteDownL( const TDesC8& aText ) |
|
361 { |
|
362 RFs fs; |
|
363 User::LeaveIfError( fs.Connect() ); |
|
364 CleanupClosePushL(fs); |
|
365 HBufC8* text = HBufC8::NewLC(1000); |
|
366 TPtr8 textptr(text->Des() ); |
|
367 textptr.Append( aText ); |
|
368 textptr.Append( _L8("\r\n") ); |
|
369 WriteDownLogL(textptr , fs); |
|
370 CleanupStack::PopAndDestroy(text); |
|
371 CleanupStack::PopAndDestroy(&fs); //fs |
|
372 } |
|
373 |
|
374 |
|
375 LOCAL_C void WriteCurrentTimeL() |
|
376 { |
|
377 RFs fs; |
|
378 User::LeaveIfError( fs.Connect() ); |
|
379 CleanupClosePushL(fs); |
|
380 HBufC8* text = HBufC8::NewLC(100); |
|
381 TPtr8 textptr(text->Des() ); |
|
382 // Date and Time display |
|
383 TTime time; |
|
384 time.HomeTime(); |
|
385 TBuf<256> dateString; |
|
386 _LIT(KDate,"%*E%*D%X%*N%*Y %1 %2 '%3"); |
|
387 time.FormatL(dateString,KDate); |
|
388 textptr.Append(_L( "\r\n\t\tData:\t" ) ); |
|
389 textptr.Append( dateString ); |
|
390 _LIT(KTime,"%-B%:0%J%:1%T%:2%S%:3%+B"); |
|
391 time.FormatL(dateString,KTime); |
|
392 textptr.Append(_L( "\r\n\t\tTime:\t" ) ); |
|
393 textptr.Append( dateString ); |
|
394 textptr.Append(_L( "\r\n" ) ); |
|
395 textptr.Append(_L( "\r\n" ) ); |
|
396 WriteDownLogL(textptr , fs); |
|
397 CleanupStack::PopAndDestroy(text); |
|
398 CleanupStack::PopAndDestroy(&fs); //fs |
|
399 } |
|
400 #endif |
|
401 |
|
402 // End of File |