bluetoothengine/btnotif/tsrc/BtNotifApiTest/src/BtSettingsObserver.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 0 f63038272f30
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
       
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "BtSettingsObserver.h"
       
    19 
       
    20 CBtSettingsObserver::CBtSettingsObserver()
       
    21     {
       
    22     }
       
    23 
       
    24 CBtSettingsObserver::~CBtSettingsObserver()
       
    25     {
       
    26     delete iSettings;
       
    27     if( iWaiter->IsStarted() )
       
    28         {
       
    29         iWaiter->AsyncStop();
       
    30         }
       
    31     delete iWaiter;
       
    32     }
       
    33 
       
    34 CBtSettingsObserver* CBtSettingsObserver::NewLC()
       
    35     {
       
    36     CBtSettingsObserver* self = new ( ELeave ) CBtSettingsObserver();
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39     return self;
       
    40     }
       
    41 
       
    42 CBtSettingsObserver* CBtSettingsObserver::NewL()
       
    43     {
       
    44     CBtSettingsObserver* self = CBtSettingsObserver::NewLC();
       
    45     CleanupStack::Pop(); // self;
       
    46     return self;
       
    47     }
       
    48 
       
    49 void CBtSettingsObserver::ConstructL()
       
    50     {
       
    51     iWaiter = new ( ELeave ) CActiveSchedulerWait();
       
    52     iSettings = CBTEngSettings::NewL( this );
       
    53     iError = KErrNone;
       
    54     }
       
    55 
       
    56 void CBtSettingsObserver::PowerStateChanged( TBTPowerStateValue /*aState*/ )
       
    57     {
       
    58     if( iWaiter->IsStarted() )
       
    59         {
       
    60         iWaiter->AsyncStop();
       
    61         }
       
    62     }
       
    63 
       
    64 void CBtSettingsObserver::VisibilityModeChanged( TBTVisibilityMode /*aState*/ )
       
    65     {
       
    66     if( iWaiter->IsStarted() )
       
    67         {
       
    68         iWaiter->AsyncStop();
       
    69         }
       
    70     }
       
    71 
       
    72 TInt CBtSettingsObserver::GetPowerState( TBTPowerStateValue& aState )
       
    73     {
       
    74     iError = iSettings->GetPowerState( aState );
       
    75     return iError;
       
    76     }
       
    77 
       
    78 TInt CBtSettingsObserver::SetPowerState( TBTPowerStateValue aState )
       
    79     {
       
    80     TBTPowerStateValue state;
       
    81     
       
    82     iError = iSettings->GetPowerState( state );
       
    83     if( iError )
       
    84         {
       
    85         return iError;
       
    86         }
       
    87     else if( state != aState )
       
    88             {
       
    89             if( state == EBTPowerOff )
       
    90                 {
       
    91                 iError = iSettings->SetPowerState( EBTPowerOn );
       
    92                 }
       
    93             else
       
    94                 {
       
    95                 iError = iSettings->SetPowerState( EBTPowerOff );
       
    96                 }
       
    97             
       
    98             if( iError )
       
    99                 {
       
   100                 return iError;
       
   101                 }
       
   102             else
       
   103                 {
       
   104                 if ( !iWaiter->IsStarted() )
       
   105                     {
       
   106                     iWaiter->Start();
       
   107                     }
       
   108                 }
       
   109             }
       
   110     return iError;
       
   111     }
       
   112 
       
   113 TInt CBtSettingsObserver::GetVisibilityMode( TBTVisibilityMode& /*aMode*/ )
       
   114     {
       
   115     return KErrNone;
       
   116     }
       
   117 
       
   118 TInt CBtSettingsObserver::SetVisibilityMode( TBTVisibilityMode /*aMode*/, TInt /*aTime*/ )
       
   119     {
       
   120     return KErrNone;
       
   121     }
       
   122 
       
   123 TInt CBtSettingsObserver::GetLocalName( TDes& aName )
       
   124     {
       
   125     iError = iSettings -> GetLocalName( aName );    
       
   126     return iError;
       
   127     }
       
   128 
       
   129 TInt CBtSettingsObserver::SetLocalName( const TDes& aName )
       
   130     {
       
   131     iError = iSettings -> SetLocalName( aName );    
       
   132     return iError;
       
   133     }