|
1 /* |
|
2 * Copyright (c) 2008-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: This file contains the implementation of CPEServiceHandling class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpephonemodelinternal.h> |
|
20 #include <mpedatastore.h> |
|
21 #include <pevirtualengine.h> |
|
22 #include <e32debug.h> |
|
23 #include <talogger.h> |
|
24 |
|
25 #include "cpeservicehandling.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CPEServiceHandling::CPEServiceHandling( MPEPhoneModelInternal& aModel ) |
|
34 : iModel( aModel ) |
|
35 { |
|
36 TEFLOGSTRING( KTAOBJECT, "PE CPEServiceHandling::CPEServiceHandling" ); |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Constructor |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CPEServiceHandling::ConstructL() |
|
44 { |
|
45 TEFLOGSTRING( KTAOBJECT, "PE CPEServiceHandling::ConstructL" ); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Constructor |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C CPEServiceHandling* CPEServiceHandling::NewL( MPEPhoneModelInternal& aModel ) |
|
53 { |
|
54 CPEServiceHandling* self = CPEServiceHandling::NewLC(aModel); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Constructor |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CPEServiceHandling* CPEServiceHandling::NewLC( MPEPhoneModelInternal& aModel ) |
|
64 { |
|
65 CPEServiceHandling* self = new( ELeave ) CPEServiceHandling( aModel ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CPEServiceHandling::~CPEServiceHandling() |
|
76 { |
|
77 TEFLOGSTRING( KTAOBJECT, "PE CPEServiceHandling::~CPEServiceHandling" ); |
|
78 delete iCchClient; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CPEServiceHandling::EnableService |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CPEServiceHandling::EnableServiceL( TInt aServiceId ) |
|
86 { |
|
87 TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::EnableServiceL" ); |
|
88 |
|
89 if ( !iCchClient ) |
|
90 { |
|
91 iCchClient = CCch::NewL(); |
|
92 } |
|
93 |
|
94 CCchService* service = iCchClient->GetService( aServiceId ); |
|
95 |
|
96 TInt error( KErrNotFound ); |
|
97 if( service ) |
|
98 { |
|
99 iCurrentServiceId = aServiceId; |
|
100 |
|
101 TCchServiceStatus serviceStatus; |
|
102 error = service->GetStatus( ECCHVoIPSub, serviceStatus ); |
|
103 TCCHSubserviceState state = serviceStatus.State(); |
|
104 |
|
105 if( error == KErrNone ) |
|
106 { |
|
107 if ( serviceStatus.Error() == KErrNone ) |
|
108 { |
|
109 error = EnableServiceIfNeeded( state, *service ); |
|
110 } |
|
111 else |
|
112 { |
|
113 TEFLOGSTRING2( KTAERROR, |
|
114 "PE CPEServiceHandling::EnableServiceL, error: %d" |
|
115 , serviceStatus.Error() ); |
|
116 SendErrorMessage( serviceStatus.Error()); |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 if ( error != KErrNone ) |
|
122 { |
|
123 if ( error == KErrNotFound ) |
|
124 { |
|
125 iModel.SendMessage( MEngineMonitor::EPEMessageNoService ); |
|
126 } |
|
127 else |
|
128 { |
|
129 TEFLOGSTRING2( KTAERROR, |
|
130 "PE CPEServiceHandling::EnableServiceL, Error: %d" |
|
131 , error ); |
|
132 SendErrorMessage( error ); |
|
133 } |
|
134 } |
|
135 |
|
136 TEFLOGSTRING2( KTAINT, |
|
137 "PE CPEServiceHandling::EnableServiceL, error: %d", error ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CPEServiceHandling::EnableServiceIfNeeded |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CPEServiceHandling::EnableServiceIfNeeded( |
|
145 const TCCHSubserviceState& aState, |
|
146 CCchService& aService ) |
|
147 { |
|
148 TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::EnableServiceIfNeeded" ); |
|
149 TInt error = KErrNone; |
|
150 |
|
151 TEFLOGSTRING2( KTAINT, |
|
152 "PE CPEServiceHandling::EnableServiceIfNeeded, aState: %d", aState ); |
|
153 switch ( aState ) |
|
154 { |
|
155 case ECCHEnabled: |
|
156 { |
|
157 iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabled ); |
|
158 } |
|
159 break; |
|
160 case ECCHUninitialized: |
|
161 case ECCHDisabled: |
|
162 case ECCHConnecting: |
|
163 { |
|
164 // Temporary solution, it will be fixed as soon as possible. |
|
165 // Message have to send before enable is called. Reason is so that progress bar |
|
166 //(global note) doesn't hide Networks's "Connection Needed" global note. |
|
167 iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabling ); |
|
168 aService.AddObserver( *this ); |
|
169 error = aService.Enable( ECCHUnknown ); |
|
170 } |
|
171 break; |
|
172 case ECCHDisconnecting: |
|
173 { |
|
174 error = KErrNotFound; |
|
175 } |
|
176 break; |
|
177 default: |
|
178 break; |
|
179 } |
|
180 TEFLOGSTRING2( KTAINT, |
|
181 "PE CPEServiceHandling::EnableServiceIfNeeded, error: %d", error ); |
|
182 return error; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CPEServiceHandling::ServiceStatusChanged |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CPEServiceHandling::ServiceStatusChanged( |
|
190 TInt aServiceId, |
|
191 const TCCHSubserviceType aType, |
|
192 const TCchServiceStatus& aServiceStatus ) |
|
193 { |
|
194 TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::ServiceStatusChanged <" ); |
|
195 |
|
196 if( aServiceId == iCurrentServiceId && aType == ECCHVoIPSub ) |
|
197 { |
|
198 TEFLOGSTRING3( KTAINT, |
|
199 "PE CPEServiceHandling::ServiceStatusChanged, state: %d, error: %d" |
|
200 , aServiceStatus.State() |
|
201 , aServiceStatus.Error() ); |
|
202 |
|
203 CCchService* service = iCchClient->GetService( aServiceId ); |
|
204 if( service ) |
|
205 { |
|
206 if( aServiceStatus.Error() != KErrNone ) |
|
207 { |
|
208 TEFLOGSTRING( KTAERROR, |
|
209 "PE CPEServiceHandling::ServiceStatusChanged, error" ); |
|
210 SendErrorMessage( aServiceStatus.Error()); |
|
211 CancelServiceEnabling(); |
|
212 } |
|
213 else |
|
214 { |
|
215 if( aServiceStatus.State() == ECCHEnabled ) |
|
216 { |
|
217 TEFLOGSTRING( KTAINT, |
|
218 "PE CPEServiceHandling::ServiceStatusChanged, enabled" ); |
|
219 iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabled ); |
|
220 } |
|
221 |
|
222 |
|
223 // Notify UI, that service is disabled. |
|
224 else if( aServiceStatus.State() == ECCHDisabled ) |
|
225 { |
|
226 TEFLOGSTRING( KTAERROR, |
|
227 "PE CPEServiceHandling::ServiceStatusChanged, disabled" ); |
|
228 iModel.SendMessage( MEngineMonitor::EPEMessageServiceDisabled ); |
|
229 } |
|
230 } |
|
231 |
|
232 // don't remove observer, if state are connecting or disconnecting |
|
233 if ( aServiceStatus.State() != ECCHConnecting && |
|
234 aServiceStatus.State() != ECCHDisconnecting ) |
|
235 { |
|
236 service->RemoveObserver( *this ); |
|
237 } |
|
238 }//if( service ) |
|
239 else |
|
240 { |
|
241 TEFLOGSTRING( KTAERROR, |
|
242 "PE CPEServiceHandling::ServiceStatusChanged, no service" ); |
|
243 } |
|
244 } |
|
245 TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::ServiceStatusChanged >" ); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CPEServiceHandling::CancelServiceEnabling |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CPEServiceHandling::CancelServiceEnabling() const |
|
253 { |
|
254 TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::CancelServiceEnabling" ); |
|
255 |
|
256 if ( iCchClient ) |
|
257 { |
|
258 CCchService* service = iCchClient->GetService( iCurrentServiceId ); |
|
259 |
|
260 if ( service ) |
|
261 { |
|
262 TCchServiceStatus serviceStatus; |
|
263 TInt error = service->GetStatus( ECCHVoIPSub, serviceStatus ); |
|
264 TCCHSubserviceState state = serviceStatus.State(); |
|
265 |
|
266 // Disable only, if service is connecting state |
|
267 if ( error == KErrNone && state == ECCHConnecting ) |
|
268 { |
|
269 TEFLOGSTRING( KTAREQOUT, |
|
270 "PE CPEServiceHandling::CancelServiceEnabling, CCchService->Disable" ); |
|
271 service->Disable( ECCHUnknown ); |
|
272 } |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CPEServiceHandling::SendErrorMessage |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CPEServiceHandling::SendErrorMessage( |
|
282 TInt aErrorCode ) |
|
283 { |
|
284 TEFLOGSTRING2( KTAINT, |
|
285 "PE CPEServiceHandling::SendErrorMessage, aErrorCode: %d", |
|
286 aErrorCode ); |
|
287 |
|
288 iModel.DataStore()->SetErrorCode( aErrorCode ); |
|
289 iModel.SendMessage( MEngineMonitor::EPEMessageServiceHandlingError ); |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CPEServiceHandling::DisableService |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CPEServiceHandling::DisableService() const |
|
297 { |
|
298 TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::DisableService" ); |
|
299 |
|
300 CCchService* service = iCchClient->GetService( iCurrentServiceId ); |
|
301 |
|
302 if ( service ) |
|
303 { |
|
304 TEFLOGSTRING( KTAREQOUT, |
|
305 "PE CPEServiceHandling::DisableService, CCchService->Disable" ); |
|
306 service->Disable( ECCHUnknown ); |
|
307 } |
|
308 } |
|
309 |
|
310 // End of File |