|
1 /* |
|
2 * Copyright (c) 2002 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 class CPEngStorageServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 #include <e32svr.h> |
|
21 #include <badesca.h> |
|
22 #include <s32mem.h> |
|
23 |
|
24 |
|
25 #include "CPEngStorageServer.h" |
|
26 #include "CPEngStorageSession.h" |
|
27 #include "CPEngStorageFolder.h" |
|
28 #include "PEngStorageServerCommon.h" |
|
29 #include "TPEngServerParams.h" |
|
30 #include "CPEngHandlerListenEvents.h" |
|
31 #include "PEngInternalGlobalConsts.h" |
|
32 #include "CPEngTimer.h" |
|
33 #include "CPEngActiveScheduler.h" |
|
34 |
|
35 // Session Slot utility |
|
36 #include "CPEngSessionSlotId.h" |
|
37 #include "CPEngSessionSlotState.h" |
|
38 #include "CPEngSessionSlotEvent.h" |
|
39 #include "RObjectArray.h" |
|
40 |
|
41 // Hash Tool |
|
42 #include "PEngHashTool.h" |
|
43 |
|
44 // Debug Prints |
|
45 #include "PresenceDebugPrint.h" |
|
46 |
|
47 |
|
48 // CONSTANTS |
|
49 |
|
50 // Init size of the buffer for client server communications |
|
51 static const TInt KBufferInitSize = 100; |
|
52 |
|
53 // Static data for Capability check configuration |
|
54 static const TInt KPEngStoreServRangeCount = 2; |
|
55 |
|
56 /** |
|
57 * Ranges for the Request values |
|
58 * All requests will fall in one range |
|
59 */ |
|
60 static const TInt PEngStoreServRanges[ KPEngStoreServRangeCount ] = |
|
61 { |
|
62 // Range from EMainSessShutdownServer to EFolderSubSessNotifyChangedSIDs |
|
63 0, |
|
64 |
|
65 // range is from EHighestStoreServerRequest request to KMaxInt |
|
66 EHighestStoreServerRequest |
|
67 }; |
|
68 |
|
69 /** |
|
70 * Element indexes for the defined ranges |
|
71 * we have only one range and for it is defined only one Element |
|
72 */ |
|
73 static const TUint8 KPEngStoreServElementsIndex[ KPEngStoreServRangeCount ] = |
|
74 { |
|
75 // First element in the element array will be applied for this range |
|
76 0, |
|
77 // Not supported will be applied for this range |
|
78 CPolicyServer::ENotSupported |
|
79 }; |
|
80 |
|
81 // Policy elements |
|
82 static const CPolicyServer::TPolicyElement KPEngStoreServElements[] = |
|
83 { |
|
84 { |
|
85 _INIT_SECURITY_POLICY_C2( ECapabilityReadUserData, |
|
86 ECapabilityWriteUserData ), |
|
87 CPolicyServer::EFailClient |
|
88 } |
|
89 }; |
|
90 |
|
91 static const CPolicyServer::TPolicy KPEngServerPolicy = |
|
92 { |
|
93 // The index into Elements,that is used to check a connection attempt |
|
94 |
|
95 0, |
|
96 |
|
97 // Number of ranges in the iRanges array |
|
98 KPEngStoreServRangeCount, |
|
99 |
|
100 // A pointer to an array of ordered ranges of request numbers |
|
101 PEngStoreServRanges, |
|
102 |
|
103 // A pointer to an array of TUint8 values specifying |
|
104 // the appropriate action to take for each range in iRanges |
|
105 KPEngStoreServElementsIndex, |
|
106 |
|
107 // A pointer to an array of distinct policy elements |
|
108 KPEngStoreServElements |
|
109 }; |
|
110 |
|
111 // MACROS |
|
112 #define RETURN_IF_ERROR( aError )\ |
|
113 if( aError != KErrNone )\ |
|
114 {\ |
|
115 return aError;\ |
|
116 } |
|
117 |
|
118 |
|
119 // ============================ MEMBER FUNCTIONS =============================== |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CPEngStorageServer::CPEngStorageServer |
|
123 // C++ default constructor can NOT contain any code, that might leave. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CPEngStorageServer::CPEngStorageServer( TInt aPriority ) |
|
127 : CPolicyServer( aPriority, KPEngServerPolicy ), |
|
128 iRunning( EFalse ) |
|
129 { |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CPEngStorageServer::ConstructL |
|
134 // Symbian 2nd phase constructor can leave. |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CPEngStorageServer::ConstructL() |
|
138 { |
|
139 StartL( KStorageServerName ); |
|
140 iBuff16.CreateL( KBufferInitSize ); |
|
141 iBuff8.CreateL( KBufferInitSize ); |
|
142 // create container collection |
|
143 iContainerIx = CObjectConIx::NewL(); |
|
144 iSubSessionCnt = iContainerIx->CreateL(); |
|
145 iFoldersCnt = iContainerIx->CreateL(); |
|
146 iObserversCnt = iContainerIx->CreateL(); |
|
147 |
|
148 // set up file system enviroment |
|
149 User::LeaveIfError( iFs.Connect() );// connect to file server |
|
150 // set session to the private folder |
|
151 TInt err( iFs.CreatePrivatePath( EDriveC ) ); |
|
152 if ( err != KErrAlreadyExists ) |
|
153 { |
|
154 User::LeaveIfError( err ); |
|
155 } |
|
156 User::LeaveIfError( iFs.SetSessionToPrivate( EDriveC ) ); |
|
157 TFileName name; |
|
158 iFs.SessionPath( name ); |
|
159 name.Append( KPEngStorageTempFolder ); |
|
160 iTempFolder = name.AllocL(); |
|
161 |
|
162 // make sure we have Storage folder, flush it first and then created |
|
163 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
164 CleanupStack::PushL( fileMan ); |
|
165 fileMan->RmDir( *iTempFolder ); |
|
166 // ignore errors |
|
167 iFs.Delete( *iTempFolder ); |
|
168 CleanupStack::PopAndDestroy(); // fileMan |
|
169 // try to create temp folder |
|
170 TInt er ( iFs.MkDirAll( *iTempFolder ) ); |
|
171 if ( er != KErrAlreadyExists ) |
|
172 { |
|
173 User::LeaveIfError( er ); |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CPEngStorageServer::NewLC |
|
180 // Two-phased constructor. |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 CPEngStorageServer* CPEngStorageServer::NewL( TInt aPriority ) |
|
184 { |
|
185 CPEngStorageServer* self = CPEngStorageServer::NewLC( aPriority ); |
|
186 CleanupStack::Pop(); |
|
187 |
|
188 return self; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CPEngStorageServer::NewLC |
|
193 // Two-phased constructor. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 CPEngStorageServer* CPEngStorageServer::NewLC( TInt aPriority ) |
|
197 { |
|
198 CPEngStorageServer* self = new( ELeave ) CPEngStorageServer( aPriority ); |
|
199 CleanupStack::PushL( self ); |
|
200 self->ConstructL(); |
|
201 return self; |
|
202 } |
|
203 |
|
204 // Destructor (virtual by CBase) |
|
205 CPEngStorageServer::~CPEngStorageServer() |
|
206 { |
|
207 // clean all containers from the objects in it |
|
208 // close all elements of the array |
|
209 if ( iFoldersCnt ) |
|
210 { |
|
211 for ( TInt x( iFoldersCnt->Count() - 1 ) ; x >= 0 ; --x ) |
|
212 { |
|
213 ( *iFoldersCnt )[ x ]->Close(); |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 // close all elements of the array |
|
219 if ( iObserversCnt ) |
|
220 { |
|
221 for ( TInt y( iObserversCnt->Count() - 1 ) ; y >= 0 ; --y ) |
|
222 { |
|
223 ( *iObserversCnt )[ y ]->Close(); |
|
224 } |
|
225 } |
|
226 |
|
227 // all containers are deleted with the collection |
|
228 delete iContainerIx; |
|
229 // clean file enviroment |
|
230 iFs.Close(); |
|
231 delete iTempFolder; |
|
232 // shut down plugin server |
|
233 delete iTimeOut; |
|
234 iBuff16.Close(); |
|
235 iBuff8.Close(); |
|
236 } |
|
237 |
|
238 |
|
239 // ============================================================================= |
|
240 // =============== Functions from base class =================================== |
|
241 // ============================================================================= |
|
242 |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CPEngStorageServer::ExecuteServerL() |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TInt CPEngStorageServer::ExecuteServerL( TPEngServerParams& aParams ) |
|
249 { |
|
250 //Renaming must be done as early as possible |
|
251 aParams.RenameMainThread( KStorageServerName ); |
|
252 |
|
253 TInt res( KErrNone ); |
|
254 |
|
255 // start scheduler and server |
|
256 CPEngActiveScheduler* pA = new( ELeave )CPEngActiveScheduler; |
|
257 CleanupStack::PushL( pA ); |
|
258 CPEngActiveScheduler::Install( pA ); |
|
259 |
|
260 //If exe server, call RunServerL directly. |
|
261 TRAP( res, RunServerL( aParams ) ); |
|
262 |
|
263 CPEngActiveScheduler::Install( NULL ); |
|
264 CleanupStack::PopAndDestroy();//pA |
|
265 return res; |
|
266 } |
|
267 |
|
268 |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CPEngStorageServer::StopServer() |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CPEngStorageServer::StopServer() |
|
275 { |
|
276 if ( iRunning ) |
|
277 { |
|
278 CPEngActiveScheduler::Stop(); |
|
279 } |
|
280 iRunning = EFalse; |
|
281 } |
|
282 |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPEngStorageServer::RunServerL() |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CPEngStorageServer::RunServerL( TPEngServerParams& aParams ) |
|
290 { |
|
291 PENG_DP( D_PENG_LIT( "CPEngStorageServer::RunServerL()" ) ); |
|
292 |
|
293 //One instance of server must be allocated here. |
|
294 CPEngStorageServer* server = CPEngStorageServer::NewLC( KServerPriority ); |
|
295 |
|
296 //must die if can't signal client |
|
297 aParams.Signal(); |
|
298 // start fielding requests from clients |
|
299 //Thread is ended when CPEngActiveScheduler::Stop is called. |
|
300 server->StartServer(); |
|
301 |
|
302 |
|
303 CleanupStack::PopAndDestroy();//server |
|
304 // finished |
|
305 } |
|
306 |
|
307 |
|
308 // ============================================================================= |
|
309 // =============== Functions from the MPEngStorageServer class ================= |
|
310 // ============================================================================= |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CPEngStorageServer::AddSubSessionL() |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CPEngStorageServer::AddSubSessionL( |
|
317 CObject& aSubSession ) |
|
318 { |
|
319 iSubSessionCnt->AddL( &aSubSession ); |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CPEngStorageServer::RemoveSubSessionL() |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CPEngStorageServer::RemoveSubSessionL( |
|
327 CObject& aSubSession ) |
|
328 { |
|
329 iSubSessionCnt->Remove( & aSubSession ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CPEngStorageServer::RegisterGlobEventListenerL() |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CPEngStorageServer::RegisterGlobEventListenerL( |
|
337 const RPEngMessage& /* aMessage */, |
|
338 TUint32 aSessionId ) |
|
339 { |
|
340 CPEngHandlerListenEvents* reqHandler = FindRequestHandler( aSessionId , |
|
341 EMainSessListenGlobalEvents ); |
|
342 if ( reqHandler ) |
|
343 { |
|
344 // this handler already exists, not allowed by multiple |
|
345 User::Leave( KErrAlreadyExists ); |
|
346 } |
|
347 // create new handler |
|
348 reqHandler = CPEngHandlerListenEvents::NewLC( aSessionId ); |
|
349 iObserversCnt->AddL( reqHandler ); |
|
350 CleanupStack::Pop(); // newHandler |
|
351 } |
|
352 |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CPEngStorageServer::CancelRequestL() |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 void CPEngStorageServer::CancelRequestL( |
|
359 const RPEngMessage& aMessage, |
|
360 TUint32 aSessionId ) |
|
361 { |
|
362 CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, |
|
363 static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) ); |
|
364 // ignore if such a request does not exists |
|
365 if ( reqHandler ) |
|
366 { |
|
367 reqHandler->CancelRequestD(); |
|
368 } |
|
369 } |
|
370 |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CPEngStorageServer::CancelRequestL() |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CPEngStorageServer::CancelAllSessionRequests( |
|
377 TUint32 aSessionId ) |
|
378 { |
|
379 for ( TInt x( iObserversCnt->Count() - 1 ) ; x >= 0 ; --x ) |
|
380 { |
|
381 CPEngRequestHandler* handler = static_cast<CPEngRequestHandler*>( ( *iObserversCnt )[ x ] ); |
|
382 if ( handler->SessionId() == aSessionId ) |
|
383 { |
|
384 handler->CancelRequestD(); |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CPEngStorageServer::ReloadAsynchronousScoutL() |
|
391 // Reload Asynchronous scout of the async observer |
|
392 // (other items were commented in a header). |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 void CPEngStorageServer::ReloadAsynchronousScoutL( |
|
396 const RPEngMessage& aMessage, |
|
397 TUint32 aSessionId ) |
|
398 { |
|
399 CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, |
|
400 static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) ); |
|
401 if ( !reqHandler ) |
|
402 { |
|
403 // there is not such a request to be reloaded |
|
404 User::Leave( KErrArgument ); |
|
405 } |
|
406 reqHandler->ReloadScoutWithNewMessageL( aMessage ); |
|
407 } |
|
408 |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CPEngStorageServer::CreateSessionFolderL() |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 void CPEngStorageServer::CreateSessionFolderL( |
|
415 const RPEngMessage& aMessage ) |
|
416 { |
|
417 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
418 CPEngSessionSlotState* state = NULL; |
|
419 CPEngStorageFolder* folder = NULL; |
|
420 HBufC* stateFile = NULL; |
|
421 // load state |
|
422 TInt cleanUp ( LoadSessionStateLCX( *sessId, ETrue, |
|
423 state, folder, stateFile ) ); |
|
424 |
|
425 // update state with the new application ID |
|
426 aMessage.ReadOneDescriptorL( KMessageSlot1, iBuff16 ); |
|
427 |
|
428 // also create session slot global event for notification |
|
429 CPEngSessionSlotEvent* globEvent = PackGlobEventLC( *state, |
|
430 EPEngEventNWSessionSlotCreated, |
|
431 iBuff16 ); |
|
432 |
|
433 TPtr stateFileName( stateFile->Des() ); |
|
434 UpdateSessionSltStateL( folder, *state, *globEvent, stateFileName ); |
|
435 |
|
436 // notify about event |
|
437 globEvent->PackEventL( iBuff8 ); |
|
438 NotifyGlobalEvent( iBuff8 ); |
|
439 |
|
440 // clean globEvent, (state), stateFile, sessId |
|
441 CleanupStack::PopAndDestroy( 2 + cleanUp ); |
|
442 } |
|
443 |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // CPEngStorageServer::RemoveSessionFolderL() |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 void CPEngStorageServer::RemoveSessionFolderL( |
|
450 const RPEngMessage& aMessage ) |
|
451 { |
|
452 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
453 CPEngSessionSlotState* state = NULL; |
|
454 CPEngStorageFolder* folder = NULL; |
|
455 HBufC* stateFile = NULL; |
|
456 // load state |
|
457 TInt cleanUp ( LoadSessionStateLCX( *sessId, |
|
458 EFalse, |
|
459 state, |
|
460 folder, |
|
461 stateFile ) ); |
|
462 |
|
463 if ( folder ) |
|
464 { |
|
465 // folder is active, refuse any deletion |
|
466 User::Leave( KErrInUse ); |
|
467 } |
|
468 // remove registered ID from the session |
|
469 aMessage.ReadOneDescriptorL( KMessageSlot1, iBuff16 ); |
|
470 |
|
471 // also create session slot global event for notification |
|
472 CPEngSessionSlotEvent* globEvent = PackGlobEventLC( |
|
473 *state, |
|
474 EPEngEventNWSessionSlotRemoved, |
|
475 iBuff16 ); |
|
476 |
|
477 TPtr stateFileName( stateFile->Des() ); |
|
478 UpdateSessionSltStateL( folder, *state, *globEvent, stateFileName ); |
|
479 |
|
480 // notify about event |
|
481 globEvent->PackEventL( iBuff8 ); |
|
482 NotifyGlobalEvent( iBuff8 ); |
|
483 |
|
484 // clean globEvent, (state), stateFile, sessId |
|
485 CleanupStack::PopAndDestroy( 2 + cleanUp ); |
|
486 } |
|
487 |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CPEngStorageServer::SessionStateL() |
|
491 // ----------------------------------------------------------------------------- |
|
492 // |
|
493 void CPEngStorageServer::SessionStateL( |
|
494 const RPEngMessage& aMessage ) |
|
495 { |
|
496 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
497 CPEngStorageFolder* folder = FindStorageFolder( *sessId ); |
|
498 CPEngSessionSlotState* state = NULL; |
|
499 if ( folder ) |
|
500 { |
|
501 state = &( folder->SessionSlotState() ); |
|
502 } |
|
503 else |
|
504 { |
|
505 HBufC* stateFile = NULL; |
|
506 state = ReadSessionStatePermanentLC( *sessId, stateFile ); |
|
507 } |
|
508 |
|
509 state->PackDataL( EPureState, iBuff8 ); |
|
510 |
|
511 TInt err( aMessage.WriteOneDescriptor( KMessageSlot1, iBuff8 ) ); |
|
512 if ( err == KErrOverflow ) |
|
513 { |
|
514 User::Leave( iBuff8.Length() ); |
|
515 } |
|
516 User::LeaveIfError( err ); |
|
517 |
|
518 if ( !folder ) |
|
519 { |
|
520 CleanupStack::PopAndDestroy( 2 ); // state, stateFile |
|
521 } |
|
522 CleanupStack::PopAndDestroy(); // sessId |
|
523 } |
|
524 |
|
525 |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CPEngStorageServer::AllSessionStatesL() |
|
529 // ----------------------------------------------------------------------------- |
|
530 // |
|
531 void CPEngStorageServer::AllSessionStatesL( |
|
532 const RPEngMessage& aMessage ) |
|
533 { |
|
534 // pack all states to one big buffer |
|
535 // this takes all active folders and adds sessions not active |
|
536 CDir* dirList = NULL; |
|
537 TFileName dir; |
|
538 User::LeaveIfError( iFs.PrivatePath( dir ) ); |
|
539 // insert drive leter on the beginning |
|
540 dir.Insert( 0, KPEngStorageDrive ); |
|
541 |
|
542 User::LeaveIfError( iFs.GetDir( dir, |
|
543 KEntryAttNormal, |
|
544 ESortByName, |
|
545 dirList ) ); |
|
546 CleanupStack::PushL( dirList ); |
|
547 TInt count( dirList->Count() ); |
|
548 RObjectArray<CPEngSessionSlotState> states; |
|
549 CleanupClosePushL( states ); |
|
550 // 4 for the count of the states |
|
551 TInt size( 4 ); |
|
552 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
553 { |
|
554 const TEntry& entry = ( *dirList )[ x ]; |
|
555 if ( ! entry.IsDir() ) |
|
556 { |
|
557 CPEngSessionSlotState* state = CPEngSessionSlotState::NewLC(); |
|
558 ReadFileL( entry.iName, iBuff8 ); |
|
559 state->UnpackDataL( iBuff8, EPermanentData ); |
|
560 states.AppendL( state ); |
|
561 size += state->Size( EPermanentData ); |
|
562 CleanupStack::Pop(); // state |
|
563 } |
|
564 } |
|
565 // now go through all session and if they are loaded as folders |
|
566 // and pack them to the buffer |
|
567 // get buffer for transfer |
|
568 CBufFlat* buf = CBufFlat::NewL( size ); |
|
569 CleanupStack::PushL( buf ); |
|
570 RBufWriteStream ws; |
|
571 CleanupClosePushL( ws ); |
|
572 ws.Open( *buf ); // CSI: 65 # |
|
573 |
|
574 // write count of all sessions |
|
575 count = states.Count(); |
|
576 ws.WriteInt32L( count ); |
|
577 |
|
578 for ( TInt i( 0 ) ; i < count ; i++ ) |
|
579 { |
|
580 CPEngStorageFolder* folder = FindStorageFolder( |
|
581 states[ i ]->SessionSlotId() ); |
|
582 if ( folder ) |
|
583 { |
|
584 // there is loaded folder, take state from there |
|
585 folder->SessionSlotState().ExternalizeL( ws, EWholeState ); |
|
586 } |
|
587 else |
|
588 { |
|
589 states[ i ]->ExternalizeL( ws, EWholeState ); |
|
590 } |
|
591 } |
|
592 // write data to the client side |
|
593 TInt err( aMessage.WriteOneDescriptor( KMessageSlot0, buf->Ptr( 0 ) ) ); |
|
594 if ( err == KErrOverflow ) |
|
595 { |
|
596 User::Leave( buf->Ptr( 0 ).Length() ); |
|
597 } |
|
598 User::LeaveIfError( err ); |
|
599 CleanupStack::PopAndDestroy( 4 ); // ws, buf, states, dirList, |
|
600 } |
|
601 |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CPEngStorageServer::StorageFolderL() |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 CPEngStorageFolder* CPEngStorageServer::StorageFolderL( |
|
608 const RPEngMessage& aMessage ) |
|
609 { |
|
610 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
611 CPEngStorageFolder* folder = LoadStorageFolderL( *sessId ); |
|
612 CleanupStack::PopAndDestroy(); // sessId |
|
613 return folder; |
|
614 } |
|
615 |
|
616 |
|
617 // ----------------------------------------------------------------------------- |
|
618 // CPEngStorageServer::NotifyGlobalEvent() |
|
619 // ----------------------------------------------------------------------------- |
|
620 // |
|
621 void CPEngStorageServer::NotifyGlobalEvent( |
|
622 const TDesC8& aGlobalEvent ) |
|
623 { |
|
624 // better to go through array from end |
|
625 for ( TInt x( iObserversCnt->Count() - 1 ) ; x >= 0 ; x-- ) |
|
626 { |
|
627 CPEngHandlerListenEvents* handler = |
|
628 static_cast<CPEngHandlerListenEvents*>( ( *iObserversCnt )[ x ] ); |
|
629 handler->NotifyEvent( aGlobalEvent ); |
|
630 } |
|
631 } |
|
632 |
|
633 |
|
634 // ----------------------------------------------------------------------------- |
|
635 // CPEngStorageServer::NotifyError() |
|
636 // ----------------------------------------------------------------------------- |
|
637 // |
|
638 void CPEngStorageServer::NotifyError( |
|
639 TInt aError ) |
|
640 { |
|
641 // better to go through array from end |
|
642 for ( TInt x( iObserversCnt->Count() - 1 ) ; x >= 0 ; x-- ) |
|
643 { |
|
644 CPEngHandlerListenEvents* handler = |
|
645 static_cast<CPEngHandlerListenEvents*>( ( *iObserversCnt )[ x ] ); |
|
646 handler->NotifyError( aError ); |
|
647 } |
|
648 } |
|
649 |
|
650 |
|
651 // ----------------------------------------------------------------------------- |
|
652 // CPEngStorageServer::IsAppIdRegisteredL() |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 void CPEngStorageServer::IsAppIdRegisteredL( |
|
656 const RPEngMessage& aMessage ) |
|
657 { |
|
658 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
659 aMessage.ReadOneDescriptorL( KMessageSlot1, iBuff16 ); |
|
660 |
|
661 CPEngSessionSlotState* state = NULL; |
|
662 CPEngStorageFolder* folder = NULL; |
|
663 HBufC* stateFile = NULL; |
|
664 // load state |
|
665 TInt cleanUp ( LoadSessionStateLCX( *sessId, ETrue, |
|
666 state, folder, stateFile ) ); |
|
667 // check if appId is registered |
|
668 state->ApplicationRegisteredL( iBuff16 ); |
|
669 // clean (state),stateFile,appId,sessId |
|
670 CleanupStack::PopAndDestroy( cleanUp + 2 ); |
|
671 } |
|
672 |
|
673 |
|
674 // ----------------------------------------------------------------------------- |
|
675 // CPEngStorageServer::BackUpActive() |
|
676 // ----------------------------------------------------------------------------- |
|
677 // |
|
678 TBool CPEngStorageServer::BackUpActive() |
|
679 { |
|
680 return iBackUpActive; |
|
681 } |
|
682 |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CPEngStorageServer::WipeSessionSlotFolderL() |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 void CPEngStorageServer::WipeSessionSlotFolderL( |
|
689 const RPEngMessage& aMessage ) |
|
690 { |
|
691 CPEngSessionSlotId* sessId = TranslateSessionIdLC( aMessage ); |
|
692 CPEngSessionSlotState* state = NULL; |
|
693 CPEngStorageFolder* folder = NULL; |
|
694 HBufC* stateFile = NULL; |
|
695 // load state |
|
696 TInt cleanUp ( LoadSessionStateLCX( *sessId, |
|
697 EFalse, |
|
698 state, |
|
699 folder, |
|
700 stateFile ) ); |
|
701 |
|
702 if ( folder ) |
|
703 { |
|
704 // folder is active, refuse any deletion |
|
705 User::Leave( KErrInUse ); |
|
706 } |
|
707 |
|
708 TPtr stateFileName( stateFile->Des() ); |
|
709 User::LeaveIfError( CleanStorageFromSessionL( stateFileName ) ); |
|
710 |
|
711 // clean globEvent, (state), stateFile, sessId |
|
712 CleanupStack::PopAndDestroy( 1 + cleanUp ); |
|
713 } |
|
714 |
|
715 |
|
716 // ============================================================================= |
|
717 // ======== New function of the CPEngStorageServer ===================== |
|
718 // ============================================================================= |
|
719 |
|
720 |
|
721 // ----------------------------------------------------------------------------- |
|
722 // CPEngStorageServer::SessionCreated() |
|
723 // Session has been created |
|
724 // (other items were commented in a header). |
|
725 // ----------------------------------------------------------------------------- |
|
726 // |
|
727 void CPEngStorageServer::SessionCreated() |
|
728 { |
|
729 iSessCount++; |
|
730 } |
|
731 |
|
732 |
|
733 // ----------------------------------------------------------------------------- |
|
734 // CPEngStorageServer::SessionDied() |
|
735 // ----------------------------------------------------------------------------- |
|
736 // |
|
737 void CPEngStorageServer::SessionDied() |
|
738 { |
|
739 iSessCount--; |
|
740 if ( iSessCount == 0 ) |
|
741 { |
|
742 // Start timer |
|
743 delete iTimeOut; |
|
744 iTimeOut = NULL; |
|
745 |
|
746 TRAP_IGNORE( |
|
747 { |
|
748 iTimeOut = CPEngTimer::NewL( *this ); |
|
749 iTimeOut->After( KServerCloseTimeOut ); |
|
750 } ); |
|
751 } |
|
752 } |
|
753 |
|
754 |
|
755 // ----------------------------------------------------------------------------- |
|
756 // CPEngStorageServer::TimeExpired() |
|
757 // ----------------------------------------------------------------------------- |
|
758 // |
|
759 void CPEngStorageServer::TimeExpired() |
|
760 { |
|
761 if ( iSessCount == 0 ) |
|
762 { |
|
763 // stop server |
|
764 StopServer(); |
|
765 } |
|
766 } |
|
767 |
|
768 |
|
769 // ============================================================================= |
|
770 // =============== Functions from the MBackupOperationObserver class =========== |
|
771 // ============================================================================= |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CPEngStorageServer::HandleBackupOperationEventL() |
|
775 // Called when a backup or restore operation either starts or ends. |
|
776 // (other items were commented in a header). |
|
777 // ----------------------------------------------------------------------------- |
|
778 // Restore is not implemented before new API won't be delivered |
|
779 /* |
|
780 void CPEngStorageServer::HandleBackupOperationEventL( |
|
781 const TBackupOperationAttributes& aBackupOperationAttributes) |
|
782 { |
|
783 } |
|
784 */ |
|
785 // ============================================================================= |
|
786 // =============== Functions from the CServer2 class =========================== |
|
787 // ============================================================================= |
|
788 |
|
789 // ----------------------------------------------------------------------------- |
|
790 // CPEngStorageServer::NewSessionL() |
|
791 // ----------------------------------------------------------------------------- |
|
792 // |
|
793 CSession2* CPEngStorageServer::NewSessionL( |
|
794 const TVersion &aVersion, |
|
795 const RMessage2& /*aMessage*/ ) const |
|
796 { |
|
797 if ( !User::QueryVersionSupported( aVersion, TVersion( |
|
798 KRequiredVersionMajor, |
|
799 KRequiredVersionMinor, |
|
800 KRequiredVersionBuild ) ) ) |
|
801 { |
|
802 User::Leave( KErrNotSupported ); |
|
803 } |
|
804 |
|
805 return CPEngStorageSession::NewL( const_cast<CPEngStorageServer&>( *this ) ); |
|
806 } |
|
807 |
|
808 |
|
809 // ============================================================================= |
|
810 // =============== New Private methods from class ============================== |
|
811 // ============================================================================= |
|
812 |
|
813 // ----------------------------------------------------------------------------- |
|
814 // CPEngStorageServer::StartServer() |
|
815 // Start Server |
|
816 // (other items were commented in a header). |
|
817 // ----------------------------------------------------------------------------- |
|
818 // |
|
819 void CPEngStorageServer::StartServer() |
|
820 { |
|
821 iRunning = ETrue; |
|
822 PENG_DP( D_PENG_LIT( "PECStorageServer::Started" ) ); |
|
823 CPEngActiveScheduler::Start(); |
|
824 PENG_DP( D_PENG_LIT( "PECStorageServer::Stopped" ) ); |
|
825 } |
|
826 |
|
827 |
|
828 // ----------------------------------------------------------------------------- |
|
829 // CPEngStorageServer::TranslateSessionIdLC() |
|
830 // Read Session ID from the client's message |
|
831 // (other items were commented in a header). |
|
832 // ----------------------------------------------------------------------------- |
|
833 // |
|
834 CPEngSessionSlotId* CPEngStorageServer::TranslateSessionIdLC( |
|
835 const RPEngMessage& aMessage ) |
|
836 { |
|
837 // 0 slot of the message has always session identification if required |
|
838 CPEngSessionSlotId* sessId = CPEngSessionSlotId::NewLC(); |
|
839 |
|
840 aMessage.ReadOneDescriptorL( KMessageSlot0, iBuff8 ); |
|
841 sessId->UnPackL( iBuff8 ); |
|
842 return sessId; |
|
843 } |
|
844 |
|
845 |
|
846 // ----------------------------------------------------------------------------- |
|
847 // CPEngStorageServer::FindStorageFolder() |
|
848 // Try to find session Folder if it is active |
|
849 // if folder is not active, it returns NULL pointer |
|
850 // (other items were commented in a header). |
|
851 // ----------------------------------------------------------------------------- |
|
852 // |
|
853 CPEngStorageFolder* CPEngStorageServer::FindStorageFolder( |
|
854 const CPEngSessionSlotId& aSessionId ) |
|
855 { |
|
856 // look for the session |
|
857 TInt count( iFoldersCnt->Count() ); |
|
858 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
859 { |
|
860 CPEngStorageFolder* folder = |
|
861 static_cast<CPEngStorageFolder*> ( ( *iFoldersCnt )[ x ] ); |
|
862 if ( KErrNone == folder->SessionSlotState().SessionSlotId().Match( aSessionId ) ) |
|
863 { |
|
864 return folder; |
|
865 } |
|
866 } |
|
867 return NULL; |
|
868 } |
|
869 |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // CPEngStorageServer::LoadStorageFolderL() |
|
873 // Load storage folder, |
|
874 // there is open handle to the returner pointer |
|
875 // (other items were commented in a header). |
|
876 // ----------------------------------------------------------------------------- |
|
877 // |
|
878 CPEngStorageFolder* CPEngStorageServer::LoadStorageFolderL( |
|
879 const CPEngSessionSlotId& aSessionId ) |
|
880 { |
|
881 CPEngStorageFolder* folder = FindStorageFolder( aSessionId ); |
|
882 if ( folder ) |
|
883 { |
|
884 TInt val = folder->Open(); // CSI: 65 # |
|
885 return folder; |
|
886 } |
|
887 |
|
888 // read session state from permanent store |
|
889 HBufC* stateFile = NULL; |
|
890 CPEngSessionSlotState* state = ReadSessionStatePermanentLC( aSessionId, |
|
891 stateFile ); |
|
892 |
|
893 // it makes directory if does not exists |
|
894 TPtr fileName = stateFile->Des(); |
|
895 UpdateFileToFolderName( fileName ); |
|
896 |
|
897 // create folder class, pass state |
|
898 CPEngStorageFolder* newFolder = CPEngStorageFolder::NewL( iFs, |
|
899 *iTempFolder, |
|
900 iBuff16 ); |
|
901 CleanupClosePushL( *newFolder ); |
|
902 |
|
903 // update Folder path to include, session part |
|
904 TFileName sessPath; |
|
905 User::LeaveIfError( iFs.SessionPath( sessPath ) ); |
|
906 stateFile = stateFile->ReAllocL( stateFile->Length() + |
|
907 sessPath.Length() ); |
|
908 stateFile->Des().Insert( 0, sessPath ); |
|
909 |
|
910 CleanupStack::Pop(); //newFolder |
|
911 CleanupStack::Pop( 2 ); // state, stateFile |
|
912 |
|
913 // following functions are transfering ownership |
|
914 newFolder->SetSessionSlotState( *state ); |
|
915 newFolder->SetSessionFolder( * stateFile ); |
|
916 |
|
917 // add folder to the folders container |
|
918 CleanupClosePushL( * newFolder ); |
|
919 iFoldersCnt->AddL( newFolder ); |
|
920 CleanupStack::Pop(); // newFolder |
|
921 return newFolder; |
|
922 } |
|
923 |
|
924 |
|
925 // ----------------------------------------------------------------------------- |
|
926 // CPEngStorageServer::LoadSessionStateLCX() |
|
927 // Load session slot state |
|
928 // If there is Storage folder for this session |
|
929 // then state is taken from it, while nothing is put on clean up stack |
|
930 // if not, then state is loaded from state file, |
|
931 // if file does not exist, depends on the aCreate flag, can be |
|
932 // created or it leave with KErrNotFound |
|
933 // order items on clan up stack is: aStateFileName, |
|
934 // or aStateFileName, aSessState |
|
935 // (other items were commented in a header). |
|
936 // ----------------------------------------------------------------------------- |
|
937 // |
|
938 TInt CPEngStorageServer::LoadSessionStateLCX( |
|
939 CPEngSessionSlotId& aSessId, |
|
940 TBool aCreate, |
|
941 CPEngSessionSlotState*& aSessState, |
|
942 CPEngStorageFolder*& aStorageFolder, |
|
943 HBufC*& aStateFileName ) |
|
944 { |
|
945 aStorageFolder = FindStorageFolder( aSessId ); |
|
946 // was state folder found or not |
|
947 if ( aStorageFolder ) |
|
948 { |
|
949 aSessState = &( aStorageFolder->SessionSlotState() ); |
|
950 aStateFileName = PEngHashTool::HashStateNameL( // CSI: 42 # |
|
951 aSessState->SessionSlotId().ServiceAddress(), |
|
952 aSessState->SessionSlotId().UserId() ); |
|
953 CleanupStack::PushL( aStateFileName ); // CSI: 42 # |
|
954 return 1; |
|
955 } |
|
956 if ( !aCreate ) |
|
957 { |
|
958 aSessState = ReadSessionStatePermanentLC( aSessId, aStateFileName ); // CSI: 42 # |
|
959 return 2; |
|
960 } |
|
961 |
|
962 // if it won't exist create it, so we need to trap leave |
|
963 TRAPD( e, |
|
964 { |
|
965 aSessState = ReadSessionStatePermanentLC( aSessId, |
|
966 aStateFileName ); |
|
967 // we need to fool TRAP CleanUp level check |
|
968 CleanupStack::Pop( 2 ); |
|
969 } ); |
|
970 |
|
971 // put those elements back to CleanUpStack |
|
972 if ( e == KErrNone ) |
|
973 { |
|
974 CleanupStack::PushL( aStateFileName ); // CSI: 42 # |
|
975 CleanupStack::PushL( aSessState ); // CSI: 42 # |
|
976 } |
|
977 |
|
978 // does even the file exist? |
|
979 else if ( e == KErrNotFound ) |
|
980 { |
|
981 // file does not exists, create state file and folder |
|
982 aStateFileName = PEngHashTool::HashStateNameL( aSessId.ServiceAddress(), // CSI: 42 # |
|
983 aSessId.UserId() ); |
|
984 CleanupStack::PushL( aStateFileName ); // CSI: 42 # |
|
985 aSessState = CPEngSessionSlotState::NewLC(); // CSI: 42 # |
|
986 aSessState->SetSessionSlotId( aSessId, EFalse ); |
|
987 TPtr fileName = aStateFileName->Des(); |
|
988 CreateSessionDirectoryL( fileName ); // CSI: 42 # |
|
989 } |
|
990 else |
|
991 { |
|
992 // was there some other error? |
|
993 User::LeaveIfError( e ); // CSI: 42 # |
|
994 } |
|
995 return 2; |
|
996 } |
|
997 |
|
998 |
|
999 // ----------------------------------------------------------------------------- |
|
1000 // CPEngStorageServer::ReadSessionStatePermanentLC() |
|
1001 // Read State file from permanent store if it does exists |
|
1002 // Function returns Session Slot state and des buffer with |
|
1003 // session slot state file name ownership of both is transfered |
|
1004 // to the calling client |
|
1005 // both items are left on clean up stack, while state is topest one |
|
1006 // (other items were commented in a header). |
|
1007 // ----------------------------------------------------------------------------- |
|
1008 // |
|
1009 CPEngSessionSlotState* CPEngStorageServer::ReadSessionStatePermanentLC( |
|
1010 const CPEngSessionSlotId& aSessionId, |
|
1011 HBufC*& aFileName ) |
|
1012 { |
|
1013 // Folder is not activated yet, check if folder does exist in the store |
|
1014 // get folder name of the session |
|
1015 aFileName = PEngHashTool::HashStateNameL( |
|
1016 aSessionId.ServiceAddress(), |
|
1017 aSessionId.UserId() ); |
|
1018 CleanupStack::PushL( aFileName ); |
|
1019 |
|
1020 // try to get state of the session if it exists |
|
1021 CPEngSessionSlotState* state = CPEngSessionSlotState::NewLC(); |
|
1022 ReadFileL( *aFileName, iBuff8 ); |
|
1023 state->UnpackDataL( iBuff8, EPermanentData ); |
|
1024 return state; |
|
1025 } |
|
1026 |
|
1027 |
|
1028 // ----------------------------------------------------------------------------- |
|
1029 // CPEngStorageServer::UpdateFileToFolderName() |
|
1030 // Modify State file name to folder name |
|
1031 // Functions remove state suffix from file name and replaces is with |
|
1032 // folder delimiter characters |
|
1033 // (other items were commented in a header). |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // |
|
1036 void CPEngStorageServer::UpdateFileToFolderName( |
|
1037 TDes& aFileName ) |
|
1038 { |
|
1039 aFileName.SetLength( aFileName.Length() - |
|
1040 KPEngStorageStateSuffix().Length() ); |
|
1041 aFileName.Append( KDirDelim ); |
|
1042 } |
|
1043 |
|
1044 |
|
1045 // ----------------------------------------------------------------------------- |
|
1046 // CPEngStorageServer::CreateSessionDirectoryL() |
|
1047 // Create session directory in the file system |
|
1048 // Passed buffer is used, modified to sued session folder |
|
1049 // and then back to the state as it was before |
|
1050 // (other items were commented in a header). |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // |
|
1053 void CPEngStorageServer::CreateSessionDirectoryL( |
|
1054 TDes& aFileName ) |
|
1055 { |
|
1056 // make directory if does not exists |
|
1057 UpdateFileToFolderName( aFileName ); |
|
1058 TFileName folderName; |
|
1059 iFs.SessionPath( folderName ); |
|
1060 folderName.Append( aFileName ); |
|
1061 TInt err( iFs.MkDirAll( folderName ) ); |
|
1062 // ignore KErrAlreadyExist |
|
1063 err = ( err == KErrAlreadyExists ? KErrNone : err ); |
|
1064 User::LeaveIfError( err ); |
|
1065 // modify folder name back to the state file name |
|
1066 aFileName.SetLength( aFileName.Length() - KDirDelimLength ); |
|
1067 aFileName.Append( KPEngStorageStateSuffix ); |
|
1068 } |
|
1069 |
|
1070 |
|
1071 // ----------------------------------------------------------------------------- |
|
1072 // CPEngStorageServer::StoreFile() |
|
1073 // Store data to the file |
|
1074 // (other items were commented in a header). |
|
1075 // ----------------------------------------------------------------------------- |
|
1076 // |
|
1077 TInt CPEngStorageServer::StoreFile( |
|
1078 const TDesC& aFileName, |
|
1079 const TDesC8& aData ) |
|
1080 { |
|
1081 // open temp file, write date into it and rename it to the correct file |
|
1082 RFile temp; |
|
1083 TFileName fName; |
|
1084 TInt err( temp.Temp( iFs, *iTempFolder, fName, EFileShareExclusive ) ); |
|
1085 RETURN_IF_ERROR( err ); |
|
1086 err = temp.Write( aData ); |
|
1087 if ( ( err != KErrNone ) ) |
|
1088 { |
|
1089 temp.Close(); |
|
1090 return err; |
|
1091 } |
|
1092 err = temp.Flush(); |
|
1093 temp.Close(); |
|
1094 RETURN_IF_ERROR( err ); |
|
1095 |
|
1096 err = iFs.Delete( aFileName ); |
|
1097 if ( ( err != KErrNone ) && ( err != KErrNotFound ) ) |
|
1098 { |
|
1099 return err; |
|
1100 } |
|
1101 return iFs.Rename( fName, aFileName ); |
|
1102 } |
|
1103 |
|
1104 |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 // CPEngStorageServer::ReadFileL() |
|
1107 // Read data from the file |
|
1108 // if file does not exists function will leave |
|
1109 // returned buffer is left on the clean up stack |
|
1110 // (other items were commented in a header). |
|
1111 // ----------------------------------------------------------------------------- |
|
1112 // |
|
1113 void CPEngStorageServer::ReadFileL( |
|
1114 const TDesC& aFileName, |
|
1115 RBuf8& aBuff ) |
|
1116 { |
|
1117 RFile f; |
|
1118 User::LeaveIfError( f.Open( iFs, aFileName, EFileRead ) ); |
|
1119 CleanupClosePushL( f ); |
|
1120 TInt size( 0 ); |
|
1121 User::LeaveIfError( f.Size( size ) ); |
|
1122 if ( size > aBuff.MaxSize() ) |
|
1123 { |
|
1124 aBuff.ReAllocL( size ); |
|
1125 } |
|
1126 aBuff.Zero(); |
|
1127 User::LeaveIfError( f.Read( aBuff ) ); |
|
1128 CleanupStack::PopAndDestroy(); // f |
|
1129 } |
|
1130 |
|
1131 |
|
1132 // ----------------------------------------------------------------------------- |
|
1133 // CPEngStorageServer::CleanStorageFromSessionL() |
|
1134 // Clean storage from session |
|
1135 // Function deletes session folder and session state |
|
1136 // (other items were commented in a header). |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // |
|
1139 TInt CPEngStorageServer::CleanStorageFromSessionL( TDes& aFileName ) |
|
1140 { |
|
1141 // delete directory |
|
1142 UpdateFileToFolderName( aFileName ); |
|
1143 TFileName sessionFolder; |
|
1144 iFs.SessionPath( sessionFolder ); |
|
1145 sessionFolder.Append( aFileName ); |
|
1146 |
|
1147 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
1148 CleanupStack::PushL( fileMan ); |
|
1149 TInt err( fileMan->RmDir( sessionFolder ) ); |
|
1150 CleanupStack::PopAndDestroy(); // fileMan |
|
1151 RETURN_IF_ERROR( err ); |
|
1152 |
|
1153 // modify folder name back to the state file name |
|
1154 aFileName.SetLength( aFileName.Length() - KDirDelimLength ); |
|
1155 aFileName.Append( KPEngStorageStateSuffix ); |
|
1156 |
|
1157 // try to delete file |
|
1158 return iFs.Delete( aFileName ); |
|
1159 } |
|
1160 |
|
1161 |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // CPEngStorageServer::PackGlobEventLC() |
|
1164 // Create Buffer with global event from the passed |
|
1165 // state and event enumeration, and application Id |
|
1166 // Function deletes session folder and session state |
|
1167 // (other items were commented in a header). |
|
1168 // ----------------------------------------------------------------------------- |
|
1169 // |
|
1170 CPEngSessionSlotEvent* CPEngStorageServer::PackGlobEventLC( |
|
1171 CPEngSessionSlotState& aState, |
|
1172 TPEngNWSessionSlotEvent aEvent, |
|
1173 const TDesC& aAppId ) |
|
1174 { |
|
1175 CPEngSessionSlotEvent* newEvent = CPEngSessionSlotEvent::NewLC(); |
|
1176 newEvent->SetSessionSlotId( &( aState.SessionSlotId() ), EFalse ); |
|
1177 newEvent->SetAppIdL( aAppId ); |
|
1178 newEvent->SetSessSltEvent( aEvent ); |
|
1179 newEvent->SetAppSessSltState( aState.AppState( aAppId ) ); |
|
1180 newEvent->SetGlobSessSltState( aState.SessionSlotState() ); |
|
1181 return newEvent; |
|
1182 } |
|
1183 |
|
1184 |
|
1185 // ----------------------------------------------------------------------------- |
|
1186 // CPEngStorageServer::UpdateSessionSltStateL() |
|
1187 // Update Session Slot state |
|
1188 // Passed session slot folder pointer can be NULL, then |
|
1189 // session slot state reference is used instead |
|
1190 // (other items were commented in a header). |
|
1191 // ----------------------------------------------------------------------------- |
|
1192 // |
|
1193 void CPEngStorageServer::UpdateSessionSltStateL( |
|
1194 CPEngStorageFolder* aFolder, |
|
1195 CPEngSessionSlotState& aState, |
|
1196 CPEngSessionSlotEvent& aEvent, |
|
1197 TDes& aFileName ) |
|
1198 { |
|
1199 // do we need to do permanent store update? |
|
1200 if ( aState.UpdateStateL( aEvent ) ) |
|
1201 { |
|
1202 // store changes |
|
1203 aState.PackDataL( EPermanentData, iBuff8 ); |
|
1204 |
|
1205 // open file and store there data |
|
1206 TInt e ( StoreFile( aFileName, iBuff8 ) ); |
|
1207 if ( e != KErrNone ) |
|
1208 { |
|
1209 // remove the ID from the sate, this is for case folder is active |
|
1210 aState.RollBackLastUpdate(); |
|
1211 User::Leave( e ); |
|
1212 } |
|
1213 } |
|
1214 aState.CommitLastUpdate(); |
|
1215 if ( aFolder ) |
|
1216 { |
|
1217 aFolder->CommiteStateUpdate(); |
|
1218 } |
|
1219 |
|
1220 // shall we clean storage? |
|
1221 if ( aState.RegisteredApplications().MdcaCount() == KErrNone ) |
|
1222 { |
|
1223 CleanStorageFromSessionL( aFileName ); |
|
1224 } |
|
1225 } |
|
1226 |
|
1227 |
|
1228 |
|
1229 // ============================================================================= |
|
1230 // ============= New notification engine functions ============================= |
|
1231 // ============================================================================= |
|
1232 |
|
1233 // ----------------------------------------------------------------------------- |
|
1234 // CPEngStorageServer::FindRequestHandler() |
|
1235 // Find Request Handler |
|
1236 // (other items were commented in a header). |
|
1237 // ----------------------------------------------------------------------------- |
|
1238 // |
|
1239 CPEngHandlerListenEvents* CPEngStorageServer::FindRequestHandler( |
|
1240 TUint32 aSessionId, |
|
1241 TPEngStorageServerMessages aFunction ) |
|
1242 { |
|
1243 TInt count( iObserversCnt->Count() ); |
|
1244 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
1245 { |
|
1246 CPEngHandlerListenEvents* reqHandler = static_cast<CPEngHandlerListenEvents*>( ( *iObserversCnt )[ x ] ); |
|
1247 if ( ( reqHandler->SessionId() == aSessionId ) |
|
1248 && ( reqHandler->RequestFunction() == aFunction ) ) |
|
1249 { |
|
1250 return reqHandler; |
|
1251 } |
|
1252 } |
|
1253 return NULL; |
|
1254 } |
|
1255 |
|
1256 // End of File |