resourcemgmt/hwresourcesmgr/test/plugins/fmtxwatcherplugin/src/hwrmfmtxtestobserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 #include "hwrmfmtxtestobserver.h"
       
    19 #include "trace.h"
       
    20 
       
    21 const TInt KTestCategory = 0x101FB3E7;
       
    22 const TInt KTestKeyNotifyChange = 0x1;
       
    23 _LIT_SECURITY_POLICY_PASS(KAlwaysPassPolicy);
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CHWRMFmtxTestObserver::NewL()
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CHWRMFmtxTestObserver* CHWRMFmtxTestObserver::NewL(
       
    32     MHWRMFmtxConnObserverCallback& aObserver )
       
    33     {
       
    34     FUNC_LOG;
       
    35     
       
    36     CHWRMFmtxTestObserver* self = new( ELeave ) CHWRMFmtxTestObserver( aObserver );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CHWRMFmtxTestObserver::~CHWRMFmtxTestObserver()
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CHWRMFmtxTestObserver::~CHWRMFmtxTestObserver()
       
    48     {
       
    49     FUNC_LOG;
       
    50     
       
    51     Cancel();
       
    52     iTestPubSubKey.Close();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CHWRMFmtxTestObserver::GetStatusL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 TBool CHWRMFmtxTestObserver::GetStatusL()
       
    60     {
       
    61     FUNC_LOG;
       
    62     
       
    63     TInt value( 0 );
       
    64     iTestPubSubKey.Get( value ); // Ignore read error
       
    65     return value > 0;
       
    66     }
       
    67     
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CHWRMFmtxTestObserver::StartObservingL
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CHWRMFmtxTestObserver::StartObservingL()
       
    74     {
       
    75     FUNC_LOG;
       
    76     
       
    77     if( !IsActive() )
       
    78         {
       
    79         OrderNotification();
       
    80         
       
    81         // check the initial status, so that only state change is notified
       
    82         iConnected = GetStatusL();
       
    83         }
       
    84     }
       
    85     
       
    86 // -----------------------------------------------------------------------------
       
    87 // CHWRMFmtxTestObserver::StopObserving
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CHWRMFmtxTestObserver::StopObserving()
       
    91     {
       
    92     FUNC_LOG;
       
    93     
       
    94     Cancel();
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CHWRMFmtxTestObserver::CHWRMFmtxTestObserver()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CHWRMFmtxTestObserver::CHWRMFmtxTestObserver( MHWRMFmtxConnObserverCallback& aObserver ) :
       
   102     CActive( EPriorityStandard ),
       
   103     iCallback( aObserver )
       
   104     {
       
   105     FUNC_LOG;
       
   106     
       
   107     CActiveScheduler::Add( this );
       
   108     }
       
   109             
       
   110 // -----------------------------------------------------------------------------
       
   111 // CHWRMFmtxTestObserver::ConstructL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CHWRMFmtxTestObserver::ConstructL()
       
   115     {
       
   116     FUNC_LOG;
       
   117     
       
   118     User::LeaveIfError( RProperty::Define(
       
   119         TUid::Uid( KTestCategory ), KTestKeyNotifyChange, RProperty::EInt,
       
   120         KAlwaysPassPolicy, KAlwaysPassPolicy ) );
       
   121     
       
   122     User::LeaveIfError( iTestPubSubKey.Attach( TUid::Uid( KTestCategory ),
       
   123         KTestKeyNotifyChange ) );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CHWRMFmtxTestObserver::OrderNotification()
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CHWRMFmtxTestObserver::OrderNotification()
       
   131     {
       
   132     FUNC_LOG;
       
   133     
       
   134     iTestPubSubKey.Subscribe( iStatus );
       
   135     SetActive();
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CHWRMFmtxTestObserver::RunL()
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CHWRMFmtxTestObserver::RunL( )
       
   143     {
       
   144     FUNC_LOG;
       
   145     
       
   146     TInt status( iStatus.Int() );
       
   147     
       
   148     LOG_IF_ERROR1( status, "CHWRMFmtxTestObserver::RunL error, status=%d", status );
       
   149 
       
   150     if ( status == KErrNone )
       
   151         {
       
   152         OrderNotification();
       
   153         TBool connected( GetStatusL() );
       
   154         INFO_LOG2( "CHWRMFmtxTestObserver::RunL: connected=%d, iConnected=%d", connected, iConnected );
       
   155         if ( connected != iConnected ) // notify only if state has changed
       
   156             {
       
   157             iConnected = connected;
       
   158             iCallback.HandleConnectionChange( EFmtxWatcherObserverTest, iConnected );
       
   159             }    
       
   160         }
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CHWRMFmtxTestObserver::DoCancel
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CHWRMFmtxTestObserver::DoCancel()
       
   168     {
       
   169     FUNC_LOG;
       
   170 
       
   171     iTestPubSubKey.Cancel();
       
   172     }
       
   173 
       
   174 //  End of File