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