|
1 /* |
|
2 * Copyright (c) 2007, 2008 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: CPresenceBuddyInfoListImp object implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include <ximpidentity.h> |
|
21 #include <presencebuddyinfo.h> |
|
22 |
|
23 #include "presencebuddyinfolistimp.h" |
|
24 #include "presencebuddyinfoimp.h" |
|
25 #include "ximpidentityimp.h" |
|
26 #include "ximptrace.h" |
|
27 #include "ximprbufhelpers.h" |
|
28 |
|
29 _LIT(KColon, ":"); |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CPresenceBuddyInfoListImp::NewLC() |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CPresenceBuddyInfoListImp* CPresenceBuddyInfoListImp::NewLC( |
|
36 const TDesC& aServiceName) |
|
37 { |
|
38 CPresenceBuddyInfoListImp* self = new( ELeave ) CPresenceBuddyInfoListImp; |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(aServiceName); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CPresenceBuddyInfoListImp::NewL() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CPresenceBuddyInfoListImp* CPresenceBuddyInfoListImp::NewL( |
|
49 const TDesC& aServiceName) |
|
50 { |
|
51 CPresenceBuddyInfoListImp* self = NewLC(aServiceName); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CPresenceBuddyInfoListImp::~CPresenceBuddyInfoListImp() |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CPresenceBuddyInfoListImp::~CPresenceBuddyInfoListImp() |
|
61 { |
|
62 if(iOwnDataObjects) |
|
63 { |
|
64 TInt count = iBuddyCollection.Count(); |
|
65 for (TInt i=0;i<count;i++) |
|
66 { |
|
67 delete iBuddyCollection[i]; |
|
68 } |
|
69 } |
|
70 iBuddyCollection.Close(); |
|
71 iService.Close(); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CPresenceBuddyInfoListImp::CPresenceBuddyInfoListImp() |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CPresenceBuddyInfoListImp::CPresenceBuddyInfoListImp() :iOwnDataObjects(ETrue) |
|
79 { |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CPresenceBuddyInfoListImp::ConstructL() |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CPresenceBuddyInfoListImp::ConstructL(const TDesC& aServiceName) |
|
87 { |
|
88 iService.Close(); |
|
89 iService.CreateL( aServiceName ); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CPresenceBuddyInfoListImp::ConstructL() |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CPresenceBuddyInfoListImp::ConstructL() |
|
97 { |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CPresenceBuddyInfoListImp::SetOwnObjects() |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C void CPresenceBuddyInfoListImp::SetOwnObjects(TBool aOwnObjects) |
|
105 { |
|
106 iOwnDataObjects = aOwnObjects; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CPresenceBuddyInfoListImp::PresenceInfo() |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 RPointerArray<MPresenceBuddyInfo>& CPresenceBuddyInfoListImp::GetObjectCollection() |
|
114 { |
|
115 return iBuddyCollection; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CPresenceBuddyInfoListImp::ServiceName() |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 TPtrC CPresenceBuddyInfoListImp::ServiceName() const |
|
123 { |
|
124 return iService; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CPresenceBuddyInfoListImp::Count() |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 TInt CPresenceBuddyInfoListImp::Count() const |
|
132 { |
|
133 return iBuddyCollection.Count(); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CPresenceBuddyInfoListImp::AddOrReplace() |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CPresenceBuddyInfoListImp::AddOrReplace( |
|
141 MPresenceBuddyInfo* aPresenceBuddyInfo) |
|
142 { |
|
143 TRACE( _L("CPresenceBuddyInfoListImp::AddOrReplace - begin") ); |
|
144 TRACE_1( _L("______identity: %S"), &(aPresenceBuddyInfo->BuddyId()->Identity())); |
|
145 if(!aPresenceBuddyInfo) |
|
146 return KErrArgument; |
|
147 |
|
148 if ( (ServiceName() != KNullDesC) && |
|
149 (ExtractService( aPresenceBuddyInfo->BuddyId()->Identity()).Compare( ServiceName()) )) |
|
150 { |
|
151 return KErrArgument; |
|
152 } |
|
153 TInt count = iBuddyCollection.Count(); |
|
154 for(TInt i=0;i<count;i++) |
|
155 { |
|
156 if( ((iBuddyCollection[i])->EqualsIdentity(aPresenceBuddyInfo))) |
|
157 { |
|
158 delete iBuddyCollection[i]; |
|
159 iBuddyCollection.Remove(i); |
|
160 TRACE( _L("_________Match found") ); |
|
161 break; |
|
162 } |
|
163 } |
|
164 iBuddyCollection.Append(aPresenceBuddyInfo); |
|
165 TRACE( _L("CPresenceBuddyInfoListImp::AddOrReplace - return")); |
|
166 return KErrNone; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CPresenceBuddyInfoListImp::FindAndRemove() |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 TInt CPresenceBuddyInfoListImp::FindAndRemove(const MXIMPIdentity& aIdentity) |
|
174 { |
|
175 TRACE( _L("CPresenceBuddyInfoListImp::FindAndRemove - begin") ); |
|
176 TRACE_1( _L("______identity: %S"), &(aIdentity.Identity())); |
|
177 TInt err(KErrNotFound); |
|
178 TInt count = iBuddyCollection.Count(); |
|
179 for(TInt i=0;i<count;i++) |
|
180 { |
|
181 if( ((iBuddyCollection[i])->BuddyId()->Identity())== aIdentity.Identity() ) |
|
182 { |
|
183 delete iBuddyCollection[i]; |
|
184 iBuddyCollection.Remove(i); |
|
185 err = KErrNone; |
|
186 break; |
|
187 } |
|
188 } |
|
189 TRACE_1( _L("CPresenceBuddyInfoListImp::FindAndRemove - err=%d"),err ); |
|
190 return err; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CPresenceBuddyInfoListImp::FindAndGet() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 MPresenceBuddyInfo* CPresenceBuddyInfoListImp::FindAndGet( |
|
198 const MXIMPIdentity& aIdentity) const |
|
199 { |
|
200 TRACE( _L("CPresenceBuddyInfoListImp::FindAndGet - begin") ); |
|
201 TRACE_1( _L("______identity: %S"), &(aIdentity.Identity())); |
|
202 MPresenceBuddyInfo* buddyPresInfo(NULL); |
|
203 |
|
204 TInt count = iBuddyCollection.Count(); |
|
205 for(TInt i=0;i<count;i++) |
|
206 { |
|
207 if( ((iBuddyCollection[i])->BuddyId()->Identity())== aIdentity.Identity() ) |
|
208 { |
|
209 buddyPresInfo = iBuddyCollection[i]; |
|
210 break; |
|
211 } |
|
212 } |
|
213 TRACE_1( _L("CPresenceBuddyInfoListImp::FindAndGet - buddyPresInfo=%d"),buddyPresInfo ); |
|
214 return buddyPresInfo; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CPresenceBuddyInfoListImp::NewFromStreamLC() |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CPresenceBuddyInfoListImp ) |
|
222 |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // Implement supported interface access. |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CPresenceBuddyInfoListImp, |
|
229 MPresenceBuddyInfoList ) |
|
230 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
231 |
|
232 |
|
233 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CPresenceBuddyInfoListImp, |
|
234 MPresenceBuddyInfoList ) |
|
235 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CPresenceBuddyInfoListImp::ExternalizeL() |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C void CPresenceBuddyInfoListImp::ExternalizeL( RWriteStream& aStream ) const |
|
242 { |
|
243 TUint32 count = iBuddyCollection.Count(); |
|
244 CPresenceBuddyInfoImp* tmp(NULL); |
|
245 |
|
246 aStream.WriteInt32L(count); |
|
247 for (TInt i=0;i<count;i++) |
|
248 { |
|
249 tmp = TXIMPGetImpClassOrPanic< CPresenceBuddyInfoImp >::From( *(iBuddyCollection[i])); |
|
250 tmp->ExternalizeL( aStream ); |
|
251 } |
|
252 |
|
253 XIMPRBuf16Helper::ExternalizeL( iService, aStream ); |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // CPresenceBuddyInfoListImp::InternalizeL() |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CPresenceBuddyInfoListImp::InternalizeL( RReadStream& aStream ) |
|
261 { |
|
262 TUint32 internalizeCount = aStream.ReadInt32L(); |
|
263 CPresenceBuddyInfoImp* tmp(NULL); |
|
264 for (TInt i=0;i<internalizeCount;i++) |
|
265 { |
|
266 tmp = CPresenceBuddyInfoImp::NewLC(); |
|
267 tmp->InternalizeL( aStream ); |
|
268 iBuddyCollection.Append(tmp); |
|
269 CleanupStack::Pop( tmp ); |
|
270 } |
|
271 XIMPRBuf16Helper::InternalizeL( iService, aStream ); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CPresenceBuddyInfoListImp::EqualsContent() |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 TBool CPresenceBuddyInfoListImp::EqualsContent( |
|
279 const CXIMPApiDataObjBase& /*aOtherInstance*/ ) const |
|
280 { |
|
281 //Not implemented |
|
282 return EFalse; |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // CPresenceBuddyInfoListImp::BlindAddL() |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C TInt CPresenceBuddyInfoListImp::BlindAddL( |
|
290 MPresenceBuddyInfo* aPresenceBuddyInfo) |
|
291 { |
|
292 if(!aPresenceBuddyInfo) |
|
293 return KErrArgument; |
|
294 iBuddyCollection.Append(aPresenceBuddyInfo); |
|
295 return KErrNone; |
|
296 } |
|
297 |
|
298 // -------------------------------------------------------------------------- |
|
299 // CPresenceBuddyInfoListImp::ExtractService |
|
300 // -------------------------------------------------------------------------- |
|
301 // |
|
302 TPtrC CPresenceBuddyInfoListImp::ExtractService( const TDesC& aXspId ) |
|
303 { |
|
304 TInt pos = aXspId.Find(KColon); |
|
305 if ( pos >= 0) |
|
306 { |
|
307 // ok input |
|
308 return aXspId.Left(pos); |
|
309 } |
|
310 else |
|
311 { |
|
312 // return something in illegal input case |
|
313 return aXspId; |
|
314 } |
|
315 } |
|
316 |
|
317 // eof |