satengine/SatServer/Engine/src/csatprofilechangeobserver.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 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:  Observes Profile state changes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "TSatSystemStateFactory.h"
       
    21 #include    "MSatSystemStateChangeNotifier.h"
       
    22 #include    "MSatUtils.h"
       
    23 #include    "csatprofilechangeobserver.h"
       
    24 #include    "SatLog.h"
       
    25 #include    "CSatSUiClientHandler.h"
       
    26 
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KSatActiveProfileOffline = 5; // value from ProfileEngine
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSatProfileChangeObserver::CSatProfileChangeObserver
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CSatProfileChangeObserver::CSatProfileChangeObserver(
       
    40     MSatUtils& aUtils ) :
       
    41     iUtils( aUtils )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSatProfileChangeObserver::NewL
       
    47 // Two-phased constructor.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CSatProfileChangeObserver* CSatProfileChangeObserver::NewL(
       
    51     MSatUtils& aUtils )
       
    52     {
       
    53     LOG( SIMPLE, "SATENGINE: CSatProfileChangeObserver::NewL calling" )
       
    54 
       
    55     CSatProfileChangeObserver* self =
       
    56         new ( ELeave ) CSatProfileChangeObserver( aUtils );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60 
       
    61     LOG( SIMPLE, "SATENGINE: CSatProfileChangeObserver::NewL exiting" )
       
    62     return self;
       
    63     }
       
    64 
       
    65 // Destructor
       
    66 CSatProfileChangeObserver::~CSatProfileChangeObserver()
       
    67     {
       
    68     LOG( SIMPLE,
       
    69         "SATENGINE: CSatProfileChangeObserver::~CSatProfileChangeObserver \
       
    70         calling" )
       
    71 
       
    72     if ( iStateNotifier )
       
    73         {
       
    74         iStateNotifier->CancelNotify();
       
    75         delete iStateNotifier;
       
    76         iStateNotifier = NULL;
       
    77         }
       
    78 
       
    79     LOG( SIMPLE,
       
    80         "SATENGINE: CSatProfileChangeObserver::~CSatProfileChangeObserver \
       
    81         exiting" )
       
    82     }
       
    83     
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSatProfileChangeObserver::ConstructL
       
    86 // Two-phased constructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CSatProfileChangeObserver::ConstructL()
       
    90     {
       
    91     LOG( SIMPLE, "SATENGINE: CSatProfileChangeObserver::ConstructL calling" )
       
    92 
       
    93     iStateNotifier = TSatSystemStateFactory::CreateProfileChangeNotifierL( *this );
       
    94     // Start observer immediately
       
    95     iStateNotifier->NotifyChangeL();
       
    96     
       
    97     // iPreviousProfile must set to -1 because values 0-49 
       
    98     // are reserved for different profiles.
       
    99     iPreviousProfile = -1;
       
   100     
       
   101     LOG( SIMPLE, "SATENGINE: CSatSAPChangeObserver::ConstructL exiting" )
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSatProfileChangeObserver::StateChanged
       
   106 // Two-phased constructor.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CSatProfileChangeObserver::StateChanged( const TInt aValue )
       
   110     {
       
   111     LOG2( SIMPLE, "SATENGINE: CSatProfileChangeObserver::StateChanged calling \
       
   112         with value %d", aValue )
       
   113 
       
   114     // If profile is off-line send removing event
       
   115     if ( KSatActiveProfileOffline == aValue )
       
   116         {
       
   117         LOG( SIMPLE, "SATENGINE: Off-line" )
       
   118         // Off-line state activated.
       
   119         // Notify listeners about SAT UI icon removing
       
   120         iUtils.NotifyEvent( MSatUtils::ERemoveSatUiCalled );       
       
   121         }
       
   122 
       
   123     // Send event if previous state was offline.
       
   124     // The event will not be sent in following case: Phone is started
       
   125     // in offline mode and profile is changed to online. Proactive 
       
   126     // SetupMenu command is received from SIM card not before phone is
       
   127     // in online mode. iPreviousProfile is -1 when StateChanged is called
       
   128     // first time.
       
   129     else if ( ( KSatActiveProfileOffline != aValue ) &&  
       
   130         ( KSatActiveProfileOffline  == iPreviousProfile ) )
       
   131         {
       
   132         LOG( SIMPLE, "SATENGINE: !Off-line" )
       
   133         // Notify listeners about SAT UI icon adding
       
   134         iUtils.NotifyEvent( MSatUtils::EAddSatUiCalled );
       
   135         }
       
   136     
       
   137     else
       
   138         {
       
   139         // meaningless else. Only for Lint
       
   140         }
       
   141 
       
   142     iPreviousProfile = aValue;
       
   143 
       
   144     LOG( SIMPLE, "SATENGINE: CSatProfileChangeObserver::StateChanged exiting" )
       
   145     }
       
   146 
       
   147 // End of file