bearermanagement/mpm/src/mpmdatausagewatcher.cpp
branchRCL_3
changeset 8 2e6c4614c58e
child 12 ea6e024ea6f9
equal deleted inserted replaced
4:77415202bfc8 8:2e6c4614c58e
       
     1 /*
       
     2  * Copyright (c) 2008-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: Listen cellular data usage key changes in central repository.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <centralrepository.h>
       
    20 #include <cmmanagerkeys.h>
       
    21 #include <cmgenconnsettings.h>
       
    22 
       
    23 #include "mpmlogger.h"
       
    24 #include "mpmserver.h"
       
    25 #include "mpmdatausagewatcher.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Default C++ constructor.
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CMpmDataUsageWatcher::CMpmDataUsageWatcher( CMPMServer* aServer ) :
       
    32     CActive( EPriorityStandard ), iServer( aServer )
       
    33     {
       
    34     MPMLOGSTRING( "CMpmDataUsageWatcher::CMpmDataUsageWatcher" )
       
    35 
       
    36     CActiveScheduler::Add( this );
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // Symbian 2nd phase constructor. Creates a central repository object.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CMpmDataUsageWatcher::ConstructL()
       
    44     {
       
    45     MPMLOGSTRING( "CMpmDataUsageWatcher::ConstructL" )
       
    46 
       
    47     iRepository = CRepository::NewL( KCRUidCmManager );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Creates a new object by calling the two-phased constructor.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CMpmDataUsageWatcher* CMpmDataUsageWatcher::NewL( CMPMServer* aServer )
       
    55     {
       
    56     MPMLOGSTRING( "CMpmDataUsageWatcher::NewL" )
       
    57 
       
    58     CMpmDataUsageWatcher* self = new( ELeave ) CMpmDataUsageWatcher( aServer );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Destructor.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CMpmDataUsageWatcher::~CMpmDataUsageWatcher()
       
    70     {
       
    71     MPMLOGSTRING( "CMpmDataUsageWatcher::~CMpmDataUsageWatcher" )
       
    72 
       
    73     Cancel();
       
    74     delete iRepository;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // Order notification from changes.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CMpmDataUsageWatcher::StartL()
       
    82     {
       
    83     MPMLOGSTRING( "CMpmDataUsageWatcher::StartL" )
       
    84 
       
    85     // Request notification
       
    86     User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
       
    87             iStatus ) );
       
    88     SetActive();
       
    89 
       
    90     // Get value from central repository
       
    91     User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
       
    92             iCellularDataUsage ) );
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // From class CActive.
       
    97 // Event is received when there is a change in central repository key.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CMpmDataUsageWatcher::RunL()
       
   101     {
       
   102     MPMLOGSTRING( "CMpmDataUsageWatcher::RunL" )
       
   103 
       
   104     User::LeaveIfError( iStatus.Int() );
       
   105 
       
   106     // Request new notification
       
   107     User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
       
   108             iStatus ) );
       
   109     SetActive();
       
   110 
       
   111     TInt oldCellularDataUsage = iCellularDataUsage;
       
   112 
       
   113     // Get the new value from central repository
       
   114     User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
       
   115             iCellularDataUsage ) );
       
   116 
       
   117     // Stop cellular connections if the setting changes into Disabled
       
   118     if (oldCellularDataUsage != ECmCellularDataUsageDisabled &&
       
   119             iCellularDataUsage == ECmCellularDataUsageDisabled)
       
   120         {
       
   121         // TODO: Uncomment this when trying to get stopping working.
       
   122         // iServer->StopCellularConns();
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // From class CActive.
       
   128 // Nothing to do over here.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TInt CMpmDataUsageWatcher::RunError( TInt /*aError*/ )
       
   132     {
       
   133     MPMLOGSTRING( "CMpmDataUsageWatcher::RunError" )
       
   134 
       
   135     return KErrNone;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // From class CActive.
       
   140 // Cancel outstanding request.
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CMpmDataUsageWatcher::DoCancel()
       
   144     {
       
   145     MPMLOGSTRING( "CMpmDataUsageWatcher::DoCancel" )
       
   146 
       
   147     iRepository->NotifyCancel( KCurrentCellularDataUsage );
       
   148     }
       
   149