|
1 /* |
|
2 * Copyright (c) 2002-2005 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: |
|
15 * fundemental commander class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "impsfundcli.h" |
|
22 #include "impsfundCommand.h" |
|
23 #include "impsutils.h" |
|
24 #include "impsdatautils.h" |
|
25 #include "ImpsPacked.h" |
|
26 |
|
27 // MACROS |
|
28 #ifndef _DEBUG |
|
29 #define _NO_IMPS_LOGGING_ |
|
30 #endif |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // CImpsFundCommand2::CImpsFundCommand2 |
|
36 // ---------------------------------------------------------------------------- |
|
37 CImpsFundCommand2::CImpsFundCommand2( TInt aPriority, RImpsFundClient2& aClient ): |
|
38 CActive( aPriority ), |
|
39 iClient( aClient ), |
|
40 iMessagePtr() |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CImpsFundCommand2::NewL |
|
47 // ---------------------------------------------------------------------------- |
|
48 CImpsFundCommand2* CImpsFundCommand2::NewL( RImpsFundClient2& aClient ) |
|
49 { |
|
50 CImpsFundCommand2* self = new (ELeave) CImpsFundCommand2( |
|
51 EPriorityUserInput, aClient); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CImpsFundCommand2::ConstructL |
|
60 // ---------------------------------------------------------------------------- |
|
61 void CImpsFundCommand2::ConstructL() |
|
62 { |
|
63 iKey = CImpsKey::NewL(); |
|
64 iImpsFields = CImpsFields::NewL(); |
|
65 iDataAccessor = CImpsDataAccessor::NewL( iImpsFields ); |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CImpsFundCommand2::~CImpsFundCommand2 |
|
70 // ---------------------------------------------------------------------------- |
|
71 CImpsFundCommand2::~CImpsFundCommand2() |
|
72 { |
|
73 //Cancel any outstanding requests |
|
74 Cancel(); |
|
75 ResetMembers(); |
|
76 delete iKey; |
|
77 delete iImpsFields; |
|
78 delete iDataAccessor; |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CImpsFundCommand2::StartRunL |
|
83 // ---------------------------------------------------------------------------- |
|
84 void CImpsFundCommand2::StartRunL() |
|
85 { |
|
86 iState = 0; |
|
87 if ( IsActive() ) |
|
88 { |
|
89 User::Leave( KErrServerBusy ); |
|
90 } |
|
91 // Set this active object active |
|
92 iStatus = KRequestPending; |
|
93 SetActive(); |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // CImpsFundCommand2::RunL |
|
98 // ---------------------------------------------------------------------------- |
|
99 void CImpsFundCommand2::RunL() |
|
100 { |
|
101 #ifndef _NO_IMPS_LOGGING_ |
|
102 CImpsClientLogger::Log( _L( "CImpsFundCommand2: RunL %d" ), iStatus.Int() ); |
|
103 #endif |
|
104 MImpsErrorHandler2* ehandler = iClient.ErrorHandler(); |
|
105 // Errors are handled here. |
|
106 // Successful cases are handled by CImpsFundHandler. |
|
107 if ( iStatus == KErrNone ) |
|
108 { |
|
109 return; |
|
110 } |
|
111 // Handler should be registered |
|
112 if ( ehandler ) |
|
113 { |
|
114 TInt err( KErrNone ); |
|
115 TRAP( err, ehandler->HandleErrorL( iStatus.Int(), iOpId, NULL, NULL, *iClient.CspIdentifier() )); |
|
116 } |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // CImpsFundCommand2::DoCancel |
|
121 // ---------------------------------------------------------------------------- |
|
122 |
|
123 void CImpsFundCommand2::DoCancel() |
|
124 { |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // CImpsFundCommand2::InitialiseL |
|
129 // ---------------------------------------------------------------------------- |
|
130 void CImpsFundCommand2::InitialiseL( const TImpsContent* aElementArray, |
|
131 const TUint aArraySize ) |
|
132 { |
|
133 ResetMembers(); |
|
134 TImpsDataUtils::AddValuesFromArrayL( iKey, aElementArray, aArraySize ); |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CImpsFundCommand2::SetUserIDsL |
|
139 // There is no count check here, since client does not |
|
140 // call this function in case the array is empty. |
|
141 // ---------------------------------------------------------------------------- |
|
142 void CImpsFundCommand2::SetUserIDsL( const MDesCArray* aUserIDs ) |
|
143 { |
|
144 #ifndef _NO_IMPS_LOGGING_ |
|
145 CImpsClientLogger::Log( _L( "CImpsFundCommand2::SetUserIDsL()" ) ); |
|
146 #endif |
|
147 TUint count = aUserIDs->MdcaCount(); |
|
148 for( TUint i = 0;i < count;i++ ) |
|
149 { |
|
150 TPtrC userID = aUserIDs->MdcaPoint( i ); |
|
151 #ifndef _NO_IMPS_LOGGING_ |
|
152 CImpsClientLogger::Log( |
|
153 _L( " User ID no. %d: \"%S\"" ), i, &userID ); |
|
154 #endif |
|
155 iKey->AddL( CREATEKEY( EImpsKeyUser, i ) ); |
|
156 iKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) ); |
|
157 iDataAccessor->StoreDescL( iKey, userID ); |
|
158 iKey->PopL( 2 ); |
|
159 } |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CImpsFundCommand2::MakeSearchPairListL |
|
164 // ----------------------------------------------------------------------------- |
|
165 void CImpsFundCommand2::MakeSearchPairListL( const CSearchPairs& aSearchPairs ) |
|
166 { |
|
167 #ifndef _NO_IMPS_LOGGING_ |
|
168 CImpsClientLogger::Log( _L( "CImpsFundCommand2::MakeSearchPairListL" ) ); |
|
169 #endif |
|
170 TInt index = 0; |
|
171 TInt count = aSearchPairs.Count(); |
|
172 CImpsSearchRequest* request = NULL; |
|
173 for( TInt i = 0;i < count;i++ ) |
|
174 { |
|
175 request = aSearchPairs.At( i ); |
|
176 TPtrC value = request->Value(); |
|
177 if( value.Length() != 0 ) |
|
178 { |
|
179 #ifndef _NO_IMPS_LOGGING_ |
|
180 CImpsClientLogger::Log( |
|
181 _L( " Value of the search pair no. %d: \"%S\"" ), i, &value ); |
|
182 #endif |
|
183 //Must use a separate index variable in order |
|
184 //no to mix up the sequence in the iKey member. |
|
185 iKey->AddL( CREATEKEY( EImpsKeySearchPairList, index ) ); |
|
186 iKey->AddL( CREATEKEY( EImpsKeySearchElement, 0 ) ); |
|
187 iDataAccessor->StoreIntegerL( iKey, request->Element() ); |
|
188 iKey->PopL(); //search element |
|
189 iKey->AddL( CREATEKEY( EImpsKeySearchString, 0 ) ); |
|
190 iDataAccessor->StoreDescL( iKey, request->Value() ); |
|
191 iKey->PopL( 2 ); |
|
192 index++; |
|
193 } |
|
194 #ifndef _NO_IMPS_LOGGING_ |
|
195 else |
|
196 { |
|
197 CImpsClientLogger::Log( _L( " Value no. %d is empty!" ), i ); |
|
198 } |
|
199 #endif |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CImpsFundCommand2::InsertEmptyElementL |
|
205 // ----------------------------------------------------------------------------- |
|
206 void CImpsFundCommand2::InsertEmptyElementL( const TImpsContent aElementName, |
|
207 const TInt aIndex ) |
|
208 { |
|
209 iKey->AddL( CREATEKEY( aElementName, aIndex ) ); |
|
210 iDataAccessor->StoreEmptyL( iKey ); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CImpsFundCommand2::SetScreenNamesL |
|
215 // There is no count check here, since client does not |
|
216 // call this function in case the arrays are empty. |
|
217 // ----------------------------------------------------------------------------- |
|
218 void CImpsFundCommand2::SetScreenNamesL( const MDesCArray* aScreenNames, |
|
219 const MDesCArray* aGroupNames ) |
|
220 { |
|
221 #ifndef _NO_IMPS_LOGGING_ |
|
222 CImpsClientLogger::Log( _L( "CImpsFundCommand2::SetScreenNamesL()" ) ); |
|
223 #endif |
|
224 TUint count = aScreenNames->MdcaCount(); |
|
225 for( TUint i = 0;i < count;i++ ) |
|
226 { |
|
227 iKey->AddL( CREATEKEY( EImpsKeyScreenName, i ) ); |
|
228 iKey->AddL( CREATEKEY( EImpsKeySName, 0 ) ); |
|
229 //Store the SName |
|
230 TPtrC SName = aScreenNames->MdcaPoint( i ); |
|
231 #ifndef _NO_IMPS_LOGGING_ |
|
232 CImpsClientLogger::Log( _L( " SName no. %d: \"%S\"" ), i, &SName ); |
|
233 #endif |
|
234 iDataAccessor->StoreDescL( iKey, SName ); |
|
235 iKey->PopL(); |
|
236 //Store the GroupID |
|
237 iKey->AddL( CREATEKEY( EImpsKeyGroupID, 0 ) ); |
|
238 #ifndef _NO_IMPS_LOGGING_ |
|
239 TPtrC groupID = aGroupNames->MdcaPoint( i ); |
|
240 CImpsClientLogger::Log( |
|
241 _L( " GroupID no. %d: \"%S\"" ), i, &groupID ); |
|
242 #endif |
|
243 iDataAccessor->StoreDescL( iKey, aGroupNames->MdcaPoint( i ) ); |
|
244 iKey->PopL(); |
|
245 } |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CImpsFundCommand2::InsertDescriptorElementL |
|
250 // ----------------------------------------------------------------------------- |
|
251 void CImpsFundCommand2::InsertDescriptorElementL( const TDesC& aElementValue, |
|
252 const TImpsContent aElementName, |
|
253 const TInt aIndex ) |
|
254 { |
|
255 iKey->AddL( CREATEKEY( aElementName, aIndex ) ); |
|
256 iDataAccessor->StoreDescL( iKey, aElementValue ); |
|
257 iKey->PopL(); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CImpsFundCommand2::InsertBooleanElementL |
|
262 // ----------------------------------------------------------------------------- |
|
263 void CImpsFundCommand2::InsertBooleanElementL( const TBool aElementValue, |
|
264 const TImpsContent aElementName, |
|
265 const TInt aIndex ) |
|
266 { |
|
267 iKey->AddL( CREATEKEY( aElementName, aIndex ) ); |
|
268 iDataAccessor->StoreBooleanL( iKey, aElementValue ); |
|
269 iKey->PopL(); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CImpsFundCommand2::InsertIntegerElementL |
|
274 // ----------------------------------------------------------------------------- |
|
275 void CImpsFundCommand2::InsertIntegerElementL( const TInt aElementValue, |
|
276 const TImpsContent aElementName, |
|
277 const TInt aIndex ) |
|
278 { |
|
279 iKey->AddL( CREATEKEY( aElementName, aIndex ) ); |
|
280 iDataAccessor->StoreIntegerL( iKey, aElementValue ); |
|
281 iKey->PopL(); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CImpsFundCommand2::ResetMembers |
|
286 // ----------------------------------------------------------------------------- |
|
287 void CImpsFundCommand2::ResetMembers() |
|
288 { |
|
289 iArraySize = 0; |
|
290 delete iMessage; |
|
291 iMessage = NULL; |
|
292 iMessagePtr.Set( KNullDesC8 ); |
|
293 if (iKey != NULL) |
|
294 { |
|
295 iKey->Reset(); |
|
296 } |
|
297 if (iImpsFields != NULL) |
|
298 { |
|
299 iImpsFields->Reset(); |
|
300 } |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CImpsFundCommand2::PackAndSendL |
|
305 // ----------------------------------------------------------------------------- |
|
306 void CImpsFundCommand2::PackAndSendL( const TImpsMessageType aMessageType, |
|
307 const TInt aOpId ) |
|
308 { |
|
309 iOpId = aOpId; |
|
310 delete iMessage; |
|
311 iMessage = NULL; |
|
312 HBufC8* buffer = HBufC8::NewLC( iImpsFields->Size() ); // << buffer |
|
313 iImpsFields->SetMessageType( aMessageType ); |
|
314 TImpsPackedEntity packedMessage( buffer ); |
|
315 TInt error = packedMessage.PackEntity( *iImpsFields ); |
|
316 if( error == KErrNone ) |
|
317 { |
|
318 TImpsServRequest req = ServerRequestTypeL( aMessageType ); |
|
319 StartRunL(); |
|
320 iMessage = buffer; |
|
321 CleanupStack::Pop(); // >> buffer |
|
322 iMessagePtr.Set( iMessage->Des() ); |
|
323 iClient.SendReceive( req, TIpcArgs( &iMessagePtr, iOpId ), iStatus ); |
|
324 } |
|
325 else |
|
326 { |
|
327 iImpsFields->Reset(); |
|
328 User::Leave( error ); // >> buffer deleted from CleanupStack |
|
329 } |
|
330 } |
|
331 |
|
332 // ---------------------------------------------------------------------------- |
|
333 // CImpsFundCommand2::ServerRequestTypeL |
|
334 // ---------------------------------------------------------------------------- |
|
335 TImpsServRequest CImpsFundCommand2::ServerRequestTypeL( |
|
336 const TImpsMessageType aMessageType ) |
|
337 { |
|
338 TImpsServRequest ret = EImpsServNone; |
|
339 switch( aMessageType ) |
|
340 { |
|
341 case EImpsSearchReq: |
|
342 case EImpsStopSearchReq: |
|
343 case EImpsSearchRes: |
|
344 ret = EImpsServFundSearch; |
|
345 break; |
|
346 case EImpsInviteReq: |
|
347 case EImpsInviteRes: |
|
348 case EImpsInviteUserReq: |
|
349 case EImpsInviteUserRes: |
|
350 case EImpsCancelInviteReq: |
|
351 case EImpsCancelInviteUserReq: |
|
352 ret = EImpsServFundInvite; |
|
353 break; |
|
354 default: |
|
355 User::Leave( ret ); |
|
356 } |
|
357 return ret; |
|
358 } |
|
359 |
|
360 |
|
361 // End of File |
|
362 |
|
363 |