convergedconnectionhandler/cchserver/src/cchwakeupeventnotifier.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2006-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:  CCCHWakeUpEventNotifier implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <spnotifychange.h>
       
    21 #include <CoreApplicationUIsSDKCRKeys.h>
       
    22 
       
    23 #include "cchwakeupeventnotifier.h"
       
    24 #include "cchwakeupeventobserver.h"
       
    25 #include "cchlogger.h"
       
    26 #include "cchetelnetworkstatusnotifier.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 // None
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES
       
    32 // None
       
    33 
       
    34 // CONSTANTS
       
    35 const TInt KOfflineTimeout = 500000;
       
    36 
       
    37 // MACROS
       
    38 // None
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 // None
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 // None
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 //None
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 // None
       
    51 
       
    52 // ============================= LOCAL FUNCTIONS =============================
       
    53 
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS =============================
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCCHWakeUpEventNotifier::CCCHWakeUpEventNotifier
       
    59 // C++ default constructor can NOT contain any code, that might leave.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CCchWakeUpEventNotifier::CCchWakeUpEventNotifier( 
       
    63     MCchWakeUpEventObserver& aWakeUpEventObserver ) :
       
    64     CActive( CActive::EPriorityStandard ),
       
    65     iWakeUpEventObserver( aWakeUpEventObserver )
       
    66     {
       
    67     CCHLOGSTRING( "CCchWakeUpEventNotifier::CCchWakeUpEventNotifier" );
       
    68     CActiveScheduler::Add( this );
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CCchWakeUpEventNotifier::ConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CCchWakeUpEventNotifier::ConstructL()
       
    77     {
       
    78     CCHLOGSTRING( "CCchWakeUpEventNotifier::ConstructL" );
       
    79     
       
    80     iSPSNotifier = CSPNotifyChange::NewL( *this );
       
    81     iCchEtelNetworkNotifier = CCchEtelNetworkStatusNotifier::NewL( *this );
       
    82     iOfflineRepository = CRepository::NewL( KCRUidCoreApplicationUIs );
       
    83     iOfflineTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
       
    84     
       
    85     StartL();
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CCchWakeUpEventNotifier::NewL
       
    90 // Two-phased constructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CCchWakeUpEventNotifier* CCchWakeUpEventNotifier::NewL(
       
    94     MCchWakeUpEventObserver& aWakeUpEventObserver )
       
    95     {
       
    96     CCchWakeUpEventNotifier* self = CCchWakeUpEventNotifier::NewLC(
       
    97             aWakeUpEventObserver );
       
    98     CleanupStack::Pop( self );
       
    99     return self;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CCchWakeUpEventNotifier::NewLC
       
   104 // Two-phased constructor.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CCchWakeUpEventNotifier* CCchWakeUpEventNotifier::NewLC(
       
   108     MCchWakeUpEventObserver& aWakeUpEventObserver )
       
   109     {
       
   110     CCchWakeUpEventNotifier* self = new (ELeave)CCchWakeUpEventNotifier(
       
   111             aWakeUpEventObserver );
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     return self;
       
   115     }
       
   116 
       
   117 // Destructor
       
   118 CCchWakeUpEventNotifier::~CCchWakeUpEventNotifier()
       
   119     {
       
   120     Cancel();
       
   121     delete iOfflineTimer;
       
   122     delete iSPSNotifier;
       
   123     delete iCchEtelNetworkNotifier;
       
   124     delete iOfflineRepository;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CCchWakeUpEventNotifier::MobileNetworkNoService
       
   129 // Handles mobile network events.
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CCchWakeUpEventNotifier::MobileNetworkNoService()
       
   133     {
       
   134     CCHLOGSTRING( "CCchWakeUpEventNotifier::MobileNetworkNoService IN" );
       
   135     
       
   136     if ( iObservationOngoing )
       
   137         {
       
   138         iWakeUpEventObserver.WakeUp();
       
   139         }
       
   140     
       
   141     CCHLOGSTRING( "CCchWakeUpEventNotifier::MobileNetworkNoService OUT" );
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CCchWakeUpEventNotifier::HandleNotifyChange
       
   146 // Handles change events generated by spsettings.
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CCchWakeUpEventNotifier::HandleNotifyChange( TServiceId /* aServiceId */ )
       
   150     {
       
   151     CCHLOGSTRING( "CCchWakeUpEventNotifier::HandleNotifyChange IN" );
       
   152     
       
   153     if ( iObservationOngoing )
       
   154         {
       
   155         iWakeUpEventObserver.WakeUp();
       
   156         }
       
   157 
       
   158     CCHLOGSTRING( "CCchWakeUpEventNotifier::HandleNotifyChange OUT" );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CCchWakeUpEventNotifier::HandleError
       
   163 // Handles errors generated by spsettings.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CCchWakeUpEventNotifier::HandleError( TInt /*aError*/ )
       
   167     {
       
   168     CCHLOGSTRING( "CCchWakeUpEventNotifier::HandleError IN OUT" );
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // CCchWakeUpEventNotifier::Cancel()
       
   173 //
       
   174 // ----------------------------------------------------------------------------
       
   175 //
       
   176 void CCchWakeUpEventNotifier::DoCancel()
       
   177     {
       
   178     CCHLOGSTRING("CCchWakeUpEventNotifier::DoCancel()"); 
       
   179     iOfflineRepository->NotifyCancel( KCoreAppUIsNetworkConnectionAllowed );
       
   180     iSPSNotifier->NotifyChangeCancel();
       
   181     CancelOfflineTimer();
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CCchWakeUpEventNotifier::RunL()
       
   186 //
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 void CCchWakeUpEventNotifier::RunL()
       
   190     {
       
   191     CCHLOGSTRING("CCchWakeUpEventNotifier::RunL() IN");
       
   192     
       
   193     iOfflineRepository->Get( 
       
   194             KCoreAppUIsNetworkConnectionAllowed, iNetworkConnectionAllowed );
       
   195     if ( ECoreAppUIsNetworkConnectionNotAllowed == iNetworkConnectionAllowed )
       
   196         {
       
   197         // Start 0.5s timer, after timeout if cellular network is still down 
       
   198         // send wakeup event to our client. Why timer -> we can avoid situtation 
       
   199         // where cellular network is down for very short period.
       
   200         if ( !iOfflineTimer->IsActive() )
       
   201             {
       
   202             CCHLOGSTRING("CCchWakeUpEventNotifier::RunL -> Start timer");
       
   203             StartOfflineTimer( CCchWakeUpEventNotifier::OfflineTimeout );
       
   204             }
       
   205         }
       
   206     
       
   207     StartL();
       
   208     
       
   209     CCHLOGSTRING("CCchWakeUpEventNotifier::RunL() OUT"); 
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CCchWakeUpEventNotifier::RunError()
       
   214 //
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 TInt CCchWakeUpEventNotifier::RunError( TInt /*aError*/ )
       
   218     {
       
   219     CCHLOGSTRING("CCchWakeUpEventNotifier::RunError IN OUT"); 
       
   220     return KErrNone;
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // CCchWakeUpEventNotifier::StartL()
       
   225 //
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 void CCchWakeUpEventNotifier::StartL()
       
   229     {
       
   230     CCHLOGSTRING("CCchWakeUpEventNotifier::StartL IN");
       
   231 
       
   232     iObservationOngoing = ETrue;
       
   233     if ( !IsActive() )
       
   234         {  
       
   235         RIdArray serviceIds;
       
   236         iSPSNotifier->NotifyChangeL( serviceIds );
       
   237         
       
   238         iOfflineRepository->NotifyRequest( 
       
   239                 KCoreAppUIsNetworkConnectionAllowed, iStatus );
       
   240         SetActive();
       
   241         }
       
   242     
       
   243     CCHLOGSTRING("CCchWakeUpEventNotifier::StartL OUT");
       
   244     }
       
   245 
       
   246 // ----------------------------------------------------------------------------
       
   247 // CCchWakeUpEventNotifier::StopL()
       
   248 //
       
   249 // ----------------------------------------------------------------------------
       
   250 //
       
   251 void CCchWakeUpEventNotifier::Stop()
       
   252     {
       
   253     CCHLOGSTRING("CCchWakeUpEventNotifier::Stop IN");
       
   254     iObservationOngoing = EFalse;
       
   255     Cancel();
       
   256     CCHLOGSTRING("CCchWakeUpEventNotifier::Stop OUT");
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CCchWakeUpEventNotifier::StartOfflineTimer
       
   261 //
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CCchWakeUpEventNotifier::StartOfflineTimer( TInt (*aFunction)(TAny* aPtr) )
       
   265     {
       
   266     if( !iOfflineTimer->IsActive() )
       
   267         {
       
   268         iOfflineTimer->Start( 
       
   269             KOfflineTimeout , 0, TCallBack( aFunction, this ) );
       
   270         }
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CCchWakeUpEventNotifier::CancelOfflineTimer
       
   275 //
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CCchWakeUpEventNotifier::CancelOfflineTimer()
       
   279     {
       
   280     if( iOfflineTimer->IsActive() )
       
   281         {
       
   282         iOfflineTimer->Cancel();
       
   283         }
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CCchWakeUpEventNotifier::OfflineTimeout
       
   288 //
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 TInt CCchWakeUpEventNotifier::OfflineTimeout( TAny* aSelf )
       
   292     {
       
   293     CCchWakeUpEventNotifier* self = 
       
   294         static_cast<CCchWakeUpEventNotifier*>( aSelf );
       
   295     self->HandleOfflineTimeout();
       
   296     return 0;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CCchWakeUpEventNotifier::HandleOfflineTimeout
       
   301 //
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CCchWakeUpEventNotifier::HandleOfflineTimeout()
       
   305     {
       
   306     CCHLOGSTRING( "CCchWakeUpEventNotifier::HandleOfflineTimeout IN" );
       
   307     
       
   308     CancelOfflineTimer();
       
   309     iOfflineRepository->Get( 
       
   310         KCoreAppUIsNetworkConnectionAllowed, iNetworkConnectionAllowed );
       
   311 
       
   312     if ( ECoreAppUIsNetworkConnectionNotAllowed == iNetworkConnectionAllowed )
       
   313         {
       
   314         // Mode is still offline, send notify to our client
       
   315         iWakeUpEventObserver.WakeUp();
       
   316         }
       
   317         
       
   318     CCHLOGSTRING( "CCchWakeUpEventNotifier::HandleOfflineTimeout OUT" );
       
   319     }
       
   320 
       
   321 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   322 
       
   323 //  End of File
       
   324