convergedconnectionhandler/cchserver/src/cchconnmonhandler.cpp
changeset 0 a4daefaec16c
child 14 be41ab7b952f
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  CCCHConnMonHandler implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cchconnmonhandler.h"
       
    21 #include "cchserverbase.h"
       
    22 #include "cchlogger.h"
       
    23 #include "cchservicehandler.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 // None
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES
       
    29 // None
       
    30 
       
    31 // CONSTANTS
       
    32 // None
       
    33 
       
    34 // MACROS
       
    35 // None
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 // None
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 // None
       
    42 
       
    43 // LOCAL FUNCTION PROTOTYPES
       
    44 // None
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 // None
       
    48 
       
    49 // ============================= LOCAL FUNCTIONS =============================
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS =============================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CCCHConnMonHandler::CCCHConnMonHandler
       
    55 // C++ default constructor can NOT contain any code, that might leave.
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCCHConnMonHandler::CCCHConnMonHandler( CCCHServerBase& aServer ) :
       
    59     CActive( CActive::EPriorityStandard ),
       
    60     iState( EUninitialized ),
       
    61     iServer( aServer )
       
    62     {
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCCHConnMonHandler::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CCCHConnMonHandler::ConstructL()
       
    72     {
       
    73     User::LeaveIfError( iConnMon.ConnectL() );
       
    74     NotifyL();
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CCCHConnMonHandler::NewL
       
    79 // Two-phased constructor.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CCCHConnMonHandler* CCCHConnMonHandler::NewL( CCCHServerBase& aServer )
       
    83     {
       
    84     CCCHConnMonHandler* self = CCCHConnMonHandler::NewLC( aServer );
       
    85     CleanupStack::Pop( self );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CCCHConnMonHandler::NewLC
       
    91 // Two-phased constructor.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CCCHConnMonHandler* CCCHConnMonHandler::NewLC( CCCHServerBase& aServer )
       
    95     {
       
    96     CCCHConnMonHandler* self = new (ELeave) CCCHConnMonHandler( aServer );
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     return self;
       
   100     }
       
   101 
       
   102 // Destructor
       
   103 CCCHConnMonHandler::~CCCHConnMonHandler()
       
   104     {
       
   105     CCHLOGSTRING( "CCCHConnMonHandler::~CCCHConnMonHandler" );
       
   106     
       
   107     StopNotify();
       
   108     Cancel();
       
   109     iAvailableSNAPs.Close();
       
   110     iAvailableIAPs.Close();
       
   111     iConnMon.Close();
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CCCHConnMonHandler::ScanNetworks
       
   116 // (other items were commented in a header).
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CCCHConnMonHandler::ScanNetworks( TBool aWlanScan )
       
   120     {
       
   121     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: IN" );
       
   122     
       
   123     if ( aWlanScan )
       
   124         {
       
   125         GetIaps( EBearerIdAll );
       
   126         }
       
   127             
       
   128     CCHLOGSTRING( "CCCHConnMonHandler::ScanNetworks: OUT" );
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CCCHConnMonHandler::ScanNetworksCancel
       
   133 // (other items were commented in a header).
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CCCHConnMonHandler::ScanNetworksCancel()
       
   137     {
       
   138     Cancel();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CCCHConnMonHandler::IsSNAPAvailable
       
   143 // (other items were commented in a header).
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 TBool CCCHConnMonHandler::IsSNAPAvailable( TUint aSNAPId ) const
       
   147     {    
       
   148     return ( KErrNotFound == iAvailableSNAPs.Find( aSNAPId ) ) 
       
   149         ? EFalse : ETrue; 
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CCCHConnMonHandler::IsIapAvailable
       
   154 // (other items were commented in a header).
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 TBool CCCHConnMonHandler::IsIapAvailable( TUint aIapId ) const
       
   158     {
       
   159     return ( KErrNotFound == iAvailableIAPs.Find( aIapId ) ) 
       
   160         ? EFalse : ETrue; 
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CCCHConnMonHandler::GetIaps
       
   165 // (other items were commented in a header).
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CCCHConnMonHandler::GetIaps( TConnMonBearerId aBearerId )
       
   169     {
       
   170     if ( !IsActive() )
       
   171         {
       
   172         iConnMon.GetPckgAttribute( aBearerId,
       
   173                                    0,
       
   174                                    KIapAvailability,
       
   175                                    iIapsBuf,
       
   176                                    iStatus );
       
   177         iState = EGetIAPS;
       
   178         SetActive();
       
   179         }
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CCCHConnMonHandler::UpdateIapArray
       
   184 // (other items were commented in a header).
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CCCHConnMonHandler::UpdateIapArray( TConnMonIapInfo aIaps )
       
   188     {
       
   189     CCHLOGSTRING2( "CCCHConnMonHandler::UpdateIapArray: IN count %d",
       
   190         iAvailableIAPs.Count() );
       
   191     
       
   192     iAvailableIAPs.Reset();
       
   193     TUint count( 0 );
       
   194 
       
   195     // Copy TConnMonIapInfo to RArray so we can use RArray::Find method
       
   196     while ( count < aIaps.iCount )
       
   197         {
       
   198         iAvailableIAPs.Append( aIaps.iIap[ count ].iIapId );
       
   199         count++;
       
   200         }
       
   201     CCHLOGSTRING2( "CCCHConnMonHandler::UpdateIapArray: OUT count %d",
       
   202         iAvailableIAPs.Count() );
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CCCHConnMonHandler::GetSNAPs
       
   207 // (other items were commented in a header).
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CCCHConnMonHandler::GetSNAPs()
       
   211     {
       
   212     CCHLOGSTRING( "CCCHConnMonHandler::GetSNAPs: IN" );
       
   213     
       
   214     if ( !IsActive() )
       
   215         {
       
   216         iConnMon.GetPckgAttribute( EBearerIdAll, // some parameter
       
   217                                    0, // pass the size of buffer
       
   218                                    KSNAPsAvailability, // specify the request
       
   219                                    iSNAPbuf, // buffer for writing data
       
   220                                    iStatus );
       
   221         iState = EGetSNAPs;
       
   222         SetActive();
       
   223         }
       
   224     
       
   225     CCHLOGSTRING( "CCCHConnMonHandler::GetSNAPs: OUT" );
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CCCHConnMonHandler::UpdateSnapArray
       
   230 // (other items were commented in a header).
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CCCHConnMonHandler::UpdateSnapArray( TConnMonSNAPInfo aSNAPs )
       
   234     {
       
   235     CCHLOGSTRING2( "CCCHConnMonHandler::UpdateSnapArray: IN count %d",
       
   236         iAvailableSNAPs.Count() );
       
   237    
       
   238     iAvailableSNAPs.Reset();
       
   239     TUint count( 0 );
       
   240     // Copy TConnMonSNAPInfo to RArray so we can use RArray::Find method
       
   241     while ( count < aSNAPs.iCount )
       
   242         {
       
   243         iAvailableSNAPs.Append( aSNAPs.iSNAP[ count ].iSNAPId );
       
   244         count++;
       
   245         }        
       
   246     CCHLOGSTRING2( "CCCHConnMonHandler::UpdateSnapArray: OUT count %d",
       
   247         iAvailableSNAPs.Count() );
       
   248     
       
   249     }
       
   250  
       
   251 // ---------------------------------------------------------------------------
       
   252 // CCCHConnMonHandler::NotifyL
       
   253 // (other items were commented in a header).
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CCCHConnMonHandler::NotifyL()
       
   257     {
       
   258     CCHLOGSTRING( "CCCHConnMonHandler::NotifyL: IN" );
       
   259     
       
   260     iConnMon.NotifyEventL( *this );
       
   261 
       
   262     // Thresholds 
       
   263     TInt err = iConnMon.SetUintAttribute( EBearerIdAll,
       
   264                                           0,
       
   265                                           KBearerAvailabilityThreshold,
       
   266                                           1 );
       
   267                                           
       
   268     CCHLOGSTRING2( "CCCHConnMonHandler::NotifyL: OUT", err );
       
   269     }
       
   270     
       
   271 // ---------------------------------------------------------------------------
       
   272 // CCCHConnMonHandler::StopNotify
       
   273 // (other items were commented in a header).
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 void CCCHConnMonHandler::StopNotify()
       
   277     {
       
   278     iConnMon.CancelNotifications();
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CCCHConnMonHandler::RunL
       
   283 // (other items were commented in a header).
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CCCHConnMonHandler::RunL()
       
   287     {
       
   288     CCHLOGSTRING2( "CCCHConnMonHandler::RunL: IN error: %d", iStatus.Int() );
       
   289     
       
   290     if ( KErrNone == iStatus.Int() )
       
   291         {
       
   292         switch ( iState )
       
   293             {
       
   294             case EGetIAPS:
       
   295                 {
       
   296                 UpdateIapArray( iIapsBuf() );
       
   297                 GetSNAPs();
       
   298                 }
       
   299             break;
       
   300             case EGetSNAPs:
       
   301                 {
       
   302                 UpdateSnapArray( iSNAPbuf() );
       
   303                 }
       
   304             break;
       
   305             default:
       
   306                 break;
       
   307             }
       
   308         }
       
   309             
       
   310     CCHLOGSTRING( "CCCHConnMonHandler::RunL: OUT" );
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CCCHConnMonHandler::DoCancel
       
   315 // (other items were commented in a header).
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CCCHConnMonHandler::DoCancel()
       
   319     {
       
   320     iConnMon.CancelAsyncRequest( EConnMonGetPckgAttribute );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CCCHConnMonHandler::EventL
       
   325 // (other items were commented in a header).
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CCCHConnMonHandler::EventL( const CConnMonEventBase &aConnMonEvent )
       
   329     {
       
   330     CCHLOGSTRING3
       
   331         ( "CCCHConnMonHandler::EventL: IN EventType = %d, ConnectionId = %d", 
       
   332             aConnMonEvent.EventType(), aConnMonEvent.ConnectionId() );
       
   333     
       
   334     switch ( aConnMonEvent.EventType() )
       
   335         {
       
   336         case EConnMonIapAvailabilityChange:
       
   337             {
       
   338             const CConnMonIapAvailabilityChange* eventIap = NULL;
       
   339             eventIap = static_cast< const CConnMonIapAvailabilityChange* >(
       
   340                 &aConnMonEvent );
       
   341 
       
   342             TConnMonIapInfo iaps = eventIap->IapAvailability();
       
   343             UpdateIapArray( iaps );
       
   344             }
       
   345             break;
       
   346 
       
   347         case EConnMonSNAPsAvailabilityChange:
       
   348             {
       
   349             const CConnMonSNAPsAvailabilityChange* eventSNAP = NULL;
       
   350             eventSNAP = static_cast< const CConnMonSNAPsAvailabilityChange* >(
       
   351                  &aConnMonEvent );
       
   352 
       
   353             TConnMonSNAPInfo snaps  = eventSNAP->SNAPAvailability();
       
   354             UpdateSnapArray( snaps );
       
   355             }
       
   356             break;
       
   357         default:
       
   358             break;
       
   359         }
       
   360     CCHLOGSTRING( "CCCHConnMonHandler::EventL: OUT" );
       
   361     }
       
   362 
       
   363 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   364 
       
   365 //  End of File