|
1 /* |
|
2 * Copyright (c) 2004 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: Implements the CIMStatusFetcher and the MImStatusList interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "imstatusimpl.h" |
|
22 #include "apiutils.h" |
|
23 #include "imconnectionimpl.h" |
|
24 #include "cntdbreader.h" |
|
25 #include "impserrors.h" |
|
26 #include "imerrors.h" |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CIMStatusFetcherImpl::CIMStatusFetcherImpl |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CIMStatusFetcherImpl::CIMStatusFetcherImpl( CImConnectionImpl* aImConnection ) |
|
38 : iImConnection( aImConnection ) |
|
39 { |
|
40 #ifdef _DEBUG |
|
41 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: Construction" ) ); |
|
42 #endif |
|
43 |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CIMStatusFetcherImpl::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CIMStatusFetcherImpl::ConstructL() |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CIMStatusFetcherImpl::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CIMStatusFetcherImpl* CIMStatusFetcherImpl::NewL( CImConnectionImpl* aImConnection ) |
|
61 { |
|
62 CIMStatusFetcherImpl* self = new( ELeave ) CIMStatusFetcherImpl( aImConnection ); |
|
63 CleanupStack::PushL( self ); |
|
64 |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CIMStatusFetcherImpl::~CIMStatusFetcherImpl |
|
73 // Destructor |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CIMStatusFetcherImpl::~CIMStatusFetcherImpl() |
|
77 { |
|
78 #ifdef _DEBUG |
|
79 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: Destruction" ) ); |
|
80 #endif |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CIMStatusFetcherImpl::RegisterL |
|
86 // Starts the registration sequence |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 TInt CIMStatusFetcherImpl::RegisterObserverL( MImStatusObserver* aObserver ) |
|
90 { |
|
91 |
|
92 #ifdef _DEBUG |
|
93 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: RegisterL" ) ); |
|
94 #endif |
|
95 |
|
96 if ( iClientObserver ) |
|
97 { |
|
98 return KImApiErrAllreadyRegistered; |
|
99 } |
|
100 |
|
101 iClientObserver = aObserver; |
|
102 iPresenceClient.RegisterL( |
|
103 ImpsEngine(), |
|
104 ImpsPresenceHandler(), |
|
105 ClientId(), |
|
106 ETrue, |
|
107 0 ); |
|
108 |
|
109 iPresenceClient.RegisterErrorObserverL( ImpsErrorHandler() ); |
|
110 |
|
111 return KErrNone; |
|
112 |
|
113 |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CIMStatusFetcherImpl::UnregisterL |
|
118 // Unregisters the client from the WV engine |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CIMStatusFetcherImpl::UnregisterObserverL() |
|
122 { |
|
123 #ifdef _DEBUG |
|
124 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: UnregisterL" ) ); |
|
125 #endif |
|
126 |
|
127 iPresenceClient.Unregister(); |
|
128 iPresenceClient.UnregisterErrorObserverL(); |
|
129 |
|
130 return KErrNone; |
|
131 |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CIMStatusFetcherImpl::GetOnlineStatusL |
|
136 // Fetches the online status of the WV users given by WV user IDs in async way |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CIMStatusFetcherImpl::GetOnlineStatusL( const CDesCArray& aUserIds ) |
|
140 { |
|
141 #ifdef _DEBUG |
|
142 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: GetOnlineStatusL" ) ); |
|
143 #endif |
|
144 iPresenceClient.GetPresenceL( aUserIds ); |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CIMStatusFetcherImpl::GetOnlineStatusL |
|
150 // Fetches the online status of the WV users given by contact IDs in async way |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TInt CIMStatusFetcherImpl::GetOnlineStatusL( const CContactIdArray& aContactIds ) |
|
154 { |
|
155 |
|
156 #ifdef _DEBUG |
|
157 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: GetOnlineStatusL" ) ); |
|
158 CImApiLogger::Log( _L( " Item count: %d" ), aContactIds.Count() ); |
|
159 #endif |
|
160 |
|
161 CDesCArraySeg* userIds = new ( ELeave ) CDesCArraySeg( 1 ); |
|
162 CleanupStack::PushL( userIds ); |
|
163 iImConnection->ContactDBReader().ReadWVIdsL( aContactIds, *userIds ); |
|
164 |
|
165 #ifdef _DEBUG |
|
166 for ( TInt i( 0 ); i < userIds->MdcaCount(); ++i ) |
|
167 { |
|
168 TPtrC tmp = ( *userIds )[i]; |
|
169 CImApiLogger::Log( _L( " User ID: %S" ), &tmp ); |
|
170 } |
|
171 #endif |
|
172 |
|
173 TInt opId( 0 ); |
|
174 |
|
175 TRAPD( err, opId = iPresenceClient.GetPresenceL( *userIds ) ); |
|
176 CleanupStack::PopAndDestroy(); // >> userIds |
|
177 |
|
178 |
|
179 if ( err != KErrNone ) |
|
180 { |
|
181 return opId; |
|
182 } |
|
183 |
|
184 return KErrGeneral; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CIMStatusFetcherImpl::HandleCompleteL |
|
189 // Implementation of MImpsPresenceHandler::HandleCompleteL |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CIMStatusFetcherImpl::HandleCompleteL( TInt /*aStatus*/, |
|
193 TInt /*aOpId*/ ) |
|
194 { |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CIMStatusFetcherImpl::HandleNewPresenceL |
|
199 // Implementation of MImpsPresenceHandler::HandleNewPresenceL |
|
200 // Creates the CIMStatusList object with the IM statuses |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CIMStatusFetcherImpl::HandleNewPresenceL( TInt aStatus, |
|
204 TInt aOpId, |
|
205 CImpsPresenceList& aPresList ) |
|
206 { |
|
207 #ifdef _DEBUG |
|
208 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: HandleNewPresenceL" ) ); |
|
209 #endif |
|
210 |
|
211 CIMStatusListImpl* statusList = CIMStatusListImpl::NewL( aPresList ); |
|
212 CleanupStack::PushL( statusList ); |
|
213 |
|
214 if ( iClientObserver ) |
|
215 { |
|
216 TRAPD( err, iClientObserver->HandleGetOnlineStatusL( |
|
217 aOpId, |
|
218 aStatus, |
|
219 statusList ) ); |
|
220 } |
|
221 |
|
222 CleanupStack::PopAndDestroy(); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CIMStatusFetcherImpl::HandleErrorL |
|
227 // Implementation of MImpsPresenceHandler::HandleErrorL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CIMStatusFetcherImpl::HandleErrorL( TInt aStatus, |
|
231 TInt aOpId, |
|
232 const TDesC* /*aDescription*/, |
|
233 const CImpsDetailed* /*aDetailedRes*/ ) |
|
234 { |
|
235 #ifdef _DEBUG |
|
236 CImApiLogger::Log( _L( "CIMStatusFetcherImpl: Error received: %d" ), aStatus ); |
|
237 #endif |
|
238 |
|
239 TInt apiError; |
|
240 |
|
241 switch ( aStatus ) |
|
242 { |
|
243 case KImpsErrorNotLogged: |
|
244 apiError = KImApiErrNotLogged; |
|
245 break; |
|
246 |
|
247 default: |
|
248 apiError = KImApiGeneralError; |
|
249 } |
|
250 |
|
251 |
|
252 if ( iClientObserver ) |
|
253 { |
|
254 TRAPD( err, iClientObserver->HandleGetOnlineStatusL( |
|
255 aOpId, |
|
256 apiError, |
|
257 NULL ) ); |
|
258 } |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CIMStatusFetcherImpl::ImpsPresenceHandler |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 MImpsPresenceHandler* CIMStatusFetcherImpl::ImpsPresenceHandler() |
|
267 { |
|
268 return this; |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CIMStatusFetcherImpl::ImpsErrorHandler |
|
274 // |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 MImpsErrorHandler& CIMStatusFetcherImpl::ImpsErrorHandler() |
|
278 { |
|
279 return *this; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CIMStatusFetcherImpl::ImpsPresenceClient |
|
284 // |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 RImpsPresenceClient& CIMStatusFetcherImpl::ImpsPresenceClient() |
|
288 { |
|
289 return iPresenceClient; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CIMStatusFetcherImpl::ImpsEngine |
|
294 // |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 RImpsEng& CIMStatusFetcherImpl::ImpsEngine() |
|
298 { |
|
299 return iImConnection->ImpsEngine(); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CIMStatusFetcherImpl::ClientId |
|
304 // |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 TDesC& CIMStatusFetcherImpl::ClientId() |
|
308 { |
|
309 return *iClientId; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CIMStatusFetcherImpl::ClientObserver |
|
314 // |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 MImStatusObserver* CIMStatusFetcherImpl::ClientObserver() |
|
318 { |
|
319 return iClientObserver; |
|
320 } |
|
321 |
|
322 |
|
323 // End of File |