|
1 /* |
|
2 * Copyright (c) 2004 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: Connection Monitor Extension. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ConnMonExt.h" |
|
19 #include "log.h" |
|
20 |
|
21 // ============================ LOCAL FUNCTIONS =============================== |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // Panic |
|
25 // Panics the client in case of programming error. |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 void Panic( TInt aPanic ) |
|
29 { |
|
30 _LIT( KPanicCategory, "ConnectionMonitor Extension API" ); |
|
31 User::Panic( KPanicCategory, aPanic ); |
|
32 } |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CConnectionMonitorPlugin::CConnectionMonitorPlugin |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CConnectionMonitorPlugin::CConnectionMonitorPlugin() |
|
41 { |
|
42 iPluginAO = 0; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // Destructor |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CConnectionMonitorPlugin::~CConnectionMonitorPlugin() |
|
50 { |
|
51 delete iPluginAO; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CConnectionMonitorPlugin::RegisterPlugin |
|
56 // Starts plugin session and registers the plug-in. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C void CConnectionMonitorPlugin::RegisterPluginL( const TUint aConnectionId ) |
|
60 { |
|
61 if ( iPluginAO == 0 ) |
|
62 { |
|
63 // Create the receiver (active object) |
|
64 iPluginAO = new ( ELeave ) CPluginAO( iSession, *this ); |
|
65 iPluginAO->ConstructL(); |
|
66 |
|
67 // Connect to the Connection Monitor server |
|
68 iConnMonServer.ConnectL(); |
|
69 |
|
70 // Open plug-in subsession to the Connection Monitor server |
|
71 TInt ret = iSession.Open( iConnMonServer, aConnectionId ); |
|
72 |
|
73 if ( ret != KErrNone ) |
|
74 { |
|
75 User::Leave( ret ); |
|
76 } |
|
77 } |
|
78 |
|
79 iPluginAO->ReceiveQuery(); |
|
80 |
|
81 LOG( Log::Printf( _L("Plugin [%d]: registered: Id:<%d>\n"), &iSession, aConnectionId ) ); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CConnectionMonitorPlugin::CancelRegisterPlugin |
|
86 // Cancels the plug-in's registration. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C void CConnectionMonitorPlugin::CancelRegisterPlugin() |
|
90 { |
|
91 if ( iPluginAO != 0 ) |
|
92 { |
|
93 // Delete receiver |
|
94 delete iPluginAO; |
|
95 iPluginAO = 0; |
|
96 |
|
97 // Close plug-in subsession |
|
98 iSession.Close(); |
|
99 |
|
100 // Disconnect from Connection Monitor server |
|
101 iConnMonServer.Close(); |
|
102 |
|
103 LOG( Log::Printf( _L("Plugin [%d]: Cancelled registration.\n"), &iSession ) ); |
|
104 } |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CConnectionMonitorPlugin::RegisterAttribute |
|
109 // Registers a new attribute to the Connection Monitor server. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C TInt CConnectionMonitorPlugin::RegisterAttribute( const TUint aAttribute ) const |
|
113 { |
|
114 LOG( Log::Printf( _L("Plugin [%d]: register attribute: Id:<%d>\n"), &iSession, aAttribute ) ); |
|
115 |
|
116 return ( iSession.RegisterAttribute( aAttribute ) ); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CConnectionMonitorPlugin::CancelRegisterAttribute |
|
121 // Cancels the attribute registration from the Connection Monitor server. |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C void CConnectionMonitorPlugin::CancelRegisterAttribute( const TUint aAttribute ) const |
|
125 { |
|
126 LOG( Log::Printf( _L("Plugin [%d]: Cancel attribute registration: Id:<%d>\n"), &iSession, aAttribute ) ); |
|
127 |
|
128 iSession.CancelRegisterAttribute( aAttribute ); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CConnectionMonitorPlugin::Event |
|
133 // Sends an event to Connnection Monitor server. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TInt CConnectionMonitorPlugin::Event( const TUint aEventId, |
|
137 const TAny* aData, |
|
138 const TUint aSize ) const |
|
139 { |
|
140 LOG( Log::Printf( _L("Plugin [%d]: Send event: EventId:<%d>\n"), &iSession, aEventId ) ); |
|
141 |
|
142 return ( iSession.SendEvent( aEventId, aData, aSize ) ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CConnectionMonitorPlugin::Version |
|
147 // Returns the client side version number. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C TVersion CConnectionMonitorPlugin::Version() const |
|
151 { |
|
152 LOG( Log::Printf( _L("Plugin [%d]: Get version.\n"), &iSession ) ); |
|
153 |
|
154 return ( iSession.Version() ); |
|
155 } |
|
156 |
|
157 // ============================ MEMBER FUNCTIONS =============================== |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // RConnMonPlugin::Open |
|
161 // Creates a new subsession with the Connection Monitor server. |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt RConnMonPlugin::Open( RConnectionMonitor &aSession, const TUint aConnectionId ) |
|
165 { |
|
166 //p[0]= ( TAny* )aConnectionId ; |
|
167 |
|
168 TIpcArgs args( aConnectionId ); |
|
169 |
|
170 return CreateSubSession( aSession, EReqPluginCreateSubSession, args ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // RConnMonPlugin::Close |
|
175 // Closes the subsession. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void RConnMonPlugin::Close() |
|
179 { |
|
180 RSubSessionBase::CloseSubSession( EReqPluginCloseSubSession ); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // RConnMonPlugin::Version |
|
185 // Returns the client side version number. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 TVersion RConnMonPlugin::Version() const |
|
189 { |
|
190 return( TVersion( KPluginMajorVersionNumber, |
|
191 KPluginMinorVersionNumber, |
|
192 KPluginBuildVersionNumber ) ); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // RConnMonPlugin::SendEvent |
|
197 // Sends an event to the Connection Monitor server. |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 TInt RConnMonPlugin::SendEvent( const TUint aEventId, |
|
201 const TAny* aData, |
|
202 const TUint aSize ) const |
|
203 { |
|
204 if ( aSize > KConnMonMaxPluginDataSize ) |
|
205 { |
|
206 return KErrTooBig; |
|
207 } |
|
208 |
|
209 TPtrC8 n( reinterpret_cast< const TUint8* >( aData ), aSize ); |
|
210 |
|
211 //p[0]= ( TAny* )aEventId; |
|
212 //p[1]= ( TAny* )&n; |
|
213 |
|
214 TIpcArgs args( aEventId, &n ); |
|
215 |
|
216 return SendReceive( EReqPluginEvent, args ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // RConnMonPlugin::RegisterAttribute |
|
221 // Registers an attribute to the Connection Monitor server. |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TInt RConnMonPlugin::RegisterAttribute( const TUint aAttribute ) const |
|
225 { |
|
226 //p[0]= ( TAny* )aAttribute; |
|
227 |
|
228 TIpcArgs args( aAttribute ); |
|
229 |
|
230 return SendReceive( EReqPluginRegisterAttribute, args ); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // RConnMonPlugin::CancelRegisterAttribute |
|
235 // Cancels the attribute registration from the Connection Monitor server. |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TInt RConnMonPlugin::CancelRegisterAttribute( const TUint aAttribute ) const |
|
239 { |
|
240 //p[0]= ( TAny* )aAttribute; |
|
241 |
|
242 TIpcArgs args( aAttribute ); |
|
243 |
|
244 return SendReceive( EReqPluginCancelRegisterAttribute, args ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // RConnMonPlugin::GetQuery |
|
249 // Gets the next attribute request from the Connection Monitor server. |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void RConnMonPlugin::GetQuery( TDes8& aBuffer, TRequestStatus& aStatus ) const |
|
253 { |
|
254 //p[ 0 ]= ( TAny* )&aBuffer; |
|
255 |
|
256 TIpcArgs args( &aBuffer ); |
|
257 |
|
258 SendReceive( EReqPluginGetQuery, args, aStatus ); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // RConnMonPlugin::CancelGetQueyry |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void RConnMonPlugin::CancelGetQuery() const |
|
266 { |
|
267 //SendReceive( EReqPluginCancelGetQuery, 0 ); |
|
268 SendReceive( EReqPluginCancelGetQuery, TIpcArgs( TIpcArgs::ENothing ) ); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // RConnMonPlugin::SendAttribute |
|
273 // Sends an attribute to the Connection Monitor server. |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 TInt RConnMonPlugin::SendAttribute( const TInt aType, |
|
277 const TUint aAttribute, |
|
278 const TInt aRet, |
|
279 const TAny* aValue, |
|
280 const TUint aSize ) const |
|
281 { |
|
282 if ( aSize > KConnMonMaxPluginDataSize ) |
|
283 { |
|
284 return KErrTooBig; |
|
285 } |
|
286 |
|
287 //p[0]= ( TAny* )aAttribute; |
|
288 //p[1]= ( TAny* )aRet; |
|
289 |
|
290 if ( ( aType == EReqGetIntAttribute ) || ( aType == EReqGetUintAttribute ) || |
|
291 ( aType == EReqGetBoolAttribute ) ) |
|
292 { |
|
293 TPtrC8 n( reinterpret_cast< const TUint8* >( aValue ), aSize ); |
|
294 |
|
295 //p[2]= ( TAny* )&n; |
|
296 |
|
297 TIpcArgs args( aAttribute, aRet, &n ); |
|
298 |
|
299 return SendReceive( EReqPluginAttribute, args ); |
|
300 } |
|
301 else |
|
302 { |
|
303 //p[2]= const_cast< TAny* >( aValue ); |
|
304 |
|
305 TIpcArgs args( aAttribute, aRet, aValue ); |
|
306 |
|
307 return SendReceive( EReqPluginAttribute, args ); |
|
308 } |
|
309 } |
|
310 |
|
311 // ============================ MEMBER FUNCTIONS =============================== |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CPluginAO::CPluginAO |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 CPluginAO::CPluginAO( RConnMonPlugin& aSession, CConnectionMonitorPlugin& aPlugin ) |
|
318 : |
|
319 CActive( EPriorityStandard ), |
|
320 iSession( aSession ), |
|
321 iPlugin( aPlugin ), |
|
322 iBuf( NULL, 0, 0 ) |
|
323 { |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CPluginAO::ConstructL |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CPluginAO::ConstructL() |
|
331 { |
|
332 // Plug-in engine must have an active scheduler |
|
333 CActiveScheduler::Add( this ); |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // Destructor |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 CPluginAO::~CPluginAO() |
|
341 { |
|
342 Cancel(); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CPluginAO::ReceiveQuery |
|
347 // Requests a new query from Connection Monitor server. |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 void CPluginAO::ReceiveQuery() |
|
351 { |
|
352 if ( IsActive() ) |
|
353 { |
|
354 return; |
|
355 } |
|
356 else |
|
357 { |
|
358 // Must be passed as a descriptor |
|
359 iReqInfo.Reset(); |
|
360 |
|
361 iBuf.Set( reinterpret_cast< TUint8* >( &iReqInfo ), sizeof( TReqInfo ), sizeof( TReqInfo ) ); |
|
362 |
|
363 iSession.GetQuery( iBuf, iStatus ); |
|
364 |
|
365 SetActive(); |
|
366 } |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CPluginAO::RunL |
|
371 // Receives the a request from the Connection Monitor server and passes it to the |
|
372 // plug-in module. Sends the result back to the server. |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 void CPluginAO::RunL() |
|
376 { |
|
377 if ( iStatus.Int() == KErrServerBusy ) |
|
378 { |
|
379 // Message slot was reserved |
|
380 // Try again |
|
381 ReceiveQuery(); |
|
382 } |
|
383 else if ( iStatus.Int() == KErrNone ) |
|
384 { |
|
385 // A new request has arrived |
|
386 |
|
387 switch ( iReqInfo.iType ) |
|
388 { |
|
389 case EReqGetIntAttribute: |
|
390 { |
|
391 TInt value( 0 ); |
|
392 TInt ret = iPlugin.GetIntAttribute( iReqInfo.iAttribute, value ); |
|
393 |
|
394 iSession.SendAttribute( EReqGetIntAttribute, |
|
395 iReqInfo.iAttribute, |
|
396 ret, |
|
397 &value, |
|
398 sizeof( TInt ) ); |
|
399 |
|
400 break; |
|
401 } |
|
402 |
|
403 case EReqGetUintAttribute: |
|
404 { |
|
405 TUint value( 0 ); |
|
406 TInt ret = iPlugin.GetUintAttribute( iReqInfo.iAttribute, value ); |
|
407 |
|
408 iSession.SendAttribute( EReqGetUintAttribute, |
|
409 iReqInfo.iAttribute, |
|
410 ret, |
|
411 &value, |
|
412 sizeof( TUint ) ); |
|
413 |
|
414 break; |
|
415 } |
|
416 |
|
417 case EReqGetBoolAttribute: |
|
418 { |
|
419 TBool value( EFalse ); |
|
420 TInt ret = iPlugin.GetBoolAttribute( iReqInfo.iAttribute, value ); |
|
421 |
|
422 iSession.SendAttribute( EReqGetBoolAttribute, |
|
423 iReqInfo.iAttribute, |
|
424 ret, |
|
425 &value, |
|
426 sizeof( TBool ) ); |
|
427 |
|
428 break; |
|
429 } |
|
430 |
|
431 case EReqGetStringAttribute: |
|
432 { |
|
433 HBufC16* value = HBufC16::NewL( KConnMonMaxStringAttributeLength ); |
|
434 |
|
435 TPtr16 auxPtr( const_cast< TUint16* >( value->Des().Ptr() ), KConnMonMaxStringAttributeLength ); |
|
436 auxPtr.FillZ(); |
|
437 |
|
438 TInt ret = iPlugin.GetStringAttribute( iReqInfo.iAttribute, auxPtr ); |
|
439 |
|
440 iSession.SendAttribute( EReqGetStringAttribute, |
|
441 iReqInfo.iAttribute, |
|
442 ret, |
|
443 &auxPtr, |
|
444 auxPtr.MaxSize() ); |
|
445 delete value; |
|
446 |
|
447 break; |
|
448 } |
|
449 |
|
450 case EReqGetPckgAttribute: |
|
451 { |
|
452 HBufC8* buf = HBufC8::New( KConnMonMaxPluginDataSize ); |
|
453 TPtr8 initptr = buf->Des(); |
|
454 |
|
455 TInt ret = iPlugin.GetPckgAttribute( iReqInfo.iAttribute, initptr ); |
|
456 |
|
457 iSession.SendAttribute( EReqGetPckgAttribute, |
|
458 iReqInfo.iAttribute, |
|
459 ret, |
|
460 &initptr, |
|
461 KConnMonMaxPluginDataSize ); |
|
462 |
|
463 delete buf; |
|
464 |
|
465 break; |
|
466 } |
|
467 |
|
468 case EReqSetIntAttribute: |
|
469 { |
|
470 iPlugin.SetIntAttribute( iReqInfo.iAttribute, iReqInfo.iData ); |
|
471 |
|
472 break; |
|
473 } |
|
474 |
|
475 case EReqSetUintAttribute: |
|
476 { |
|
477 iPlugin.SetUintAttribute( iReqInfo.iAttribute, static_cast< TUint >( iReqInfo.iData ) ); |
|
478 |
|
479 break; |
|
480 } |
|
481 |
|
482 case EReqSetBoolAttribute: |
|
483 { |
|
484 iPlugin.SetBoolAttribute( iReqInfo.iAttribute, static_cast< TBool >( iReqInfo.iData ) ); |
|
485 |
|
486 break; |
|
487 } |
|
488 |
|
489 case EReqSetStringAttribute: |
|
490 { |
|
491 // Not supported |
|
492 break; |
|
493 } |
|
494 |
|
495 case EReqSetPckgAttribute: |
|
496 { |
|
497 // Not supported |
|
498 break; |
|
499 } |
|
500 |
|
501 default: |
|
502 break; |
|
503 } |
|
504 |
|
505 LOG( Log::Printf( _L("Plugin [%d]: served attribute query: Type:<%d>, Attribute:<%d> \n"), |
|
506 &iSession, |
|
507 iReqInfo.iType, |
|
508 iReqInfo.iAttribute ) ); |
|
509 |
|
510 // initiate the next receive |
|
511 ReceiveQuery(); |
|
512 } |
|
513 else |
|
514 { |
|
515 // Log error |
|
516 LOG( Log::Printf( _L("Error in CPluginAO::RunL(): [%d].\n"), iStatus.Int() ) ); |
|
517 } |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CPluginAO::DoCancel |
|
522 // Cancels the request from Connection Monitor server. |
|
523 // ----------------------------------------------------------------------------- |
|
524 // |
|
525 void CPluginAO::DoCancel() |
|
526 { |
|
527 if ( IsActive() ) |
|
528 { |
|
529 iSession.CancelGetQuery(); |
|
530 } |
|
531 } |
|
532 |