sysstatemgmt/systemstatemgr/cmd/src/ssmcommandlistutils.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 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:
       
    14 //
       
    15 
       
    16 
       
    17 #include <ssm/ssmcommandlist.h>
       
    18 #include <ssm/ssmcmd.hrh>
       
    19 
       
    20 #include "ssmcommandlistutils.h"
       
    21 #include <ssm/ssmcommand.h>
       
    22 #include "ssmdebug.h"
       
    23 #include "ssmpanic.h"
       
    24 
       
    25 
       
    26 EXPORT_C TBool CSsmCommandListUtils::IsValidStateList(const CSsmCommandList& aCommandList)
       
    27 	{
       
    28 	// Validation 1: A command list used to transition to a system state must
       
    29 	// contain exactly one publish system state command
       
    30 	// and must not contain any publish swp commands
       
    31 	
       
    32 	//Validation 2:In a command list,  if there are one or more commands with their
       
    33 	//execution behaviour as ESsmDeferredWaitForSignal that should be followed by a
       
    34 	//SSM_MULTIPLE_WAIT command  
       
    35 	
       
    36 	
       
    37 	return IsValidList(aCommandList, ESsmCmdPublishSystemState) && ValidateDeferredWaitCommand(aCommandList);
       
    38 	}
       
    39 
       
    40 EXPORT_C TBool CSsmCommandListUtils::IsValidSwpList(const CSsmCommandList& aCommandList)
       
    41 	{
       
    42 	//Validation 1: A command list used to change the value of a swp must
       
    43 	// contain exactly one publish swp command
       
    44 	// and must not contain any publish system state commands
       
    45 	
       
    46 	//Validation 2:In a command list,  if there are one or more commands with their
       
    47 	//execution behaviour as ESsmDeferredWaitForSignal that should be followed by a
       
    48 	//SSM_MULTIPLE_WAIT command 
       
    49 		
       
    50 	return IsValidList(aCommandList, ESsmCmdPublishSwp)  && ValidateDeferredWaitCommand(aCommandList);
       
    51 	}
       
    52 
       
    53 TBool CSsmCommandListUtils::IsValidList(const CSsmCommandList& aCommandList, TSsmCommandType aRequiredType)
       
    54  	{
       
    55 	TBool ret = EFalse;
       
    56 	TInt publishSystemStateCount = 0;
       
    57 	TInt publishSwpCount = 0;
       
    58  	const TInt KRequiredCount = 1;
       
    59 	
       
    60  	//From Commandlist fetch 1.) no. of publish system state command 
       
    61  	//2.) no. of publish swp command
       
    62 
       
    63 	aCommandList.GetDataToValidateCommandlist(publishSystemStateCount,publishSwpCount);
       
    64 	
       
    65 	 if (aRequiredType == ESsmCmdPublishSystemState)	//if commandlist has a Publish System State command
       
    66  		{
       
    67 		if (publishSwpCount != 0)	//and a Publish SWP command also
       
    68  			{
       
    69 			DEBUGPRINT1A("PublishSwp command illegal in PublishSystemState command list");
       
    70  			}
       
    71 		else if (publishSystemStateCount != KRequiredCount)	//number of publish System State commands is not equal to 1
       
    72  			{
       
    73 			DEBUGPRINT2A("Command list incorrectly contains %d PublishSystemState command ", publishSystemStateCount);
       
    74  			}
       
    75  		else
       
    76  			{
       
    77 			ret = ETrue;
       
    78  			}
       
    79  		}
       
    80   	else if (aRequiredType == ESsmCmdPublishSwp)	//if commandlist has a Publish SWP command
       
    81  		{
       
    82 		if (publishSystemStateCount != 0)	//and a Publish System state command also
       
    83 			{
       
    84 			DEBUGPRINT1A("PublishSystemState command illegal in PublishSwp command list");
       
    85 			}
       
    86 		else if (publishSwpCount != KRequiredCount)	//number of publish SWP commands is not equal to 1
       
    87  			{
       
    88 			DEBUGPRINT2A("Command list incorrectly contains %d PublishSwp command ", publishSwpCount);
       
    89  			}
       
    90 		else
       
    91  			{
       
    92 			ret = ETrue;
       
    93  			}
       
    94  		}
       
    95 	 
       
    96 	 return ret;
       
    97  	}
       
    98 
       
    99 /**
       
   100 This method runs through the command list from start to end checks for existence
       
   101 of command with execution behaviour ESsmDeferredWaitForSignal
       
   102 If one or more such commands found then it checks for ESsmCmdMultipleWait type command.
       
   103 If ESsmCmdMultipleWait command not found corresponding to one or more ESsmDeferredWaitForSignal
       
   104 returns EFalse.
       
   105 */  
       
   106 
       
   107 TBool CSsmCommandListUtils::ValidateDeferredWaitCommand(const CSsmCommandList& aCommandList)
       
   108     {
       
   109     TBool ret = ETrue;
       
   110     TBool deferredWaitFound = EFalse;
       
   111     const TInt CommandsCount = aCommandList.Count();
       
   112     
       
   113     TSsmCommandType commandType; 
       
   114         
       
   115     for (TInt count = 0 ; count < CommandsCount ; count++)
       
   116         {
       
   117         if(deferredWaitFound)
       
   118             {
       
   119             commandType = aCommandList[count]->Type();
       
   120             if(commandType == ESsmCmdMultipleWait)
       
   121                 {
       
   122                 deferredWaitFound = EFalse;                 
       
   123                 }
       
   124             }
       
   125         if(aCommandList[count]->ExecutionBehaviour() == ESsmDeferredWaitForSignal)  
       
   126             {
       
   127             deferredWaitFound = ETrue;              
       
   128             }
       
   129         }
       
   130         
       
   131     if(deferredWaitFound)
       
   132         {
       
   133         DEBUGPRINT1A("Command list incorrectly contains deferredWaitSignal command and no later Multiple_Wait");        
       
   134         ret = EFalse;                   
       
   135         }
       
   136 
       
   137     return ret;
       
   138     }