1 /* |
|
2 * Copyright (c) 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: Class handling the use of Cch |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32def.h> |
|
21 #include <cchserver.h> |
|
22 #include <cchclient.h> |
|
23 #include <spsettings.h> |
|
24 #include <spproperty.h> |
|
25 #include "cimcvenginefactory.h" |
|
26 |
|
27 #include "cimcvenginecchhandler.h" |
|
28 #include "imcvuiliterals.h" |
|
29 |
|
30 #include "imcvlogger.h" |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CIMCVEngineCchHandler::CIMCVEngineCchHandler |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CIMCVEngineCchHandler::CIMCVEngineCchHandler(TUint aServiceId, |
|
41 CIMCVEngine& aEngine) |
|
42 : iServiceId(aServiceId), |
|
43 iEngine(aEngine) |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CIMCVEngineCchHandler::ConstructL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CIMCVEngineCchHandler::ConstructL( ) |
|
52 { |
|
53 // Create service selection here |
|
54 iCchClient = CCch::NewL(); |
|
55 |
|
56 if (iCchClient) |
|
57 { |
|
58 CCchService* service = iCchClient->GetService( iServiceId ); |
|
59 |
|
60 if( service ) |
|
61 { |
|
62 service->SetObserver( *this ); |
|
63 } |
|
64 } |
|
65 iPrevNwError = 0; |
|
66 |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CIMCVEngineCchHandler::NewL |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CIMCVEngineCchHandler* |
|
74 CIMCVEngineCchHandler::NewL( TUint aServiceId, CIMCVEngine& aEngine ) |
|
75 { |
|
76 CIMCVEngineCchHandler* self = NewLC(aServiceId, aEngine); |
|
77 CleanupStack::Pop(self); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CIMCVEngineCchHandler::NewLC |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CIMCVEngineCchHandler* |
|
86 CIMCVEngineCchHandler::NewLC(TUint aServiceId, CIMCVEngine& aEngine ) |
|
87 { |
|
88 CIMCVEngineCchHandler* self = |
|
89 new (ELeave) CIMCVEngineCchHandler(aServiceId, aEngine); |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL( ); |
|
92 return self; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CIMCVEngineCchHandler::~CIMCVEngineCchHandler |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CIMCVEngineCchHandler::~CIMCVEngineCchHandler() |
|
100 { |
|
101 |
|
102 if(iCchClient) |
|
103 { |
|
104 CCchService* service = iCchClient->GetService( iServiceId ); |
|
105 if( service ) |
|
106 { |
|
107 service->RemoveObserver(); |
|
108 } |
|
109 delete iCchClient; |
|
110 } |
|
111 |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CIMCVEngineCchHandler::GetServiceState |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CIMCVEngineCchHandler::GetServiceState( |
|
121 TCCHSubserviceState& aCCHState |
|
122 ) |
|
123 { |
|
124 TInt err = KErrNone; |
|
125 CCchService* service = iCchClient->GetService( iServiceId ); |
|
126 TCchServiceStatus status; |
|
127 status.SetState(ECCHUninitialized); |
|
128 |
|
129 if( service ) |
|
130 { |
|
131 // Get status from the client |
|
132 err = service->GetStatus( ECCHIMSub, status ); |
|
133 } |
|
134 |
|
135 aCCHState = status.State(); |
|
136 |
|
137 return err; |
|
138 } |
|
139 |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CIMCVEngineCchHandler::EnableService |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CIMCVEngineCchHandler::EnableService() |
|
146 { |
|
147 |
|
148 // Retrieve service interface from the CCH client to be used to |
|
149 // enable aServiceType |
|
150 CCchService* service = iCchClient->GetService( iServiceId ); |
|
151 //Allowing Connectivity Dialogs for cch |
|
152 iCchClient->SetConnectivityDialogsAllowed( ETrue ); |
|
153 |
|
154 // By default set to fault value; if service pointer is valid then we |
|
155 // return the disable value, otherwise we return KErrNotFound |
|
156 TInt error = KErrNotFound; |
|
157 if( service ) |
|
158 { |
|
159 |
|
160 error = service->Enable( ECCHUnknown ); |
|
161 |
|
162 } |
|
163 |
|
164 |
|
165 return error; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CIMCVEngineCchHandler::GetAdapterUidL() |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CIMCVEngineCchHandler::GetAdapterUidL() |
|
173 { |
|
174 TInt ret = KErrNotFound; |
|
175 CSPProperty* property = CSPProperty::NewLC(); |
|
176 CSPSettings* settings = CSPSettings::NewLC(); |
|
177 TInt err = settings->FindPropertyL( iServiceId, |
|
178 EPropertyPCSPluginId,*property ); |
|
179 if (KErrNone == err) |
|
180 { |
|
181 property->GetValue( ret ); |
|
182 } |
|
183 CleanupStack::PopAndDestroy( settings ); |
|
184 CleanupStack::PopAndDestroy( property ); |
|
185 return ret; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CIMCVEngineCchHandler::GetUserIdL |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 HBufC* CIMCVEngineCchHandler::GetUserIdL() |
|
193 { |
|
194 HBufC* temp = NULL; |
|
195 CCchService* service = iCchClient->GetService( iServiceId ); |
|
196 // By default set to fault value; if service pointer is valid then we |
|
197 // return the disable value, otherwise we return KErrNotFound |
|
198 TInt error = KErrNotFound; |
|
199 if( service ) |
|
200 { |
|
201 RBuf username; |
|
202 username.Create(KMAXUSERIDLENGTH); |
|
203 CleanupClosePushL( username ); |
|
204 error = service->GetConnectionParameter(ECCHIMSub,ECchUsername,username); |
|
205 User::LeaveIfError( error); |
|
206 if( username.Length() > 0) |
|
207 { |
|
208 temp = username.AllocL(); // ownership transferred |
|
209 } |
|
210 CleanupStack::PopAndDestroy( &username ); |
|
211 } |
|
212 return temp; |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CIMCVEngineCchHandler::DisableService |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 TInt CIMCVEngineCchHandler::DisableService() |
|
222 { |
|
223 |
|
224 // Retrieve service interface from the CCH client to be used to |
|
225 // enable aServiceType |
|
226 CCchService* service = iCchClient->GetService( iServiceId ); |
|
227 // By default set to fault value; if service pointer is valid then we |
|
228 // return the disable value, otherwise we return KErrNotFound |
|
229 TInt error = KErrNotFound; |
|
230 if( service ) |
|
231 { |
|
232 error = service->Disable( ECCHUnknown ); |
|
233 } |
|
234 |
|
235 |
|
236 return error; |
|
237 } |
|
238 |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CIMCVEngineCchHandler::IsServiceLoggedIn |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 TBool CIMCVEngineCchHandler::IsServiceLoggedIn() |
|
245 { |
|
246 TCCHSubserviceState serviceState = ECCHUninitialized; |
|
247 |
|
248 TInt error = GetServiceState( serviceState ); |
|
249 |
|
250 if ( !error && ECCHEnabled == serviceState ) |
|
251 { |
|
252 return ETrue; |
|
253 } |
|
254 |
|
255 return EFalse; |
|
256 |
|
257 } |
|
258 |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CIMCVEngineCchHandler::ServiceStatusChanged |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CIMCVEngineCchHandler::ServiceStatusChanged( |
|
265 TInt aServiceId, |
|
266 const TCCHSubserviceType aType, |
|
267 const TCchServiceStatus& aServiceStatus ) |
|
268 { |
|
269 TRAP_IGNORE(DoHandleServiceStatusChangedL(aServiceId, aType, aServiceStatus)); |
|
270 } |
|
271 |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CIMCVEngineCchHandler::DoHandleServiceStatusChanged |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CIMCVEngineCchHandler::DoHandleServiceStatusChangedL( |
|
278 TInt aServiceId, |
|
279 const TCCHSubserviceType aType, |
|
280 const TCchServiceStatus& aServiceStatus ) |
|
281 { |
|
282 |
|
283 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL ") ); |
|
284 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL:TCCHSubserviceType=%d"),aType); |
|
285 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL:aServiceStatus.Error()=%d"),aServiceStatus.Error()); |
|
286 if (aType == ECCHPresenceSub) |
|
287 { |
|
288 /* SIP Adaptation -- sends error in Network Lost. This is added so that once we get it, we will unbindL and delete the context |
|
289 * This happens only in case of SIP as it does not send the event in IM Subservice. |
|
290 */ |
|
291 if (aServiceStatus.Error() && ECCHDisabled != aServiceStatus.State()) |
|
292 { |
|
293 iEngine.ReleaseConnectionL (); |
|
294 iEngine.DeleteContextL (); |
|
295 } |
|
296 } |
|
297 else if (aType == ECCHIMSub) |
|
298 { |
|
299 MIMCVEngineCCHObserver::TServiceState notifyEvent = |
|
300 MIMCVEngineCCHObserver::ENotLoggedIn; |
|
301 switch (aServiceStatus.State()) |
|
302 { |
|
303 case ECCHUninitialized: |
|
304 { |
|
305 //Nothing to be done |
|
306 break; |
|
307 } |
|
308 case ECCHDisabled: |
|
309 { |
|
310 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL DISABLED")); |
|
311 if(iPrevNwError != KCCHErrorNetworkLost) |
|
312 { |
|
313 iEngine.CloseAllOpenChatsL (); |
|
314 } |
|
315 iEngine.ReleaseConnectionL(); |
|
316 iEngine.DeleteContextL (); |
|
317 break; |
|
318 } |
|
319 case ECCHConnecting: |
|
320 { |
|
321 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL ECCHConnecting") ); |
|
322 iPrevNwError = aServiceStatus.Error(); |
|
323 notifyEvent = MIMCVEngineCCHObserver::EConnecting; |
|
324 break; |
|
325 } |
|
326 case ECCHEnabled: |
|
327 { |
|
328 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL ECCHEnabled") ); |
|
329 notifyEvent = MIMCVEngineCCHObserver::ELogin; |
|
330 iEngine.CreateContextL(); |
|
331 break; |
|
332 } |
|
333 case ECCHDisconnecting: |
|
334 { |
|
335 // If NetworkErrorLost error is received by CCH on this state, then do not close all chats |
|
336 // as user would loose all the on-going conversation when the network connection is |
|
337 // restored. |
|
338 IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL ECCHDisconnecting") ); |
|
339 // if (aServiceStatus.Error () != KCCHErrorNetworkLost ) |
|
340 // { |
|
341 // iEngine.CloseAllOpenChatsL(); |
|
342 // iEngine.ReleaseConnectionL (); |
|
343 // iEngine.DeleteContextL (); |
|
344 // } |
|
345 notifyEvent = MIMCVEngineCCHObserver::EDisconnecting; |
|
346 break; |
|
347 } |
|
348 default: |
|
349 { |
|
350 break; |
|
351 } |
|
352 } |
|
353 |
|
354 if (iObserver) |
|
355 { |
|
356 iObserver->ServiceStatusChanged( aServiceId, |
|
357 notifyEvent ); |
|
358 |
|
359 } |
|
360 |
|
361 } |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // CIMCVEngineCchHandler::RegisterObserver |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CIMCVEngineCchHandler::RegisterObserver(MIMCVEngineCCHObserver* aObserver) |
|
369 { |
|
370 if (aObserver) |
|
371 { |
|
372 iObserver = aObserver; |
|
373 } |
|
374 } |
|
375 |
|
376 |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CIMCVEngineCchHandler::UnRegisterObserver |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CIMCVEngineCchHandler::UnRegisterObserver() |
|
383 { |
|
384 iObserver = NULL; |
|
385 } |
|
386 |
|
387 |
|
388 // End of file |
|
389 |
|