sysstatemgmt/ssmpolicyplugins/ssmstatepolicybase/src/ssmstatepolicybase.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: Implementation of CSsmStatePolicyBase class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <bautils.h>
       
    19 #include <ssm/ssmcommandlistresourcereader.h>
       
    20 #include <ssm/ssmstate.h>
       
    21 #include <ssm/ssmstatetransition.h>
       
    22 
       
    23 #include "ssmstatepolicybase.h"
       
    24 #include "ssmmapperutilitystatic.h"
       
    25 #include "trace.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CSsmStatePolicyBase::CSsmStatePolicyBase
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 EXPORT_C CSsmStatePolicyBase::CSsmStatePolicyBase()
       
    34     {
       
    35     FUNC_LOG;
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CSsmStatePolicyBase::~CSsmStatePolicyBase
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CSsmStatePolicyBase::~CSsmStatePolicyBase()
       
    44     {
       
    45     FUNC_LOG;
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CSsmStatePolicyBase::Initialize
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C void CSsmStatePolicyBase::Initialize( TRequestStatus& aStatus )
       
    54     {
       
    55     FUNC_LOG;
       
    56     ASSERT_TRACE( iCommandListResourceReader );
       
    57 
       
    58 	// initialise command list resource reader.
       
    59 	iCommandListResourceReader->Initialise( aStatus );
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CSsmStatePolicyBase::InitializeCancel
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C void CSsmStatePolicyBase::InitializeCancel()
       
    68     {
       
    69     FUNC_LOG;
       
    70 
       
    71     iCommandListResourceReader->InitialiseCancel();
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CSsmStatePolicyBase::TransitionAllowed
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C MSsmStatePolicy::TResponse CSsmStatePolicyBase::TransitionAllowed(
       
    80     const TSsmStateTransition& aRequest,
       
    81     TSsmStateTransition const* aCurrent,
       
    82     TSsmStateTransition const* aQueued,
       
    83     const RMessagePtr2& aMessage )
       
    84     {
       
    85     FUNC_LOG;
       
    86     INFO_2( "Requested state transition: %04x.%04x", aRequest.State().MainState(), aRequest.State().SubState() );
       
    87 
       
    88     SsmMapperUtility::CheckCaps( aMessage );
       
    89 
       
    90     if ( IsAllowedTargetState( aRequest ) )
       
    91         {
       
    92         if ( aCurrent )
       
    93             {
       
    94             INFO_2( "Current state transition: %04x.%04x", aCurrent->State().MainState(), aCurrent->State().SubState() );
       
    95 
       
    96             TUint16 mainState( aRequest.State().MainState() );
       
    97             if ( mainState == ESsmFail || mainState == ESsmShutdown )
       
    98                 {
       
    99     		    INFO( "Failure / shutdown transition requested -> start immediately" );
       
   100                 return EReplaceCurrentClearQueue;
       
   101                 }
       
   102 
       
   103             if ( aQueued ) // There propably can be a queued transition only if there is a current transition(?)
       
   104                 {
       
   105                 INFO_2( "Queued state transition: %04x.%04x", aQueued->State().MainState(), aQueued->State().SubState() );
       
   106                 }
       
   107 
       
   108             INFO( "Queuing state transition" );
       
   109             return ECurrentRemainReplaceQueued;
       
   110             }
       
   111 
       
   112 		INFO( "No current state transition -> start immediately" );
       
   113         return EDefinitelyAllowed;
       
   114         }
       
   115     else
       
   116 		{
       
   117 		INFO( "State is not reachable" );
       
   118 		return ENotAllowed;
       
   119 		}
       
   120     }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CSsmStatePolicyBase::PrepareCommandList
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void CSsmStatePolicyBase::PrepareCommandList(
       
   128     TSsmState aState,
       
   129 #ifdef INFO_TRACE
       
   130     TInt aReason,
       
   131 #else
       
   132     TInt /*aReason*/,
       
   133 #endif
       
   134     TRequestStatus& aStatus )
       
   135     {
       
   136     FUNC_LOG;
       
   137     INFO_3( "State %04x.%04x, reason %04x", aState.MainState(), aState.SubState(), aReason );
       
   138 
       
   139 	TSsmState publishState(
       
   140 	    aState.MainState(), TargetSubState( aState.SubState() ) );
       
   141 
       
   142 	// Build the commandlist from resource.
       
   143 	// Substate id is used as a command list id.
       
   144 	iCommandListResourceReader->PrepareCommandList(
       
   145 	    publishState.SubState(), publishState, aStatus );
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CSsmStatePolicyBase::PrepareCommandListCancel
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CSsmStatePolicyBase::PrepareCommandListCancel()
       
   154     {
       
   155     FUNC_LOG;
       
   156 
       
   157     iCommandListResourceReader->PrepareCommandListCancel();
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CSsmStatePolicyBase::CommandList
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C CSsmCommandList* CSsmStatePolicyBase::CommandList()
       
   166     {
       
   167     FUNC_LOG;
       
   168 
       
   169 	return iCommandListResourceReader->GetCommandList();
       
   170     }
       
   171 
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CSsmStatePolicyBase::Release
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C void CSsmStatePolicyBase::Release()
       
   178     {
       
   179     FUNC_LOG;
       
   180 
       
   181     delete this;
       
   182     }