idlefw/src/idleint/aistate.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    "aistate.h"
       
    20 #include    "aifwpanic.h"
       
    21 #include    <e32property.h>
       
    22 #include    <activeidle2domainpskeys.h>
       
    23 #include    "debug.h"
       
    24 
       
    25 CActiveIdleState::CActiveIdleState()
       
    26     {
       
    27     }
       
    28 
       
    29 void CActiveIdleState::ConstructL()
       
    30     {
       
    31     iUpdater = 
       
    32         CIdle::NewL( CActive::EPriorityStandard );
       
    33 
       
    34     //for the sake of safe, this function is called here
       
    35     UpdateStateAsync();
       
    36     }
       
    37 
       
    38 CActiveIdleState* CActiveIdleState::NewL()
       
    39     {
       
    40     CActiveIdleState* self = 
       
    41         new (ELeave) CActiveIdleState();
       
    42     
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop(self);
       
    46 
       
    47     return self;
       
    48     }
       
    49 
       
    50 CActiveIdleState::~CActiveIdleState()
       
    51     {
       
    52     delete iUpdater;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CActiveIdleState::UpdateState
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CActiveIdleState::SetIsIdleForeground(
       
    60         TBool aIsForeground )
       
    61     {
       
    62     __PRINT( __DBG_FORMAT("XAI: CActiveIdleState::SetIsIdleForeground(%d), iIsIdleForeground=%d"), 
       
    63         aIsForeground, iIsIdleForeground );
       
    64     if ( iIsIdleForeground != aIsForeground )
       
    65         {
       
    66         iIsIdleForeground = aIsForeground;
       
    67         UpdateStateAsync();
       
    68         }
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CActiveIdleState::UpdateStateAsync
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CActiveIdleState::UpdateStateAsync()
       
    76     {
       
    77     // Asynchronous change is done only when going to idle state.
       
    78     if ( iIsIdleForeground )
       
    79         {
       
    80         if ( !iUpdater->IsActive() )
       
    81             {
       
    82             iUpdater->Start( 
       
    83                 TCallBack( DoUpdateState, this ) );
       
    84             }
       
    85         }
       
    86     else
       
    87         {
       
    88         iUpdater->Cancel();
       
    89         UpdateActiveIdleState();
       
    90         }
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CActiveIdleState::UpdateActiveIdleState
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CActiveIdleState::UpdateActiveIdleState()
       
    98     {
       
    99     const EPSActiveIdleState state =
       
   100         iIsIdleForeground ? EPSAiForeground : EPSAiBackground;
       
   101 
       
   102     TInt setResult = 
       
   103         RProperty::Set(
       
   104             KPSUidAiInformation, 
       
   105             KActiveIdleState, 
       
   106             state );
       
   107 
       
   108     __PRINT( __DBG_FORMAT( "XAI: Set CActiveIdleState::UpdateActiveIdleState: KTelephonyIdleStatus=%d, P&S result=%d" ),
       
   109         TInt(state), setResult );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CActiveIdleState::DoUpdateSaSetting
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CActiveIdleState::DoUpdateState( TAny* aAny )
       
   117     {
       
   118     __ASSERT_DEBUG( aAny, AiFwPanic::Panic(AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   119     static_cast< CActiveIdleState* >( aAny )->UpdateActiveIdleState();
       
   120     return KErrNone;
       
   121     }
       
   122