|
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 * commander class for im. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 |
|
23 #include "impsimcli.h" |
|
24 #include "impsimcommand.h" |
|
25 #include "impsfields.h" |
|
26 #include "impspacked.h" |
|
27 #include "impsutils.h" |
|
28 #include "impsdataaccessor.h" |
|
29 #include "impscdatautils.h" |
|
30 #include "impsdetailed.h" |
|
31 |
|
32 // MACROS |
|
33 #ifndef _DEBUG |
|
34 #define _NO_IMPS_LOGGING_ |
|
35 #endif |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CImpsImCommand2::CImpsImCommand2 |
|
41 // ---------------------------------------------------------------------------- |
|
42 CImpsImCommand2::CImpsImCommand2( |
|
43 TInt aPriority, |
|
44 RImpsImClient2& aClient ) : |
|
45 CActive( aPriority ), iClient( aClient ) |
|
46 { |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CImpsImCommand2::NewL |
|
52 // ---------------------------------------------------------------------------- |
|
53 CImpsImCommand2* CImpsImCommand2::NewL( RImpsImClient2& aClient ) |
|
54 { |
|
55 |
|
56 // Perform the construction. |
|
57 CImpsImCommand2* self = new (ELeave) |
|
58 CImpsImCommand2( EPriorityUserInput, aClient); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(1); // self |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CImpsImCommand2::ConstructL |
|
68 // ---------------------------------------------------------------------------- |
|
69 void CImpsImCommand2::ConstructL( ) |
|
70 { |
|
71 iDetailed = new (ELeave) CImpsDetailed(1); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // CImpsImCommand2::~CImpsImCommand2 |
|
76 // ---------------------------------------------------------------------------- |
|
77 CImpsImCommand2::~CImpsImCommand2() |
|
78 { |
|
79 // Cancel any outstanding requests |
|
80 Cancel(); |
|
81 delete iMessageStream; |
|
82 delete iDetailed; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CImpsImCommand2::StartRunL |
|
87 // ---------------------------------------------------------------------------- |
|
88 void CImpsImCommand2::StartRunL( |
|
89 TInt aOpId, |
|
90 TImpsServRequest aType ) |
|
91 { |
|
92 iOpId = aOpId; |
|
93 iType = aType; |
|
94 iState = 0; |
|
95 |
|
96 if ( IsActive() ) |
|
97 { |
|
98 User::Leave( KErrServerBusy ); |
|
99 } |
|
100 |
|
101 // Set this active object active |
|
102 iStatus = KRequestPending; |
|
103 SetActive(); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CImpsImCommand2::SetParametersL |
|
108 // version for newtextmessage |
|
109 // ---------------------------------------------------------------------------- |
|
110 void CImpsImCommand2::SetParametersL( |
|
111 const TDesC* aSenderSn, |
|
112 const MDesCArray* aUserIds, |
|
113 const TDesC* aGroupId, |
|
114 const MDesCArray* aScreenNames, |
|
115 const TDesC& aContent, |
|
116 TBool aDeliveryReportWanted ) |
|
117 { |
|
118 |
|
119 // Generate one flat message presentation |
|
120 if ( IsActive() ) |
|
121 { |
|
122 User::Leave( KErrServerBusy ); |
|
123 } |
|
124 |
|
125 if ( !iMessageStream ) |
|
126 { |
|
127 iMessageStream = HBufC8::NewL( KImpsStreamSize ); |
|
128 } |
|
129 *iMessageStream = KNullDesC8; |
|
130 |
|
131 // Initialize internal structure |
|
132 CImpsFields* fields = CImpsFields::NewL(); |
|
133 CleanupStack::PushL( fields ); // <<< fields |
|
134 fields->SetMessageType( EImpsSendMessageReq ); |
|
135 |
|
136 CImpsDataAccessor* myAccess = CImpsDataAccessor::NewL( fields ); |
|
137 CleanupStack::PushL( myAccess ); // <<< myAccess |
|
138 CImpsKey* myKey = CImpsKey::NewLC(); // <<< myKey |
|
139 |
|
140 CPtrC16Array* grs = new (ELeave) CPtrC16Array(4); |
|
141 CleanupStack::PushL( grs ); // <<< grs |
|
142 |
|
143 CPtrC16Array* grns = new (ELeave) CPtrC16Array(4); |
|
144 CleanupStack::PushL( grns ); // <<< grns |
|
145 |
|
146 TImpsCDataUtils::AddValuesFromArrayL( |
|
147 myKey, |
|
148 KSendMessageElements, |
|
149 sizeof( KSendMessageElements ) / |
|
150 sizeof( KSendMessageElements[0] ) ); |
|
151 |
|
152 // add delivery report |
|
153 myKey->AddL( CREATEKEY( EImpsKeyDeliveryReport, 0 ) ); |
|
154 myAccess->StoreBooleanL( myKey, aDeliveryReportWanted ); |
|
155 myKey->PopL(); |
|
156 |
|
157 if ( aScreenNames ) |
|
158 { |
|
159 TInt count = aScreenNames->MdcaCount(); |
|
160 for ( TInt i = 0; i < count ; i++ ) |
|
161 { |
|
162 grns->AppendL( *aGroupId ); |
|
163 } |
|
164 // GroupID is used as Recipient( Group ( GroupID ) ) also |
|
165 // if aScreenNames is empty |
|
166 if ( count == 0 && aGroupId ) |
|
167 { |
|
168 grs->AppendL( *aGroupId ); |
|
169 } |
|
170 } |
|
171 // GroupID is used as Recipient( Group ( GroupID ) ) if |
|
172 // aScreenNames is omitted. |
|
173 else if ( aGroupId ) |
|
174 { |
|
175 grs->AppendL( *aGroupId ); |
|
176 } |
|
177 |
|
178 myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) ); |
|
179 |
|
180 TImpsCDataUtils::SetRecipientsL( |
|
181 myKey, |
|
182 myAccess, |
|
183 grs, |
|
184 aUserIds, |
|
185 grns, // ScreenName( GroupId ) |
|
186 aScreenNames ); // ScreenName( SName ); |
|
187 |
|
188 TImpsCDataUtils::SetSenderL( |
|
189 myKey, |
|
190 myAccess, |
|
191 aSenderSn, |
|
192 NULL ); |
|
193 |
|
194 myKey->PopL(); |
|
195 |
|
196 // notice: MessageInfo:ContentType is default now |
|
197 // Add actual ContentData |
|
198 TImpsCDataUtils::SetContentDataL( |
|
199 myKey, myAccess, aContent ); |
|
200 // Set sender |
|
201 // This is a "fuzzy" logic. |
|
202 // aSenderSn + aGroupId -> Sender ( ScreenName( SName, GroupID ) ) |
|
203 // !aSenderSn + !aGroupId -> Sender ( User ( UserID )) added by engine! |
|
204 // aSenderSn + !aGroupId -> Sender ( User ( UserID )) |
|
205 // !aSenderSn + aGroupId -> Sender ( Group ( GroupID )) |
|
206 |
|
207 CleanupStack::PopAndDestroy(4); // >>> grns, grs, myKey, myAccess |
|
208 |
|
209 // pack, or actullay serialize the message data |
|
210 TImpsPackedEntity packedMessage( iMessageStream ); |
|
211 TInt myError = packedMessage.PackEntity( *fields ); |
|
212 |
|
213 // Allocate more memory if needed |
|
214 if ( ( myError != KErrNone ) && |
|
215 ( iMessageStream->Des().Size() < fields->Size() ) ) |
|
216 { |
|
217 // notice: consider how to shrink buffer later |
|
218 // increase the size of the buffer and try again |
|
219 iMessageStream->Des().SetLength(0); // to avoid copying contents |
|
220 iMessageStream = iMessageStream->ReAllocL( fields->Size() + 10 ); |
|
221 myError = packedMessage.PackEntity( *fields ); |
|
222 User::LeaveIfError( myError ); |
|
223 } |
|
224 |
|
225 CleanupStack::PopAndDestroy( 1 ); // fields |
|
226 |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CImpsImCommand2::SetParametersL |
|
231 // version for newcontentmessage |
|
232 // ---------------------------------------------------------------------------- |
|
233 void CImpsImCommand2::SetParametersL( |
|
234 const TDesC* aSenderSn, |
|
235 const MDesCArray* aUserIds, |
|
236 const TDesC* aGroupId, |
|
237 const MDesCArray* aScreenNames, |
|
238 const TDesC& aContentType, |
|
239 const TDesC8& aContent, |
|
240 TBool aDeliveryReportWanted ) |
|
241 { |
|
242 |
|
243 // Generate one flat message presentation |
|
244 if ( IsActive() ) |
|
245 { |
|
246 User::Leave( KErrServerBusy ); |
|
247 } |
|
248 |
|
249 if ( !iMessageStream ) |
|
250 { |
|
251 iMessageStream = HBufC8::NewL( KImpsStreamSize ); |
|
252 } |
|
253 *iMessageStream = KNullDesC8; |
|
254 |
|
255 // Initialize internal structure |
|
256 CImpsFields* fields = CImpsFields::NewL(); |
|
257 CleanupStack::PushL( fields ); // <<< fields |
|
258 fields->SetMessageType( EImpsSendMessageReq ); |
|
259 |
|
260 CImpsDataAccessor* myAccess = CImpsDataAccessor::NewL( fields ); |
|
261 CleanupStack::PushL( myAccess ); // <<< myAccess |
|
262 CImpsKey* myKey = CImpsKey::NewLC(); // <<< myKey |
|
263 |
|
264 CPtrC16Array* grs = new (ELeave) CPtrC16Array(4); |
|
265 CleanupStack::PushL( grs ); // <<< grs |
|
266 |
|
267 CPtrC16Array* grns = new (ELeave) CPtrC16Array(4); |
|
268 CleanupStack::PushL( grns ); // <<< grns |
|
269 |
|
270 TImpsCDataUtils::AddValuesFromArrayL( |
|
271 myKey, |
|
272 KSendMessageElements, |
|
273 sizeof( KSendMessageElements ) / |
|
274 sizeof( KSendMessageElements[0] ) ); |
|
275 |
|
276 // add delivery report |
|
277 myKey->AddL( CREATEKEY( EImpsKeyDeliveryReport, 0 ) ); |
|
278 myAccess->StoreBooleanL( myKey, aDeliveryReportWanted ); |
|
279 myKey->PopL(); |
|
280 |
|
281 if ( aScreenNames ) |
|
282 { |
|
283 TInt count = aScreenNames->MdcaCount(); |
|
284 for ( TInt i = 0; i < count ; i++ ) |
|
285 { |
|
286 grns->AppendL( *aGroupId ); |
|
287 } |
|
288 // GroupID is used as Recipient( Group ( GroupID ) ) also |
|
289 // if aScreenNames is empty |
|
290 if ( count == 0 && aGroupId ) |
|
291 { |
|
292 grs->AppendL( *aGroupId ); |
|
293 } |
|
294 } |
|
295 // GroupID is used as Recipient( Group ( GroupID ) ) only if |
|
296 // aScreenNames is omitted. |
|
297 else if ( aGroupId ) |
|
298 { |
|
299 grs->AppendL( *aGroupId ); |
|
300 } |
|
301 |
|
302 myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) ); |
|
303 |
|
304 TImpsCDataUtils::SetRecipientsL( |
|
305 myKey, |
|
306 myAccess, |
|
307 grs, |
|
308 aUserIds, |
|
309 grns, // ScreenName( GroupId ) |
|
310 aScreenNames ); // ScreenName( SName ); |
|
311 |
|
312 TImpsCDataUtils::SetSenderL( |
|
313 myKey, |
|
314 myAccess, |
|
315 aSenderSn, |
|
316 NULL ); |
|
317 |
|
318 TPtrC myContentType( aContentType ); |
|
319 TImpsCDataUtils::SetContentTypeL( myAccess, myContentType ); |
|
320 |
|
321 TImpsCDataUtils::SetBinaryContentDataL( |
|
322 myKey, myAccess, aContent ); |
|
323 // Set sender |
|
324 // This is a "fuzzy" logic. |
|
325 // aSenderSn + aGroupId -> Sender ( ScreenName( SName, GroupID ) ) |
|
326 // !aSenderSn + !aGroupId -> Sender ( User ( UserID )) added by engine! |
|
327 // aSenderSn + !aGroupId -> Sender ( User ( UserID )) |
|
328 // !aSenderSn + aGroupId -> Sender ( Group ( GroupID )) |
|
329 |
|
330 CleanupStack::PopAndDestroy(4); // >>> grns, grs, myKey, myAccess |
|
331 |
|
332 // pack, or actullay serialize the message data |
|
333 TImpsPackedEntity packedMessage( iMessageStream ); |
|
334 TInt myError = packedMessage.PackEntity( *fields ); |
|
335 |
|
336 // Allocate more memory if needed |
|
337 if ( ( myError != KErrNone ) && |
|
338 ( iMessageStream->Des().Size() < fields->Size() ) ) |
|
339 { |
|
340 // notice: consider how to shrink buffer later |
|
341 // increase the size of the buffer and try again |
|
342 iMessageStream->Des().SetLength(0); // to avoid copying contents |
|
343 iMessageStream = iMessageStream->ReAllocL( fields->Size() + 10 ); |
|
344 myError = packedMessage.PackEntity( *fields ); |
|
345 User::LeaveIfError( myError ); |
|
346 } |
|
347 |
|
348 CleanupStack::PopAndDestroy( 1 ); // fields |
|
349 |
|
350 } |
|
351 |
|
352 // ---------------------------------------------------------------------------- |
|
353 // CImpsImCommand2::SetParametersL |
|
354 // ---------------------------------------------------------------------------- |
|
355 void CImpsImCommand2::SetParametersL( |
|
356 const MDesCArray* aBlockEntity, |
|
357 const MDesCArray* aUnBlockEntity, |
|
358 TBool aBlockedListInUse, |
|
359 const MDesCArray* aGrantedEntityList, |
|
360 const MDesCArray* aUnGrantEntity, |
|
361 TBool aGrantedListInUse ) |
|
362 { |
|
363 |
|
364 // Generate one flat message presentation |
|
365 |
|
366 if ( IsActive() ) |
|
367 { |
|
368 User::Leave( KErrServerBusy ); |
|
369 } |
|
370 |
|
371 if ( !iMessageStream ) |
|
372 { |
|
373 iMessageStream = HBufC8::NewL( KImpsStreamSize ); |
|
374 } |
|
375 *iMessageStream = KNullDesC8; |
|
376 |
|
377 // Initialize internal structure |
|
378 CImpsFields* fields = CImpsFields::NewL(); |
|
379 CleanupStack::PushL( fields ); // <<< fields |
|
380 fields->SetMessageType( EImpsBlockEntityReq ); |
|
381 |
|
382 CImpsDataAccessor* myAccess = CImpsDataAccessor::NewL( fields ); |
|
383 CleanupStack::PushL( myAccess ); // <<< myAccess |
|
384 CImpsKey* myKey = CImpsKey::NewLC(); // <<< myKey |
|
385 |
|
386 TImpsCDataUtils::SetBlockedListRequestL( |
|
387 myKey, |
|
388 myAccess, |
|
389 aBlockEntity, |
|
390 aUnBlockEntity, |
|
391 aBlockedListInUse, |
|
392 aGrantedEntityList, |
|
393 aUnGrantEntity, |
|
394 aGrantedListInUse ); |
|
395 |
|
396 CleanupStack::PopAndDestroy(2); // >>> myKey, myAccess |
|
397 |
|
398 // pack, or actullay serialize the message data |
|
399 TImpsPackedEntity packedMessage( iMessageStream ); |
|
400 TInt myError = packedMessage.PackEntity( *fields ); |
|
401 |
|
402 // Allocate more memory if needed |
|
403 if ( ( myError != KErrNone ) && |
|
404 ( iMessageStream->Des().Size() < fields->Size() ) ) |
|
405 { |
|
406 // notice: consider how to shrink buffer later |
|
407 // increase the size of the buffer and try again |
|
408 iMessageStream->Des().SetLength(0); // to avoid copying contents |
|
409 iMessageStream = iMessageStream->ReAllocL( fields->Size() + 10 ); |
|
410 myError = packedMessage.PackEntity( *fields ); |
|
411 User::LeaveIfError( myError ); |
|
412 } |
|
413 |
|
414 CleanupStack::PopAndDestroy( 1 ); // fields |
|
415 |
|
416 } |
|
417 |
|
418 // ---------------------------------------------------------------------------- |
|
419 // CImpsImCommand2::RunL |
|
420 // ---------------------------------------------------------------------------- |
|
421 |
|
422 void CImpsImCommand2::RunL() |
|
423 { |
|
424 |
|
425 #ifndef _NO_IMPS_LOGGING_ |
|
426 CImpsClientLogger::Log(_L("CImpsImCommand2: RunL stat=%d h=%d cli=%d"), |
|
427 iStatus.Int(), (TInt)this, (TInt)&iClient ); |
|
428 #endif |
|
429 |
|
430 MImpsErrorHandler2* ehandler = iClient.ErrorHandler(); |
|
431 |
|
432 // Errors are handled here only. |
|
433 // Successful cases are handled by CImpsImHandler. |
|
434 if ( iStatus == KErrNone ) |
|
435 { |
|
436 return; |
|
437 } |
|
438 |
|
439 // Handler should be registered |
|
440 if ( ehandler ) |
|
441 { |
|
442 TInt err( KErrNone ); |
|
443 TRAP( err, ehandler->HandleErrorL( |
|
444 iStatus.Int(), |
|
445 iOpId, |
|
446 NULL, |
|
447 NULL, |
|
448 *iClient.CspIdentifier() )); |
|
449 } |
|
450 } |
|
451 |
|
452 // ---------------------------------------------------------------------------- |
|
453 // CImpsImCommand2::DoCancel |
|
454 // Before calling this the Cancel should have sent to the engine! |
|
455 // ---------------------------------------------------------------------------- |
|
456 |
|
457 void CImpsImCommand2::DoCancel() |
|
458 { |
|
459 } |
|
460 |
|
461 // End of File |
|
462 |