1 /* |
|
2 * Copyright (c) 2010 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 |
|
19 |
|
20 #include "creator_contactsetcache.h" |
|
21 |
|
22 |
|
23 CContactLinkCacheImp* ContactLinkCache::iImp = 0; |
|
24 |
|
25 CCreatorContactSet* CCreatorContactSet::NewL(TInt aLinkId, TInt aNumOfExistingContacts) |
|
26 { |
|
27 return new (ELeave) CCreatorContactSet(aLinkId, aNumOfExistingContacts); |
|
28 } |
|
29 |
|
30 TInt CCreatorContactSet::LinkId() const |
|
31 { |
|
32 return iLinkId; |
|
33 } |
|
34 |
|
35 void CCreatorContactSet::AppendL(TUint32 aContactLink) |
|
36 { |
|
37 iContactLinks.AppendL(aContactLink); |
|
38 } |
|
39 |
|
40 RArray<TUint32> CCreatorContactSet::ContactLinks() |
|
41 { |
|
42 return iContactLinks; |
|
43 } |
|
44 |
|
45 const RArray<TUint32> CCreatorContactSet::ContactLinks() const |
|
46 { |
|
47 return iContactLinks; |
|
48 } |
|
49 |
|
50 |
|
51 TInt CCreatorContactSet::NumberOfExistingContacts() const |
|
52 { |
|
53 return iNumOfExistingContacts; |
|
54 } |
|
55 |
|
56 CCreatorContactSet::~CCreatorContactSet() |
|
57 { |
|
58 iContactLinks.Reset(); |
|
59 iContactLinks.Close(); |
|
60 } |
|
61 |
|
62 |
|
63 CCreatorContactSet::CCreatorContactSet(TInt aLinkId, TInt aNumOfExistingContacts) |
|
64 { |
|
65 iLinkId = aLinkId; |
|
66 iNumOfExistingContacts = aNumOfExistingContacts; |
|
67 } |
|
68 |
|
69 class CContactLinkCacheImp : public CBase, public MContactLinkCache |
|
70 { |
|
71 public: |
|
72 static CContactLinkCacheImp* NewL(); |
|
73 virtual ~CContactLinkCacheImp(); |
|
74 virtual void AppendL(CCreatorContactSet* aContactSet); |
|
75 |
|
76 virtual RArray<TUint32> ContactLinks(TInt aLinkId); |
|
77 virtual const RArray<TUint32> ContactLinks(TInt aLinkId) const; |
|
78 |
|
79 virtual RPointerArray<CCreatorContactSet>& ContactSets(); |
|
80 virtual const RPointerArray<CCreatorContactSet>& ContactSets() const; |
|
81 virtual const CCreatorContactSet& ContactSet(TInt aLinkId) const; |
|
82 virtual CCreatorContactSet& ContactSet(TInt aLinkId); |
|
83 |
|
84 private: |
|
85 void ConstructL(); |
|
86 CContactLinkCacheImp(); |
|
87 |
|
88 RArray<TUint32> iEmptyLinks; |
|
89 |
|
90 RPointerArray<CCreatorContactSet> iContactSets; |
|
91 CCreatorContactSet* iDummyContactSet; |
|
92 }; |
|
93 |
|
94 CContactLinkCacheImp* CContactLinkCacheImp::NewL() |
|
95 { |
|
96 CContactLinkCacheImp* self = new (ELeave) CContactLinkCacheImp(); |
|
97 CleanupStack::PushL(self); |
|
98 self->ConstructL(); |
|
99 CleanupStack::Pop(); |
|
100 return self; |
|
101 } |
|
102 |
|
103 void CContactLinkCacheImp::ConstructL() |
|
104 { |
|
105 if( iDummyContactSet == 0 ) |
|
106 iDummyContactSet = CCreatorContactSet::NewL(-1, 0); |
|
107 } |
|
108 |
|
109 CContactLinkCacheImp::CContactLinkCacheImp() |
|
110 : iDummyContactSet(0) |
|
111 {} |
|
112 |
|
113 CContactLinkCacheImp::~CContactLinkCacheImp() |
|
114 { |
|
115 iEmptyLinks.Reset();// just in case... |
|
116 iEmptyLinks.Close(); |
|
117 |
|
118 iContactSets.ResetAndDestroy(); |
|
119 iContactSets.Close(); |
|
120 delete iDummyContactSet; |
|
121 } |
|
122 void CContactLinkCacheImp::AppendL(CCreatorContactSet* aContactSet) |
|
123 { |
|
124 iContactSets.AppendL(aContactSet); |
|
125 } |
|
126 RArray<TUint32> CContactLinkCacheImp::ContactLinks(TInt aLinkId) |
|
127 { |
|
128 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
129 { |
|
130 if( iContactSets[i]->LinkId() == aLinkId ) |
|
131 { |
|
132 return iContactSets[i]->ContactLinks(); |
|
133 } |
|
134 } |
|
135 return iEmptyLinks; |
|
136 } |
|
137 |
|
138 const RArray<TUint32> CContactLinkCacheImp::ContactLinks(TInt aLinkId) const |
|
139 { |
|
140 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
141 { |
|
142 if( iContactSets[i]->LinkId() == aLinkId ) |
|
143 { |
|
144 return iContactSets[i]->ContactLinks(); |
|
145 } |
|
146 } |
|
147 return iEmptyLinks; |
|
148 } |
|
149 |
|
150 |
|
151 const CCreatorContactSet& CContactLinkCacheImp::ContactSet(TInt aLinkId) const |
|
152 { |
|
153 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
154 { |
|
155 if( iContactSets[i]->LinkId() == aLinkId ) |
|
156 { |
|
157 return *iContactSets[i]; |
|
158 } |
|
159 } |
|
160 |
|
161 return *iDummyContactSet; |
|
162 } |
|
163 |
|
164 CCreatorContactSet& CContactLinkCacheImp::ContactSet(TInt aLinkId) |
|
165 { |
|
166 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
167 { |
|
168 if( iContactSets[i]->LinkId() == aLinkId ) |
|
169 { |
|
170 return *iContactSets[i]; |
|
171 } |
|
172 } |
|
173 |
|
174 return *iDummyContactSet; |
|
175 } |
|
176 |
|
177 RPointerArray<CCreatorContactSet>& CContactLinkCacheImp::ContactSets() |
|
178 { |
|
179 return iContactSets; |
|
180 } |
|
181 |
|
182 const RPointerArray<CCreatorContactSet>& CContactLinkCacheImp::ContactSets() const |
|
183 { |
|
184 return iContactSets; |
|
185 } |
|
186 |
|
187 |
|
188 void ContactLinkCache::InitializeL() |
|
189 { |
|
190 if( iImp == 0 ) |
|
191 { |
|
192 iImp = CContactLinkCacheImp::NewL(); |
|
193 } |
|
194 } |
|
195 |
|
196 void ContactLinkCache::DestroyL() |
|
197 { |
|
198 delete iImp; |
|
199 iImp = 0; |
|
200 } |
|
201 |
|
202 MContactLinkCache* ContactLinkCache::Instance() |
|
203 { |
|
204 return iImp; |
|
205 } |
|
206 |
|
207 |
|
208 /*{ |
|
209 public: |
|
210 static void ; |
|
211 static void DestructLD(); |
|
212 |
|
213 static MContactLinkCache* Instance(); |
|
214 |
|
215 private: |
|
216 CContactLinkImp* iImp; |
|
217 };*/ |
|
218 |
|