|
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: This class handles all client requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32file.h> |
|
21 #include <f32file.h> |
|
22 #include "drmcommon.h" |
|
23 #include "DRMClockSession.h" |
|
24 #include "drmclockclientserver.h" |
|
25 #include "DRMClockServer.h" |
|
26 #include <DrmTypes.h> |
|
27 |
|
28 #include <e32test.h> |
|
29 |
|
30 #include "drmlog.h" |
|
31 |
|
32 // NAMESPACES |
|
33 using namespace DRMClock; |
|
34 |
|
35 // EXTERNAL DATA STRUCTURES |
|
36 // EXTERNAL FUNCTION PROTOTYPES |
|
37 // CONSTANTS |
|
38 |
|
39 |
|
40 // MACROS |
|
41 |
|
42 #define IPCREAD0L( a ) aMessage.ReadL( 0, a ) |
|
43 #define IPCREAD1L( a ) aMessage.ReadL( 1, a ) |
|
44 #define IPCREAD2L( a ) aMessage.ReadL( 2, a ) |
|
45 #define IPCWRITE0L( a ) aMessage.WriteL( 0, a ) |
|
46 #define IPCWRITE1L( a ) aMessage.WriteL( 1, a ) |
|
47 #define IPCWRITE2L( a ) aMessage.WriteL( 2, a ) |
|
48 |
|
49 |
|
50 // LOCAL CONSTANTS AND MACROS |
|
51 // MODULE DATA STRUCTURES |
|
52 // DATA TYPES |
|
53 // LOCAL FUNCTION PROTOTYPES |
|
54 // FORWARD DECLARATIONS |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CDRMClockSession::NewL |
|
58 // Two-phased constructor. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CDRMClockSession* CDRMClockSession::NewL( CDRMClock* aClock) |
|
62 { |
|
63 CDRMClockSession* self = new( ELeave ) CDRMClockSession( aClock ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); // self |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CDRMClockSession::~CDRMClockSession |
|
72 // Destructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CDRMClockSession::~CDRMClockSession() |
|
76 { |
|
77 DRMLOG( _L( "CDRMClockSession::Notifier session closed." ) ); |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CDRMClockSession::ServiceL |
|
83 // This method runs DispatchL() under TRAP harness, since every error case |
|
84 // can be handled ==> no need to let this function leave. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CDRMClockSession::ServiceL( const RMessage2& aMessage ) |
|
88 { |
|
89 DRMLOG( _L( "CDRMClockSession::ServiceL called" ) ); |
|
90 // Trap possible errors... |
|
91 |
|
92 TRAPD( error, DispatchL( aMessage ) ); |
|
93 |
|
94 if ( error ) |
|
95 { |
|
96 DRMLOG2( _L( "CDRMClockSession::DispatcL threw an exception %d" ), error ); |
|
97 // ...and complete the request in case of an error. |
|
98 aMessage.Complete( error ); |
|
99 return; |
|
100 } |
|
101 |
|
102 // The message has already completed successfully. |
|
103 DRMLOG( _L( "CDRMClockSession::DispatchL completed successfully" ) ); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CDRMClockSession::CDRMClockSession |
|
108 // Default constructor. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 CDRMClockSession::CDRMClockSession( CDRMClock* aClock ) : |
|
112 // Base class' constructor is called first. |
|
113 iDRMClock( aClock ) |
|
114 { |
|
115 // Nothing. |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CDRMClockSession::ConstructL |
|
120 // Second phase constructor. Initializes the log tool in DRM internal testing. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CDRMClockSession::ConstructL() |
|
124 { |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CDRMClockSession::DispatchL |
|
129 // Checks which command the user requested, and forwards the request to |
|
130 // appropriate private method. This helps to keep the code more readable. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CDRMClockSession::DispatchL( const RMessage2& aMessage ) |
|
134 { |
|
135 switch ( aMessage.Function() ) |
|
136 { |
|
137 case EGetDRMTime: |
|
138 GetDRMTimeL( aMessage ); |
|
139 break; |
|
140 case EUpdateDRMTime: |
|
141 UpdateDRMTimeL( aMessage ); |
|
142 break; |
|
143 default: |
|
144 DRMLOG( _L( "CDRMClockSession::DispatchL: Invalid command" ) ); |
|
145 User::Leave( KErrNotSupported ); |
|
146 } |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CDRMClockSession::GetDRMTimeL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CDRMClockSession::GetDRMTimeL( const RMessage2& aMessage ) |
|
154 { |
|
155 DRMLOG( _L( "CDRMClockSession::GetDRMTimeL" ) ); |
|
156 TTime drmTime; |
|
157 TInt timeZone; |
|
158 DRMClock::ESecurityLevel level; |
|
159 |
|
160 iDRMClock->GetSecureTime( drmTime, timeZone, level ); |
|
161 |
|
162 TPckg<TTime> package(drmTime); |
|
163 TPckg<TInt> package2(timeZone); |
|
164 TPckg<DRMClock::ESecurityLevel> package3(level); |
|
165 |
|
166 IPCWRITE0L( package ); |
|
167 IPCWRITE1L( package2 ); |
|
168 IPCWRITE2L( package3 ); |
|
169 |
|
170 aMessage.Complete( KErrNone ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CDRMClockSession::UpdateDRMTimeL |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CDRMClockSession::UpdateDRMTimeL( const RMessage2& aMessage ) |
|
178 { |
|
179 DRMLOG( _L( "CDRMClockSession::UpdateDRMTimeL" ) ); |
|
180 TInt error = KErrNone; |
|
181 TTime drmTime; |
|
182 TInt timeZone; |
|
183 TPckg<TTime> package( drmTime ); |
|
184 TPckg<TInt> package2( timeZone ); |
|
185 TInt r = KErrAccessDenied; |
|
186 |
|
187 // Add a check for the vendor id |
|
188 _LIT_SECURITY_POLICY_V0(vidCheck, VID_DEFAULT); // Check Default VID |
|
189 _LIT_SECURITY_POLICY_C1(drmCheck, ECapabilityDRM); |
|
190 RThread client; |
|
191 |
|
192 aMessage.ClientL( client ); |
|
193 |
|
194 if( vidCheck.CheckPolicy( client ) || drmCheck().CheckPolicy(client) ) |
|
195 { |
|
196 r = KErrNone; |
|
197 } |
|
198 |
|
199 client.Close(); |
|
200 User::LeaveIfError( r ); |
|
201 |
|
202 IPCREAD0L( package ); |
|
203 IPCREAD1L( package2 ); |
|
204 |
|
205 TRAP( error, iDRMClock->ResetSecureTimeL( drmTime, timeZone ) ); |
|
206 |
|
207 // All done. |
|
208 aMessage.Complete( error ); |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
214 // End of File |
|
215 |