|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "mceitcreceiverbase.h" |
|
23 #include "mceitc.h" |
|
24 #include "mceclilogs.h" |
|
25 |
|
26 |
|
27 _LIT8( KMceEmpty, ""); |
|
28 |
|
29 #ifdef MCE_UNIT_TEST |
|
30 #define MCE_UNIT_TEST_RETURN { if ( aError == KErrNoMemory ) return aError; } |
|
31 #else |
|
32 #define MCE_UNIT_TEST_RETURN |
|
33 #endif |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CMceItcReceiverBase::CMceItcReceiverBase |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CMceItcReceiverBase::CMceItcReceiverBase ( MMceItc& aITC ) |
|
40 : CActive( EPriorityStandard ), |
|
41 iITC( aITC ) |
|
42 { |
|
43 CActiveScheduler::Add ( this ); |
|
44 |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CMceItcReceiverBase::~CMceItcReceiverBase |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CMceItcReceiverBase::~CMceItcReceiverBase () |
|
52 { |
|
53 CActive::Cancel(); |
|
54 } |
|
55 |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CMceItcReceiverBase::Init |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CMceItcReceiverBase::Init() |
|
62 { |
|
63 |
|
64 iITCMsgArgs.Set (EMceItcArgIds, &iIdsPckg); |
|
65 iITCMsgArgs.Set (EMceItcArgBufSizes, &iSizesPckg); |
|
66 |
|
67 ReceiveNext(); |
|
68 |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CMceItcReceiverBase::RunL |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CMceItcReceiverBase::RunL () |
|
77 { |
|
78 MCECLI_DEBUG("CMceItcReceiverBase::RunL, Entry"); |
|
79 |
|
80 TInt err = iStatus.Int(); |
|
81 MCECLI_DEBUG_DVALUE("status", err ); |
|
82 |
|
83 if (err == KErrServerTerminated) |
|
84 { |
|
85 MCECLI_DEBUG("unrecoverable error!"); |
|
86 // This will leave to RunError-function. See below. |
|
87 User::Leave( err ); |
|
88 } |
|
89 // Take copy of the ids. iIdsPckg could be overwritten by ReceiveNext. |
|
90 TMceIds ids( iIdsPckg() ); |
|
91 if ( err == KErrNone ) |
|
92 { |
|
93 MCECLI_DEBUG("itc received"); |
|
94 IncomingEventL( ids ); |
|
95 } |
|
96 else if ( err == KErrCompletion ) |
|
97 { |
|
98 MCECLI_DEBUG("itc completed"); |
|
99 err = KErrNone; |
|
100 } |
|
101 else |
|
102 { |
|
103 MCECLI_DEBUG("renew itc"); |
|
104 // For errors receive has to be renewed before calling the observer |
|
105 // which might delete the CMCE or CMCEConnection, |
|
106 // which leads to deletion of this object. |
|
107 ReceiveNext(); |
|
108 ErrorOccuredL( ids, err ); |
|
109 } |
|
110 MCECLI_DEBUG("CMceItcReceiverBase::RunL, Exit"); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CMceItcReceiverBase::RunError |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CMceItcReceiverBase::RunError( TInt aError ) |
|
118 { |
|
119 MCECLI_DEBUG("CMceItcReceiverBase::RunError, Entry"); |
|
120 MCECLI_DEBUG_DVALUE("error", aError ); |
|
121 |
|
122 if (aError == KErrServerTerminated) |
|
123 { |
|
124 // Return the error to the active scheduler and stop receiving. |
|
125 // Receiving must be stopped. |
|
126 // It would lead to infinite RunL-RunError-loop. |
|
127 return aError; |
|
128 } |
|
129 // Ignore all the other errors and continue receiving |
|
130 ReceiveNext (); |
|
131 |
|
132 MCECLI_DEBUG("CMceItcReceiverBase::RunError, Exit"); |
|
133 |
|
134 MCE_UNIT_TEST_RETURN |
|
135 |
|
136 return KErrNone; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CMceItcReceiverBase::RunError |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CMceItcReceiverBase::DoCancel() |
|
144 { |
|
145 MCECLI_DEBUG("CMceItcReceiverBase::DoCancel, Entry"); |
|
146 |
|
147 iITC.CancelReceive( iITCMsgArgs ); |
|
148 |
|
149 MCECLI_DEBUG("CMceItcReceiverBase::DoCancel, Exit"); |
|
150 |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CMceItcReceiverBase::ReceiveNext |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CMceItcReceiverBase::ReceiveNext() |
|
158 { |
|
159 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveNext, Entry"); |
|
160 |
|
161 if (!IsActive()) |
|
162 { |
|
163 iITC.Receive( iITCMsgArgs,iStatus ); |
|
164 SetActive(); |
|
165 } |
|
166 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveNext, Exit"); |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CMceItcReceiverBase::ReceiveDataLC |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CMceItcReceiverBase::ReceiveDataLC( HBufC8*& aContext, HBufC8*& aContent ) |
|
175 { |
|
176 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveDataLC, Entry"); |
|
177 |
|
178 TIpcArgs tmpITCArgs; |
|
179 TMceIds ids( iIdsPckg() ); |
|
180 TPckgBuf<TMceIds> tmpIdsPckg( ids ); |
|
181 tmpITCArgs.Set( EMceItcArgIds, &tmpIdsPckg ); |
|
182 |
|
183 if ( iSizesPckg().iContextBufSize != KErrNotFound ) |
|
184 { |
|
185 aContext = HBufC8::NewLC( iSizesPckg().iContextBufSize ); |
|
186 } |
|
187 |
|
188 if ( iSizesPckg().iContentBufSize != KErrNotFound ) |
|
189 { |
|
190 aContent = HBufC8::NewLC( iSizesPckg().iContentBufSize ); |
|
191 } |
|
192 |
|
193 __ASSERT_ALWAYS( !( !aContext && aContent ), User::Leave( KErrGeneral ) ); |
|
194 |
|
195 if ( aContext || aContent ) |
|
196 { |
|
197 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveDataLC, receiving data!!") |
|
198 |
|
199 HBufC8* dummy = KMceEmpty().AllocLC(); |
|
200 TInt err = iITC.Receive( tmpITCArgs, |
|
201 ( aContext ? aContext->Des() : dummy->Des() ), |
|
202 ( aContent ? aContent->Des() : dummy->Des() ) ); |
|
203 |
|
204 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveDataLC, data received") |
|
205 CleanupStack::PopAndDestroy( dummy ); |
|
206 |
|
207 if ( err != KErrNone ) |
|
208 { |
|
209 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveDataLC, receiving failed") |
|
210 User::Leave( err ); |
|
211 } |
|
212 } |
|
213 MCECLI_DEBUG("CMceItcReceiverBase::ReceiveDataLC, Exit"); |
|
214 |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CMceItcReceiverBase::IncomingEventL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CMceItcReceiverBase::IncomingEventL( TMceIds& aIds ) |
|
224 { |
|
225 MCECLI_DEBUG("CMceItcReceiverBase::IncomingEventL, Entry"); |
|
226 |
|
227 HBufC8* context = NULL; |
|
228 HBufC8* content = NULL; |
|
229 TMceItcCallBack callback = static_cast<TMceItcCallBack>( aIds.iCallbackID ); |
|
230 |
|
231 MCECLI_DEBUG_CALLBACK( "CALLBACK", callback ); |
|
232 MCECLI_DEBUG_IDS( "IDS", aIds ); |
|
233 |
|
234 ReceiveDataLC( context, content ); |
|
235 |
|
236 ReceiveNext(); |
|
237 |
|
238 if ( context && content ) |
|
239 { |
|
240 MCECLI_DEBUG("CMceItcReceiverBase::IncomingEventL, received both data") |
|
241 IncomingEventL( callback, aIds, *context, content ); |
|
242 CleanupStack::Pop( content ); |
|
243 CleanupStack::PopAndDestroy( context );//context |
|
244 } |
|
245 else if ( !context && !content ) |
|
246 { |
|
247 MCECLI_DEBUG("CMceItcReceiverBase::IncomingEventL, received no data") |
|
248 IncomingEventL( callback, aIds ); |
|
249 } |
|
250 else |
|
251 { |
|
252 MCECLI_DEBUG("CMceItcReceiverBase::IncomingEventL, received context") |
|
253 IncomingEventL( callback, aIds, *context ); |
|
254 CleanupStack::PopAndDestroy( context ); |
|
255 } |
|
256 |
|
257 MCECLI_DEBUG("CMceItcReceiverBase::IncomingEventL, Exit"); |
|
258 } |
|
259 |