PECengine/PresenceServer2/ServerSrc/CPEngCSPSessManager.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  One Session manager of the presence server
       
    15 * 				 Handles all management concerning one network session
       
    16 *  				 Opening, closing, ownership handling, updating
       
    17 *  				 of Session related data to network
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include	<e32std.h>
       
    25 #include    "CPEngCSPSessManager.h"
       
    26 
       
    27 #include	"CPEngAppAccessContainer.h"
       
    28 #include	"MPEngSubSession.h"
       
    29 
       
    30 #include	"MPEngRequestHandler.h"
       
    31 #include	"CPEngHandlerLogIn.h"
       
    32 #include	"CPEngHandlerLogOff.h"
       
    33 #include	"CPEngHandlerSendData.h"
       
    34 #include	"MPEngOutgoingTransactionHandler.h"
       
    35 #include	"CPEngIncomingDataHandler.h"
       
    36 
       
    37 
       
    38 #include	"TPEngServerMessages.h"
       
    39 #include	"MPEngServer.h"
       
    40 
       
    41 #include	"CPEngSessionSlotId.h"
       
    42 #include	"CPEngSessionSlotEvent.h"
       
    43 #include	"PEngWVServices2.h"
       
    44 #include	"RObjectArray.h"
       
    45 
       
    46 #include	"PEngTransferAdapter.h"
       
    47 
       
    48 
       
    49 // transaction factories
       
    50 #include	"MPEngTransactionFactory.h"
       
    51 #include	"PEngAttrLibFactory.h"
       
    52 #include	"PEngListLibraryFactory.h"
       
    53 
       
    54 // pure data handler
       
    55 #include	"MPEngPureDataHandler.h"
       
    56 #include	"MPEngAccessHandler.h"
       
    57 
       
    58 //	Own RMessage class wraper
       
    59 #include	"RPEngMessage.h"
       
    60 
       
    61 // Debug prints
       
    62 #include	"PresenceDebugPrint.h"
       
    63 
       
    64 
       
    65 
       
    66 // CONSTANTS
       
    67 const TInt KLastRefAccessCount = 1;
       
    68 
       
    69 
       
    70 // ============================ MEMBER FUNCTIONS ===============================
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CPEngCSPSessManager::CPEngCSPSessManager
       
    74 // C++ default constructor can NOT contain any code, that
       
    75 // might leave.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CPEngCSPSessManager::CPEngCSPSessManager(
       
    79     MPEngServer& aServer )
       
    80         : iAccessCount( 1 ), // init access count to 1
       
    81         iState( EPEngNWPresenceSessionClosed ),
       
    82         iServer( aServer ),
       
    83         iRequestHandlers( 2 ),	// not many requests at time
       
    84         iTransFactories( 3 ) // there 3 three factories
       
    85 
       
    86     {
       
    87     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::CPEngCSPSessManager" ) );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CPEngCSPSessManager::ConstructL
       
    92 // Symbian 2nd phase constructor can leave.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CPEngCSPSessManager::ConstructL(
       
    96     const CPEngSessionSlotId& aSessId,
       
    97     RPEngStorageAdminClient& aAdmin )
       
    98     {
       
    99     iSessionSlotId = aSessId.CloneL();
       
   100 
       
   101     iAccessCounters = CObjectCon::NewL();
       
   102     // we need to set Unique ID of the containers so they own their objects
       
   103     iAccessCounters->iUniqueID = reinterpret_cast<TInt> ( this );
       
   104 
       
   105     HBufC8* sessId = aSessId.PackLC();
       
   106     User::LeaveIfError( iStoreAdmin.Connect( aAdmin, *sessId ) );
       
   107     CleanupStack::PopAndDestroy( sessId ); // sessId
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CPEngCSPSessManager::NewL
       
   112 // Two-phased constructor.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CPEngCSPSessManager* CPEngCSPSessManager::NewLC(
       
   116     MPEngServer& aServer,
       
   117     const CPEngSessionSlotId& aSessId,
       
   118     RPEngStorageAdminClient& aAdmin )
       
   119     {
       
   120     CPEngCSPSessManager* self = new( ELeave ) CPEngCSPSessManager( aServer );
       
   121 
       
   122     CleanupClosePushL( *self );
       
   123     self->ConstructL( aSessId, aAdmin );
       
   124 
       
   125     return self;
       
   126     }
       
   127 
       
   128 
       
   129 // Destructor
       
   130 CPEngCSPSessManager::~CPEngCSPSessManager()
       
   131     {
       
   132     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::~CPEngCSPSessManager" ) );
       
   133 
       
   134     delete iSessionSlotId;
       
   135     ResetAccessContainers();
       
   136     delete iAccessCounters;
       
   137 
       
   138     iRequestHandlers.ResetAndDestroy();
       
   139     // set state to the Close, so all resources are sure deleted
       
   140     iState = EPEngNWPresenceSessionClosed;
       
   141     UnloadResources();
       
   142 
       
   143     iIncomingHandlers.ResetAndDestroy();
       
   144 
       
   145     iStoreAdmin.Close();
       
   146     iServer.RemoveCSPSessManager( this );
       
   147 
       
   148     iServSubSessions.Reset();
       
   149 
       
   150 
       
   151 #if _BullseyeCoverage
       
   152     cov_write();
       
   153 #endif
       
   154     }
       
   155 
       
   156 /////////////////////////////////////////////////////////////////////////////////
       
   157 // ========== Functions from MPEngRequestHandlerObserver ========================
       
   158 /////////////////////////////////////////////////////////////////////////////////
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CPEngCSPSessManager::CompleteRequestHandler()
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CPEngCSPSessManager::CompleteRequestHandler(
       
   165     MPEngRequestHandler* aRequestHandler )
       
   166     {
       
   167     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::CompleteRequestHandler: %d" ),
       
   168              ( TInt )aRequestHandler  );
       
   169 
       
   170     TInt handlerIndex ( iRequestHandlers.Find( aRequestHandler ) );
       
   171     if ( handlerIndex != KErrNotFound )
       
   172         {
       
   173         iRequestHandlers.Remove( handlerIndex );
       
   174         }
       
   175     // if we are offline and there is no more request handler, unload
       
   176     // resources
       
   177     if (
       
   178         ( iState == EPEngNWPresenceSessionClosed )
       
   179         &&
       
   180         ( iRequestHandlers.Count() == 0 )
       
   181     )
       
   182         {
       
   183         UnloadResources();
       
   184         }
       
   185     CheckReferenceAccessD();
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CPEngCSPSessManager::SetCSPSessionOpenedL()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CPEngCSPSessManager::SetCSPSessionOpenedL()
       
   193     {
       
   194     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::SetCSPSessionOpenedL: %d" ) );
       
   195 
       
   196     // Load resources
       
   197     LoadResourcesL();
       
   198     // set state to online
       
   199     iState	= EPEngNWPresenceSessionOpen;
       
   200     }
       
   201 
       
   202 
       
   203 /////////////////////////////////////////////////////////////////////////////////
       
   204 // ========== Functions from MPEngRequestHandlerObserver ========================
       
   205 /////////////////////////////////////////////////////////////////////////////////
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CPEngCSPSessManager::StatusChangedL()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CPEngCSPSessManager::StatusChangedL(
       
   212     TPEngNWSessionSlotState aNewState,
       
   213     TPEngNWSessionSlotEvent aNewEvent )
       
   214     {
       
   215     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::StatusChangedL: state:%d Event:%d" ),
       
   216              aNewState,
       
   217              aNewEvent );
       
   218 
       
   219 
       
   220     // is tate different than holder is
       
   221     if ( aNewState == iState )
       
   222         {
       
   223         // state is same, do nothing
       
   224         return;
       
   225         }
       
   226     // update state and inform about it
       
   227     iState = aNewState;
       
   228     if ( iState == EPEngNWPresenceSessionClosed )
       
   229         {
       
   230         // we are closed, unload resources
       
   231         UnloadResources();
       
   232         TInt count( iAccessCounters->Count() );
       
   233         for ( TInt x( 0 ) ; x < count ; ++x )
       
   234             {
       
   235             NotifyNewEventL( aNewEvent,
       
   236                              static_cast<CPEngAppAccessContainer*>
       
   237                              ( ( *iAccessCounters )[ x ] )->AppId(),
       
   238                              EPEngNWPresenceSessionClosed );
       
   239             }
       
   240         // remove all access containers
       
   241         ResetAccessContainers();
       
   242         }
       
   243     else if ( iState == EPEngNWPresenceSessionOpen )
       
   244         {
       
   245         LoadResourcesL();
       
   246         // Do not notify, it will be done by LogIn Handler
       
   247         }
       
   248     }
       
   249 
       
   250 /////////////////////////////////////////////////////////////////////////////////
       
   251 //======================== New Functions of main class ==========================
       
   252 /////////////////////////////////////////////////////////////////////////////////
       
   253 // -----------------------------------------------------------------------------
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CPEngCSPSessManager::Open()
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CPEngCSPSessManager::Open()
       
   260     {
       
   261     iAccessCount++;
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CPEngCSPSessManager::Close()
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CPEngCSPSessManager::Close()
       
   269     {
       
   270     iAccessCount--;
       
   271     CheckReferenceAccessD();
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CPEngCSPSessManager::OpenL()
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CPEngCSPSessManager::OpenL(
       
   279     MPEngSubSession& aServSubSession )
       
   280     {
       
   281     iServSubSessions.AppendL( &aServSubSession );
       
   282     iAccessCount++;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CPEngCSPSessManager::Close()
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CPEngCSPSessManager::Close(
       
   290     MPEngSubSession* aServSubSession )
       
   291     {
       
   292     TInt x( iServSubSessions.Find( aServSubSession ) );
       
   293     if ( x != KErrNotFound )
       
   294         {
       
   295         iServSubSessions.Remove( x );
       
   296         iAccessCount--;
       
   297         }
       
   298     CheckReferenceAccessD();
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CPEngCSPSessManager::AttachAppIdL()
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CPEngCSPSessManager::AttachAppIdL(
       
   306     const TDesC& aAppId )
       
   307     {
       
   308     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::AttachAppIdL:%S" ), &aAppId );
       
   309 
       
   310 
       
   311     // allow attaching of the App Id only if CSP is opened
       
   312     LeaveIfNotConnectedL();
       
   313 
       
   314     CPEngAppAccessContainer* accessCounter = AccessCounter( aAppId );
       
   315     if ( accessCounter )
       
   316         {
       
   317         TInt val = accessCounter->Open(); // CSI: 65 #
       
   318         return;
       
   319         }
       
   320     // does not exist, create and append
       
   321     CPEngAppAccessContainer* newContainer =
       
   322         CPEngAppAccessContainer::NewLC( aAppId );
       
   323     iAccessCounters->AddL( newContainer );
       
   324     // notify about new App Id logging
       
   325     NotifyNewEventL( EPEngEventAppNWPresenceSessionOpened,
       
   326                      aAppId,
       
   327                      EPEngNWPresenceSessionOpen );
       
   328     CleanupStack::Pop( newContainer ); // newContainer
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CPEngCSPSessManager::DetachAppId()
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CPEngCSPSessManager::DetachAppId(
       
   336     const TDesC& aAppId )
       
   337     {
       
   338     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::DetachAppId:%S " ), &aAppId );
       
   339 
       
   340     CPEngAppAccessContainer* accessCounter = AccessCounter( aAppId );
       
   341     TBool notify( EFalse );
       
   342     if ( accessCounter )
       
   343         {
       
   344         notify = accessCounter->CloseAccess();
       
   345         }
       
   346     if ( iState == EPEngNWPresenceSessionClosed )
       
   347         {
       
   348         // no need to notify, it was already done
       
   349         notify = EFalse;
       
   350         }
       
   351     // do we need to do Log Out from CSP?
       
   352     else if ( !( iAccessCounters->Count() ) )
       
   353         {
       
   354         // quite brutal, but unload everything, we cannot do lot more
       
   355         iRequestHandlers.ResetAndDestroy();
       
   356         UnloadResources();
       
   357         iState = EPEngNWPresenceSessionClosed;
       
   358         notify = ETrue;
       
   359         }
       
   360     // notify event
       
   361     if ( notify )
       
   362         {
       
   363         TRAP_IGNORE( NotifyNewEventL( EPEngEventAppNWPresenceSessionClosed,
       
   364                                       aAppId,
       
   365                                       EPEngNWPresenceSessionClosed ) );
       
   366         }
       
   367     CheckReferenceAccessD();
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CPEngCSPSessManager::AppIdActiveL()
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 void CPEngCSPSessManager::AppIdActiveL(
       
   375     const TDesC& aAppId )
       
   376     {
       
   377     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::AppIdActiveL:%S" ), &aAppId );
       
   378 
       
   379     CPEngAppAccessContainer* accessCounter = AccessCounter( aAppId );
       
   380     if ( !accessCounter )
       
   381         {
       
   382         User::Leave( KErrNotReady );
       
   383         }
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CPEngCSPSessManager::ReserveProcessL()
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CPEngCSPSessManager::ReserveProcessL(
       
   391     const TDesC& aAppId,
       
   392     const TDesC& aProcessId )
       
   393     {
       
   394     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::ReserveProcessL: %S : %S" ),
       
   395              &aAppId,
       
   396              &aProcessId );
       
   397 
       
   398     CPEngAppAccessContainer* accessCounter = AccessCounter( aAppId );
       
   399     if ( accessCounter )
       
   400         {
       
   401         accessCounter->ReserveProcessL( aProcessId );
       
   402         return;
       
   403         }
       
   404     // does not exist, leave
       
   405     User::Leave( KErrNotFound );
       
   406     }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // CPEngCSPSessManager::ActivateProcessL()
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CPEngCSPSessManager::ActivateProcessL(
       
   413     const TDesC& aAppId,
       
   414     const TDesC& aProcessId )
       
   415     {
       
   416     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::ReserveProcessL: %S : %S" ),
       
   417              &aAppId,
       
   418              &aProcessId );
       
   419 
       
   420     CPEngAppAccessContainer* accessCounter = AccessCounter( aAppId );
       
   421     if ( accessCounter )
       
   422         {
       
   423         // it will leave if not find
       
   424         accessCounter->ActivateProcessIdL( aProcessId );
       
   425         return;
       
   426         }
       
   427 
       
   428     User::Leave( KErrNotReady );
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CPEngCSPSessManager::SessionId()
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 const CPEngSessionSlotId& CPEngCSPSessManager::SessionId() const
       
   436     {
       
   437     return *iSessionSlotId;
       
   438     }
       
   439 
       
   440 ////////////////////////////////////////////////////////////////////////////////
       
   441 // =========== New Function for Request handling ===============================
       
   442 ////////////////////////////////////////////////////////////////////////////////
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CPEngCSPSessManager::HandleAsynchronousRequestL()
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void  CPEngCSPSessManager::HandleAsynchronousRequestL(
       
   449     const RPEngMessage& aMessage,
       
   450     MPEngSubSession& aServSubSession,
       
   451     TInt32 aServSessionId,
       
   452     TInt   aServSubSessionId )
       
   453     {
       
   454     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::HandleAsynchronousRequestL:%d" ),
       
   455              aMessage.Function() );
       
   456 
       
   457     TInt function( aMessage.Function() );
       
   458     // first check that this kind of request is allowed
       
   459     CheckRequestValidityL( function, aServSessionId, aServSubSessionId );
       
   460     // request can be proceeded
       
   461     switch ( function )
       
   462         {
       
   463         case ESubSessUpdateData:
       
   464             {
       
   465             HandleUpdateDataRequestL( aMessage,
       
   466                                       aServSubSession,
       
   467                                       aServSessionId,
       
   468                                       aServSubSessionId );
       
   469             break;
       
   470             }
       
   471 
       
   472         default:
       
   473             {
       
   474             User::Leave( KErrNotSupported );
       
   475             }
       
   476         }
       
   477     }
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CPEngCSPSessManager::HandleSynchronousRequestL()
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void  CPEngCSPSessManager::HandleSynchronousRequestL(
       
   484     const RPEngMessage& aMessage,
       
   485     TInt32 /* aServSessionId */,
       
   486     TInt /* aServSubSessionId */ )
       
   487     {
       
   488     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::HandleSynchronousRequestL:%d" ),
       
   489              aMessage.Function() );
       
   490 
       
   491     // first check that this kind of request is allowed
       
   492     TInt function( aMessage.Function() );
       
   493     switch ( function )
       
   494         {
       
   495             // Get Session service tree
       
   496         case ESubSessGetServiceTree:
       
   497             {
       
   498             LeaveIfNotConnectedL();
       
   499             TPckgBuf<TPEngWVCspServicesTree2> serviceTree(
       
   500                 iAccessHandler->ServiceCapabilities() );
       
   501             aMessage.WriteOneDescriptorL( KMessageSlot0, serviceTree );
       
   502             break;
       
   503             }
       
   504 
       
   505         // get Session Log in data
       
   506         case ESubSessGetLogInData:
       
   507             {
       
   508             LeaveIfNotConnectedL();
       
   509             TInt err( aMessage.WriteOneDescriptor( KMessageSlot0,
       
   510                                                    iAccessHandler->LogInData() ) );
       
   511             if ( err == KErrOverflow )
       
   512                 {
       
   513                 User::Leave( iAccessHandler->LogInData().Length() );
       
   514                 }
       
   515             User::LeaveIfError( err );
       
   516             break;
       
   517             }
       
   518 
       
   519         default:
       
   520             {
       
   521             User::Leave( KErrNotSupported );
       
   522             break;
       
   523             }
       
   524         }
       
   525     }
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // CPEngCSPSessManager::HandleLogInRequestL
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 void CPEngCSPSessManager::HandleLogInRequestL(
       
   532     const RPEngMessage& aMessage,
       
   533     MPEngSubSession& aSubSession,
       
   534     TInt32 aServSessionId,
       
   535     TInt   aServSubSessionId  )
       
   536     {
       
   537     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::HandleLogInRequestL:" ) );
       
   538 
       
   539     // is CSP session active?
       
   540     if ( iState == EPEngNWPresenceSessionOpen )
       
   541         {
       
   542         // verify password and leave if password is not correct
       
   543         HBufC8*	loginData = aMessage.ReadOneDescriptor8LC( KMessageSlot0 );
       
   544         iAccessHandler->AssertLoginDataL( *loginData );
       
   545         CleanupStack::PopAndDestroy( loginData ); // loginData
       
   546 
       
   547         // session is active, inform sub-session to Open Ref to the App Id
       
   548         aSubSession.HandleLogInL();
       
   549         // done
       
   550         aMessage.Complete( KErrNone );
       
   551         return;
       
   552         }
       
   553     // Open network connection, not logged
       
   554     DoLogInL( aMessage, aSubSession, aServSessionId, aServSubSessionId );
       
   555     // done here
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // CPEngCSPSessManager::HandleForceLogOutRequestL
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CPEngCSPSessManager::HandleForceLogOutRequestL(
       
   563     const RPEngMessage& aMessage,
       
   564     MPEngSubSession& aSubSession,
       
   565     TInt32 aServSessionId,
       
   566     TInt   aServSubSessionId )
       
   567     {
       
   568     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::HandleForceLogOutRequestL:" ) );
       
   569 
       
   570     // is CSP session active or does App id exists
       
   571     CPEngAppAccessContainer* accessCounter = AccessCounter(
       
   572                                                  aSubSession.AppId() );
       
   573 
       
   574     if ( ( iState == EPEngNWPresenceSessionClosed )
       
   575          ||
       
   576          ( !accessCounter )
       
   577        )
       
   578         {
       
   579         aSubSession.HandleLogOut();
       
   580         // we are already closed
       
   581         aMessage.Complete( KErrNotReady );
       
   582         return;
       
   583         }
       
   584 
       
   585     // check how many active app ids we have
       
   586     if ( iAccessCounters->Count() == KLastRefAccessCount )
       
   587         {
       
   588         // we need to do proper log out of whole CSP
       
   589         DoLogOutL( aMessage,
       
   590                    aSubSession,
       
   591                    aServSessionId,
       
   592                    aServSubSessionId );
       
   593         return;
       
   594         }
       
   595 
       
   596     // just remove appId from active and inform sub-sessions
       
   597     NotifyNewEventL( EPEngEventAppNWPresenceSessionClosed,
       
   598                      aSubSession.AppId(),
       
   599                      EPEngNWPresenceSessionClosed );
       
   600     NotifyDisconnectedAppId( aSubSession.AppId() );
       
   601     accessCounter->CloseContainer();
       
   602     aSubSession.HandleLogOut();
       
   603     aMessage.Complete( KErrNone );
       
   604     CheckReferenceAccessD();
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CPEngCSPSessManager::HandleDetachAppIdL()
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 void CPEngCSPSessManager::HandleDetachAppIdL(
       
   612     const RPEngMessage& aMessage,
       
   613     MPEngSubSession& aSubSession,
       
   614     TInt32 aServSessionId,
       
   615     TInt   aServSubSessionId )
       
   616     {
       
   617     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::HandleDetachAppIdL:" ) );
       
   618 
       
   619     CPEngAppAccessContainer* accessCounter = AccessCounter(
       
   620                                                  aSubSession.AppId() );
       
   621 
       
   622     if ( ( iState == EPEngNWPresenceSessionClosed )
       
   623          ||
       
   624          ( !accessCounter )
       
   625        )
       
   626         {
       
   627         aSubSession.HandleLogOut();
       
   628         // we are already closed
       
   629         aMessage.Complete( KErrNone );
       
   630         return;
       
   631         }
       
   632 
       
   633     // is this last connection holder
       
   634     if (
       
   635         ( KLastRefAccessCount == accessCounter->ActiveAccessCount() )
       
   636         &&
       
   637         ( KLastRefAccessCount == iAccessCounters->Count() )
       
   638     )
       
   639         {
       
   640         // Issue log out of the CSP
       
   641         DoLogOutL( aMessage,
       
   642                    aSubSession,
       
   643                    aServSessionId,
       
   644                    aServSubSessionId );
       
   645         return;
       
   646         }
       
   647     // remove session Id
       
   648     TBool notify( accessCounter->CloseAccess() );
       
   649     // Notify about close of the App Id
       
   650     if ( notify )
       
   651         {
       
   652         NotifyNewEventL( EPEngEventAppNWPresenceSessionClosed,
       
   653                          aSubSession.AppId(),
       
   654                          EPEngNWPresenceSessionClosed );
       
   655         NotifyDisconnectedAppId( aSubSession.AppId() );
       
   656         aSubSession.HandleLogOut();
       
   657         aMessage.Complete( KErrNone );
       
   658         CheckReferenceAccessD();
       
   659         }
       
   660     }
       
   661 
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CPEngCSPSessManager::CancelAsynchronousRequest()
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void  CPEngCSPSessManager::CancelAsynchronousRequest(
       
   668     const RPEngMessage& aMessage,
       
   669     TInt32 aServSessionId,
       
   670     TInt   aServSubSessionId )
       
   671     {
       
   672     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::CancelAsynchronousRequest:%d" ),
       
   673              aMessage.Int0() );
       
   674 
       
   675     TInt function( aMessage.Int0() );
       
   676     // there can be only one async request of each kind per each Sub session,
       
   677     TInt fescue( FindRequestInSubSession(	function,
       
   678                                           aServSessionId,
       
   679                                           aServSubSessionId ) );
       
   680     if ( fescue != KErrNotFound )
       
   681         {
       
   682         iRequestHandlers[ fescue ]->CancelRequestD();
       
   683         }
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CPEngCSPSessManager::CancelAllSessionRequests()
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 void  CPEngCSPSessManager::CancelAllSessionRequests(
       
   691     TInt32 aServSessionId )
       
   692     {
       
   693     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::CancelAllSessionRequests:" ) );
       
   694 
       
   695     for ( TInt fescue( iRequestHandlers.Count() - 1 );
       
   696           fescue >= 0;
       
   697           --fescue )
       
   698         {
       
   699         // check handlers only in case, handlerCount is smaller them
       
   700         // real number of requests this is because,canceling
       
   701         // of particular requests can complete other requests
       
   702         if ( fescue < iRequestHandlers.Count() )
       
   703             {
       
   704             if ( iRequestHandlers[ fescue ]->SessionId() == aServSessionId )
       
   705                 {
       
   706                 iRequestHandlers[ fescue ]->CancelRequestD();
       
   707                 }
       
   708             }
       
   709         }
       
   710     }
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CPEngCSPSessManager::CancelAllSubSessionRquests()
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 void CPEngCSPSessManager::CancelAllSubSessionRquests(
       
   717     TInt32 aServSessionId,
       
   718     TInt   aServSubSessionId )
       
   719     {
       
   720     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::CancelAllSubSessionRquests:" ) );
       
   721 
       
   722     for ( TInt fescue( iRequestHandlers.Count() - 1 );
       
   723           fescue >= 0;
       
   724           --fescue )
       
   725         {
       
   726         // check handlers only in case, handlerCount is smaller them
       
   727         // real number of requests this is because,canceling
       
   728         // of particular requests can complete other requests
       
   729         if (
       
   730             ( fescue < iRequestHandlers.Count() )
       
   731             &&
       
   732             ( iRequestHandlers[ fescue ]->SessionId() == aServSessionId )
       
   733             &&
       
   734             ( iRequestHandlers[ fescue]->SubSessionId() == aServSubSessionId )
       
   735         )
       
   736             {
       
   737             iRequestHandlers[ fescue ]->CancelRequestD();
       
   738             }
       
   739         }
       
   740     }
       
   741 
       
   742 /////////////////////////////////////////////////////////////////////////////////
       
   743 //===================== Functions for resource handling =========================
       
   744 /////////////////////////////////////////////////////////////////////////////////
       
   745 // -----------------------------------------------------------------------------
       
   746 
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CPEngCSPSessManager::LoadResourcesL()
       
   750 // Load Pure data handler
       
   751 // Load transaction factories
       
   752 // start listening of the incoming request from network
       
   753 // (other items were commented in a header).
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 void CPEngCSPSessManager::LoadResourcesL()
       
   757     {
       
   758     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::LoadResourcesL:" ) );
       
   759 
       
   760     // load pure data handler
       
   761     if ( !iPureDataHandler )
       
   762         {
       
   763         iPureDataHandler = PEngTransferAdapter::PureDataHandlerL(
       
   764                                *iSessionSlotId );
       
   765         }
       
   766 
       
   767     if ( iTransFactories.Count() == 0 )
       
   768         {
       
   769         // load and initialize factories
       
   770         // create List library transaction factory
       
   771 
       
   772         MPEngTransactionFactory* transFactory =
       
   773             PEngListLibraryFactory::AttributeListsTransactionManagerLC(
       
   774                 *iSessionSlotId );
       
   775         iTransFactories.AppendL( transFactory );
       
   776         CleanupStack::Pop(); // transFactory
       
   777 
       
   778         // create attribute List Transaction factory
       
   779         transFactory =
       
   780             PEngListLibraryFactory::ContactListTransactionManagerLC(
       
   781                 *iSessionSlotId );
       
   782         iTransFactories.AppendL( transFactory );
       
   783         CleanupStack::Pop(); // transFactory
       
   784 
       
   785         // create attribute library transaction factory
       
   786         transFactory = PEngAttrLibFactory::AttributeTransFactoryInstanceLC(
       
   787                            *iSessionSlotId );
       
   788         iTransFactories.AppendL( transFactory );
       
   789         CleanupStack::Pop(); // transFactory
       
   790 
       
   791         // create autorization transaction factory
       
   792         transFactory = PEngListLibraryFactory::AuthorizationTransactionManagerLC(
       
   793                            *iSessionSlotId );
       
   794         iTransFactories.AppendL( transFactory );
       
   795         CleanupStack::Pop(); // transFactory
       
   796 
       
   797         }
       
   798 
       
   799     if ( iIncomingHandlers.Count() == 0 )
       
   800         {
       
   801         CPEngIncomingDataHandler* handler =
       
   802             CPEngIncomingDataHandler::NewLC( *iPureDataHandler,
       
   803                                              iTransFactories,
       
   804                                              *this );
       
   805         handler->StartListeningL();
       
   806         iIncomingHandlers.AppendL( handler );
       
   807         CleanupStack::Pop( handler ); // handler
       
   808         }
       
   809     if ( !iPluginsLoaded )
       
   810         {
       
   811         iServer.SessionOpened();
       
   812         iPluginsLoaded = ETrue;
       
   813         }
       
   814     }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CPEngCSPSessManager::UnloadResources()
       
   818 // Stop Incoming data listening and processing
       
   819 // close transaction factories
       
   820 // unload pure data handler
       
   821 // (other items were commented in a header).
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 void CPEngCSPSessManager::UnloadResources()
       
   825     {
       
   826     PENG_DP( D_PENG_LIT( "CPEngCSPSessManager::UnloadResources:" ) );
       
   827 
       
   828     // Stop listening
       
   829     iIncomingHandlers.ResetAndDestroy();
       
   830     if ( !iRequestHandlers.Count() || iState == EPEngNWPresenceSessionClosed )
       
   831         {
       
   832         UnloadTransactionFactories();
       
   833         if ( iPureDataHandler )
       
   834             {
       
   835             iPureDataHandler->Close();
       
   836             iPureDataHandler = NULL;
       
   837             }
       
   838         if ( iAccessHandler )
       
   839             {
       
   840             iAccessHandler->UnregisterSessionObserver( *this );
       
   841             iAccessHandler->Close();
       
   842             iAccessHandler = NULL;
       
   843             }
       
   844         }
       
   845     if ( iPluginsLoaded )
       
   846         {
       
   847         iServer.SessionClosed();
       
   848         iPluginsLoaded = EFalse;
       
   849         }
       
   850     }
       
   851 
       
   852 /////////////////////////////////////////////////////////////////////////////////
       
   853 //================= Private Functions of request management =====================
       
   854 /////////////////////////////////////////////////////////////////////////////////
       
   855 
       
   856 // -----------------------------------------------------------------------------
       
   857 // CPEngCSPSessManager::CheckRequestValidityL()
       
   858 // Check if request is allowed to be handled
       
   859 // If request is not allowed, function leaves, so request message is
       
   860 // completed by the framework
       
   861 // If not needed, server session and sub-session Ids are not obeyed
       
   862 // (other items were commented in a header).
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 void CPEngCSPSessManager::CheckRequestValidityL(
       
   866     TInt aRequestFunction,
       
   867     TInt32 aServSessionId,
       
   868     TInt   aServSubSessionId )
       
   869     {
       
   870     // according to the request function, check if there is already
       
   871     // such a request pending and if yes, then if another is allowed
       
   872     switch ( aRequestFunction )
       
   873         {
       
   874         case ESubSessLogIn:
       
   875         case ESubSessForceLogOut:
       
   876             {
       
   877             // only one request of this kind per session manager
       
   878             if ( KErrNotFound != FindRequest( aRequestFunction ) )
       
   879                 {
       
   880                 User::Leave( KErrAlreadyExists );
       
   881                 }
       
   882             break;
       
   883             }
       
   884 
       
   885         case ESubSessUpdateData:
       
   886             {
       
   887             // only one request of this kind per session
       
   888             if ( KErrNotFound != FindRequestInSubSession(
       
   889                      aRequestFunction,
       
   890                      aServSessionId,
       
   891                      aServSubSessionId ) )
       
   892                 {
       
   893                 User::Leave( KErrAlreadyExists );
       
   894                 }
       
   895             break;
       
   896             }
       
   897 
       
   898         default:
       
   899             break;
       
   900         }
       
   901     }
       
   902 
       
   903 // -----------------------------------------------------------------------------
       
   904 // CPEngCSPSessManager::FindRequest()
       
   905 // Look for the particular request within all sessions
       
   906 // (other items were commented in a header).
       
   907 // -----------------------------------------------------------------------------
       
   908 //
       
   909 TInt CPEngCSPSessManager::FindRequest(
       
   910     TInt aRequestFunction )
       
   911     {
       
   912     TInt handlerCount( iRequestHandlers.Count() );
       
   913     for ( TInt x( 0 ) ; x < handlerCount ; x++ )
       
   914         {
       
   915         if ( iRequestHandlers[x]->RequestFunction() == aRequestFunction )
       
   916             {
       
   917             return x;
       
   918             }
       
   919         }
       
   920     return KErrNotFound;
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // CPEngCSPSessManager::FindRequestInSession()
       
   925 // Look for the particular request within the session
       
   926 // (other items were commented in a header).
       
   927 // -----------------------------------------------------------------------------
       
   928 //
       
   929 TInt CPEngCSPSessManager::FindRequestInSession(
       
   930     TInt aRequestFunction,
       
   931     TInt32 aServSessionId )
       
   932     {
       
   933     TInt handlerCount( iRequestHandlers.Count() );
       
   934     for ( TInt x( 0 ) ; x < handlerCount ; x++ )
       
   935         {
       
   936         if (
       
   937             ( iRequestHandlers[ x ]->SessionId() == aServSessionId )
       
   938             &&
       
   939             ( iRequestHandlers[ x ]->RequestFunction() == aRequestFunction )
       
   940         )
       
   941             {
       
   942             return x;
       
   943             }
       
   944         }
       
   945     return KErrNotFound;
       
   946     }
       
   947 
       
   948 
       
   949 // -----------------------------------------------------------------------------
       
   950 // CPEngCSPSessManager::FindRequestInSubSession()
       
   951 // Look for the particular request within the session
       
   952 // (other items were commented in a header).
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 TInt CPEngCSPSessManager::FindRequestInSubSession(
       
   956     TInt aRequestFunction,
       
   957     TInt32 aServSessionId,
       
   958     TInt   aServSubSessionId )
       
   959     {
       
   960     TInt handlerCount( iRequestHandlers.Count() );
       
   961     for ( TInt x( 0 ) ; x < handlerCount ; x++ )
       
   962         {
       
   963         if (
       
   964             ( iRequestHandlers[ x ]->SessionId() == aServSessionId )
       
   965             &&
       
   966             ( iRequestHandlers[ x ]->SubSessionId() == aServSubSessionId )
       
   967             &&
       
   968             ( iRequestHandlers[ x ]->RequestFunction() == aRequestFunction )
       
   969         )
       
   970             {
       
   971             return x;
       
   972             }
       
   973         }
       
   974     return KErrNotFound;
       
   975     }
       
   976 
       
   977 
       
   978 
       
   979 // -----------------------------------------------------------------------------
       
   980 // CPEngCSPSessManager::HandleUpdateDataRequestL
       
   981 // Handle Send Attributes Request
       
   982 // (other items were commented in a header).
       
   983 // -----------------------------------------------------------------------------
       
   984 //
       
   985 void CPEngCSPSessManager::HandleUpdateDataRequestL(
       
   986     const RPEngMessage& aMessage,
       
   987     MPEngSubSession& aServSubSession,
       
   988     TInt32 aServSessionId,
       
   989     TInt   aServSubSessionId )
       
   990     {
       
   991     // get factory and operation enumerations
       
   992     TInt opId( aMessage.Int0() );
       
   993 
       
   994     LeaveIfNotConnectedL();
       
   995 
       
   996     // read data to be updated
       
   997     HBufC* data = aMessage.ReadOneDescriptor16LC( KMessageSlot1 );
       
   998     RObjectArray<MPEngOutgoingTransactionHandler> transactions;
       
   999     CleanupClosePushL( transactions	);
       
  1000     TInt count( iTransFactories.Count() );
       
  1001     for ( TInt x( 0 ) ; x < count ; ++x )
       
  1002         {
       
  1003         iTransFactories[ x ]->OutgoingTransactionHandlerL( opId,
       
  1004                                                            *data,
       
  1005                                                            transactions );
       
  1006         }
       
  1007     if ( transactions.Count() == 0 )
       
  1008         {
       
  1009         // nothing to do, complete Message
       
  1010         aMessage.Complete( KErrNone );
       
  1011         CleanupStack::PopAndDestroy( 2 ); // transactions, data,
       
  1012         return;
       
  1013         }
       
  1014 
       
  1015     CPEngHandlerSendData* newHandler = CPEngHandlerSendData::NewLC(
       
  1016                                            *this,
       
  1017                                            *iPureDataHandler,
       
  1018                                            aServSubSession,
       
  1019                                            aMessage,
       
  1020                                            transactions,
       
  1021                                            aServSessionId,
       
  1022                                            aServSubSessionId );
       
  1023 
       
  1024     iRequestHandlers.AppendL( newHandler );
       
  1025     // keep handler in the clean up for Starting,
       
  1026     // so it is deleted when start fails
       
  1027     newHandler->StartHandlerL();
       
  1028     newHandler->SetMessage( aMessage );
       
  1029     CleanupStack::Pop( newHandler ); // newHandler
       
  1030     CleanupStack::PopAndDestroy( 2 ); // transactions, data,
       
  1031     }
       
  1032 
       
  1033 // -----------------------------------------------------------------------------
       
  1034 // CPEngCSPSessManager::DoLogInL
       
  1035 // Do Log In to the CSP session
       
  1036 // (other items were commented in a header).
       
  1037 // -----------------------------------------------------------------------------
       
  1038 //
       
  1039 void CPEngCSPSessManager::DoLogInL(
       
  1040     const RPEngMessage& aMessage,
       
  1041     MPEngSubSession& aServSubSession,
       
  1042     TInt32 aServSessionId,
       
  1043     TInt   aServSubSessionId )
       
  1044     {
       
  1045     // Load access handler and start listening
       
  1046     if ( !iAccessHandler )
       
  1047         {
       
  1048         iAccessHandler = PEngTransferAdapter::AccessHandlerL(
       
  1049                              *iSessionSlotId );
       
  1050         iAccessHandler->RegisterSessionObserverL( *this );
       
  1051         }
       
  1052     // create new handler
       
  1053     CPEngHandlerLogIn* newHandler = CPEngHandlerLogIn::NewLC(
       
  1054                                         *this,
       
  1055                                         *iAccessHandler,
       
  1056                                         aServSubSession,
       
  1057                                         aMessage,
       
  1058                                         aServSessionId,
       
  1059                                         aServSubSessionId );
       
  1060 
       
  1061     // store new handler
       
  1062     iRequestHandlers.AppendL( newHandler );
       
  1063     // keep handler in the clean up for Starting,
       
  1064     // so it is deleted when start fails
       
  1065     newHandler->StartHandlerL( aMessage );
       
  1066     newHandler->SetMessage( aMessage );
       
  1067     CleanupStack::Pop( newHandler ); // newHandler
       
  1068     }
       
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CPEngCSPSessManager::DoLogOutL
       
  1072 // Do log out from the CSP session
       
  1073 // (other items were commented in a header).
       
  1074 // -----------------------------------------------------------------------------
       
  1075 //
       
  1076 void CPEngCSPSessManager::DoLogOutL(
       
  1077     const RPEngMessage& aMessage,
       
  1078     MPEngSubSession& aServSubSession,
       
  1079     TInt32 aServSessionId,
       
  1080     TInt   aServSubSessionId )
       
  1081     {
       
  1082     // create new handler
       
  1083     CPEngHandlerLogOff* newHandler = CPEngHandlerLogOff::NewLC(
       
  1084                                          *this,
       
  1085                                          *iAccessHandler,
       
  1086                                          aServSubSession,
       
  1087                                          aMessage,
       
  1088                                          aServSessionId,
       
  1089                                          aServSubSessionId );
       
  1090 
       
  1091     // store new handler
       
  1092     iRequestHandlers.AppendL( newHandler );
       
  1093     // keep handler in the clean up for Starting,
       
  1094     // so it is deleted when start fails
       
  1095     newHandler->StartHandlerL();
       
  1096     newHandler->SetMessage( aMessage );
       
  1097     CleanupStack::Pop( newHandler ); // newHandler
       
  1098     // we are done
       
  1099     }
       
  1100 
       
  1101 
       
  1102 ////////////////////////////////////////////////////////////////////////////////
       
  1103 // ================ New private Helping functions ==============================
       
  1104 ////////////////////////////////////////////////////////////////////////////////
       
  1105 
       
  1106 // -----------------------------------------------------------------------------
       
  1107 // CPEngCSPSessManager::AccessCounter
       
  1108 // Find Access counter
       
  1109 // (other items were commented in a header).
       
  1110 // -----------------------------------------------------------------------------
       
  1111 //
       
  1112 CPEngAppAccessContainer* CPEngCSPSessManager::AccessCounter(
       
  1113     const TDesC& aAppId )
       
  1114     {
       
  1115     // look for the access counter manually
       
  1116     TInt count( iAccessCounters->Count() );
       
  1117     for ( TInt x( 0 ) ; x < count ; ++x )
       
  1118         {
       
  1119         CPEngAppAccessContainer* accessContainer =
       
  1120             static_cast <CPEngAppAccessContainer*>
       
  1121             ( ( *iAccessCounters )[ x ] );
       
  1122 
       
  1123         if ( KErrNone == accessContainer->AppId().Compare( aAppId ) )
       
  1124             {
       
  1125             return accessContainer;
       
  1126             }
       
  1127         }
       
  1128     return NULL;
       
  1129     }
       
  1130 
       
  1131 // -----------------------------------------------------------------------------
       
  1132 // CPEngCSPSessManager::CheckReferenceAccessD
       
  1133 // Check TInt ref access and reference access by the application Ids
       
  1134 // if all accesses are zero, it deletes itself
       
  1135 // (other items were commented in a header).
       
  1136 // -----------------------------------------------------------------------------
       
  1137 //
       
  1138 void CPEngCSPSessManager::CheckReferenceAccessD()
       
  1139     {
       
  1140     if ( !iAccessCount && !iAccessCounters->Count() )
       
  1141         {
       
  1142         delete this;
       
  1143         return;
       
  1144         }
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // CPEngCSPSessManager::UnloadTransactionFactories
       
  1149 // Unload Transaction factories
       
  1150 // Transaction factories are ref-counted singletons, so they should
       
  1151 // be closed rather than destroyed
       
  1152 // (other items were commented in a header).
       
  1153 // -----------------------------------------------------------------------------
       
  1154 //
       
  1155 void CPEngCSPSessManager::UnloadTransactionFactories()
       
  1156     {
       
  1157     for ( TInt x( iTransFactories.Count() - 1 ) ; x >= 0  ; --x )
       
  1158         {
       
  1159         iTransFactories[ x ]->Close();
       
  1160         iTransFactories.Remove( x );
       
  1161         }
       
  1162     iTransFactories.Reset();
       
  1163     }
       
  1164 
       
  1165 // -----------------------------------------------------------------------------
       
  1166 // CPEngCSPSessManager::ResetAccessContainers
       
  1167 // Reset access Containers
       
  1168 // Go through all access containers and close them
       
  1169 // (other items were commented in a header).
       
  1170 // -----------------------------------------------------------------------------
       
  1171 //
       
  1172 void CPEngCSPSessManager::ResetAccessContainers()
       
  1173     {
       
  1174     for ( TInt x( iAccessCounters->Count() - 1 ) ; x >= 0  ; --x )
       
  1175         {
       
  1176         static_cast<CPEngAppAccessContainer*>(
       
  1177             ( *iAccessCounters )[ x ] )->CloseContainer();
       
  1178         }
       
  1179 
       
  1180     // notify all connected sub-session to disattach their app ids
       
  1181     NotifyCPSClose();
       
  1182     }
       
  1183 
       
  1184 // -----------------------------------------------------------------------------
       
  1185 // CPEngCSPSessManager::NotifyDisconnectedAppId
       
  1186 // Inform sub-session about app Id disconnection
       
  1187 // (other items were commented in a header).
       
  1188 // -----------------------------------------------------------------------------
       
  1189 //
       
  1190 void CPEngCSPSessManager::NotifyDisconnectedAppId(
       
  1191     const TDesC& aAppId )
       
  1192     {
       
  1193     for ( TInt x( iServSubSessions.Count() - 1 ) ; x >= 0 ; --x )
       
  1194         {
       
  1195         iServSubSessions[ x ]->DisconnectAppId( aAppId );
       
  1196         }
       
  1197     }
       
  1198 
       
  1199 // -----------------------------------------------------------------------------
       
  1200 // CPEngCSPSessManager::NotifyCPSClose
       
  1201 // Inform sub-sessions about CPS close state
       
  1202 // (other items were commented in a header).
       
  1203 // -----------------------------------------------------------------------------
       
  1204 //
       
  1205 void CPEngCSPSessManager::NotifyCPSClose()
       
  1206     {
       
  1207     for ( TInt x( iServSubSessions.Count() - 1 ) ; x >= 0 ; --x )
       
  1208         {
       
  1209         iServSubSessions[ x ]->CSPSessionClosed();
       
  1210         }
       
  1211     }
       
  1212 
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CPEngCSPSessManager::NotifyNewEventL
       
  1215 // Inform sub-sessions about CPS close state
       
  1216 // (other items were commented in a header).
       
  1217 // -----------------------------------------------------------------------------
       
  1218 //
       
  1219 void CPEngCSPSessManager::NotifyNewEventL(
       
  1220     TPEngNWSessionSlotEvent aEvent,
       
  1221     const TDesC& aAppId,
       
  1222     TPEngNWSessionSlotState aAppIdState )
       
  1223     {
       
  1224     CPEngSessionSlotEvent* newEvent = CPEngSessionSlotEvent::NewLC();
       
  1225     newEvent->SetSessionSlotId( iSessionSlotId, EFalse );
       
  1226     newEvent->SetGlobSessSltState( iState );
       
  1227     newEvent->SetSessSltEvent( aEvent );
       
  1228     if ( aAppId != KNullDesC )
       
  1229         {
       
  1230         newEvent->SetAppIdL( aAppId );
       
  1231         newEvent->SetAppSessSltState( aAppIdState );
       
  1232         }
       
  1233     HBufC8* eventBuff = newEvent->PackEventLC();
       
  1234     // ignore error from notify
       
  1235     iStoreAdmin.NotifyEvent( *eventBuff );
       
  1236     CleanupStack::PopAndDestroy( 2 ); // eventBuff, newEvent
       
  1237     }
       
  1238 
       
  1239 
       
  1240 
       
  1241 // -----------------------------------------------------------------------------
       
  1242 // CPEngCSPSessManager::LeaveIfNotConnectedL()
       
  1243 // -----------------------------------------------------------------------------
       
  1244 //
       
  1245 void CPEngCSPSessManager::LeaveIfNotConnectedL() const
       
  1246     {
       
  1247     if ( iState != EPEngNWPresenceSessionOpen )
       
  1248         {
       
  1249         User::Leave( KErrNotReady );
       
  1250         }
       
  1251     }
       
  1252 
       
  1253 
       
  1254 //  End of File
       
  1255