|
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: DRM3 Engine manages all DRM related database operations. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "DRMNotifierServer.h" |
|
23 #include "drmnotifierclientserver.h" |
|
24 #include "drmcommonclientserver.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 // CONSTANTS |
|
29 // MACROS |
|
30 |
|
31 #define _LOGBUFNUM( a, b ) |
|
32 #define LOGBUFNUM( a, b ) |
|
33 #define LOG( a ) |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 LOCAL_C const TUint8 KMaxStartTries = 5; |
|
37 LOCAL_C const TInt KWaitingTime = 1000000; // 10 secs |
|
38 _LIT( KNotifierThread, "drmnotifier" ); |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 using DRMNotifier::KServerMajorVersion; |
|
42 using DRMNotifier::KServerMinorVersion; |
|
43 using DRMNotifier::KServerBuildVersion; |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 LOCAL_C TInt StartNotifierServer( RSemaphore& aClientSem ); |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // Function StartNotifierServer(). |
|
55 // This function starts the actual server under TRAP harness and starts |
|
56 // waiting for connections. This function returns only if there has been |
|
57 // errors during server startup or the server is stopped for some reason. |
|
58 // |
|
59 // Returns: TInt: Symbian OS error code. |
|
60 // ----------------------------------------------------------------------------- |
|
61 TInt StartNotifierServer( RSemaphore& aClientSem ) |
|
62 |
|
63 { |
|
64 TInt error = KErrNone; |
|
65 CDRMNotifierServer* server = NULL; |
|
66 |
|
67 TUint8 count = 0; |
|
68 |
|
69 #ifdef _DRM_TESTING |
|
70 TTime time; |
|
71 _LIT8( KDRMErrorDebugText, "Error: " ); |
|
72 RFs fs; |
|
73 RFile file; |
|
74 |
|
75 TFileName filename; |
|
76 |
|
77 time.UniversalTime(); |
|
78 |
|
79 TRAPD( error2, time.FormatL( filename, KDateTimeFormat ) ); |
|
80 filename.Append( _L( "DRMNotifier.txt " ) ); |
|
81 |
|
82 error = fs.Connect(); |
|
83 if ( error ) |
|
84 { |
|
85 return error; |
|
86 } |
|
87 |
|
88 file.Replace( fs, filename, EFileStreamText | EFileWrite ); |
|
89 file.Write( _L8( "Started." ) ); |
|
90 #endif |
|
91 |
|
92 do |
|
93 { |
|
94 _LOGBUFNUM( KDRMErrorDebugText, error ); |
|
95 |
|
96 ++count; |
|
97 |
|
98 TRAP( error, ( server = CDRMNotifierServer::NewL() ) ); |
|
99 |
|
100 if ( error ) |
|
101 { |
|
102 User::After( TTimeIntervalMicroSeconds32(KWaitingTime) ); |
|
103 } |
|
104 |
|
105 } while( error && ( count <= KMaxStartTries ) ); |
|
106 |
|
107 if( error ) |
|
108 { |
|
109 |
|
110 #ifdef _DRM_TESTING |
|
111 _LOGBUFNUM( _L8( "Failed: " ), error ); |
|
112 file.Close(); |
|
113 fs.Close(); |
|
114 #endif |
|
115 // Failed |
|
116 return error; |
|
117 } |
|
118 |
|
119 #ifdef _DRM_TESTING |
|
120 file.Write( _L8( "OK!" ) ); |
|
121 file.Close(); |
|
122 fs.Close(); |
|
123 #endif |
|
124 |
|
125 #ifdef __WINS__ |
|
126 |
|
127 //UserSvr::ServerStarted(); |
|
128 #endif |
|
129 // Release the semaphore... |
|
130 aClientSem.Signal(); |
|
131 aClientSem.Close(); |
|
132 |
|
133 // Start waiting for connections |
|
134 CActiveScheduler::Start(); |
|
135 |
|
136 // Dying. |
|
137 // Delete CDRMRigntsServer |
|
138 delete server; |
|
139 |
|
140 return KErrNone; |
|
141 } |
|
142 |
|
143 // ============================ MEMBER FUNCTIONS =============================== |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CDRMNotifierServer::NewLC |
|
147 // Two-phased constructor. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 CDRMNotifierServer* CDRMNotifierServer::NewL() |
|
151 { |
|
152 CDRMNotifierServer* self = new( ELeave ) CDRMNotifierServer(); |
|
153 |
|
154 CleanupStack::PushL( self ); |
|
155 |
|
156 self->ConstructL(); |
|
157 |
|
158 CleanupStack::Pop( self ); |
|
159 |
|
160 return self; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // Destructor |
|
165 // ----------------------------------------------------------------------------- |
|
166 CDRMNotifierServer::~CDRMNotifierServer() |
|
167 { |
|
168 if( iStorage ) |
|
169 { |
|
170 delete iStorage; |
|
171 iStorage = 0; |
|
172 } |
|
173 |
|
174 LOG( _L8( "Dying..." ) ); |
|
175 |
|
176 #ifdef _DRM_TESTING |
|
177 delete iLog; |
|
178 #endif |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CDRMNotifierServer::RunErrorL |
|
183 // From CActive. Complete the request and restart the scheduler. |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TInt CDRMNotifierServer::RunError( TInt aError ) |
|
187 { |
|
188 // Inform the client. |
|
189 Message().Complete( aError ); |
|
190 |
|
191 // Restart the scheduler. |
|
192 ReStart(); |
|
193 |
|
194 // Error handled. |
|
195 return KErrNone; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CDRMNotifierServer::NewSessionL |
|
200 // Called when a client requires a new instance. |
|
201 // ----------------------------------------------------------------------------- |
|
202 CSession2* CDRMNotifierServer::NewSessionL( |
|
203 const TVersion& aVersion, |
|
204 const RMessage2& /*aMessage*/) const |
|
205 { |
|
206 RThread client; |
|
207 LOG( _L8( "NewSessionL" ) ); |
|
208 |
|
209 // Check that the versions are compatible. |
|
210 if ( ! User::QueryVersionSupported( TVersion( KServerMajorVersion, |
|
211 KServerMinorVersion, |
|
212 KServerBuildVersion ), |
|
213 aVersion ) ) |
|
214 { |
|
215 // Sorry, no can do. |
|
216 User::Leave( KErrNotSupported ); |
|
217 } |
|
218 |
|
219 LOG( _L8( "NewSessionL: Creating a new session" ) ); |
|
220 |
|
221 return CDRMNotifierSession::NewL( iStorage ); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CDRMNotifierServer::CDRMNotifierServer |
|
226 // C++ default constructor can NOT contain any code, that |
|
227 // might leave. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 CDRMNotifierServer::CDRMNotifierServer() : |
|
231 CServer2( EPriorityStandard ) |
|
232 { |
|
233 // Nothing |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CDRMNotifierServer::ConstructL |
|
238 // Symbian 2nd phase constructor can leave. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CDRMNotifierServer::ConstructL() |
|
242 { |
|
243 RFs fs; |
|
244 |
|
245 // Ignore errors |
|
246 User::RenameThread( KNotifierThread ); |
|
247 |
|
248 User::LeaveIfError( fs.Connect() ); |
|
249 |
|
250 fs.Close(); |
|
251 |
|
252 #ifdef _DRM_TESTING |
|
253 _LIT( KLogFile, "notifier.txt" ); |
|
254 TFileName logFile( KLogFile ); |
|
255 TTime time; |
|
256 time.UniversalTime(); |
|
257 |
|
258 time.FormatL( logFile, KDateTimeFormat ); |
|
259 logFile.Append( KLogFile ); |
|
260 |
|
261 iLog = CLogFile::NewL( logFile, ETrue ); |
|
262 iLog->SetAutoFlush( ETrue ); |
|
263 iLog->SetAutoNewline( ETrue ); |
|
264 |
|
265 LOG( _L8( "DRM Server starting..." ) ); |
|
266 #endif |
|
267 iStorage = CDRMMessageStorage::NewL(); |
|
268 |
|
269 LOG( _L8( "Notification Server started." ) ); |
|
270 |
|
271 // Add the server to the scheduler. |
|
272 StartL( DRMNotifier::KServerName ); |
|
273 } |
|
274 |
|
275 |
|
276 #ifdef _DRM_TESTING |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CDRMNotifierServer::Log |
|
280 // Logging operation. |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 void CDRMNotifierServer::Log( const TDesC8& aLog ) const |
|
284 { |
|
285 iLog->Log( aLog ); |
|
286 } |
|
287 |
|
288 |
|
289 void CDRMNotifierServer::Log( const TDesC& aLog ) const |
|
290 { |
|
291 iLog->Log( aLog ); |
|
292 } |
|
293 #endif |
|
294 |
|
295 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
296 // ----------------------------------------------------------------------------- |
|
297 // Function StartupNotifier(). |
|
298 // This function starts the actual DRM Notifier |
|
299 // the cleanup stack and active scheduler. |
|
300 // Returns: TInt: Symbian OS error code. |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 |
|
304 TInt StartupNotifier( TAny* ) |
|
305 { |
|
306 TInt error = KErrNone; |
|
307 CTrapCleanup* trap = CTrapCleanup::New(); |
|
308 |
|
309 // Check that memory allocation was successful. |
|
310 __ASSERT_ALWAYS( trap, User::Invariant() ); |
|
311 |
|
312 CActiveScheduler* scheduler = new CActiveScheduler(); |
|
313 |
|
314 __ASSERT_ALWAYS( scheduler, User::Invariant() ); |
|
315 |
|
316 CActiveScheduler::Install( scheduler ); |
|
317 |
|
318 RSemaphore clientSem; |
|
319 error = clientSem.OpenGlobal( KDRMEngCommonSemaphore ); |
|
320 if( error ) |
|
321 { |
|
322 return error; |
|
323 } |
|
324 error = StartNotifierServer( clientSem ); |
|
325 |
|
326 if ( error ) { |
|
327 // If errors didn't occur, signal has been sent. |
|
328 clientSem.Signal(); |
|
329 clientSem.Close(); |
|
330 } |
|
331 |
|
332 delete scheduler; |
|
333 scheduler = NULL; |
|
334 |
|
335 delete trap; |
|
336 trap = NULL; |
|
337 |
|
338 // __ASSERT_ALWAYS( !error, User::Invariant() ); |
|
339 |
|
340 return KErrNone; |
|
341 } |
|
342 |
|
343 // End of File |