sysstatemgmt/ssmcustcmds/ssmsystemcmds/src/ssmwaitpskey.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 CSsmWaitPsKey class.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "ssmwaitpskey.h"
       
    20 #include "ssmpskeyobserver.h"
       
    21 #include "ssmpskeyobserverexactvalue.h"
       
    22 #include "ssmpskeyobserverrange.h"
       
    23 #include "ssmmapperutilitystatic.h"
       
    24 #include "trace.h"
       
    25 
       
    26 #include <barsread2.h>
       
    27 
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CSsmWaitPsKey::NewL
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CSsmWaitPsKey* CSsmWaitPsKey::NewL( TSsmWaitPsKeyType aPsKeyWaitType )
       
    36 	{
       
    37     FUNC_LOG;
       
    38 	return new ( ELeave ) CSsmWaitPsKey( aPsKeyWaitType );
       
    39 	}
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CSsmWaitPsKey::~CSsmWaitPsKey
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CSsmWaitPsKey::~CSsmWaitPsKey()
       
    47     {
       
    48     FUNC_LOG;
       
    49 	delete iPsObserver;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CSsmWaitPsKey::Initialize
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TInt CSsmWaitPsKey::Initialize( CSsmCustomCommandEnv* /*aCmdEnv*/ )
       
    58     {
       
    59     FUNC_LOG;
       
    60 
       
    61     return KErrNone;
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CSsmWaitPsKey::Execute
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CSsmWaitPsKey::Execute( const TDesC8& aParams, TRequestStatus& aRequest )
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     aRequest = KRequestPending;
       
    74 
       
    75     TRAPD( errorCode, iPsObserver = ExtractParamsL( aParams ) );
       
    76     ERROR( errorCode, "Failed to extract parameters" );
       
    77     if ( errorCode == KErrNone )
       
    78         {
       
    79         iPsObserver->StartObserving( aRequest );
       
    80         }
       
    81     else
       
    82         {
       
    83         TRequestStatus* request = &aRequest;
       
    84         User::RequestComplete( request, errorCode );
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CSsmWaitPsKey::ExecuteCancel
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CSsmWaitPsKey::ExecuteCancel()
       
    94     {
       
    95     FUNC_LOG;
       
    96 
       
    97     if ( iPsObserver )
       
    98         {
       
    99         iPsObserver->Cancel();
       
   100         }
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CSsmWaitPsKey::Close
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CSsmWaitPsKey::Close()
       
   109     {
       
   110     FUNC_LOG;
       
   111     }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CSsmWaitPsKey::Release
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CSsmWaitPsKey::Release()
       
   119     {
       
   120     FUNC_LOG;
       
   121 
       
   122 	delete this;
       
   123     }
       
   124 // ---------------------------------------------------------------------------
       
   125 // CSsmWaitPsKey::CSsmWaitPsKey
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CSsmWaitPsKey::CSsmWaitPsKey( TSsmWaitPsKeyType aPsKeyWaitType )
       
   129              : iWaitType( aPsKeyWaitType )
       
   130     {
       
   131     }
       
   132 // ---------------------------------------------------------------------------
       
   133 // CSsmWaitPsKey::ExtractParamsL
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 CSsmPsKeyObserver* CSsmWaitPsKey::ExtractParamsL( const TDesC8& aParams )
       
   137     {
       
   138     FUNC_LOG;
       
   139 
       
   140     RResourceReader reader;
       
   141     reader.OpenLC( aParams );
       
   142     TUid category = TUid::Uid( reader.ReadInt32L() );
       
   143     category = SsmMapperUtility::PsUid( category );
       
   144     
       
   145     TUint key = static_cast<TUint>( reader.ReadInt32L() );
       
   146 
       
   147     CSsmPsKeyObserver* observer = NULL;
       
   148     if ( iWaitType == ESsmWaitPsExactValue )
       
   149         {
       
   150         TInt targetValue = reader.ReadInt32L();
       
   151         observer = new ( ELeave ) CSsmPsKeyObserverExactValue( category,
       
   152                                                                key,
       
   153                                                                targetValue );
       
   154         }
       
   155     else if ( iWaitType == ESsmWaitPsRange )
       
   156         {
       
   157         TInt targetLow = reader.ReadInt32L();
       
   158         TInt targetHigh = reader.ReadInt32L();
       
   159         observer = new ( ELeave ) CSsmPsKeyObserverRange( category,
       
   160                                                           key,
       
   161                                                           targetLow,
       
   162                                                           targetHigh );
       
   163         }
       
   164 
       
   165     CleanupStack::PopAndDestroy( &reader );
       
   166     return observer;
       
   167     }
       
   168