connectionmonitoring/connmon/connectionmonitor/src/ConnMonBearerNotifier.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  Active object to listen for EGPRS and HSxPA notifications.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <etelmm.h>
       
    20 
       
    21 #include "ConnMonBearerNotifier.h"
       
    22 #include "ConnMonServ.h"
       
    23 #include "CEventQueue.h"
       
    24 #include "ConnMonBearerGroupManager.h"
       
    25 #include "ConnMonIAP.h"
       
    26 #include "ConnMonEGprsNotifier.h"
       
    27 #include "ConnMonHsdpaNotifier.h"
       
    28 #include "log.h"
       
    29 
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CConnMonBearerNotifier::CConnMonBearerNotifier
       
    33 // Notifies when the bearer changes from EGPRS to GPRS on vice versa.
       
    34 // This information is cell specific.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CConnMonBearerNotifier::CConnMonBearerNotifier(
       
    38         CConnMonServer* aServer,
       
    39         RMobilePhone& aMobilePhone,
       
    40         TUint& aConnectionId )
       
    41         :
       
    42         iServer( aServer ),
       
    43         iMobilePhone( aMobilePhone ),
       
    44         iConnectionId( aConnectionId )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CConnMonBearerNotifier::ConstructL
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CConnMonBearerNotifier::ConstructL()
       
    53     {
       
    54     //LOGENTRFN("CConnMonBearerNotifier::ConstructL()")
       
    55 
       
    56     iEGprsNotifier = CConnMonEGprsNotifier::NewL( this, iMobilePhone );
       
    57     iHsdpaNotifier = CConnMonHsdpaNotifier::NewL( this, iServer, iMobilePhone );
       
    58     iEventInfo.iData = EBearerUnknown;
       
    59     LOGIT("Created CConnMonBearerNotifier")
       
    60 
       
    61     //LOGEXITFN("CConnMonBearerNotifier::ConstructL()")
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CConnMonBearerNotifier::NewL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CConnMonBearerNotifier* CConnMonBearerNotifier::NewL(
       
    69         CConnMonServer* aServer,
       
    70         RMobilePhone& aMobilePhone,
       
    71         TUint& aConnectionId )
       
    72     {
       
    73     CConnMonBearerNotifier* self = new( ELeave ) CConnMonBearerNotifier(
       
    74             aServer,
       
    75             aMobilePhone,
       
    76             aConnectionId );
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81 
       
    82     return self;
       
    83     }
       
    84 
       
    85 // Destructor
       
    86 CConnMonBearerNotifier::~CConnMonBearerNotifier()
       
    87     {
       
    88     if ( iEGprsNotifier )
       
    89         {
       
    90         iEGprsNotifier->Cancel();
       
    91         delete iEGprsNotifier;
       
    92         iEGprsNotifier = NULL;
       
    93         }
       
    94 
       
    95     if ( iHsdpaNotifier )
       
    96         {
       
    97         iHsdpaNotifier->Cancel();
       
    98         delete iHsdpaNotifier;
       
    99         iHsdpaNotifier = NULL;
       
   100         }
       
   101 
       
   102     iServer = NULL;
       
   103     }
       
   104 
       
   105 void CConnMonBearerNotifier::Listen()
       
   106     {
       
   107     iEGprsNotifier->Receive();
       
   108     iHsdpaNotifier->Receive();
       
   109     }
       
   110 
       
   111 void CConnMonBearerNotifier::CancelListen()
       
   112     {
       
   113     iEGprsNotifier->Cancel();
       
   114     iHsdpaNotifier->Cancel();
       
   115     }
       
   116 
       
   117 TBool CConnMonBearerNotifier::Listening()
       
   118     {
       
   119     // It is enough to know that atleast 1 active object is active.
       
   120     if ( iEGprsNotifier->IsActive() )
       
   121         {
       
   122         return ETrue;
       
   123         }
       
   124     if ( iHsdpaNotifier->IsActive() )
       
   125         {
       
   126         return ETrue;
       
   127         }
       
   128     return EFalse;
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CConnMonBearerNotifier::RunL
       
   134 // Handles the event that has arrived from ETel
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CConnMonBearerNotifier::HandleEvent()
       
   138     {
       
   139     LOGIT("SERVER: CConnMonBearerNotifier::HandleEvent()")
       
   140 
       
   141     TBool eventSent( EFalse );
       
   142     iEventInfo.Reset();
       
   143     TConnMonBearerInfo bearerInfo( EBearerInfoUnknown );
       
   144 
       
   145     // Check the mode (GPRS or WCDMA).
       
   146     RMobilePhone::TMobilePhoneNetworkMode mode( RMobilePhone::ENetworkModeUnknown );
       
   147     TInt ret = iMobilePhone.GetCurrentMode( mode );
       
   148     iEventInfo.iEventType = EConnMonBearerInfoChange;
       
   149     iEventInfo.iConnectionId = iConnectionId;
       
   150 
       
   151     if ( KErrNone == ret
       
   152          && mode == RMobilePhone::ENetworkModeGsm
       
   153          && iEGprsNotifier->IsActive() == EFalse )
       
   154         {
       
   155         LOGIT("SERVER: CConnMonBearerNotifier::HandleEvent(): NetworkMode is GSM")
       
   156         if ( iEGprsNotifier->EGprsActive() )
       
   157             {
       
   158             iEventInfo.iData = EBearerInfoEdgeGPRS;
       
   159             }
       
   160         else
       
   161             {
       
   162             iEventInfo.iData = EBearerInfoGPRS;
       
   163             }
       
   164 
       
   165         iServer->EventQueue()->Add( iEventInfo );
       
   166 
       
   167         LOGIT2("SERVER: EVENT -> Bearer changed: BearerId %d, data %d", iEventInfo.iConnectionId, iEventInfo.iData)
       
   168         }
       
   169 
       
   170     else if ( KErrNone == ret
       
   171               && mode == RMobilePhone::ENetworkModeWcdma
       
   172               && iHsdpaNotifier->IsActive() == EFalse )
       
   173         {
       
   174         LOGIT("SERVER: NetworkMode is Wcdma")
       
   175 
       
   176         bearerInfo = (TConnMonBearerInfo)iHsdpaNotifier->HsxpaStatus();
       
   177         iEventInfo.iData = bearerInfo;
       
   178 
       
   179         iServer->EventQueue()->Add( iEventInfo );
       
   180 
       
   181         LOGIT2("SERVER: EVENT -> Bearer changed: BearerId %d, data %d", iEventInfo.iConnectionId, iEventInfo.iData)
       
   182         eventSent = ETrue;
       
   183         }
       
   184 
       
   185     if ( eventSent )
       
   186         {
       
   187         SendBearerGroupEvent( bearerInfo );
       
   188         }
       
   189 
       
   190     // New request
       
   191     Listen();
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CConnMonBearerNotifier::SendBearerGroupEvent
       
   196 // This function was made for sending the dynamic caps information
       
   197 // about the bearer in sync with the bearer group event.
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CConnMonBearerNotifier::SendBearerGroupEvent( TConnMonBearerInfo& aBearerInfo )
       
   201     {
       
   202     LOGENTRFN("CConnMonBearerNotifier::SendBearerGroupEvent()")
       
   203 
       
   204     if ( aBearerInfo == EBearerInfoWLAN )
       
   205         {
       
   206         LOGIT("SERVER: WLAN connection-->bearer group changed event NOT sent")
       
   207         LOGIT("SERVER: CConnMonBearerNotifier::SendBearerGroupEvent() OUT")
       
   208         return;
       
   209         }
       
   210 
       
   211     TUint bearerMask( 0 );
       
   212     TUint bearerMask2( 0 );
       
   213 
       
   214     TInt err = iServer->BearerGroupManager()->GetBearerGroups(
       
   215             aBearerInfo,
       
   216             bearerMask,
       
   217             bearerMask2 );
       
   218 
       
   219     if ( KErrNone != err )
       
   220         {
       
   221         LOGIT1("SERVER: CConnMonBearerNotifier::SendBearerGroupEvent(): GetBearerGroups() error <%d>", err)
       
   222         return;
       
   223         }
       
   224 
       
   225     iEventInfo.iConnectionId = iConnectionId;
       
   226     iEventInfo.iEventType = EConnMonBearerGroupChange;
       
   227 
       
   228     iEventInfo.iData = 1;
       
   229     iEventInfo.iData2 = bearerMask;
       
   230     iEventInfo.iData3 = bearerMask2;
       
   231 
       
   232     iServer->EventQueue()->Add( iEventInfo );
       
   233 
       
   234     LOGIT3("SERVER: EVENT -> Bearer group info changed: connId %d, internal %d, groups %d",
       
   235             iEventInfo.iConnectionId, iEventInfo.iData, iEventInfo.iData2)
       
   236     LOGEXITFN("CConnMonBearerNotifier::SendBearerGroupEvent()")
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CConnMonBearerNotifier::SendBearerGroupEvent
       
   242 //
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CConnMonBearerNotifier::SendBearerGroupEvent()
       
   246     {
       
   247     LOGENTRFN("CConnMonBearerNotifier::SendBearerGroupEvent()")
       
   248 
       
   249     TInt bearer( EBearerUnknown );
       
   250     TBearerInfo bearerInfo;
       
   251 
       
   252     TInt err = iServer->Iap()->GetBearer(
       
   253             iConnectionId,
       
   254             bearer,
       
   255             bearerInfo );
       
   256 
       
   257     if ( KErrNone != err )
       
   258         {
       
   259         LOGIT1("SERVER: CConnMonBearerNotifier::SendBearerGroupEvent(): GetBearer() error <%d>", err)
       
   260         return;
       
   261         }
       
   262 
       
   263     if ( bearerInfo.iBearer == EBearerInfoWLAN )
       
   264         {
       
   265         LOGIT("SERVER: WLAN connection-->bearer group changed event NOT sent")
       
   266         LOGIT("SERVER: CConnMonBearerNotifier::SendBearerGroupEvent() OUT")
       
   267         return;
       
   268         }
       
   269 
       
   270     TUint bearerMask( 0 );
       
   271     TUint bearerMask2( 0 );
       
   272 
       
   273     err = iServer->BearerGroupManager()->GetBearerGroups(
       
   274             (TConnMonBearerInfo)bearerInfo.iBearer,
       
   275             bearerMask,
       
   276             bearerMask2 );
       
   277 
       
   278     if ( KErrNone != err )
       
   279         {
       
   280         LOGIT1("SERVER: CConnMonBearerNotifier::SendBearerGroupEvent(): GetBearerGroups() error <%d>", err)
       
   281         return;
       
   282         }
       
   283 
       
   284     iEventInfo.iConnectionId = iConnectionId;
       
   285     iEventInfo.iEventType = EConnMonBearerGroupChange;
       
   286 
       
   287     iEventInfo.iData = bearerInfo.iInternal;
       
   288     iEventInfo.iData2 = bearerMask;
       
   289     iEventInfo.iData3 = bearerMask2;
       
   290 
       
   291     iServer->EventQueue()->Add( iEventInfo );
       
   292 
       
   293     LOGIT3("SERVER: EVENT -> Bearer group info changed: connId %d, internal %d, groups %d",
       
   294             iEventInfo.iConnectionId, iEventInfo.iData, iEventInfo.iData2)
       
   295     LOGEXITFN("CConnMonBearerNotifier::SendBearerGroupEvent()")
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CConnMonBearerNotifier::SendBearerInfoEvent
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CConnMonBearerNotifier::SendBearerInfoEvent()
       
   304     {
       
   305     TInt bearer( EBearerUnknown );
       
   306     TBearerInfo bearerInfo;
       
   307 
       
   308     TInt err = iServer->Iap()->GetBearer(
       
   309             iConnectionId,
       
   310             bearer,
       
   311             bearerInfo );
       
   312 
       
   313     if ( KErrNone != err )
       
   314         {
       
   315         LOGIT1("SERVER: CConnMonBearerNotifier::SendBearerInfoEvent(): GetBearer() error <%d>", err)
       
   316         return;
       
   317         }
       
   318 
       
   319     iEventInfo.Reset();
       
   320 
       
   321     iEventInfo.iEventType = EConnMonBearerInfoChange;
       
   322     iEventInfo.iConnectionId = iConnectionId;
       
   323     iEventInfo.iData = bearerInfo.iBearer;
       
   324 
       
   325     iServer->EventQueue()->Add( iEventInfo );
       
   326 
       
   327     LOGIT2("SERVER: EVENT -> Bearer info changed: connId %d, bearerInfo %d", iEventInfo.iConnectionId, iEventInfo.iData)
       
   328     }
       
   329 
       
   330 // End-of-file