sysstatemgmt/systemstatemgr/test/tcmn/src/t_stateawaresession2.cpp
changeset 76 cb32bcc88bad
equal deleted inserted replaced
73:d38941471f1c 76:cb32bcc88bad
       
     1 // Copyright (c) 2010 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: Test wrapper for CSsmStateAwareSession2
       
    14 
       
    15 #include <e32std.h>
       
    16 #include <e32capability.h>
       
    17 #include <test/datawrapper.h>
       
    18 #include <ssm/ssmdomaindefs.h> 
       
    19 #include <ssm/ssmsubstates.hrh>
       
    20 #include "ssmsubstateext.hrh"
       
    21 
       
    22 #include "t_stateawaresession2.h"
       
    23 
       
    24 const TDmDomainId KTestDdmDomain = {KSM2AppServicesDomain3};
       
    25 
       
    26 //
       
    27 _LIT(KError,                     "error");
       
    28 _LIT(KAsyncIndex,                "asyncIndex");
       
    29 _LIT(KAcknowledge,               "acknowledge");
       
    30 
       
    31 //commands
       
    32 _LIT(KCmdNewL,                                      "NewL");
       
    33 _LIT(KCmdReadIniData,                               "ReadIniData");
       
    34 _LIT(KCmdRequestStateNotification,                  "RequestStateNotification");
       
    35 _LIT(KCmdAcknowledgeStateNotification,              "AcknowledgeStateNotification");
       
    36 _LIT(KCmdRequestStateNotificationCancel,            "RequestStateNotificationCancel");
       
    37 _LIT(KCmdDestructor,                                "~");
       
    38 
       
    39 /**
       
    40  * Constructor
       
    41  */
       
    42 TIniData3::TIniData3()
       
    43          : iAcknowledge(ETrue)
       
    44          , iAsyncIndex(0)
       
    45          {}
       
    46 /**
       
    47 * @return pointer to the object that the data wraps
       
    48 */
       
    49 TAny*  CTestCStateAwareSession::GetObject()
       
    50     {
       
    51     return iSsmStateAwareSession;
       
    52     }
       
    53 
       
    54 /**
       
    55  * SetObjectL
       
    56  */
       
    57 void CTestCStateAwareSession::SetObjectL(TAny* aAny)
       
    58     {
       
    59     DoCleanup();
       
    60     iSsmStateAwareSession=static_cast<CSsmStateAwareSession2*> (aAny);
       
    61     }
       
    62 
       
    63 /**
       
    64  * DisownObjectL
       
    65  */
       
    66 void CTestCStateAwareSession::DisownObjectL()
       
    67     {
       
    68     iSsmStateAwareSession=NULL;
       
    69     }
       
    70 
       
    71 /**
       
    72  * Constructor.
       
    73  */
       
    74 CTestCStateAwareSession::CTestCStateAwareSession():
       
    75 CDataWrapper()
       
    76     {
       
    77     }
       
    78 
       
    79 /**
       
    80  * Destructor.
       
    81  */
       
    82 CTestCStateAwareSession::~CTestCStateAwareSession()
       
    83     {
       
    84     DoCleanup();
       
    85     }
       
    86 
       
    87 /**
       
    88  * Process a command read from the ini file
       
    89  *
       
    90  * @param aCommand  the command to process
       
    91  * @param aSection      the entry in the ini file requiring the command to be processed
       
    92  *
       
    93  * @return ETrue if the command is processed
       
    94  */
       
    95 TBool CTestCStateAwareSession::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
    96     {
       
    97     TBool retVal = ETrue;
       
    98     if (aCommand == KCmdNewL)
       
    99         {
       
   100         DoCmdNew();
       
   101         }
       
   102     else if (aCommand == KCmdReadIniData)
       
   103         {
       
   104         DoCmdReadIniData(aSection);
       
   105         }
       
   106     else if (aCommand == KCmdAcknowledgeStateNotification)
       
   107         {
       
   108         DoCmdAcknowledgeStateNotification(aSection);
       
   109         }
       
   110     else if (aCommand == KCmdRequestStateNotification)
       
   111         {
       
   112         DoCmdRequestStateNotification();
       
   113         }
       
   114     else if (aCommand == KCmdRequestStateNotificationCancel)
       
   115         {
       
   116         DoCmdRequestStateNotificationCancel();
       
   117         }
       
   118     else if (aCommand == KCmdDestructor)
       
   119         {
       
   120         DoCmdDestructor();
       
   121         }
       
   122     else
       
   123         {
       
   124         retVal = EFalse;
       
   125         }    
       
   126    
       
   127     return retVal;
       
   128     }
       
   129 
       
   130 /**
       
   131  * Creates CSsmStateAwareSession2 class instance
       
   132  */
       
   133 void CTestCStateAwareSession::DoCmdNew()
       
   134     {
       
   135     INFO_PRINTF1(_L("Create CSsmStateAwareSession2 class instance"));
       
   136     DoCleanup();
       
   137     
       
   138     TRAPD(err, iSsmStateAwareSession = CSsmStateAwareSession2::NewL(KTestDdmDomain, *this));
       
   139     
       
   140     if (err != KErrNone)
       
   141         {
       
   142         ERR_PRINTF2(_L("CSsmStateAwareSession2::NewL() error %d"), err);
       
   143         SetError(err);
       
   144         }
       
   145     }
       
   146 
       
   147 /*
       
   148  * Helper function to read ini file data
       
   149  */
       
   150 void CTestCStateAwareSession::DoCmdReadIniData(const TDesC& aSection)
       
   151     {
       
   152     if( !GetIntFromConfig(aSection, KAsyncIndex(), iIniData.iAsyncIndex ) ||
       
   153         !GetBoolFromConfig(aSection, KAcknowledge(), iIniData.iAcknowledge ) )
       
   154         {
       
   155         ERR_PRINTF1(_L("Error reading ini file data"));
       
   156         SetError(KErrNotFound);
       
   157         }
       
   158     }
       
   159 
       
   160 /**
       
   161  * Contains cleanup implementation
       
   162  */
       
   163 void CTestCStateAwareSession::DoCleanup()
       
   164     {
       
   165     if(iSsmStateAwareSession != NULL)
       
   166         {
       
   167         INFO_PRINTF1(_L("Deleting current CSsmStateAwareSession2"));
       
   168         delete iSsmStateAwareSession;
       
   169         iSsmStateAwareSession = NULL;
       
   170         }
       
   171     }
       
   172 
       
   173 /**
       
   174  * Destroy CSsmStateAwareSession2 object
       
   175  */
       
   176 void CTestCStateAwareSession::DoCmdDestructor()
       
   177     {
       
   178     INFO_PRINTF1(_L("Destroying the CStateAwareSession2 object"));
       
   179     DoCleanup();
       
   180     }
       
   181 
       
   182 /**
       
   183  * DoCmdRequestStateNotification 
       
   184  */
       
   185 void CTestCStateAwareSession::DoCmdRequestStateNotification()
       
   186     {
       
   187     INFO_PRINTF1(_L("CTestCStateAwareSession: RequestStateNotification"));
       
   188     iSsmStateAwareSession->RequestStateNotification();
       
   189     IncOutstanding();
       
   190     }
       
   191 
       
   192 /**
       
   193  * DoCmdAcknowledgeStateNotification
       
   194  */
       
   195 void CTestCStateAwareSession::DoCmdAcknowledgeStateNotification(const TDesC& aSection)
       
   196     {
       
   197     INFO_PRINTF1(_L("CTestCStateAwareSession: AcknowledgeStateNotification"));
       
   198     TInt error;
       
   199     if (!GetIntFromConfig(aSection, KError(), error ))
       
   200         {
       
   201         //set default error value if value is not provided in .ini file
       
   202         error = KErrNone;
       
   203         }
       
   204    iSsmStateAwareSession->AcknowledgeStateNotification(error);    
       
   205     }
       
   206 
       
   207 /**
       
   208  * DoCmdAcknowledgeAndRequestStateNotification
       
   209  */
       
   210 void CTestCStateAwareSession::DoCmdAcknowledgeAndRequestStateNotification(const TDesC& aSection)
       
   211     {
       
   212     INFO_PRINTF1(_L("CTestCStateAwareSession: AcknowledgeAndRequestStateNotification"));
       
   213     TInt error;
       
   214     if (!GetIntFromConfig(aSection, KError(), error ))
       
   215         {
       
   216         //set default error value if value is not provided in .ini file
       
   217         error = KErrNone;
       
   218         }
       
   219     iSsmStateAwareSession->AcknowledgeAndRequestStateNotification(error);
       
   220     IncOutstanding();
       
   221     }
       
   222 
       
   223 /**
       
   224  * DoCmdRequestStateNotificationCancel
       
   225  */
       
   226 void CTestCStateAwareSession::DoCmdRequestStateNotificationCancel()
       
   227     {
       
   228     INFO_PRINTF1(_L("CTestCStateAwareSession: RequestStateNotificationCancel"));
       
   229     iSsmStateAwareSession->RequestStateNotificationCancel();
       
   230     }
       
   231 
       
   232 /**
       
   233  * HandleTransition
       
   234  */
       
   235 void CTestCStateAwareSession::HandleTransition(TInt aError)
       
   236     { 
       
   237     INFO_PRINTF1(_L("CTestCStateAwareSession::HandleTransition"));
       
   238     TSsmState currentState;
       
   239     currentState = iSsmStateAwareSession->GetState();
       
   240     TUint16 currentMainState = currentState.MainState();
       
   241     TUint16 currentSubState = currentState.SubState();
       
   242     if(currentMainState == ESsmShutdown && 
       
   243        currentSubState == ESsmShutdownSubStateCritical && 
       
   244        iIniData.iAcknowledge)
       
   245         {    
       
   246         iSsmStateAwareSession->AcknowledgeStateNotification(aError);
       
   247         }
       
   248     }
       
   249 
       
   250 /**
       
   251  * HandleDeferralError
       
   252  */
       
   253 TInt CTestCStateAwareSession::HandleDeferralError(TInt aError)
       
   254     {
       
   255     INFO_PRINTF2(_L("CTestCStateAwareSession::HandleDeferralError error = %d"), aError);
       
   256     RDebug::Printf("Entered CTestCStateAwareSession::HandleDeferralError() with error %d", aError);
       
   257     TSsmState currentState;
       
   258     currentState = iSsmStateAwareSession->GetState();
       
   259     TUint16 currentMainState = currentState.MainState();
       
   260     TUint16 currentSubState = currentState.SubState();
       
   261     if(currentMainState == ESsmShutdown && 
       
   262        currentSubState == ESsmNormalShutdown)
       
   263         {
       
   264         iSsmStateAwareSession->AcknowledgeAndRequestStateNotification(KErrNone);
       
   265         IncOutstanding();
       
   266         }
       
   267     else
       
   268         {
       
   269         SetAsyncError(iIniData.iAsyncIndex, aError);
       
   270         }
       
   271     DecOutstanding();
       
   272     return KErrNone;
       
   273     }