|
1 /* |
|
2 * Copyright (c) 2009 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: Definitions for the class CATStorageServer. Includes also the |
|
15 * entry point of the atoolstorageserver.exe executable. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #include "atstorageserver.h" |
|
25 #include "atstorageserversession.h" |
|
26 #include "atstorageservercommon.h" |
|
27 #include "atlog.h" |
|
28 #include "atdynprocessinfo.h" |
|
29 |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 |
|
34 // The amount of different ranges of requests specified for this policy server. |
|
35 // In a policy server, different actions can be determined for different ranges |
|
36 // of requests. |
|
37 const TUint8 KAmountOfRanges = 2; |
|
38 |
|
39 |
|
40 const TInt ranges[KAmountOfRanges] = |
|
41 { |
|
42 CATStorageServer::EProcessStarted, |
|
43 CATStorageServer::EOutOfBounds |
|
44 }; |
|
45 |
|
46 |
|
47 const TUint8 actionForRange[ KAmountOfRanges ] = |
|
48 { 0, CPolicyServer::ENotSupported }; |
|
49 |
|
50 |
|
51 const CPolicyServer::TPolicyElement elements[] = |
|
52 { |
|
53 |
|
54 { _INIT_SECURITY_POLICY_C1( ECapability_None ), |
|
55 CPolicyServer::EFailClient } |
|
56 |
|
57 }; |
|
58 |
|
59 |
|
60 const CPolicyServer::TPolicy policy = |
|
61 { |
|
62 CPolicyServer::EAlwaysPass, // On connect |
|
63 KAmountOfRanges, // Range count |
|
64 ranges, |
|
65 actionForRange, |
|
66 elements, |
|
67 }; |
|
68 |
|
69 |
|
70 |
|
71 // ENTRY POINT |
|
72 |
|
73 TInt E32Main() |
|
74 { |
|
75 LOGSTR1( "STSE TInt E32Main() in ATStorageServer.cpp" ); |
|
76 |
|
77 __UHEAP_MARK; |
|
78 |
|
79 // Create a cleanup stack |
|
80 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
81 |
|
82 TInt errorCode( KErrNoMemory ); |
|
83 |
|
84 // If there was enough memory to create a cleanup stack, |
|
85 // create and start the server. |
|
86 if( cleanup ) |
|
87 { |
|
88 // If RunServerL() doesn't leave, errorCode will be set to KErrNone |
|
89 TRAP( errorCode, CATStorageServer::RunServerL() ); |
|
90 delete cleanup; |
|
91 } |
|
92 |
|
93 // Signal the client that server creation failed, if a leave occured during |
|
94 // the call to 'RunServerL()' function |
|
95 if( errorCode != KErrNone ) |
|
96 { |
|
97 RProcess::Rendezvous( errorCode ); |
|
98 } |
|
99 |
|
100 __UHEAP_MARKEND; |
|
101 |
|
102 return errorCode; |
|
103 |
|
104 } |
|
105 |
|
106 |
|
107 // ============================ MEMBER FUNCTIONS =============================== |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CATStorageServer::CATStorageServer |
|
111 // C++ default constructor can NOT contain any code that |
|
112 // might leave. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CATStorageServer::CATStorageServer( TInt aPriority ) : |
|
116 CPolicyServer( aPriority, policy, ESharableSessions ), |
|
117 iSessionCount( 0 ) |
|
118 { |
|
119 LOGSTR1( "STSE CATStorageServer::CATStorageServer()" ); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CATStorageServer::ConstructL |
|
124 // Symbian 2nd phase constructor can leave. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CATStorageServer::ConstructL() |
|
128 { |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CATStorageServer::NewL |
|
133 // Two-phased constructor. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 CATStorageServer* CATStorageServer::NewL() |
|
137 { |
|
138 CATStorageServer* self = NewLC(); |
|
139 CleanupStack::Pop( self ); |
|
140 |
|
141 return self; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CATStorageServer::NewLC |
|
146 // Two-phased constructor. |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 CATStorageServer* CATStorageServer::NewLC() |
|
150 { |
|
151 CATStorageServer* self = new ( ELeave ) CATStorageServer( EPriorityStandard ); |
|
152 CleanupStack::PushL( self ); |
|
153 self->ConstructL(); |
|
154 self->StartL( KStorageServerName ); |
|
155 return self; |
|
156 } |
|
157 |
|
158 // Destructor |
|
159 CATStorageServer::~CATStorageServer() |
|
160 { |
|
161 LOGSTR1( "STSE CATStorageServer::~CATStorageServer()" ); |
|
162 |
|
163 iProcesses.Close(); |
|
164 iProcessesDyn.ResetAndDestroy(); |
|
165 iProcessesDyn.Close(); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CATStorageServer::NewSessionL |
|
170 // Create a new server session. |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 CSession2* CATStorageServer::NewSessionL( |
|
174 const TVersion &aVersion, |
|
175 const RMessage2& /*aMessage*/ ) const |
|
176 { |
|
177 LOGSTR1( "STSE CSession2* CATStorageServer::NewSessionL()" ); |
|
178 |
|
179 // The server's version |
|
180 TVersion version( KVersionNumberMaj, KVersionNumberMin, |
|
181 KVersionNumberBld ); |
|
182 |
|
183 // Check this is a high enough version of the server |
|
184 if ( !User::QueryVersionSupported(version, aVersion) ) |
|
185 { |
|
186 User::Leave( KErrNotSupported ); |
|
187 } |
|
188 |
|
189 // Construct and return a new session object |
|
190 return CATStorageServerSession::NewL( const_cast<CATStorageServer&>(*this) ); |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CATStorageServer::RunServerL |
|
195 // Create active scheduler and a server object |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CATStorageServer::RunServerL() |
|
199 { |
|
200 LOGSTR1( "STSE void CATStorageServer::RunServerL()" ); |
|
201 |
|
202 // Create and install an active scheduler |
|
203 CActiveScheduler* activeSched = new (ELeave) CActiveScheduler; |
|
204 CleanupStack::PushL( activeSched ); |
|
205 CActiveScheduler::Install( activeSched ); |
|
206 |
|
207 // Create server |
|
208 CATStorageServer::NewLC(); |
|
209 |
|
210 // The initialization performed alright, signal the client |
|
211 RProcess::Rendezvous( KErrNone ); |
|
212 |
|
213 // Start the active scheduler |
|
214 CActiveScheduler::Start(); |
|
215 |
|
216 // Remove the server and active scheduler from the cleanup stack |
|
217 CleanupStack::PopAndDestroy( 2, activeSched ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CATStorageServer::IncSessionCount |
|
222 // Increments the count of active sessions for this server. |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CATStorageServer::IncSessionCount() |
|
226 { |
|
227 LOGSTR1( "STSE void CATStorageServer::IncSessionCount()" ); |
|
228 |
|
229 iSessionCount++; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CATStorageServer::DecSessionCount |
|
234 // Decrements the count of active sessions for this server. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CATStorageServer::DecSessionCount() |
|
238 { |
|
239 LOGSTR1( "STSE void CATStorageServer::DecSessionCount()" ); |
|
240 |
|
241 iSessionCount--; |
|
242 |
|
243 // Cancels all outstanding messages and stops the active scheduler, |
|
244 // if there are no other sessions open at the moment |
|
245 if ( iSessionCount <= 0 ) |
|
246 { |
|
247 this->Cancel(); |
|
248 CActiveScheduler::Stop(); |
|
249 } |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CATStorageServer::AddProcessL |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CATStorageServer::AddProcessL( const TDesC8& aProcessName, |
|
257 TUint aProcessId, |
|
258 CATStorageServerSession* aSessionObject, |
|
259 const TInt64& aStartTime ) |
|
260 { |
|
261 LOGSTR1( "STSE TInt CATStorageServer::AddProcessL()" ); |
|
262 |
|
263 TInt error( KErrNone ); |
|
264 TATProcessInfo processInfo; |
|
265 |
|
266 processInfo.iProcessId = aProcessId; |
|
267 processInfo.iProcessName.Copy( aProcessName ); |
|
268 processInfo.iStartTime = aStartTime; |
|
269 |
|
270 // Insert the static process info into the iProcesses array |
|
271 error = iProcesses.InsertInUnsignedKeyOrder( processInfo ); |
|
272 |
|
273 // Return if an error occured |
|
274 if ( error != KErrNone) |
|
275 { |
|
276 return error; |
|
277 } |
|
278 |
|
279 // Construct a CATDynProcessInfo object with the given process ID and logging mode |
|
280 CATDynProcessInfo* dynProcessInfo = |
|
281 new (ELeave) CATDynProcessInfo( aProcessId, |
|
282 aSessionObject ); |
|
283 |
|
284 // Insert the dynamic process info into the iProcessesDyn array |
|
285 TLinearOrder<CATDynProcessInfo> order( CATDynProcessInfo::Compare ); |
|
286 error = iProcessesDyn.InsertInOrder( dynProcessInfo, order ); |
|
287 |
|
288 return error; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CATStorageServer::RemoveProcessL |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CATStorageServer::RemoveProcessL( TUint aProcessId ) |
|
296 { |
|
297 LOGSTR1( "STSE TInt CATStorageServer::RemoveProcessL()" ); |
|
298 |
|
299 TATProcessInfo processInfo; |
|
300 processInfo.iProcessId = aProcessId; |
|
301 |
|
302 TInt index = iProcesses.FindInUnsignedKeyOrder( processInfo ); |
|
303 |
|
304 // Return, if a process with the requested process ID was not found |
|
305 if ( index == KErrNotFound ) |
|
306 { |
|
307 return index; |
|
308 } |
|
309 |
|
310 // Remove the TATProcessInfo object at "index" from the array |
|
311 iProcesses.Remove( index ); |
|
312 |
|
313 // Now, start removing the associated dynamic process info object |
|
314 |
|
315 // Construct a CATDynProcessInfo object with the given process ID |
|
316 CATDynProcessInfo* dynProcessInfo = |
|
317 new (ELeave) CATDynProcessInfo( aProcessId ); |
|
318 |
|
319 // Find the index of a CATDynProcessInfo object with the given ID in the array |
|
320 TLinearOrder<CATDynProcessInfo> order( CATDynProcessInfo::Compare ); |
|
321 index = iProcessesDyn.FindInOrder( dynProcessInfo, order ); |
|
322 delete dynProcessInfo; |
|
323 dynProcessInfo = NULL; |
|
324 |
|
325 // Return, if a process with the requested process ID was not found |
|
326 if ( index == KErrNotFound ) |
|
327 { |
|
328 return index; |
|
329 } |
|
330 |
|
331 // Otherwise, delete the object and remove the pointer at "index" |
|
332 delete iProcessesDyn[index]; |
|
333 iProcessesDyn.Remove( index ); |
|
334 |
|
335 return KErrNone; |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CATStorageServer::AddDllL |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 TInt CATStorageServer::AddDllL( TUint aProcessId, |
|
343 const TATDllInfo aDllInfo ) |
|
344 { |
|
345 LOGSTR1( "STSE TInt CATStorageServer::AddDllL()" ); |
|
346 |
|
347 // Construct a CATDynProcessInfo object with the given process ID |
|
348 CATDynProcessInfo* dynProcessInfo = |
|
349 new (ELeave) CATDynProcessInfo( aProcessId ); |
|
350 |
|
351 // Find out if a process with this ID can be found in the dynamic process array |
|
352 TLinearOrder<CATDynProcessInfo> order( CATDynProcessInfo::Compare ); |
|
353 TInt index = iProcessesDyn.FindInOrder( dynProcessInfo, order ); |
|
354 delete dynProcessInfo; |
|
355 dynProcessInfo = NULL; |
|
356 |
|
357 // Return, if a process with the requested process ID was not found |
|
358 if ( index == KErrNotFound ) |
|
359 { |
|
360 return index; |
|
361 } |
|
362 |
|
363 // If we are here, the wanted process was found at index => append a DLL for it |
|
364 dynProcessInfo = iProcessesDyn[index]; |
|
365 |
|
366 // Get the DLL array from this dynamic process info object |
|
367 RArray<TATDllInfo>& dllArray = dynProcessInfo->iDlls; |
|
368 |
|
369 // Let's see if the DLL to be added already exists |
|
370 TIdentityRelation<TATDllInfo> matcher( TATDllInfo::Match ); |
|
371 index = dllArray.Find( aDllInfo, matcher ); |
|
372 |
|
373 // If so, return KErrAlreadyExists |
|
374 if ( index != KErrNotFound ) |
|
375 { |
|
376 return KErrAlreadyExists; |
|
377 } |
|
378 |
|
379 // Otherwise append this DLL to the array and return |
|
380 return dynProcessInfo->iDlls.Append( aDllInfo ); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CATStorageServer::RemoveDllL |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 TInt CATStorageServer::RemoveDllL( TUint aProcessId, |
|
388 const TDesC8& aDllName ) |
|
389 { |
|
390 LOGSTR1( "STSE TInt CATStorageServer::RemoveDllL()" ); |
|
391 |
|
392 // Construct a CATDynProcessInfo object with the given process ID |
|
393 CATDynProcessInfo* dynProcessInfo = |
|
394 new (ELeave) CATDynProcessInfo( aProcessId ); |
|
395 |
|
396 // Find out if a process with this ID can be found in the dynamic process array |
|
397 TLinearOrder<CATDynProcessInfo> order( CATDynProcessInfo::Compare ); |
|
398 TInt index = iProcessesDyn.FindInOrder( dynProcessInfo, order ); |
|
399 delete dynProcessInfo; |
|
400 dynProcessInfo = NULL; |
|
401 |
|
402 // Return, if a process with the requested process ID was not found |
|
403 if ( index == KErrNotFound ) |
|
404 { |
|
405 return index; |
|
406 } |
|
407 |
|
408 // If we are here, the wanted process was found at index |
|
409 dynProcessInfo = iProcessesDyn[index]; |
|
410 |
|
411 // Get the DLL array from this dynamic process info object |
|
412 RArray<TATDllInfo>& dllArray = dynProcessInfo->iDlls; |
|
413 |
|
414 // Try to find wanted DLL |
|
415 TIdentityRelation<TATDllInfo> matcher( TATDllInfo::Match ); |
|
416 index = dllArray.Find( TATDllInfo( 0, 0, 0, aDllName ), matcher ); |
|
417 |
|
418 // Return, if a process with the requested process ID was not found |
|
419 if ( index == KErrNotFound ) |
|
420 { |
|
421 return index; |
|
422 } |
|
423 |
|
424 // Otherwise remove the found DLL at "index" |
|
425 dllArray.Remove( index ); |
|
426 |
|
427 return KErrNone; |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CATStorageServer::ProcessInfoArray |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 const RArray<TATProcessInfo>& CATStorageServer::ProcessInfoArray() |
|
435 { |
|
436 LOGSTR1( "STSE RArray<TATProcessInfo>& CATStorageServer::ProcessInfoArray()" ); |
|
437 |
|
438 return iProcesses; |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CATStorageServer::DynProcessInfoArray |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 const RPointerArray<CATDynProcessInfo>& CATStorageServer::DynProcessInfoArray() |
|
446 { |
|
447 LOGSTR1( "STSE RPointerArray<CATDynProcessInfo>& CATStorageServer::DynProcessInfoArray()" ); |
|
448 |
|
449 return iProcessesDyn; |
|
450 } |
|
451 |
|
452 // End of File |