pimprotocols/pbap/inc/pbappbhandlecache.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef PBAPPBHANDLECACHE_H
       
    17 #define PBAPPBHANDLECACHE_H
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <badesca.h>
       
    21 #include <cntdef.h>
       
    22 #include <cntdbobs.h>
       
    23 
       
    24 //constants
       
    25 const TInt KOwnCardHandle = 0;
       
    26 
       
    27 //forward declarations
       
    28 class CContactDatabase;
       
    29 class CContactChangeNotifier;
       
    30 
       
    31 
       
    32 class MPbHandleCacheObserver
       
    33 	{
       
    34 public:
       
    35 	virtual void HandleCacheChanged()=0;
       
    36 	};
       
    37 	
       
    38 
       
    39 class TPbHandleAndId
       
    40 	{
       
    41 public:
       
    42 	inline TPbHandleAndId(TInt aHandle, TContactItemId aContactId) : iHandle(aHandle), iContactId(aContactId) {};
       
    43 	
       
    44 public:
       
    45 	TInt iHandle;
       
    46 	TContactItemId iContactId;
       
    47 	};
       
    48 
       
    49 				
       
    50 class CPbapPbHandleCache : public CBase, public MContactDbObserver
       
    51 	{
       
    52 public:
       
    53 	static CPbapPbHandleCache* NewL(CContactDatabase& aDatabase, MPbHandleCacheObserver& aObserver);
       
    54 	~CPbapPbHandleCache();
       
    55 
       
    56 public:
       
    57 	TInt HandleAtL(TUint aIndex) const;
       
    58 	TContactItemId ContactIdAtL(TUint aIndex) const;
       
    59 	TInt FindHandle(TInt aHandle) const;
       
    60 	TInt FindContactId(TContactItemId aContactId) const;	
       
    61 	inline TInt Count() const;	
       
    62 
       
    63 public:
       
    64 	static TInt CompareHandles(const TPbHandleAndId& aFirst, const TPbHandleAndId& aSecond);
       
    65 	static TBool MatchContactIds(const TPbHandleAndId& aFirst, const TPbHandleAndId& aSecond);
       
    66 
       
    67 private:
       
    68 	CPbapPbHandleCache(CContactDatabase& aDatabase, MPbHandleCacheObserver& aObserver);
       
    69 	void ConstructL();
       
    70 	void CreateHandleListL();
       
    71 
       
    72 	void HandleContactAddedL(TContactItemId aContactId);
       
    73 	void HandleContactDeleted(TContactItemId aContactId);
       
    74 	void HandleOwnCardChangedL();
       
    75 	void HandleOwnCardDeleted();
       
    76 	TInt NextAvailableHandleL() const;
       
    77 		
       
    78 private: 
       
    79 	//from MContactDbObserver	
       
    80 	void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
       
    81 	
       
    82 private:
       
    83 	CContactDatabase& iDatabase;
       
    84 	MPbHandleCacheObserver& iObserver;
       
    85 	CContactChangeNotifier* iChangeNotifier;
       
    86 
       
    87 	RArray<TPbHandleAndId> iHandleList;
       
    88 	
       
    89 	};
       
    90 
       
    91 inline TInt CPbapPbHandleCache::Count() const
       
    92 	{
       
    93 	return iHandleList.Count();
       
    94 	}
       
    95 		
       
    96 #endif // PBAPPBHANDLECACHE_H