|
1 /* |
|
2 * Copyright (c) 2007 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 DRMHelperServer Client |
|
15 * session functionality |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include <e32math.h> |
|
23 #include "drmhelpercommon.h" |
|
24 #include "drmhelperserver.h" |
|
25 #include "rdrmhelperclient.h" |
|
26 |
|
27 // LOCAL CONSTANTS AND MACROS |
|
28 |
|
29 // Number of message slots to reserve for this client server session. |
|
30 // Since we only communicate synchronously here, we never have any |
|
31 // outstanding asynchronous requests. |
|
32 |
|
33 const TUint KDefaultMessageSlots = 0; |
|
34 const TUid KServerUid3 = {0x101F6DC5}; |
|
35 |
|
36 |
|
37 // ============================= LOCAL FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // AutomatedServiceTypeToHs Converts AutomatedUsage service type |
|
41 // to HelperServer. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 LOCAL_C TInt AutomatedServiceTypeToHs( |
|
45 const DRM::TDrmAutomatedServiceType aServiceType, |
|
46 TInt& aHsServiceType ) |
|
47 { |
|
48 if ( aServiceType == DRM::EAUActive ) |
|
49 { |
|
50 aHsServiceType = CDRMHelperServer::EActive; |
|
51 return KErrNone; |
|
52 } |
|
53 if ( aServiceType == DRM::EAUPassive ) |
|
54 { |
|
55 aHsServiceType = CDRMHelperServer::EPassive; |
|
56 return KErrNone; |
|
57 } |
|
58 return KErrArgument; |
|
59 } |
|
60 |
|
61 // ============================ MEMBER FUNCTIONS =============================== |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // RDrmHelperClient::RDrmHelperClient |
|
65 // C++ default constructor can NOT contain any code, that might leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 RDrmHelperClient::RDrmHelperClient() : RSessionBase() |
|
69 { |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // RDrmHelperClient::Connect |
|
74 // |
|
75 // Connect to the server session |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 TInt RDrmHelperClient::Connect() |
|
79 { |
|
80 TInt error = StartServer(); |
|
81 |
|
82 if ( !error ) |
|
83 { |
|
84 error = CreateSession( KDRMHelperServerName, |
|
85 Version(), |
|
86 KDefaultMessageSlots ); |
|
87 } |
|
88 return error; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // RDrmHelperClient::Version |
|
93 // |
|
94 // return server version |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 TVersion RDrmHelperClient::Version() const |
|
98 { |
|
99 return ( TVersion( KDRMHSMajorVersionNumber, |
|
100 KDRMHSMinorVersionNumber, |
|
101 KDRMHSBuildVersionNumber ) ); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // RDrmHelperClient::SetAutomated |
|
106 // |
|
107 // Register one content uri to the helper server |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TInt RDrmHelperClient::SetAutomated( |
|
111 const TDesC8& aUri, |
|
112 const DRM::TDrmAutomatedType aAutomatedType, |
|
113 const ContentAccess::TIntent aIntent, |
|
114 const DRM::TDrmAutomatedServiceType aServiceType ) const |
|
115 { |
|
116 TInt ret( KErrNone ); |
|
117 TInt drmHsServiceType( 0 ); |
|
118 |
|
119 ret = AutomatedServiceTypeToHs( aServiceType, drmHsServiceType ); |
|
120 if ( ret ) |
|
121 { |
|
122 return ret; |
|
123 } |
|
124 |
|
125 // Create descriptor to enable copying data between |
|
126 // client and server. Note: This can be local since |
|
127 // this is a synchronous call. |
|
128 // Note : Using TPtr8 since this is binary information |
|
129 TPtrC8 descriptor( aUri ); |
|
130 |
|
131 // This call waits for the server to complete the request before |
|
132 // proceeding. |
|
133 return SendReceive( ERegister, |
|
134 TIpcArgs( aIntent, |
|
135 drmHsServiceType, |
|
136 aAutomatedType, |
|
137 &descriptor ) ); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // RDrmHelperClient::RemoveAutomated |
|
142 // |
|
143 // Unregister one content uri |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt RDrmHelperClient::RemoveAutomated( |
|
147 const TDesC8& aUri, |
|
148 const DRM::TDrmAutomatedType aAutomatedType, |
|
149 const ContentAccess::TIntent aIntent, |
|
150 const DRM::TDrmAutomatedServiceType aServiceType ) const |
|
151 { |
|
152 TInt ret( KErrNone ); |
|
153 TInt drmHsServiceType( 0 ); |
|
154 |
|
155 ret = AutomatedServiceTypeToHs( aServiceType, drmHsServiceType ); |
|
156 if( ret ) |
|
157 { |
|
158 return ret; |
|
159 } |
|
160 |
|
161 // Create descriptor to enable copying data between |
|
162 // client and server. Note: This can be local since |
|
163 // this is a synchronous call. |
|
164 // Note : Using TPtr8 since this is binary information |
|
165 TPtrC8 descriptor( aUri ); |
|
166 |
|
167 // This call waits for the server to complete the request before |
|
168 // proceeding. |
|
169 ret = SendReceive( ERemove, |
|
170 TIpcArgs( aIntent, |
|
171 drmHsServiceType, |
|
172 aAutomatedType, |
|
173 &descriptor ) ); |
|
174 |
|
175 if ( ret == KErrNotFound ) |
|
176 { |
|
177 // content was never actually registered |
|
178 ret = KErrNone; |
|
179 } |
|
180 return ret; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // RDrmHelperClient::RemoveAutomatedAll |
|
185 // |
|
186 // Unregister one content uri |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt RDrmHelperClient::RemoveAutomatedAll( |
|
190 const TDesC8& aUri, |
|
191 const DRM::TDrmAutomatedType aAutomatedType, |
|
192 const ContentAccess::TIntent aIntent, |
|
193 const DRM::TDrmAutomatedServiceType aServiceType ) const |
|
194 { |
|
195 TPtrC8 descriptor( aUri ); |
|
196 TInt ret( KErrNone ); |
|
197 TInt drmHsServiceType( 0 ); |
|
198 |
|
199 ret = AutomatedServiceTypeToHs( aServiceType, drmHsServiceType ); |
|
200 if ( ret ) |
|
201 { |
|
202 return ret; |
|
203 } |
|
204 |
|
205 TBool automated( EFalse ); |
|
206 |
|
207 // This call waits for the server to complete the request before |
|
208 // proceeding. |
|
209 ret = SendReceive( ERemove, |
|
210 TIpcArgs( aIntent, |
|
211 drmHsServiceType, |
|
212 aAutomatedType, |
|
213 &descriptor ) ); |
|
214 |
|
215 ret = IsAutomated( aUri, |
|
216 aAutomatedType, |
|
217 aIntent, |
|
218 aServiceType, |
|
219 automated ); |
|
220 |
|
221 while ( automated ) |
|
222 { |
|
223 // unregister all |
|
224 ret = SendReceive( ERemove, |
|
225 TIpcArgs( aIntent, |
|
226 drmHsServiceType, |
|
227 aAutomatedType, |
|
228 &descriptor ) ); |
|
229 |
|
230 IsAutomated( aUri, aAutomatedType, aIntent, aServiceType, automated ); |
|
231 } |
|
232 |
|
233 if ( ret == KErrNotFound ) |
|
234 { |
|
235 ret = KErrNone; |
|
236 } |
|
237 return ret; |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // RDrmHelperClient::IndicateIdle |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 TInt RDrmHelperClient::IndicateIdle() const |
|
245 { |
|
246 return SendReceive( EIndicateIdle, TIpcArgs() ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // RDrmHelperClient::IsAutomated |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TInt RDrmHelperClient::IsAutomated( |
|
254 const TDesC8& aUri, |
|
255 const DRM::TDrmAutomatedType aAutomatedType, |
|
256 const ContentAccess::TIntent aIntent, |
|
257 const DRM::TDrmAutomatedServiceType aServiceType, |
|
258 TBool& aAutomated ) const |
|
259 { |
|
260 TPtr8 flag( reinterpret_cast< TUint8* >( &aAutomated ), 0, sizeof( TInt ) ); |
|
261 TInt ret( KErrNone ); |
|
262 TInt drmHsServiceType( 0 ); |
|
263 |
|
264 ret = AutomatedServiceTypeToHs( aServiceType, drmHsServiceType ); |
|
265 if ( ret ) |
|
266 { |
|
267 return ret; |
|
268 } |
|
269 |
|
270 TInt type( CDRMHelperServer::EActive ); |
|
271 |
|
272 // Create descriptor to enable copying data between |
|
273 // client and server. Note: This can be local since |
|
274 // this is a synchronous call. |
|
275 // Note : Using TPtr8 since this is binary information |
|
276 TPtrC8 descriptor( aUri ); |
|
277 |
|
278 // This call waits for the server to complete the request before |
|
279 // proceeding. |
|
280 ret = SendReceive( EIsRegistered, |
|
281 TIpcArgs( aIntent, |
|
282 type, |
|
283 aAutomatedType, |
|
284 &descriptor ) ); |
|
285 if ( !ret ) |
|
286 { |
|
287 type = CDRMHelperServer::EPassive; |
|
288 |
|
289 ret = SendReceive( EIsRegistered, |
|
290 TIpcArgs( aIntent, |
|
291 type, |
|
292 aAutomatedType, |
|
293 &descriptor ) ); |
|
294 } |
|
295 aAutomated = ret ? ETrue : EFalse; |
|
296 return KErrNone; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // RDrmHelperClient::StartServer |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 TInt RDrmHelperClient::StartServer() |
|
304 { |
|
305 TInt result(0); |
|
306 |
|
307 TFindServer findHelperServer( KDRMHelperServerName ); |
|
308 TFullName name; |
|
309 |
|
310 result = findHelperServer.Next( name ); |
|
311 if ( !result ) |
|
312 { |
|
313 // Server already running |
|
314 return KErrNone; |
|
315 } |
|
316 |
|
317 RSemaphore semaphore; |
|
318 result = semaphore.CreateGlobal( KDRMHelperServerSemaphoreName, 0 ); |
|
319 if ( result ) |
|
320 { |
|
321 return result; |
|
322 } |
|
323 |
|
324 result = CreateServerProcess(); |
|
325 if ( result ) |
|
326 { |
|
327 return result; |
|
328 } |
|
329 |
|
330 semaphore.Wait(); |
|
331 semaphore.Close(); |
|
332 |
|
333 return KErrNone; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // RDrmHelperClient::CreateServerProcess |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 TInt RDrmHelperClient::CreateServerProcess() |
|
341 { |
|
342 TInt result( 0 ); |
|
343 const TUidType serverUid( KNullUid, KNullUid, KServerUid3 ); |
|
344 |
|
345 RProcess server; |
|
346 result = server.Create( KDRMHSServerFileName, _L(""), serverUid ); |
|
347 if ( result ) |
|
348 { |
|
349 return result; |
|
350 } |
|
351 |
|
352 server.Resume(); |
|
353 server.Close(); |
|
354 |
|
355 return KErrNone; |
|
356 } |
|
357 |
|
358 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
359 |
|
360 |
|
361 // End of File |