presencecache/presencecacheserver2/src/presencecacheexpiry.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "presencecacheexpiry.h"
       
    20 #include    "presencecachebuddystore.h"
       
    21 #include    "presencecacheserver.h"
       
    22 #include    "presencecachesession.h"
       
    23 #include    "mpresencebuddyinfo2.h"
       
    24 #include    "presencecacheservicestore.h"
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CPresenceCacheExpiry::CPresenceCacheExpiry
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 inline CPresenceCacheExpiry::CPresenceCacheExpiry(
       
    34         CPresenceCacheServer& aServer )
       
    35 : iAsyncCallBack( TCallBack( CPresenceCacheExpiry::ExpiryCheck, this ),
       
    36         CActive::EPriorityIdle),
       
    37   iServer( aServer )
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CPresenceCacheExpiry::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CPresenceCacheExpiry* CPresenceCacheExpiry::NewL(
       
    46         CPresenceCacheServer& aServer )
       
    47     {
       
    48     return new( ELeave ) CPresenceCacheExpiry(aServer);
       
    49     }
       
    50 
       
    51 
       
    52 // Destructor
       
    53 CPresenceCacheExpiry::~CPresenceCacheExpiry()
       
    54     {
       
    55     iAsyncCallBack.Cancel();
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CPresenceCacheExpiry::ExpiryCheck
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 TInt CPresenceCacheExpiry::ExpiryCheck(TAny *aPtr)
       
    63     {
       
    64     CPresenceCacheExpiry* self = static_cast<CPresenceCacheExpiry*>(aPtr);
       
    65     TRAP_IGNORE(self->DoExpiryCheckL());
       
    66     return EFalse;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CPresenceCacheExpiry::NotifySubscribersL
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CPresenceCacheExpiry::NotifySubscribersL( 
       
    74         CPresenceCacheBuddyStore& aBuddyStore )
       
    75     {
       
    76     RPointerArray<CPresenceCacheSession> sessions = 
       
    77             aBuddyStore.GetSubscribedSessions();
       
    78     const TInt sessionCount( sessions.Count() );
       
    79     MPresenceBuddyInfo2* buddyInfoTemp =  MPresenceBuddyInfo2::NewLC();
       
    80     buddyInfoTemp->SetIdentityL( aBuddyStore.BuddyId() );
       
    81     
       
    82     for( TInt i = 0 ; i < sessionCount ; ++i )
       
    83         {
       
    84         CPresenceCacheSession* session = sessions[i];
       
    85         if (iServer.SessionExists(session))
       
    86             {
       
    87             session->NotifyPresenceChangeL( buddyInfoTemp );
       
    88             }
       
    89         }
       
    90     CleanupStack::PopAndDestroy(); // buddyInfoTemp
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CPresenceCacheExpiry::DoExpiryCheckL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CPresenceCacheExpiry::DoExpiryCheckL()
       
    98     {
       
    99     RPointerArray<CPresenceCacheServiceStore>& presenceCache = 
       
   100             iServer.iPresenceCache;
       
   101     
       
   102     RPointerArray<CPresenceCacheBuddyStore> buddyStores;
       
   103     
       
   104     const TInt serviceCount(presenceCache.Count());
       
   105     for( TInt i = 0 ; i < serviceCount ; ++i )
       
   106         {
       
   107         presenceCache[i]->RemoveExpiredBuddyInfos( buddyStores );
       
   108         }
       
   109     
       
   110     const TInt buddyStoreCount( buddyStores.Count() );
       
   111     for( TInt i = 0 ; i < buddyStoreCount ; ++i )
       
   112         {
       
   113         NotifySubscribersL( *( buddyStores[i] ) );
       
   114         }
       
   115     }
       
   116 
       
   117 //  End of File