messagingappbase/msgerrorwatcher/src/MsgErrorConnectionObserver.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     CMsgErrorConnectionObserver implementation file
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <rconnmon.h>
       
    24 
       
    25 #include "MsgErrorWatcher.h"
       
    26 #include "MsgErrorConnectionObserver.h"
       
    27 
       
    28 #ifdef USE_LOGGER
       
    29 #include "MsgErrorWatcherLogging.h"
       
    30 #endif
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // CMsgErrorConnectionObserver::CMsgErrorConnectionObserver
       
    36 //
       
    37 // C++ constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CMsgErrorConnectionObserver::CMsgErrorConnectionObserver( CMsgErrorWatcher* aWatcher )
       
    42     : iWatcher( aWatcher ),
       
    43     iStarted( EFalse )
       
    44     {
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CMsgErrorConnectionObserver::ConstructL
       
    49 //
       
    50 // Symbian OS default constructor can leave.
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void CMsgErrorConnectionObserver::ConstructL()
       
    54     {
       
    55     User::LeaveIfError( iConnMon.ConnectL() ); 
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CMsgErrorConnectionObserver::NewL
       
    60 //
       
    61 // Two-phased constructor.
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CMsgErrorConnectionObserver* CMsgErrorConnectionObserver::NewL( CMsgErrorWatcher* aWatcher )
       
    65     {
       
    66     CMsgErrorConnectionObserver* self = new ( ELeave )
       
    67         CMsgErrorConnectionObserver( aWatcher );
       
    68     
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72 
       
    73     return self;
       
    74     }
       
    75 
       
    76     
       
    77 // ---------------------------------------------------------
       
    78 // CMsgErrorConnectionObserver::~CMsgErrorConnectionObserver
       
    79 //
       
    80 // Destructor
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CMsgErrorConnectionObserver::~CMsgErrorConnectionObserver()
       
    84     {
       
    85 #ifdef USE_LOGGER
       
    86     MEWLOGGER_ENTERFN( "CMsgErrorConnectionObserver destructor" );
       
    87 #endif
       
    88     iConnMon.CancelNotifications();
       
    89     iConnMon.Close();
       
    90 #ifdef USE_LOGGER
       
    91     MEWLOGGER_LEAVEFN( "CMsgErrorConnectionObserver destructor" );
       
    92 #endif
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CMsgErrorConnectionObserver::ConnectionsOpen
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 TUint CMsgErrorConnectionObserver::ConnectionsOpen()
       
   100     {
       
   101     // Get number of active (packet data) connections
       
   102 #ifdef USE_LOGGER
       
   103     MEWLOGGER_ENTERFN( "CMsgErrorConnectionObserver::ConnectionsOpen" );
       
   104 #endif
       
   105     TUint conns( 0 );
       
   106     TUint subConns( 0 );
       
   107     TUint packetDataConns( 0 );
       
   108     TUint connId( 0 );    
       
   109     TInt bearer( 0 );
       
   110 
       
   111     TRequestStatus status;
       
   112     iConnMon.GetConnectionCount( conns, status );
       
   113     User::WaitForRequest( status );
       
   114 #ifdef USE_LOGGER
       
   115     MEWLOGGER_WRITEF( _L("Connections open: %d"), conns );
       
   116 #endif
       
   117 
       
   118     while ( conns-- )
       
   119         {
       
   120         // Connection indexing starts from 1
       
   121         // --> Add one to index
       
   122         iConnMon.GetConnectionInfo( conns + 1, connId, subConns );
       
   123         iConnMon.GetIntAttribute( connId, 0, KBearer, bearer, status );
       
   124         User::WaitForRequest( status );
       
   125         switch ( bearer )
       
   126             {
       
   127             case EBearerGPRS:
       
   128             case EBearerEdgeGPRS:
       
   129             case EBearerExternalGPRS:
       
   130             case EBearerExternalEdgeGPRS:
       
   131             case EBearerWCDMA:
       
   132             case EBearerExternalWCDMA:
       
   133 //#ifdef __WINS__
       
   134 //            case EBearerLAN:
       
   135 //#endif // WINS
       
   136                 {
       
   137                 packetDataConns++;
       
   138                 break;
       
   139                 }
       
   140             default :
       
   141                 {
       
   142                 break;
       
   143                 }                
       
   144             }
       
   145         }
       
   146 #ifdef USE_LOGGER
       
   147     MEWLOGGER_WRITEF( _L("Packet data connections open: %d"), packetDataConns );
       
   148 #endif
       
   149     return packetDataConns;
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CMsgErrorConnectionObserver::Start
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 void CMsgErrorConnectionObserver::StartL()
       
   158     {
       
   159     if ( !iStarted )
       
   160         {
       
   161         iConnectionsOpenWhenStarted = ConnectionsOpen();
       
   162         iConnMon.NotifyEventL( *this );
       
   163         iStarted = ETrue;
       
   164         }
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // CMsgErrorConnectionObserver::EventL
       
   170 //
       
   171 // From MConnectionMonitorObserver
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CMsgErrorConnectionObserver::EventL( const CConnMonEventBase& aConnMonEvent )
       
   175     {
       
   176 #ifdef USE_LOGGER
       
   177     MEWLOGGER_ENTERFN( "CMsgErrorConnectionObserver::EventL" );
       
   178     MEWLOGGER_WRITEF( _L("EventType: %d"), aConnMonEvent.EventType() );
       
   179 #endif
       
   180     switch( aConnMonEvent.EventType() )
       
   181         {
       
   182         case EConnMonDeleteConnection:
       
   183             {
       
   184             if ( ConnectionsOpen() < iConnectionsOpenWhenStarted )
       
   185                 {
       
   186                 iWatcher->HandleConnectionEvent();
       
   187                 }
       
   188             //const CConnMonDeleteConnection *delEvent =
       
   189             //    static_cast<const CConnMonDeleteConnection*>( &aConnMonEvent );
       
   190             break;
       
   191             }
       
   192         default:
       
   193             break;
       
   194         }
       
   195 #ifdef USE_LOGGER
       
   196     MEWLOGGER_LEAVEFN( "CMsgErrorConnectionObserver::EventL" );
       
   197 #endif
       
   198     }
       
   199 
       
   200 
       
   201 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   202 
       
   203 //  End of File