wvuing/IMPSAlwaysOnlinePlugin/src/CPEngAONwStatusObserver.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  Handles the always online functionality for the presence
       
    15 *				 engine and instant messaging application
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <flogger.h>
       
    23 
       
    24 #include "MPEngAONwStatusObserver.h"
       
    25 #include "CPEngAONwStatusObserver.h"
       
    26 #include "CIMPSSharedDataFactory.h"
       
    27 #include "IMPSSystemNotifyDefs.h"
       
    28 
       
    29 #include "ImpsCommonUiDebugPrint.h"
       
    30 
       
    31 // LOCAL CONSTANTS AND MACROS
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CPEngAONwStatusObserver::CPEngAONwStatusObserver
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CPEngAONwStatusObserver::CPEngAONwStatusObserver( MPEngAONwStatusObserver& aObserver ) :
       
    42         iObserver( aObserver )
       
    43     {
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CPEngAONwStatusObserver::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CPEngAONwStatusObserver::ConstructL()
       
    52     {
       
    53     iSystemNotifier =
       
    54         CIMPSSharedDataFactory::CreateSystemNotifyHandlerL( *this,
       
    55                                                             KIMPSSystemUidNetworkStatus );
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CPEngAONwStatusObserver::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CPEngAONwStatusObserver* CPEngAONwStatusObserver::NewL( MPEngAONwStatusObserver& aObserver )
       
    64     {
       
    65     CPEngAONwStatusObserver* self = new( ELeave ) CPEngAONwStatusObserver( aObserver );
       
    66 
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // Destructor
       
    75 CPEngAONwStatusObserver::~CPEngAONwStatusObserver()
       
    76     {
       
    77     delete iSystemNotifier;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CPEngAONwStatusObserver::HandleSystemNotifierEventL
       
    82 //
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void CPEngAONwStatusObserver::HandleSystemNotifierEventL( TUid /*aKey*/, TInt
       
    86 // Compile warning removal
       
    87 #ifndef _DEBUG
       
    88                                                           aValue
       
    89 #endif
       
    90                                                         )
       
    91     {
       
    92     IMPSCUI_DP( D_IMPSCUI_LIT( "CPEngAONwStatusObserver::RunL" ) );
       
    93 
       
    94 #ifdef _DEBUG
       
    95     iObserver.HandleNwStatusChange( ETrue );
       
    96     return;
       
    97 #else // #else used instead of #endif, to get rvct compile warning removed
       
    98     if ( aValue != EIMPSSystemNetworkAvailable )
       
    99         {
       
   100         iObserver.HandleNwStatusChange( EFalse );
       
   101         }
       
   102     else
       
   103         {
       
   104         iSystemNotifier->UnSubscribe();
       
   105         iObserver.HandleNwStatusChange( ETrue );
       
   106         }
       
   107 #endif
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // CPEngAONwStatusObserver::IsNetworkAvailable
       
   112 //
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 TBool CPEngAONwStatusObserver::IsNetworkAvailable()
       
   116     {
       
   117 #ifdef _DEBUG
       
   118     return ETrue;
       
   119 #else // #else used instead of #endif, to get rvct compile warning removed
       
   120     TInt err( KErrNone );
       
   121     TInt value( KErrNone );
       
   122 
       
   123     err = iSystemNotifier->GetIntKey( value );
       
   124 
       
   125     if ( ( ( value == EIMPSSystemNetworkAvailable ) && ( err == KErrNone ) )
       
   126          || ( err != KErrNone ) )
       
   127         {
       
   128         return ETrue;
       
   129         }
       
   130     else
       
   131         {
       
   132         // start observing network status
       
   133         iSystemNotifier->Subscribe();
       
   134         return EFalse;
       
   135         }
       
   136 #endif
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CPEngAONwStatusObserver::StopObserving
       
   141 //
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 void CPEngAONwStatusObserver::StopObserving()
       
   145     {
       
   146     iSystemNotifier->UnSubscribe();
       
   147     }
       
   148 
       
   149 //  End of File