|
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: Wrapper for Back Stepping Service. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwcommon.h> |
|
20 #include <liwservicehandler.h> |
|
21 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
22 |
|
23 #include "irbsserviceconstants.h" |
|
24 #include "irbacksteppingservicewrapper.h" |
|
25 |
|
26 _LIT8( KIRBackSteppingPrefix, "IRBS" ); |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ================================================= |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CIRBackSteppingServiceWrapper::NewL |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CIRBackSteppingServiceWrapper* CIRBackSteppingServiceWrapper::NewL( TUid aUid ) |
|
35 { |
|
36 CIRBackSteppingServiceWrapper* self = new( ELeave ) CIRBackSteppingServiceWrapper; |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL( aUid ); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CIRBackSteppingServiceWrapper::~CIRBackSteppingServiceWrapper |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CIRBackSteppingServiceWrapper::~CIRBackSteppingServiceWrapper() |
|
48 { |
|
49 if ( iBsInterface ) |
|
50 { |
|
51 iBsInterface->Close(); |
|
52 } |
|
53 if ( iServiceHandler ) |
|
54 { |
|
55 delete iServiceHandler; |
|
56 } |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CIRBackSteppingServiceWrapper::HandleViewActivationEventL |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CIRBackSteppingServiceWrapper::HandleViewActivationEventL( const TVwsViewId aViewId, |
|
64 TBool aEnter ) |
|
65 { |
|
66 // Make Service Handler param lists. |
|
67 iInParamList->Reset(); |
|
68 iOutParamList->Reset(); |
|
69 |
|
70 RBuf8 buffer; |
|
71 CleanupClosePushL( buffer ); |
|
72 buffer.CreateL( KIRBackSteppingPrefix().Length() + KDefaultRealWidth ); |
|
73 buffer.Copy( KIRBackSteppingPrefix ); |
|
74 // Convert 32-bit signed integer (TInt32) view uid to TInt. |
|
75 TInt64 viewUid = static_cast< TInt64 >( aViewId.iViewUid.iUid ); |
|
76 buffer.AppendNum( viewUid ); |
|
77 |
|
78 TLiwGenericParam state( KIRBSInParamState, TLiwVariant( buffer ) ); |
|
79 iInParamList->AppendL( state ); |
|
80 TLiwGenericParam enter( KIRBSInParamEnter, TLiwVariant( aEnter ) ); |
|
81 iInParamList->AppendL( enter ); |
|
82 |
|
83 // Execute view activation event. |
|
84 iBsInterface->ExecuteCmdL( KIRBSCmdForwardActivationEvent, *iInParamList, *iOutParamList ); |
|
85 CleanupStack::PopAndDestroy(&buffer); |
|
86 |
|
87 // Check if BS Service consumed the event. |
|
88 HandleResultL(); |
|
89 |
|
90 iInParamList->Reset(); |
|
91 iOutParamList->Reset(); |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CIRBackSteppingServiceWrapper::HandleBackCommandL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 TBool CIRBackSteppingServiceWrapper::HandleBackCommandL( const TVwsViewId aViewId ) |
|
100 { |
|
101 // Make Service Handler param lists. |
|
102 iInParamList->Reset(); |
|
103 iOutParamList->Reset(); |
|
104 |
|
105 // Create message for back stepping wrapper to handle back command event. |
|
106 RBuf8 buffer; |
|
107 CleanupClosePushL( buffer ); |
|
108 buffer.CreateL( KIRBackSteppingPrefix().Length() + KDefaultRealWidth ); |
|
109 buffer.Copy( KIRBackSteppingPrefix ); |
|
110 // Convert 32-bit signed integer (TInt32) view uid to TInt64. |
|
111 TInt64 viewUid = static_cast< TInt64 >( aViewId.iViewUid.iUid ); |
|
112 buffer.AppendNum( viewUid ); |
|
113 |
|
114 TLiwGenericParam state( KIRBSInParamState, TLiwVariant( buffer ) ); |
|
115 iInParamList->AppendL( state ); |
|
116 |
|
117 // Execute back event. |
|
118 iBsInterface->ExecuteCmdL( KIRBSCmdHandleBackCommand, *iInParamList, *iOutParamList ); |
|
119 CleanupStack::PopAndDestroy(&buffer); |
|
120 |
|
121 // Check if BS Service consumes the event. |
|
122 TBool retVal = HandleResultL(); |
|
123 |
|
124 iInParamList->Reset(); |
|
125 iOutParamList->Reset(); |
|
126 |
|
127 return retVal; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // CIRBackSteppingServiceWrapper::CIRBackSteppingServiceWrapper |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CIRBackSteppingServiceWrapper::CIRBackSteppingServiceWrapper() |
|
135 { |
|
136 // No implementation required. |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CIRBackSteppingServiceWrapper::ConstructL |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CIRBackSteppingServiceWrapper::ConstructL( TUid aUid ) |
|
144 { |
|
145 // Create Service Handler and keep as long as access to BS Service needed. |
|
146 iServiceHandler = CLiwServiceHandler::NewL(); |
|
147 // For convenience keep pointers to Service Handler param lists. |
|
148 iInParamList = &iServiceHandler->InParamListL(); |
|
149 iOutParamList = &iServiceHandler->OutParamListL(); |
|
150 |
|
151 // Create AIW criteria. |
|
152 RCriteriaArray criteriaArray; |
|
153 CleanupResetAndDestroyPushL( criteriaArray ); |
|
154 CLiwCriteriaItem* criterion = CLiwCriteriaItem::NewLC( |
|
155 KLiwCmdAsStr, |
|
156 KIRBSInterface, |
|
157 KIRBSServiceID ); |
|
158 criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
159 criteriaArray.AppendL( criterion ); |
|
160 CleanupStack::Pop( criterion ); |
|
161 |
|
162 // Attach AIW criteria. |
|
163 iServiceHandler->AttachL( criteriaArray ); |
|
164 // Get BS Service interface. |
|
165 iServiceHandler->ExecuteServiceCmdL( *criterion, *iInParamList, *iOutParamList ); |
|
166 CleanupStack::PopAndDestroy( &criteriaArray ); |
|
167 |
|
168 // Check if BS interface can be found from output params. |
|
169 TInt pos( 0 ); |
|
170 iOutParamList->FindFirst( pos, KIRBSInterface ); |
|
171 if( KErrNotFound != pos ) |
|
172 { |
|
173 // Extract BS interface from output params. |
|
174 ASSERT( pos >= 0 && pos < iOutParamList->Count() ); |
|
175 iBsInterface = ( *iOutParamList )[pos].Value().AsInterface(); |
|
176 } |
|
177 |
|
178 if ( !iBsInterface ) |
|
179 { |
|
180 // No BS Service available. |
|
181 User::Leave( KErrNotSupported ); |
|
182 } |
|
183 |
|
184 // Initialize BS Service. |
|
185 InitializeL( aUid ); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CIRBackSteppingServiceWrapper::InitializeL |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CIRBackSteppingServiceWrapper::InitializeL( const TUid aUid ) |
|
193 { |
|
194 // Initialize BS Service. |
|
195 iInParamList->Reset(); |
|
196 iOutParamList->Reset(); |
|
197 |
|
198 TLiwGenericParam appUid( KIRBSInParamAppUid, TLiwVariant( aUid.iUid ) ); |
|
199 iInParamList->AppendL( appUid ); |
|
200 |
|
201 iBsInterface->ExecuteCmdL( KIRBSCmdInitialize, *iInParamList, *iOutParamList ); |
|
202 |
|
203 if ( !HandleResultL() ) |
|
204 { |
|
205 // Initialize command was not consumed. |
|
206 User::Leave( KErrArgument ); |
|
207 } |
|
208 |
|
209 iInParamList->Reset(); |
|
210 iOutParamList->Reset(); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CIRBackSteppingServiceWrapper::HandleResultL |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CIRBackSteppingServiceWrapper::HandleResultL() |
|
218 { |
|
219 TBool retVal( EFalse ); |
|
220 // Check if error can be found from outparams. |
|
221 TInt posErr( 0 ); |
|
222 iOutParamList->FindFirst( posErr, LIW::EGenericParamError ); |
|
223 if( KErrNotFound != posErr ) |
|
224 { |
|
225 // Error code found - extract and handle |
|
226 ASSERT( posErr >= 0 && posErr < iOutParamList->Count() ); |
|
227 TInt errorCode( KErrNone ); |
|
228 ( *iOutParamList )[posErr].Value().Get( errorCode ); |
|
229 User::LeaveIfError( errorCode ); |
|
230 } |
|
231 // No errors found. Check if status info can be found from outparams. |
|
232 TInt posStat( 0 ); |
|
233 iOutParamList->FindFirst( posStat, KIRBSOutParamStatusInfo ); |
|
234 if( KErrNotFound != posStat ) |
|
235 { |
|
236 // Status info present - extract. |
|
237 ASSERT( posStat >= 0 && posStat < iOutParamList->Count() ); |
|
238 ( *iOutParamList )[posStat].Value().Get( retVal ); |
|
239 } |
|
240 else |
|
241 { |
|
242 // No status info found. |
|
243 User::Leave( KErrNotFound ); |
|
244 } |
|
245 return retVal; |
|
246 } |