|
1 /* |
|
2 * ============================================================================== |
|
3 * Name: sa_common_isc_service.cpp |
|
4 * Part of: System adaptation |
|
5 * Description: Implementation of CSACommonIscService class |
|
6 * %version: 1 % |
|
7 * %date_modified: Tue Dec 29 15:59:32 2009 % |
|
8 * |
|
9 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
10 * All rights reserved. |
|
11 * This component and the accompanying materials are made available |
|
12 * under the terms of the License "Eclipse Public License v1.0" |
|
13 * which accompanies this distribution, and is available |
|
14 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
15 * |
|
16 * Initial Contributors: |
|
17 * Nokia Corporation - initial contribution. |
|
18 * |
|
19 * Contributors: |
|
20 * |
|
21 * Description: |
|
22 * Implementation of CSACommonIscService class |
|
23 * |
|
24 */ |
|
25 |
|
26 |
|
27 // INCLUDE FILES |
|
28 #include "OstTraceDefinitions.h" |
|
29 #ifdef OST_TRACE_COMPILER_IN_USE |
|
30 #include "sa_common_isc_serviceTraces.h" |
|
31 #endif |
|
32 #include <iscapi.h> |
|
33 #include <iscnokiadefinitions.h> // For NokiaISC |
|
34 #include "sa_common_isc_service.h" |
|
35 #include "sa_common_isc_service_channel_listener.h" |
|
36 #include "sa_common_trace.h" |
|
37 #include "msa_isc_service.h" |
|
38 |
|
39 // EXTERNAL DATA STRUCTURES |
|
40 |
|
41 // EXTERNAL FUNCTION PROTOTYPES |
|
42 |
|
43 // CONSTANTS |
|
44 |
|
45 // MACROS |
|
46 |
|
47 // LOCAL CONSTANTS AND MACROS |
|
48 |
|
49 // Minimum received message length |
|
50 // ( = Phonet header + ISI transaction id + ISI message id) |
|
51 const TUint8 KSASMinIscMessageLength = 10; |
|
52 |
|
53 // MODULE DATA STRUCTURES |
|
54 |
|
55 // LOCAL FUNCTION PROTOTYPES |
|
56 |
|
57 // FORWARD DECLARATIONS |
|
58 |
|
59 // ============================= LOCAL FUNCTIONS =============================== |
|
60 |
|
61 |
|
62 // ============================ MEMBER FUNCTIONS =============================== |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CSACommonIscService::CSACommonIscService |
|
66 // C++ default constructor can NOT contain any code, that |
|
67 // might leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CSACommonIscService::CSACommonIscService( |
|
71 MSAIscService& aAdaptation, |
|
72 const TUint16 aChannelNumber, |
|
73 const TUint16 aClientISIMessageSize ) |
|
74 : CActive( CActive::EPriorityStandard ) |
|
75 , iAdaptation( aAdaptation ) |
|
76 , iChannelNumber( aChannelNumber ) |
|
77 , iClientISIMessageSize( aClientISIMessageSize ) |
|
78 , iMessageLength( 0 ) |
|
79 , iBuffer( NULL ) |
|
80 , iBufferPtr( NULL, 0 ) |
|
81 { |
|
82 OstTraceExt3( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_1, |
|
83 "ISCSERVICE # CSACommonIscService::CSACommonIscService(0x%x,0x%x,0x%x)", |
|
84 (TUint)&aAdaptation, (TUint)aChannelNumber, (TUint)aClientISIMessageSize ); |
|
85 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::CSACommonIscService(0x%x,0x%x,0x%x)" ), |
|
86 &aAdaptation, aChannelNumber, aClientISIMessageSize ) ); |
|
87 |
|
88 CActiveScheduler::Add( this ); |
|
89 |
|
90 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_2, |
|
91 "ISCSERVICE # CSACommonIscService::CSACommonIscService - return void" ); |
|
92 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::CSACommonIscService - return void" ) ) ); |
|
93 } |
|
94 |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CSACommonIscService::ConstructL |
|
98 // Symbian 2nd phase constructor can leave. |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CSACommonIscService::ConstructL( TDes8* aEvents ) |
|
102 { |
|
103 OstTrace1( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_3, |
|
104 "ISCSERVICE # CSACommonIscService::ConstructL(0x%x)", aEvents ); |
|
105 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::ConstructL(0x%x)" ), aEvents ) ); |
|
106 |
|
107 TRequestStatus status; |
|
108 |
|
109 /* Open ISC channel */ |
|
110 OstTrace0( TRACE_API, SA_COMMON_ISC_SERVICE_AUTOMATED_4, |
|
111 "ISCSERVICE - CSACommonIscService::ConstructL() - Opening ISC channel" ); |
|
112 API_TRACE( ( _L( "ISCSERVICE - CSACommonIscService::ConstructL() - Opening ISC channel" ) ) ); |
|
113 iIscApi.Open( iChannelNumber, status ); |
|
114 User::WaitForRequest( status ); |
|
115 |
|
116 if ( status.Int() != KErrNone ) |
|
117 { |
|
118 ASSERT_ALWAYS_TRACE( _L( "ISCSERVICE - CSACommonIscService::ConstructL() - Failed to open ISC channel!") ); |
|
119 User::LeaveIfError( status.Int() ); |
|
120 } |
|
121 |
|
122 if(aEvents) |
|
123 { |
|
124 /* Subscribe reception of events via ISC channel */ |
|
125 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_5, |
|
126 "ISCSERVICE - CSACommonIscService::ConstructL() - Subscribe events" ); |
|
127 INTERNAL_TRACE( ( _L( "ISCSERVICE - CSACommonIscService::ConstructL() - Subscribe events" ) ) ); |
|
128 SubscribeEventsL( aEvents ); |
|
129 } |
|
130 |
|
131 /* Start receiving messages via ISC channel */ |
|
132 ReceiveMessageL( iClientISIMessageSize ); |
|
133 |
|
134 /* Create ISC channel listener to monitor the state of ISC channel */ |
|
135 iSACommonIscServiceChannelListener = CSACommonIscServiceChannelListener::NewL( iAdaptation, iIscApi ); |
|
136 |
|
137 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_6, |
|
138 "ISCSERVICE # CSACommonIscService::ConstructL - return void" ); |
|
139 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::ConstructL - return void" ) ) ); |
|
140 } |
|
141 |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CSACommonIscService::NewL |
|
145 // Two-phased constructor. |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 CSACommonIscService* CSACommonIscService::NewL( MSAIscService& aAdaptation, |
|
149 const TUint16 aChannelNumber, |
|
150 TDes8* aEvents, |
|
151 const TUint16 aClientISIMessageSize ) |
|
152 { |
|
153 OstTraceExt4( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_7, |
|
154 "ISCSERVICE # CSACommonIscService::NewL(0x%x,0x%x,0x%x,0x%x)", |
|
155 (TUint)&aAdaptation, (TUint)aChannelNumber, (TUint)aEvents, (TUint)aClientISIMessageSize ); |
|
156 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::NewL(0x%x,0x%x,0x%x,0x%x)" ), |
|
157 &aAdaptation, aChannelNumber, aEvents, aClientISIMessageSize ) ); |
|
158 |
|
159 CSACommonIscService* self = new( ELeave ) CSACommonIscService( |
|
160 aAdaptation, |
|
161 aChannelNumber, |
|
162 aClientISIMessageSize ); |
|
163 |
|
164 CleanupStack::PushL( self ); |
|
165 self->ConstructL( aEvents ); |
|
166 CleanupStack::Pop( self ); |
|
167 |
|
168 OstTrace1( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_8, |
|
169 "ISCSERVICE # CSACommonIscService::NewL - return 0x%x", self ); |
|
170 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::NewL - return 0x%x" ), self ) ); |
|
171 |
|
172 return self; |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CSACommonIscService::~CSACommonIscService |
|
178 // Destructor. |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 CSACommonIscService::~CSACommonIscService() |
|
182 { |
|
183 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_9, |
|
184 "ISCSERVICE # CSACommonIscService::~CSACommonIscService()" ); |
|
185 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::~CSACommonIscService()" ) ) ); |
|
186 |
|
187 /* Cancel any outstanding request */ |
|
188 Cancel(); |
|
189 |
|
190 /* Delete message buffer */ |
|
191 delete iBuffer; |
|
192 iBuffer = NULL; |
|
193 |
|
194 /* Cancel monitoring ISC channel state */ |
|
195 delete iSACommonIscServiceChannelListener; |
|
196 iSACommonIscServiceChannelListener = NULL; |
|
197 |
|
198 /* Close ISC channel */ |
|
199 OstTrace0( TRACE_API, SA_COMMON_ISC_SERVICE_AUTOMATED_10, |
|
200 "ISCSERVICE - CSACommonIscService::~CSACommonIscService - Close ISC channel" ); |
|
201 API_TRACE( ( _L( "ISCSERVICE - CSACommonIscService::~CSACommonIscService - Close ISC channel" ) ) ); |
|
202 iIscApi.Close(); |
|
203 |
|
204 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_11, |
|
205 "ISCSERVICE # CSACommonIscService::~CSACommonIscService - return void" ); |
|
206 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::~CSACommonIscService - return void" ) ) ); |
|
207 } |
|
208 |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CSACommonIscService::SendMessageL |
|
212 // This function is used to send a message via ISC channel |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CSACommonIscService::SendMessageL( |
|
216 TDesC8& aMessage ) |
|
217 { |
|
218 OstTrace1( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_12, |
|
219 "ISCSERVICE # CSACommonIscService::SendMessageL(0x%x)", (TUint)&aMessage ); |
|
220 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::SendMessageL(0x%x)" ), (TUint)&aMessage ) ); |
|
221 |
|
222 OstTrace1( TRACE_API, SA_COMMON_ISC_SERVICE_AUTOMATED_13, |
|
223 "ISCSERVICE - CSACommonIscService::SendMessageL() - Sending ISI Message;aData=%x", |
|
224 (TUint)&aMessage ); |
|
225 ISIMSG_API_TRACE( _L("ISCSERVICE # CSACommonIscService::SendMessageL() - Sending ISI Message: "), aMessage); |
|
226 |
|
227 User::LeaveIfError( iIscApi.Send( aMessage ) ); |
|
228 |
|
229 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_14, |
|
230 "ISCSERVICE # CSACommonIscService::SendMessageL - return void" ); |
|
231 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::SendMessageL - return void" ) ) ); |
|
232 } |
|
233 |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CSACommonIscService::ReceiveMessageL |
|
237 // This function starts receiving messages via ISC channel |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CSACommonIscService::ReceiveMessageL( TUint16 aMessageLength ) |
|
241 { |
|
242 OstTrace1( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_16, |
|
243 "ISCSERVICE # CSACommonIscService::ReceiveMessageL(0x%x)", aMessageLength ); |
|
244 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::ReceiveMessageL(0x%x)" ), |
|
245 aMessageLength ) ); |
|
246 |
|
247 if ( !IsActive() ) |
|
248 { |
|
249 |
|
250 OstTrace0( TRACE_API, SA_COMMON_ISC_SERVICE_AUTOMATED_17, |
|
251 "ISCSERVICE - CSACommonIscService::ReceiveMessageL() - Receiving message" ); |
|
252 API_TRACE( ( _L( "ISCSERVICE - CSACommonIscService::ReceiveMessageL() - Receiving message" ) ) ); |
|
253 |
|
254 /* Reserve space for the received message buffer */ |
|
255 delete iBuffer; |
|
256 iBuffer = NULL; |
|
257 iBuffer = HBufC8::NewL( aMessageLength ); |
|
258 iBufferPtr.Set( iBuffer->Des() ); |
|
259 |
|
260 /* Start receiving messages via ISC channel */ |
|
261 iMessageLength = 0; |
|
262 iIscApi.Receive( iStatus, iBufferPtr, iMessageLength ); |
|
263 SetActive(); |
|
264 } |
|
265 else |
|
266 { |
|
267 /* Receiving request pending */ |
|
268 ASSERT_ALWAYS_TRACE( _L( "ISCSERVICE - CSACommonIscService::ReceiveMessageL() - Request pending") ); |
|
269 } |
|
270 |
|
271 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_18, |
|
272 "ISCSERVICE # CSACommonIscService::ReceiveMessageL - return void" ); |
|
273 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::ReceiveMessageL - return void" ) ) ); |
|
274 } |
|
275 |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CSACommonIscService::RunL |
|
279 // This function is called when a message is received via ISC channel |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CSACommonIscService::RunL() |
|
283 { |
|
284 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_19, |
|
285 "ISCSERVICE # CSACommonIscService::RunL()" ); |
|
286 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::RunL()" ) ) ); |
|
287 |
|
288 TInt err( KErrNone ); |
|
289 TUint16 length( iClientISIMessageSize ); |
|
290 |
|
291 switch ( iStatus.Int() ) |
|
292 { |
|
293 case KErrNone: |
|
294 if ( iBufferPtr.Length() >= KSASMinIscMessageLength ) |
|
295 { |
|
296 /* Forward receive message to System Adaptation proxy */ |
|
297 OstTrace1( TRACE_API, SA_COMMON_ISC_SERVICE_AUTOMATED_20, |
|
298 "ISCSERVICE - CSACommonIscService::RunL() - Receive ISI Message;iBufferPtr=%x", |
|
299 (TUint)&(iBufferPtr) ); |
|
300 ISIMSG_API_TRACE( _L("ISCSERVICE - CSACommonIscService::RunL() - Receive ISI Message: " ), |
|
301 iBufferPtr); |
|
302 |
|
303 TRAP( err, iAdaptation.ReceiveIsiMessageL( iBufferPtr ) ); |
|
304 ASSERT_TRACE( _L( "ISCSERVICE - CSACommonIscService::RunL() - Processing message failed" ), |
|
305 ( err == KErrNone ) ); |
|
306 } |
|
307 else |
|
308 { |
|
309 ASSERT_ALWAYS_TRACE( _L( "ISCSERVICE - CSACommonIscService::RunL() - Invalid message" ) ); |
|
310 } |
|
311 break; |
|
312 |
|
313 case KErrNoMemory: |
|
314 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_21, |
|
315 "ISCSERVICE # CSACommonIscService::RunL() - Reallocate message buffer" ); |
|
316 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::RunL() - Reallocate message buffer" ) ) ); |
|
317 /* Reserved message buffer overflow - |
|
318 Reallocate message buffer and receive the message again |
|
319 ( iMessageLength contains the required buffer length for the message ) */ |
|
320 length = iMessageLength; |
|
321 break; |
|
322 |
|
323 default: |
|
324 /* Other errors are ignored - Continue receiving messages via ISC channel */ |
|
325 ASSERT_ALWAYS_TRACE( _L( "ISCSERVICE - CSACommonIscService::RunL() - Other error" ) ); |
|
326 break; |
|
327 } |
|
328 |
|
329 /* Continue receiving messages via ISC channel */ |
|
330 TRAP( err, ReceiveMessageL( length ) ); |
|
331 |
|
332 if ( err != KErrNone ) |
|
333 { |
|
334 ASSERT_ALWAYS_TRACE( _L( "ISCSERVICE - CSACommonIscService::RunL() - Memory allocation failed" ) ); |
|
335 User::Panic( _L( "ISCSERVICE - CSACommonIscService" ), err ); |
|
336 } |
|
337 |
|
338 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_22, |
|
339 "ISCSERVICE # CSACommonIscService::RunL - return void" ); |
|
340 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::RunL - return void" ) ) ); |
|
341 } |
|
342 |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CSACommonIscService::DoCancel |
|
346 // This function cancels the receiving messages via ISC channel |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CSACommonIscService::DoCancel() |
|
350 { |
|
351 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_23, |
|
352 "ISCSERVICE # CSACommonIscService::DoCancel()" ); |
|
353 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::DoCancel()" ) ) ); |
|
354 |
|
355 iIscApi.ReceiveCancel(); |
|
356 |
|
357 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_24, |
|
358 "ISCSERVICE # CSACommonIscService::DoCancel - return void" ); |
|
359 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::DoCancel - return void" ) ) ); |
|
360 } |
|
361 |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CSACommonIscService::SubscribeEvents |
|
365 // This function subscribes reception of events via ISC channel |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 void CSACommonIscService::SubscribeEventsL( TDes8 *aEvents ) |
|
369 { |
|
370 OstTrace1( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_25, |
|
371 "ISCSERVICE # CSACommonIscService::SubscribeEventsL(0x%x)", aEvents ); |
|
372 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::SubscribeEventsL(0x%x)" ), aEvents ) ); |
|
373 |
|
374 User::LeaveIfError( iIscApi.CustomFunction( EIscNokiaEventSubscribe, aEvents ) ); |
|
375 |
|
376 OstTrace0( TRACE_NORMAL, SA_COMMON_ISC_SERVICE_AUTOMATED_26, |
|
377 "ISCSERVICE # CSACommonIscService::SubscribeEventsL - return void" ); |
|
378 INTERNAL_TRACE( ( _L( "ISCSERVICE # CSACommonIscService::SubscribeEventsL - return void" ) ) ); |
|
379 } |
|
380 |
|
381 |
|
382 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
383 |
|
384 |
|
385 // End of File |