|
1 /* |
|
2 * Copyright (c) 2007 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: MPX Back Stepping Service API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // from AIW and LIW |
|
20 #include <liwcommon.h> |
|
21 #include <liwservicehandler.h> |
|
22 |
|
23 // for CleanupResetAndDestroyPushL |
|
24 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
25 |
|
26 #include "mpxbacksteppingutilityimp.h" |
|
27 #include <mpxlog.h> |
|
28 |
|
29 // definitions needed by BackStepping service. (ref. bsserviceconstants.h) |
|
30 |
|
31 // BSS Service and Interface ID |
|
32 _LIT8( KBSServiceID, "Service.BackStepping" ); |
|
33 _LIT8( KBSInterface, "IBackStepping" ); |
|
34 |
|
35 // BSS commands |
|
36 _LIT8( KBSCmdInitialize, "Initialize" ); |
|
37 _LIT8( KBSCmdForwardActivationEvent, "ForwardActivationEvent" ); |
|
38 _LIT8( KBSCmdHandleBackCommand, "HandleBackCommand" ); |
|
39 |
|
40 // BSS in param names |
|
41 _LIT8( KBSInParamAppUid, "AppUid" ); |
|
42 _LIT8( KBSInParamState, "State" ); |
|
43 _LIT8( KBSInParamEnter, "Enter" ); |
|
44 |
|
45 // BSS out param names |
|
46 _LIT8( KBSOutParamStatusInfo, "StatusInfo" ); |
|
47 |
|
48 // ======== MEMBER FUNCTIONS ======== |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Private Constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CMPXBackSteppingUtilityImp::CMPXBackSteppingUtilityImp() |
|
55 { |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Destructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CMPXBackSteppingUtilityImp::~CMPXBackSteppingUtilityImp() |
|
63 { |
|
64 MPX_DEBUG1( "CMPXBackSteppingUtilityImp::~CMPXBackSteppingUtilityImp" ); |
|
65 if ( iBSInterface ) |
|
66 { |
|
67 iBSInterface->Close(); |
|
68 } |
|
69 |
|
70 delete iServiceHandler; |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // 2nd-Phased Constructor |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 void CMPXBackSteppingUtilityImp::ConstructL() |
|
78 { |
|
79 MPX_DEBUG1( "-->CMPXBackSteppingUtilityImp::ConstructL" ); |
|
80 // create Service Handler and keep as long as access to BS Service needed |
|
81 iServiceHandler = CLiwServiceHandler::NewL(); |
|
82 // for convinience keep pointers to Service Handler param lists |
|
83 iInParamList = &iServiceHandler->InParamListL(); |
|
84 iOutParamList = &iServiceHandler->OutParamListL(); |
|
85 |
|
86 RCriteriaArray criteriaArray; |
|
87 CleanupResetAndDestroyPushL( criteriaArray ); |
|
88 |
|
89 // create AIW criteria |
|
90 CLiwCriteriaItem* criterion = CLiwCriteriaItem::NewLC( |
|
91 KLiwCmdAsStr, KBSInterface, KBSServiceID ); |
|
92 criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
93 |
|
94 criteriaArray.AppendL( criterion ); |
|
95 CleanupStack::Pop( criterion ); |
|
96 |
|
97 // attach AIW criteria |
|
98 iServiceHandler->AttachL( criteriaArray ); |
|
99 // get BS Service interface |
|
100 iServiceHandler->ExecuteServiceCmdL( |
|
101 *criterion, |
|
102 *iInParamList, |
|
103 *iOutParamList ); |
|
104 |
|
105 CleanupStack::PopAndDestroy( &criteriaArray ); |
|
106 |
|
107 // extract BS interface from output params |
|
108 TInt pos( 0 ); |
|
109 iOutParamList->FindFirst( pos, KBSInterface ); |
|
110 if( pos != KErrNotFound ) |
|
111 { |
|
112 iBSInterface = (*iOutParamList)[pos].Value().AsInterface(); |
|
113 } |
|
114 |
|
115 if ( !iBSInterface ) |
|
116 { |
|
117 // handle no BS Service |
|
118 User::Leave( KErrNotFound ); |
|
119 } |
|
120 |
|
121 MPX_DEBUG1( "<--CMPXBackSteppingUtilityImp::ConstructL" ); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // Two-Phased Constructor |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 CMPXBackSteppingUtilityImp* CMPXBackSteppingUtilityImp::NewL() |
|
129 { |
|
130 CMPXBackSteppingUtilityImp* self = CMPXBackSteppingUtilityImp::NewLC(); |
|
131 CleanupStack::Pop( self ); |
|
132 return self; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Two-Phased Constructor |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 CMPXBackSteppingUtilityImp* CMPXBackSteppingUtilityImp::NewLC() |
|
140 { |
|
141 CMPXBackSteppingUtilityImp* self = new( ELeave ) CMPXBackSteppingUtilityImp; |
|
142 CleanupStack::PushL( self ); |
|
143 self->ConstructL(); |
|
144 return self; |
|
145 } |
|
146 |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Retrieves view utility from TLS. Creates if it's not there. |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 MMPXBackSteppingUtility* CMPXBackSteppingUtilityImp::UtilityL() |
|
153 { |
|
154 MPX_DEBUG1( "-->CMPXBackSteppingUtilityImp::UtilityL" ); |
|
155 MMPXBackSteppingUtility* utility = |
|
156 reinterpret_cast<MMPXBackSteppingUtility*>( Dll::Tls() ); |
|
157 if ( !utility ) |
|
158 { |
|
159 utility = CMPXBackSteppingUtilityImp::NewL(); |
|
160 StoreUtility( utility ); |
|
161 } |
|
162 |
|
163 static_cast<CMPXBackSteppingUtilityImp*>( utility )->iRefCount++; |
|
164 MPX_DEBUG1( "<--CMPXBackSteppingUtilityImp::UtilityL" ); |
|
165 return utility; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Store back stepping utility to TLS. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CMPXBackSteppingUtilityImp::StoreUtility( MMPXBackSteppingUtility* aUtility ) |
|
173 { |
|
174 Dll::SetTls( aUtility ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // From CMPXBackSteppingUtilityImp |
|
179 // This method must be called when the client no longer needs this instance. |
|
180 // This object will be destroyed when no one is using it. |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void CMPXBackSteppingUtilityImp::Close() |
|
184 { |
|
185 ASSERT( iRefCount > 0 ); |
|
186 MPX_FUNC_EX( "CMPXBackSteppingUtilityImp::Close" ); |
|
187 MPX_DEBUG2( "CMPXBackSteppingUtilityImp::Close ref count = %d", iRefCount ); |
|
188 if ( --iRefCount == 0 ) |
|
189 { |
|
190 MPX_DEBUG1( "CMPXBackSteppingUtilityImp::Close deleting this" ); |
|
191 // last client released |
|
192 StoreUtility( NULL ); |
|
193 delete this; |
|
194 } |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // Forwards activation event |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CMPXBackSteppingUtilityImp::ForwardActivationEventL( |
|
202 const TDesC8& aState, |
|
203 const TBool aEnter ) |
|
204 { |
|
205 MPX_DEBUG1( "-->CMPXBackSteppingUtilityImp::ForwardActivationEventL" ); |
|
206 iInParamList->Reset(); |
|
207 iOutParamList->Reset(); |
|
208 |
|
209 TLiwGenericParam state( KBSInParamState, TLiwVariant( aState ) ); |
|
210 iInParamList->AppendL( state ); |
|
211 TLiwGenericParam enter( KBSInParamEnter, TLiwVariant( aEnter ) ); |
|
212 iInParamList->AppendL( enter ); |
|
213 |
|
214 iBSInterface->ExecuteCmdL( |
|
215 KBSCmdForwardActivationEvent, |
|
216 *iInParamList, |
|
217 *iOutParamList ); |
|
218 |
|
219 TInt result = HandleResultL(); |
|
220 |
|
221 iInParamList->Reset(); |
|
222 iOutParamList->Reset(); |
|
223 |
|
224 MPX_DEBUG1( "<--CMPXBackSteppingUtilityImp::ForwardActivationEventL" ); |
|
225 return result; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // Handles back command |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 TInt CMPXBackSteppingUtilityImp::HandleBackCommandL( |
|
233 const TDesC8& aState ) |
|
234 { |
|
235 MPX_DEBUG1( "-->CMPXBackSteppingUtilityImp::HandleBackCommandL" ); |
|
236 iInParamList->Reset(); |
|
237 iOutParamList->Reset(); |
|
238 |
|
239 TLiwGenericParam state( KBSInParamState, TLiwVariant( aState ) ); |
|
240 iInParamList->AppendL( state ); |
|
241 |
|
242 iBSInterface->ExecuteCmdL( |
|
243 KBSCmdHandleBackCommand, |
|
244 *iInParamList, |
|
245 *iOutParamList ); |
|
246 |
|
247 TInt result = HandleResultL(); |
|
248 |
|
249 iInParamList->Reset(); |
|
250 iOutParamList->Reset(); |
|
251 |
|
252 MPX_DEBUG1( "<--CMPXBackSteppingUtilityImp::HandleBackCommandL" ); |
|
253 return result; |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // Initializes BS Service |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 void CMPXBackSteppingUtilityImp::InitializeL( const TUid aUid ) |
|
261 { |
|
262 MPX_DEBUG2( "-->CMPXBackSteppingUtilityImp::InitializeL aUid=0x%x", aUid.iUid ); |
|
263 iInParamList->Reset(); |
|
264 iOutParamList->Reset(); |
|
265 |
|
266 TLiwGenericParam appUid( KBSInParamAppUid, TLiwVariant( aUid.iUid ) ); |
|
267 iInParamList->AppendL( appUid ); |
|
268 |
|
269 iBSInterface->ExecuteCmdL( |
|
270 KBSCmdInitialize, |
|
271 *iInParamList, |
|
272 *iOutParamList ); |
|
273 |
|
274 if ( HandleResultL() != 1 ) |
|
275 { |
|
276 // Initialize command was not consumed - handle failiure |
|
277 User::Leave( KErrArgument ); |
|
278 } |
|
279 |
|
280 iInParamList->Reset(); |
|
281 iOutParamList->Reset(); |
|
282 MPX_DEBUG1( "<--CMPXBackSteppingUtilityImp::InitializeL" ); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Handles the result of a LIW command |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 TInt CMPXBackSteppingUtilityImp::HandleResultL() |
|
290 { |
|
291 MPX_DEBUG1( "-->CMPXBackSteppingUtilityImp::HandleResultL" ); |
|
292 TInt statusInfo( KErrNotFound ); |
|
293 |
|
294 TInt posErr( 0 ); |
|
295 iOutParamList->FindFirst( posErr, LIW::EGenericParamError ); |
|
296 if( posErr != KErrNotFound ) |
|
297 { |
|
298 // error code found - extract and handle |
|
299 TInt errorCode( KErrNone ); |
|
300 (*iOutParamList)[posErr].Value().Get( errorCode ); |
|
301 |
|
302 User::LeaveIfError( errorCode ); |
|
303 } |
|
304 |
|
305 // if no error returned, carry on |
|
306 TInt posStat( 0 ); |
|
307 iOutParamList->FindFirst( posStat, KBSOutParamStatusInfo ); |
|
308 if( posStat != KErrNotFound ) |
|
309 { |
|
310 // status info present - extract and return |
|
311 (*iOutParamList)[posStat].Value().Get( statusInfo ); |
|
312 } |
|
313 else |
|
314 { |
|
315 // no return value |
|
316 // this should not happen |
|
317 User::Leave( KErrNotFound ); |
|
318 } |
|
319 |
|
320 MPX_DEBUG2( "<--CMPXBackSteppingUtilityImp::HandleResultL statusInfo=%d", statusInfo ); |
|
321 return statusInfo; |
|
322 } |
|
323 |
|
324 // End of file |