|
1 /* |
|
2 * Copyright (c) 2007-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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <xmlengdom.h> |
|
20 #include <liwservicehandler.h> |
|
21 |
|
22 #include "hnservicehandler.h" |
|
23 #include "hnliwutils.h" |
|
24 #include "hnglobals.h" |
|
25 #include "hnmdbasekey.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 void CHnServiceHandler::ConstructL( |
|
34 const TDesC8& aService, const TDesC8& aInterface, |
|
35 const TDesC8& aCommand, |
|
36 CLiwGenericParamList* aConstructor, |
|
37 CLiwGenericParamList* aServiceCommand ) |
|
38 { |
|
39 iServiceName.CreateL( aService ); |
|
40 iInterfaceName.CreateL( aInterface ); |
|
41 iCommandName.CreateL( aCommand ); |
|
42 |
|
43 iServiceHandler = CLiwServiceHandler::NewL(); |
|
44 iInput = CLiwGenericParamList::NewL(); |
|
45 |
|
46 iOutputForAS = CLiwGenericParamList::NewL(); |
|
47 |
|
48 iServiceInterface = NULL; |
|
49 SetServiceInterfaceL( aConstructor ); |
|
50 |
|
51 // Please note that by setting these two member variables |
|
52 // we take ownership of aConstructor and aServiceCommand. |
|
53 // No leaving functions may be called in ConstructL from |
|
54 // now on. |
|
55 iConstructor = aConstructor; |
|
56 iCommand = aServiceCommand; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CHnServiceHandler* CHnServiceHandler::NewL( |
|
64 const TDesC8& aService, const TDesC8& aInterface, |
|
65 const TDesC8& aCommand, TServiceMode aMode, |
|
66 CLiwGenericParamList* aConstructor, |
|
67 CLiwGenericParamList* aServiceCommand ) |
|
68 { |
|
69 CHnServiceHandler* self = CHnServiceHandler::NewLC( aService, aInterface, |
|
70 aCommand, aMode, aConstructor, aServiceCommand ); |
|
71 CleanupStack::Pop( self ); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CHnServiceHandler* CHnServiceHandler::NewLC( |
|
80 const TDesC8& aService, const TDesC8& aInterface, |
|
81 const TDesC8& aCommandName, TServiceMode aMode, |
|
82 CLiwGenericParamList* aConstructor, |
|
83 CLiwGenericParamList* aServiceCommand ) |
|
84 { |
|
85 CHnServiceHandler* self = new( ELeave ) CHnServiceHandler( aMode ); |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL( aService, aInterface, aCommandName, aConstructor, |
|
88 aServiceCommand ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CHnServiceHandler::CHnServiceHandler( TServiceMode aMode ) : |
|
97 iMode( aMode ) |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C CHnServiceHandler::~CHnServiceHandler() |
|
107 { |
|
108 |
|
109 iServiceName.Close(); |
|
110 iInterfaceName.Close(); |
|
111 iCommandName.Close(); |
|
112 |
|
113 if ( iServiceInterface ) |
|
114 { |
|
115 iServiceInterface->Close(); |
|
116 } |
|
117 |
|
118 delete iInput; |
|
119 delete iConstructor; |
|
120 delete iCommand; |
|
121 delete iOutputForAS; |
|
122 |
|
123 if ( iServiceHandler ) |
|
124 { |
|
125 iServiceHandler->Reset(); |
|
126 delete iServiceHandler; |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C TBool CHnServiceHandler::ServiceHandlerMatchesModel( |
|
135 const TDesC8& aService, |
|
136 const TDesC8& aInterface, |
|
137 const CLiwGenericParamList* aConstructor ) const |
|
138 { |
|
139 __ASSERT_DEBUG( aConstructor, User::Invariant() ); |
|
140 |
|
141 TBool ret = ( aInterface == iInterfaceName && aService == iServiceName ); |
|
142 |
|
143 if ( ret ) |
|
144 { |
|
145 const TInt count = iConstructor->Count(); |
|
146 ret = ( count == aConstructor->Count() ); |
|
147 for ( TInt i = 0; ret && i < count; ++i ) |
|
148 { |
|
149 ret = ( ( *iConstructor )[i] == ( *aConstructor )[i] ); |
|
150 } |
|
151 } |
|
152 |
|
153 return ret; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C void CHnServiceHandler::PrepareForNextExecutionL( |
|
161 const TDesC8& aCommand, TServiceMode aMode, |
|
162 CLiwGenericParamList* aServiceCommand ) |
|
163 { |
|
164 __ASSERT_DEBUG( aServiceCommand && aServiceCommand != iCommand, |
|
165 User::Invariant() ); |
|
166 |
|
167 { // braces for scope only |
|
168 RBuf8 copy; |
|
169 CleanupClosePushL( copy ); |
|
170 copy.CreateL( aCommand ); |
|
171 iCommandName.Swap( copy ); |
|
172 CleanupStack::PopAndDestroy( © ); |
|
173 } |
|
174 |
|
175 iMode = aMode; |
|
176 |
|
177 delete iCommand; |
|
178 iCommand = aServiceCommand; |
|
179 // Ownership of aServiceCommand has been taken. Do not add any piece of |
|
180 // code that could leave after this line. |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C TInt CHnServiceHandler::ExecuteL( MLiwNotifyCallback* aCallback, |
|
188 TInt aCmdOptions) |
|
189 { |
|
190 TInt err( KErrNotSupported ); |
|
191 if( iServiceInterface ) |
|
192 { |
|
193 err = KErrNotSupported; |
|
194 iOutputForAS->Reset(); |
|
195 iInput->Reset(); |
|
196 iInput->AppendL( *iCommand ); |
|
197 switch( iMode ) |
|
198 { |
|
199 case EServiceModeAsynchronous: |
|
200 { |
|
201 __ASSERT_DEBUG( aCallback , User::Panic( KMatrixPanic , 0 ) ); |
|
202 TRAP(err, iServiceInterface->ExecuteCmdL( |
|
203 iCommandName, *iInput, *iOutputForAS, aCmdOptions, aCallback ) ); |
|
204 } |
|
205 break; |
|
206 case EServiceModeSynchronous: |
|
207 { |
|
208 TRAP(err, iServiceInterface->ExecuteCmdL( |
|
209 iCommandName, *iInput, *iOutputForAS, aCmdOptions, NULL ) ); |
|
210 } |
|
211 break; |
|
212 } |
|
213 } |
|
214 return err; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 EXPORT_C TInt CHnServiceHandler::ExecuteL( |
|
222 CLiwGenericParamList& aOutParamList, TRequestStatus& aStatus ) |
|
223 { |
|
224 iClientStatus = &aStatus; |
|
225 (*iClientStatus) = KRequestPending; |
|
226 iOutputForAO = &aOutParamList; |
|
227 |
|
228 TInt err( KErrNotSupported ); |
|
229 if( iServiceInterface ) |
|
230 { |
|
231 err = KErrNone; |
|
232 iInput->Reset(); |
|
233 iInput->AppendL( *iCommand ); |
|
234 |
|
235 switch (iMode) |
|
236 { |
|
237 case EServiceModeAsynchronous: |
|
238 { |
|
239 TRAP(err, iServiceInterface->ExecuteCmdL( |
|
240 iCommandName, *iInput, *iOutputForAO, 0, this ) ); |
|
241 if ( err != KErrNone ) |
|
242 { |
|
243 User::RequestComplete( iClientStatus, err ); |
|
244 } |
|
245 } |
|
246 break; |
|
247 case EServiceModeSynchronous: |
|
248 { |
|
249 TRAP(err, iServiceInterface->ExecuteCmdL( |
|
250 iCommandName, *iInput, *iOutputForAO ) ); |
|
251 User::RequestComplete( iClientStatus, KErrNone ); |
|
252 } |
|
253 break; |
|
254 default: |
|
255 break; |
|
256 } |
|
257 } |
|
258 else |
|
259 { |
|
260 // KErrNone ensures that CHnQueryResultCollector::HandleQueryResultsL() |
|
261 // is called, empty results are added to list, and |
|
262 // CHnMdItem::ResultsCollectedL doesn't get confused |
|
263 User::RequestComplete( iClientStatus, KErrNone ); |
|
264 } |
|
265 |
|
266 return err; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 EXPORT_C TInt CHnServiceHandler::HandleNotifyL( |
|
273 TInt /*aCmdId*/, |
|
274 TInt /*aEventId*/, |
|
275 CLiwGenericParamList& aEventParamList, |
|
276 const CLiwGenericParamList& /*aInParamList*/ ) |
|
277 { |
|
278 // reset |
|
279 if( iOutputForAO ) |
|
280 { |
|
281 iOutputForAO->Reset(); |
|
282 iOutputForAO->AppendL( aEventParamList ); |
|
283 |
|
284 TLiwGenericParam param; |
|
285 TInt error(KErrNone); |
|
286 param.PushL(); |
|
287 for (TInt i = 0; i < aEventParamList.Count(); i++) |
|
288 { |
|
289 if ( param.Name().Compare( KErrorCode8 ) == 0 |
|
290 && param.Value().AsTInt32() == KSErrNoMemory ) |
|
291 { |
|
292 error = KErrNoMemory; |
|
293 break; |
|
294 } |
|
295 } |
|
296 CleanupStack::PopAndDestroy(¶m); |
|
297 User::RequestComplete( iClientStatus, error); |
|
298 } |
|
299 return KErrNone; |
|
300 } |
|
301 |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 // ----------------------------------------------------------------------------- |
|
306 TInt CHnServiceHandler::SetServiceInterfaceL( |
|
307 CLiwGenericParamList* aConstructor ) |
|
308 { |
|
309 CLiwGenericParamList& inParam = iServiceHandler->InParamListL(); |
|
310 CLiwGenericParamList& outParam = iServiceHandler->OutParamListL(); |
|
311 |
|
312 CLiwCriteriaItem* critItem = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, |
|
313 iInterfaceName, iServiceName ); |
|
314 |
|
315 critItem->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
316 RCriteriaArray critArr; |
|
317 CleanupClosePushL( critArr ); |
|
318 critArr.AppendL( critItem ); |
|
319 iServiceHandler->AttachL( critArr ); |
|
320 inParam.AppendL( *aConstructor ); |
|
321 iServiceHandler->ExecuteServiceCmdL( *critItem, inParam, outParam ); |
|
322 CleanupStack::PopAndDestroy( &critArr ); |
|
323 CleanupStack::PopAndDestroy( critItem ); |
|
324 |
|
325 TInt pos( KErrNone ); |
|
326 outParam.FindFirst( pos, iInterfaceName ); |
|
327 if ( pos != KErrNotFound ) |
|
328 { |
|
329 iServiceInterface = outParam[pos].Value().AsInterface(); |
|
330 } |
|
331 |
|
332 return pos; |
|
333 } |
|
334 |
|
335 // End of file |