sysstatemgmt/ssmcustcmds/ssmsystemcmds/src/ssmpskeyobserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 * Implementation of CSsmPsKeyObserver class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "ssmpskeyobserver.h"
       
    21 #include "trace.h"
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CSsmPsKeyObserver::CSsmPsKeyObserver
       
    27 //
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CSsmPsKeyObserver::CSsmPsKeyObserver( TUid aCategory, TUint aKey )
       
    31   : CActive( EPriorityHigh ),
       
    32     iCategory( aCategory ),
       
    33     iKey( aKey )
       
    34     {
       
    35     FUNC_LOG;
       
    36 
       
    37     CActiveScheduler::Add( this );
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CSsmPsKeyObserver::~CSsmPsKeyObserver
       
    43 //
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CSsmPsKeyObserver::~CSsmPsKeyObserver()
       
    47     {
       
    48     FUNC_LOG;
       
    49 
       
    50     Cancel();
       
    51     iProperty.Close();
       
    52     Complete( KErrCancel ); // Just in case
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSsmPsKeyObserver::StartObserving
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CSsmPsKeyObserver::StartObserving( TRequestStatus& aStatus )
       
    62     {
       
    63     FUNC_LOG;
       
    64     ASSERT_TRACE( !IsActive() );
       
    65 
       
    66     aStatus = KRequestPending;
       
    67     iClientStatus = &aStatus;
       
    68 
       
    69     TInt errorCode = iProperty.Attach( iCategory, iKey );
       
    70     ERROR_2( errorCode, "Failed to attach to property 0x%08x::0x%08x", 
       
    71              iCategory.iUid, iKey );
       
    72     
       
    73     if ( errorCode == KErrNone )
       
    74         {
       
    75         CheckKeyValue();
       
    76         }
       
    77     else
       
    78         {
       
    79         Complete( errorCode );
       
    80         }
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CSsmPsKeyObserver::DoCancel
       
    86 //
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CSsmPsKeyObserver::DoCancel()
       
    90     {
       
    91     FUNC_LOG;
       
    92 
       
    93     iProperty.Cancel();
       
    94     Complete( KErrCancel );
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CSsmPsKeyObserver::RunL
       
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CSsmPsKeyObserver::RunL()
       
   104     {
       
   105     FUNC_LOG;
       
   106     INFO_1( "CSsmPsKeyObserver::iStatus = %d", iStatus.Int() );
       
   107 
       
   108     if ( iStatus == KErrCancel ||
       
   109          iStatus == KErrServerTerminated ||
       
   110          iStatus ==KErrNotSupported )
       
   111         {
       
   112         Complete( iStatus.Int() );
       
   113         }
       
   114     else
       
   115         {
       
   116         CheckKeyValue();
       
   117         }
       
   118     }
       
   119 
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CSsmPsKeyObserver::CheckKeyValue
       
   123 //
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CSsmPsKeyObserver::CheckKeyValue()
       
   127     {
       
   128     FUNC_LOG;
       
   129     ASSERT( !IsActive() );
       
   130 
       
   131     iProperty.Subscribe( iStatus );
       
   132     SetActive();
       
   133 
       
   134     TInt value( -KMaxTInt );
       
   135     TInt errorCode = iProperty.Get( value );
       
   136     ERROR_2( errorCode, "Failed to get value of property 0x%08x::0x%08x",
       
   137              iCategory.iUid, iKey );
       
   138     if ( errorCode != KErrNone || IsMatch( value ) )
       
   139         {
       
   140         INFO_3( "Property 0x%08x::0x%08x reached the target value %d.", 
       
   141                  iCategory.iUid, iKey, value );
       
   142 
       
   143         Complete( errorCode );
       
   144         Cancel();
       
   145         }
       
   146     else
       
   147         {
       
   148         INFO_3( "Value of property 0x%08x::0x%08x is %d. Waiting...",
       
   149                  iCategory.iUid, iKey, value );
       
   150         }
       
   151     }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CSsmPsKeyObserver::Complete
       
   156 //
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CSsmPsKeyObserver::Complete( const TInt aErrorCode )
       
   160     {
       
   161     FUNC_LOG;
       
   162 
       
   163     if ( iClientStatus )
       
   164         {
       
   165         INFO_1( "Completing request with status %d", aErrorCode );
       
   166 
       
   167         User::RequestComplete( iClientStatus, aErrorCode );
       
   168         iClientStatus = NULL;
       
   169         }
       
   170     }