connectionmonitoring/connmon/connectionmonitor/src/CPlugin.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2003-2007 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:  Plug-in object subsession.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ConnMonServ.h"
       
    19 #include "ConnMonIAP.h"
       
    20 #include "CEventQueue.h"
       
    21 #include "CPlugin.h"
       
    22 #include "log.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // Constructor
       
    27 TAttributeRequest::TAttributeRequest(
       
    28         TUint aType,
       
    29         TUint aAttribute,
       
    30         TUint aData )
       
    31         :
       
    32         iType( aType ),
       
    33         iAttribute( aAttribute ),
       
    34         iData( aData )
       
    35     {
       
    36     }
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CPlugin::CPlugin
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CPlugin::CPlugin()
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Destructor
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CPlugin::~CPlugin()
       
    53     {
       
    54     // Complete any outstanding plug-in request
       
    55     CancelGetQuery();
       
    56 
       
    57     // Close the attributes array
       
    58     iAttributesSupported.Close();
       
    59 
       
    60     // Complete all outstanding client requests
       
    61     TInt count = iClientRequests.Count();
       
    62 
       
    63     for ( TInt i = 0; i < count; i++ )
       
    64         {
       
    65         const TClientRequest* req = &( iClientRequests[i] );
       
    66 
       
    67         // Complete only asynchronous client requests
       
    68         if ( req->iType == EReqGetIntAttribute ||
       
    69              req->iType == EReqGetUintAttribute ||
       
    70              req->iType == EReqGetBoolAttribute ||
       
    71              req->iType == EReqGetStringAttribute ||
       
    72              req->iType == EReqGetPckgAttribute )
       
    73             {
       
    74             req->iMessage.Complete( KErrCancel );
       
    75             }
       
    76         }
       
    77 
       
    78     iClientRequests.Close();
       
    79 
       
    80     iSession = 0;
       
    81 
       
    82     LOGIT1("SERVER: Plugin destroyed, id <%d>", iPluginId )
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPlugin::NewL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CPlugin* CPlugin::NewL( CConnMonSession* aSession, const TUint aPluginId )
       
    90     {
       
    91     CPlugin* self = new ( ELeave ) CPlugin;
       
    92 
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL( aSession, aPluginId );
       
    95     CleanupStack::Pop( self );
       
    96 
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CPlugin::ConstructL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CPlugin::ConstructL( CConnMonSession* aSession, const TUint aPluginId )
       
   105     {
       
   106     TName name;
       
   107 
       
   108     name.Format( KPluginName, this );
       
   109     SetNameL( &name );
       
   110 
       
   111     iSession = aSession;
       
   112     iPluginId = aPluginId;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CPlugin::RegisterAttribute
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CPlugin::RegisterAttribute( const TUint aAttribute )
       
   120     {
       
   121     LOGIT2("SERVER: EReqPluginRegisterAttribute, id <%d>, attr <%d>", iPluginId, aAttribute )
       
   122 
       
   123     for ( TInt i = 0; i < iAttributesSupported.Count(); i++ )
       
   124         {
       
   125         if ( iAttributesSupported[i] == aAttribute )
       
   126             {
       
   127             // Attribute has already been registered
       
   128             return ( KErrNone );
       
   129             }
       
   130         }
       
   131 
       
   132     iAttributesSupported.Append( aAttribute );
       
   133 
       
   134     // Check if the clients have set 'KBearerAvailabilityThreshold' earlier
       
   135     if ( aAttribute == KBearerAvailabilityThreshold )
       
   136        {
       
   137        TUint th( 0 );
       
   138 
       
   139        // Have clients set the threshold earlier
       
   140        iSession->iCmServer->CalculateThreshold( 0, EBearerAvailabilityThreshold, th );
       
   141 
       
   142        if ( th == 1 )
       
   143            {
       
   144            // Add the request (set threshold) to the queue (aPending is EFalse)
       
   145            const RMessage2 dummy;
       
   146 
       
   147            TClientRequest clientReq( EReqInternalSetThreshold, EFalse, dummy );
       
   148            iClientRequests.Append( clientReq );
       
   149            }
       
   150        }
       
   151 
       
   152     return KErrNone;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CPlugin::CancelRegisterAttribute
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CPlugin::CancelRegisterAttribute( const TUint aAttribute )
       
   160     {
       
   161     LOGIT2("SERVER: EReqPluginCancelRegisterAttribute, id <%d>, attr <%d>", iPluginId, aAttribute )
       
   162 
       
   163     for ( TInt i = 0; i < iAttributesSupported.Count(); i++ )
       
   164         {
       
   165         if ( iAttributesSupported[i] == aAttribute )
       
   166             {
       
   167             // Complete any outstanding client requets
       
   168             TInt count = iClientRequests.Count();
       
   169 
       
   170             for ( TInt j = 0; j < count; j++ )
       
   171                 {
       
   172                 const TClientRequest* req = &( iClientRequests[j] );
       
   173 
       
   174                 if  ( static_cast< TInt >( aAttribute ) == req->iMessage.Int2( ) )
       
   175                     {
       
   176                     // Complete only asynchronous client requests
       
   177                     if ( req->iType == EReqGetIntAttribute ||
       
   178                          req->iType == EReqGetUintAttribute ||
       
   179                          req->iType == EReqGetBoolAttribute ||
       
   180                          req->iType == EReqGetStringAttribute ||
       
   181                          req->iType == EReqGetPckgAttribute )
       
   182                         {
       
   183                         req->iMessage.Complete( KErrCancel );
       
   184                         }
       
   185                     iClientRequests.Remove( j );
       
   186                     count--;
       
   187                     j--;
       
   188                     }
       
   189                 }
       
   190 
       
   191             iAttributesSupported.Remove( i );
       
   192             return ( KErrNone );
       
   193             }
       
   194         }
       
   195 
       
   196     return KErrNotFound;
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CPlugin::Event
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TInt CPlugin::Event(
       
   204         const RMessage2& aMessage,
       
   205         TEventInfo& aEventInfo,
       
   206         TUint8*& aPtr,
       
   207         TInt& aSize ) const
       
   208     {
       
   209     TUint eventId = aMessage.Int0();
       
   210 
       
   211     TUint desLen = aMessage.GetDesLength( 1 );
       
   212 
       
   213     // Max allowed data size is 512 bytes
       
   214     if ( desLen > KConnMonMaxPluginDataSize )
       
   215         {
       
   216         return KErrTooBig;
       
   217         }
       
   218 
       
   219     HBufC8* buf = HBufC8::New( desLen );
       
   220 
       
   221     if ( !buf )
       
   222         {
       
   223         return KErrNoMemory;
       
   224         }
       
   225 
       
   226     TPtr8 initptr = buf->Des();
       
   227 
       
   228     // Read the contents of the client pointer into a TPtr.
       
   229     TInt res = aMessage.Read( 1, initptr );
       
   230 
       
   231     if ( res != KErrNone )
       
   232         {
       
   233         delete buf;
       
   234         iSession->iCmServer->PanicClient( EBadDescriptor );
       
   235         return KErrBadHandle;
       
   236         }
       
   237 
       
   238     // Create the event to be forwarded to the clients
       
   239     aEventInfo.Reset();
       
   240 
       
   241     aEventInfo.iEventType = eventId;
       
   242     aEventInfo.iConnectionId = iPluginId;
       
   243 
       
   244     if ( ( eventId == EConnMonSignalStrengthChange ) && ( desLen == sizeof( TInt ) ) )
       
   245         {
       
   246         // Signal strength changed event
       
   247         aEventInfo.iData = static_cast<TInt>( *initptr.Ptr() );
       
   248         }
       
   249     else if ( ( eventId == EConnMonBearerAvailabilityChange ) && ( desLen == sizeof( TBool ) ) )
       
   250         {
       
   251         // Bearer availability changed event
       
   252         aEventInfo.iData = static_cast<TBool>( *initptr.Ptr() );
       
   253         }
       
   254     else if ( ( eventId == EConnMonIapAvailabilityChange ) &&
       
   255               ( desLen == sizeof( TConnMonIapInfo ) ) )
       
   256         {
       
   257         // IAP availability changed event
       
   258         TConnMonIapInfo* receivedIapInfo =
       
   259             const_cast<TConnMonIapInfo*>(
       
   260                 reinterpret_cast<const TConnMonIapInfo*>( initptr.Ptr() ) );
       
   261 
       
   262         // Event contains only limited info on IAPs (= count + IDs)
       
   263         TConnMonIapInfo* eventIaps( NULL );
       
   264         eventIaps = new TConnMonIapInfo;
       
   265 
       
   266         if ( eventIaps )
       
   267             {
       
   268             aEventInfo.iData = receivedIapInfo->Count();
       
   269 
       
   270             eventIaps->iCount = receivedIapInfo->Count();
       
   271 
       
   272             for ( TInt i = 0; i < KConnMonMaxIAPCount && i < receivedIapInfo->Count(); i++ )
       
   273                 {
       
   274                 eventIaps->iIap[i].iIapId = receivedIapInfo->iIap[i].iIapId;
       
   275                 }
       
   276 
       
   277             aPtr = reinterpret_cast<TUint8*>( eventIaps );
       
   278             aSize = sizeof( TConnMonIapInfo );
       
   279             }
       
   280         }
       
   281     else if ( ( eventId >= EConnMonPluginEventBase ) && ( desLen == sizeof( TUint ) ) )
       
   282         {
       
   283         // Plugin specific event. Only 32-bit data (desLen is 4 bytes) supported so far
       
   284         aEventInfo.iData = static_cast<TUint>( *initptr.Ptr() );
       
   285         aEventInfo.iData2 = desLen;
       
   286         }
       
   287     else
       
   288         {
       
   289         // Event is not supported
       
   290         LOGIT2("SERVER: Plugin sent unsupported event or length of the data was invalid. -> id <%d>, event <%d>", iPluginId, eventId )
       
   291 
       
   292         delete buf;
       
   293         return KErrNotSupported;
       
   294         }
       
   295 
       
   296     delete buf;
       
   297 
       
   298     return KErrNone;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CPlugin::Attribute
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 TInt CPlugin::Attribute( const RMessage2& aMessage )
       
   306     {
       
   307     TUint attribute( aMessage.Int0() );
       
   308     TInt  returnCode( aMessage.Int1() );
       
   309 
       
   310     TUint desLen = aMessage.GetDesLength( 2 );
       
   311 
       
   312     // Max allowed data size is 512 bytes
       
   313     if ( desLen > KConnMonMaxPluginDataSize )
       
   314         {
       
   315         return KErrTooBig;
       
   316         }
       
   317 
       
   318     // Allocate a buffer for reading
       
   319     HBufC8* buf = HBufC8::New( desLen );
       
   320     TPtr8 initptr = buf->Des();
       
   321 
       
   322     // read the contents of the client pointer into a TPtr.
       
   323     TInt res = aMessage.Read( 2, initptr );
       
   324 
       
   325     if ( res != KErrNone )
       
   326         {
       
   327         delete buf;
       
   328         iSession->iCmServer->PanicClient( EBadDescriptor );
       
   329 
       
   330         return KErrBadHandle;
       
   331         }
       
   332 
       
   333     TInt count = iClientRequests.Count();
       
   334 
       
   335     // Complete all outstanding client request for this attribute
       
   336     for ( TInt i = 0; i < count; i++ )
       
   337         {
       
   338         const TClientRequest* req = &( iClientRequests[i] );
       
   339 
       
   340         if ( static_cast< TInt >( attribute ) == req->iMessage.Int2( ) )
       
   341             {
       
   342             // Found a request matching the attribute
       
   343             switch ( req->iType )
       
   344                 {
       
   345                 case EReqGetIntAttribute:
       
   346                     {
       
   347                     if ( desLen != sizeof( TInt ) )
       
   348                         {
       
   349                         req->iMessage.Complete( KErrArgument );
       
   350                         break;
       
   351                         }
       
   352 
       
   353                     TInt value = static_cast< TInt >( *initptr.Ptr() );
       
   354 
       
   355                     LOGIT4("SERVER: Attribute from plugin, id <%d>, attr <%d>, -> value <%d>, ret <%d>", iPluginId, attribute, value, returnCode )
       
   356 
       
   357                     TPtr8 n( reinterpret_cast< TUint8* >( &value ),
       
   358                              sizeof( TInt ),
       
   359                              sizeof( TInt ) );
       
   360 
       
   361                     res = req->iMessage.Write( KAttributeParameterIndex, n );
       
   362 
       
   363                     if ( res != KErrNone )
       
   364                         {
       
   365                         PanicWaitingClient( EBadDescriptor, req->iMessage );
       
   366                         }
       
   367                     else
       
   368                         {
       
   369                         req->iMessage.Complete( returnCode );
       
   370                         }
       
   371 
       
   372                     break;
       
   373                     }
       
   374                 case EReqGetUintAttribute:
       
   375                     {
       
   376                     if ( desLen != sizeof( TUint ) )
       
   377                         {
       
   378                         req->iMessage.Complete( KErrArgument );
       
   379                         break;
       
   380                         }
       
   381 
       
   382                     TUint value = static_cast< TUint >( *initptr.Ptr() );
       
   383 
       
   384                     LOGIT4("SERVER: Attribute from plugin, id <%d>, attr <%d>, -> value <%d>, ret <%d>", iPluginId, attribute, value, returnCode )
       
   385 
       
   386                     TPtr8 n( reinterpret_cast< TUint8* >( &value ),
       
   387                              sizeof( TUint ),
       
   388                              sizeof( TUint ) );
       
   389 
       
   390                     res = req->iMessage.Write( KAttributeParameterIndex, n );
       
   391 
       
   392                     if ( res != KErrNone )
       
   393                         {
       
   394                         PanicWaitingClient( EBadDescriptor, req->iMessage );
       
   395                         }
       
   396                     else
       
   397                         {
       
   398                         req->iMessage.Complete( returnCode );
       
   399                         }
       
   400                     break;
       
   401                     }
       
   402                 case EReqGetBoolAttribute:
       
   403                     {
       
   404                     if ( desLen != sizeof( TBool ) )
       
   405                         {
       
   406                         req->iMessage.Complete( KErrArgument );
       
   407                         break;
       
   408                         }
       
   409 
       
   410                     TBool value = static_cast< TBool >( *initptr.Ptr() );
       
   411 
       
   412                     LOGIT4("SERVER: Attribute from plugin, id <%d>, attr <%d>, -> value <%d>, ret <%d>", iPluginId, attribute, value, returnCode )
       
   413 
       
   414                     TPtr8 n( reinterpret_cast< TUint8* >( &value ),
       
   415                              sizeof( TBool ),
       
   416                              sizeof( TBool ) );
       
   417 
       
   418                     res = req->iMessage.Write( KAttributeParameterIndex, n );
       
   419 
       
   420                     if ( res != KErrNone )
       
   421                         {
       
   422                         PanicWaitingClient( EBadDescriptor, req->iMessage );
       
   423                         }
       
   424                     else
       
   425                         {
       
   426                         req->iMessage.Complete( returnCode );
       
   427                         }
       
   428 
       
   429                     break;
       
   430                     }
       
   431                  case EReqGetPckgAttribute:
       
   432                     {
       
   433                     // Write as such to the client area since this is TDes8
       
   434                     LOGIT3("SERVER: Attribute from plugin, id <%d>, attr <%d>, -> ret <%d>", iPluginId, attribute, returnCode )
       
   435 
       
   436                     res = req->iMessage.Write( KAttributeParameterIndex, initptr );
       
   437 
       
   438                     if ( res != KErrNone )
       
   439                         {
       
   440                         PanicWaitingClient( EBadDescriptor, req->iMessage );
       
   441                         }
       
   442                     else
       
   443                         {
       
   444                         req->iMessage.Complete( returnCode );
       
   445                         }
       
   446                     break;
       
   447                     }
       
   448                  case EReqGetStringAttribute:
       
   449                     {
       
   450                     // String is a 16-bit descriptor.
       
   451                     // Allocate a 16-bit buffer for reading the string.
       
   452                     HBufC* buf16 = HBufC::New( desLen );
       
   453                     TPtr initptr16 = buf16->Des();
       
   454 
       
   455                     // read the contents of the client pointer into a TPtr.
       
   456                     res = aMessage.Read( 2, initptr16 );
       
   457 
       
   458                     if ( res != KErrNone )
       
   459                         {
       
   460                         delete buf;
       
   461                         delete buf16;
       
   462                         iSession->iCmServer->PanicClient( EBadDescriptor );
       
   463 
       
   464                         return KErrBadHandle;
       
   465                         }
       
   466 
       
   467                     LOGIT3("SERVER: Attribute from plugin, id <%d>, attr <%d>, -> ret <%d>", iPluginId, attribute, returnCode )
       
   468 
       
   469                     res = req->iMessage.Write( KAttributeParameterIndex, initptr16 );
       
   470 
       
   471                     if ( res != KErrNone )
       
   472                         {
       
   473                         PanicWaitingClient( EBadDescriptor, req->iMessage );
       
   474                         }
       
   475                     else
       
   476                         {
       
   477                         req->iMessage.Complete( returnCode );
       
   478                         }
       
   479 
       
   480                     delete buf16;
       
   481 
       
   482                     break;
       
   483                     }
       
   484                  default:
       
   485                     {
       
   486                     delete buf;
       
   487                     return KErrNotSupported;
       
   488                     }
       
   489                 } // switch
       
   490 
       
   491             // Remove the query because it has been served
       
   492             iClientRequests.Remove( i );
       
   493             count--;
       
   494             i--;
       
   495             }  // if
       
   496         } // For
       
   497 
       
   498     delete buf;
       
   499 
       
   500     return KErrNone;
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CPlugin::GetQuery
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 TInt CPlugin::GetQuery()
       
   508     {
       
   509     if ( !iPluginReqActive )
       
   510         {
       
   511         return KErrNotReady;
       
   512         }
       
   513 
       
   514     // Check if there is a client request waiting in the queue
       
   515     TInt count = iClientRequests.Count();
       
   516 
       
   517     for ( TInt i = 0; i < count; i++ )
       
   518         {
       
   519         if ( !iClientRequests[i].iPending )
       
   520             {
       
   521             TInt attribute( iClientRequests[i].iMessage.Int2() );
       
   522             TInt data( iClientRequests[i].iMessage.Int3() );
       
   523 
       
   524             // Send the attribute request to the plug-in
       
   525             TAttributeRequest req( iClientRequests[i].iType, attribute, 0 );
       
   526 
       
   527             if ( req.iType == EReqSetIntAttribute ||
       
   528                  req.iType == EReqSetUintAttribute ||
       
   529                  req.iType == EReqSetBoolAttribute )
       
   530                 {
       
   531                 req.iData = data;
       
   532                 }
       
   533             else if ( req.iType == EReqInternalSetThreshold )
       
   534                 {
       
   535                 req.iType      = EReqSetUintAttribute;
       
   536                 req.iAttribute = KBearerAvailabilityThreshold;
       
   537                 req.iData      = 1;
       
   538                 }
       
   539             else if ( req.iType == EReqInternalResetThreshold )
       
   540                 {
       
   541                 req.iType      = EReqSetUintAttribute;
       
   542                 req.iAttribute = KBearerAvailabilityThreshold;
       
   543                 req.iData      = 0;
       
   544                 }
       
   545 
       
   546             TPtr8 n( reinterpret_cast< TUint8* >( &req ),
       
   547                      sizeof( TAttributeRequest ),
       
   548                      sizeof( TAttributeRequest ) );
       
   549 
       
   550             TInt res = iPluginReqMessage.Write( 0, n );
       
   551 
       
   552             if ( res != KErrNone )
       
   553                 {
       
   554                 iSession->iCmServer->PanicClient( EBadDescriptor );
       
   555                 }
       
   556             else
       
   557                 {
       
   558                 // Complete the message
       
   559                 iPluginReqMessage.Complete( KErrNone );
       
   560                 }
       
   561 
       
   562             iPluginReqActive=EFalse;
       
   563 
       
   564             if ( req.iType == EReqSetIntAttribute ||
       
   565                  req.iType == EReqSetUintAttribute ||
       
   566                  req.iType == EReqSetBoolAttribute ||
       
   567                  req.iType == EReqSetStringAttribute ||
       
   568                  req.iType == EReqSetPckgAttribute )
       
   569                 {
       
   570                 // This request is synchronous and has already been completed
       
   571                 iClientRequests.Remove( i );
       
   572                 count--;
       
   573                 i--;
       
   574                 }
       
   575 
       
   576             return KErrNone;
       
   577             }
       
   578         }
       
   579 
       
   580     // Queue was empty.
       
   581     // Just wait for a client request to arrive.
       
   582     return KRequestPending;
       
   583     }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // CPlugin::GetQuery
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 TInt CPlugin::GetQuery( const RMessage2& aMessage )
       
   590     {
       
   591     __ASSERT_DEBUG( !iPluginReqActive, PanicServer( EReceiveAlreadyActive ) );
       
   592 
       
   593     LOGIT("SERVER: EReqPluginGetQuery")
       
   594 
       
   595     // Remember attribute request
       
   596     iPluginReqMessage = aMessage;
       
   597     iPluginReqBuffer = aMessage.Ptr0();
       
   598     iPluginReqActive = ETrue;
       
   599 
       
   600     return GetQuery();
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CPlugin::CancelGetQuery
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 TInt CPlugin::CancelGetQuery()
       
   608     {
       
   609     LOGIT("SERVER: EReqPluginCancelGetQuery")
       
   610 
       
   611     if ( iPluginReqActive )
       
   612         {
       
   613         iPluginReqMessage.Complete( KErrCancel );
       
   614         iPluginReqActive = EFalse;
       
   615         }
       
   616 
       
   617     return KErrNone;
       
   618     }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CPlugin::GetAttributeForClient
       
   622 // From a CLIENT.
       
   623 // -----------------------------------------------------------------------------
       
   624 //
       
   625 TInt CPlugin::GetAttributeForClient( const TInt aType, const RMessage2& aMessage )
       
   626     {
       
   627     LOGENTRFN("CPlugin::GetAttributeForClient()")
       
   628     TUint connectionId( aMessage.Int0() );
       
   629     TUint attribute( aMessage.Int2() );
       
   630     TInt data( aMessage.Int3() );
       
   631 
       
   632     if ( aType == EReqInternalSetThreshold || aType == EReqInternalResetThreshold )
       
   633         {
       
   634         connectionId = iPluginId;
       
   635         attribute = KBearerAvailabilityThreshold;
       
   636         }
       
   637 
       
   638     if ( connectionId <= KMaxConnectionId )
       
   639         {
       
   640         // Client is asking an attribute using a normal connectionID instead of pluginID.
       
   641         TInt bearer( EBearerUnknown );
       
   642         TBearerInfo bearerInfo;
       
   643 
       
   644         TInt ret = iSession->iCmServer->Iap()->GetBearer( connectionId, bearer, bearerInfo );
       
   645 
       
   646         if ( ret == KErrNone )
       
   647             {
       
   648             // Find the corresponding pluginID
       
   649             if ( bearer == EBearerWLAN )
       
   650                 {
       
   651                 connectionId = EBearerIdWLAN;
       
   652                 }
       
   653             else if ( bearer == EBearerLAN )
       
   654                 {
       
   655                 connectionId = EBearerIdLAN;
       
   656                 }
       
   657             }
       
   658         }
       
   659 
       
   660     // Check that request is aimed to this plugin.
       
   661     if ( connectionId != iPluginId )
       
   662         {
       
   663         LOGEXITFN1("CPlugin::GetAttributeForClient()", KErrNotSupported)
       
   664         return KErrNotSupported;
       
   665         }
       
   666 
       
   667     if ( aType == EReqSetStringAttribute || aType == EReqSetPckgAttribute )
       
   668         {
       
   669         // Setting string or packaged attributes is not supported
       
   670         LOGEXITFN1("CPlugin::GetAttributeForClient()", KErrNotSupported)
       
   671         return KErrNotSupported;
       
   672         }
       
   673 
       
   674     for ( TInt i = 0; i < iAttributesSupported.Count(); i++ )
       
   675         {
       
   676         if ( iAttributesSupported[i] == attribute )
       
   677             {
       
   678             TAttributeRequest req( aType, attribute, 0 );
       
   679 
       
   680             if ( aType == EReqSetIntAttribute ||
       
   681                  aType == EReqSetUintAttribute ||
       
   682                  aType == EReqSetBoolAttribute )
       
   683                 {
       
   684                 req.iData = data;
       
   685                 }
       
   686             else if ( aType == EReqInternalSetThreshold )
       
   687                 {
       
   688                 req.iType = EReqSetUintAttribute;
       
   689                 req.iData = 1;
       
   690                 }
       
   691             else if ( aType == EReqInternalResetThreshold )
       
   692                 {
       
   693                 req.iType = EReqSetUintAttribute;
       
   694                 req.iData = 0;
       
   695                 }
       
   696 
       
   697             if ( iPluginReqActive )
       
   698                 {
       
   699                 TBool pending( ETrue );
       
   700 
       
   701                 // Send the attribute request to the plug-in
       
   702                 TPtr8 n( reinterpret_cast< TUint8* >( &req ),
       
   703                          sizeof( TAttributeRequest ),
       
   704                          sizeof( TAttributeRequest ) );
       
   705 
       
   706                 TInt res = iPluginReqMessage.Write( 0, n );
       
   707 
       
   708                 if ( res != KErrNone )
       
   709                     {
       
   710                     PanicWaitingClient( EBadDescriptor, iPluginReqMessage );
       
   711                     pending = EFalse;
       
   712                     }
       
   713                 else
       
   714                     {
       
   715                     // Complete the message
       
   716                     iPluginReqMessage.Complete( KErrNone );
       
   717                     }
       
   718 
       
   719                 iPluginReqActive=EFalse;
       
   720 
       
   721                 // Add the request to queue
       
   722                 // aPending is ETrue
       
   723                 if ( aType == EReqGetIntAttribute ||
       
   724                      aType == EReqGetUintAttribute ||
       
   725                      aType == EReqGetBoolAttribute ||
       
   726                      aType == EReqGetStringAttribute ||
       
   727                      aType == EReqGetPckgAttribute )
       
   728                     {
       
   729                     TClientRequest clientReq( aType, pending, aMessage );
       
   730                     iClientRequests.Append( clientReq );
       
   731                     }
       
   732                 }
       
   733             else
       
   734                 {
       
   735                 // Add the request to the queue
       
   736                 // aPending is EFalse
       
   737                 TClientRequest clientReq( aType, EFalse, aMessage );
       
   738                 iClientRequests.Append( clientReq );
       
   739                 }
       
   740 
       
   741             LOGEXITFN1("CPlugin::GetAttributeForClient()", KRequestPending)
       
   742             return KRequestPending;
       
   743             }
       
   744         }
       
   745 
       
   746     LOGEXITFN1("CPlugin::GetAttributeForClient()", KErrNotSupported)
       
   747     return KErrNotSupported;
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CPlugin::CancelGetAttributeForClient
       
   752 // From a CLIENT.
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 void CPlugin::CancelGetAttributeForClient( const RThread& aClient, const TInt aType )
       
   756     {
       
   757     TInt count = iClientRequests.Count();
       
   758 
       
   759     for ( TInt i = 0; i < count; i++ )
       
   760         {
       
   761         const TClientRequest* req = &( iClientRequests[i] );
       
   762 
       
   763         RThread client;
       
   764 
       
   765         TInt err = req->iMessage.Client( client );
       
   766 
       
   767         if ( err == KErrNone )
       
   768             {
       
   769             if  ( ( static_cast< TUint >( aType ) == req->iType )  &&
       
   770                   ( client.Id() == aClient.Id() ) )
       
   771                 {
       
   772                 req->iMessage.Complete( KErrCancel );
       
   773 
       
   774                 iClientRequests.Remove( i );
       
   775                 count--;
       
   776                 i--;
       
   777                 }
       
   778 
       
   779             client.Close();
       
   780             }
       
   781         }
       
   782     }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CPlugin::SetAttributeForClient
       
   786 // From a CLIENT.
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 TInt CPlugin::SetAttributeForClient( const TInt aType, const RMessage2& aMessage )
       
   790     {
       
   791     TInt ret = GetAttributeForClient( aType, aMessage );
       
   792 
       
   793     if ( ret == KRequestPending )
       
   794         {
       
   795         // Complete immediately
       
   796         return KErrNone;
       
   797         }
       
   798     else
       
   799         {
       
   800         return ret;
       
   801         }
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CPlugin::PanicWaitingClient
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 void CPlugin::PanicWaitingClient( TInt aPanic, const RMessage2& aMessage ) const
       
   809     {
       
   810     // Let's have a look before we panic the client
       
   811     __DEBUGGER()
       
   812 
       
   813     // Ok, go for it
       
   814     RThread client;
       
   815 
       
   816     TInt err =  aMessage.Client( client );
       
   817 
       
   818     if ( err == KErrNone )
       
   819         {
       
   820         _LIT( KPanicMessage, "ConnMonServ" );
       
   821         client.Panic( KPanicMessage, aPanic );
       
   822         client.Close();
       
   823         }
       
   824     }
       
   825 
       
   826 // End-of-file