lafagnosticuifoundation/graphicseffects/ClientSrc/policyhandler.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2006-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 // GFXTRANSEFFECT.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "PolicyHandler.h"
       
    19 #include "GfxTransUtils.h"
       
    20 
       
    21 //---------------------------------
       
    22 // construct/destruct  
       
    23 //---------------------------------
       
    24 
       
    25 CPolicyHandler::CPolicyHandler() 
       
    26 	{
       
    27 	
       
    28 	}
       
    29 	 
       
    30 CPolicyHandler::~CPolicyHandler() 
       
    31 	{
       
    32 	iPolicies.ResetAndDestroy();
       
    33 	iPolicies.Close();
       
    34 	}
       
    35 
       
    36 
       
    37 //---------------------------------
       
    38 // get/set policies 
       
    39 //---------------------------------
       
    40  
       
    41 TPolicy CPolicyHandler::GetPolicy(TUid aUid, TUint aAction) 
       
    42 	{
       
    43 	TInt cpIdx = FindControlPolicy(aUid);
       
    44 	if(IsValidIndex(cpIdx))
       
    45 		{
       
    46 		TInt apIdx = FindActionPolicy(iPolicies[cpIdx], aAction);
       
    47 		if(IsValidIndex(apIdx))
       
    48 			{
       
    49 			return iPolicies[cpIdx]->iActions[apIdx].iPolicy;
       
    50 			}
       
    51 		}
       
    52 	return ENotSupported;
       
    53 	}
       
    54 	 
       
    55 void CPolicyHandler::UpdatePolicy(TUid aUid, TUint aAction, TPolicy aPolicy) 
       
    56 	{
       
    57 	TInt const cpIdx = FindControlPolicy(aUid);
       
    58 	if(IsValidIndex(cpIdx))
       
    59 		{
       
    60 		CControlPolicy *policy = iPolicies[cpIdx];
       
    61 		
       
    62 		TInt apIdx = FindActionPolicy(policy, aAction);
       
    63 		if(IsValidIndex(apIdx))
       
    64 			{
       
    65 			if(aPolicy == ENotSupported)
       
    66 				{ //remove current existing policy
       
    67 				policy->iActions.Remove(apIdx);
       
    68 				if(policy->iActions.Count() == 0)
       
    69 					{
       
    70 					iPolicies.Remove(cpIdx);
       
    71 					delete policy;
       
    72 					}
       
    73 				}
       
    74 			else 
       
    75 				{
       
    76 				//change the policy
       
    77 				policy->iActions[apIdx].iPolicy = aPolicy;
       
    78 				}
       
    79 			return;
       
    80 			}
       
    81 		if(aPolicy == ENotSupported)
       
    82 			{
       
    83 			//already not existing so do nothing
       
    84 			return;
       
    85 			}
       
    86 		else 
       
    87 			{
       
    88 			//create the action policy
       
    89 			TActionPolicy actionPolicy;
       
    90 			actionPolicy.iAction = aAction;
       
    91 			actionPolicy.iPolicy = aPolicy;
       
    92 			policy->iActions.Append(actionPolicy); //nothing to do if we fail
       
    93 			return;
       
    94 			}
       
    95 		}
       
    96 	if(aPolicy == ENotSupported)
       
    97 		{
       
    98 		//already not existing so do nothing
       
    99 		return;
       
   100 		}
       
   101 	else 
       
   102 		{
       
   103 		//Create the policy
       
   104 		CControlPolicy* policy = new CControlPolicy();
       
   105 		if(!policy)
       
   106 			return; //nothing to do if we fail
       
   107 		policy->iUid = aUid;
       
   108 		TActionPolicy actionPolicy;
       
   109 		actionPolicy.iAction = aAction;
       
   110 		actionPolicy.iPolicy = aPolicy;
       
   111 		if(KErrNone != policy->iActions.Append(actionPolicy))
       
   112 			{
       
   113 			delete policy;
       
   114 			return;
       
   115 			}
       
   116 		if(KErrNone != iPolicies.Append(policy))
       
   117 			{
       
   118 			delete policy;
       
   119 			return; //nothing to do if we fail
       
   120 			}
       
   121 		}
       
   122 	}
       
   123 		
       
   124 void CPolicyHandler::SetTransitionPolicies(TControlPolicy* aPolicies, TInt aNum)
       
   125 	{
       
   126 	iPolicies.ResetAndDestroy();
       
   127 	for(TInt i = 0;i < aNum; i++)
       
   128 		{
       
   129 		UpdatePolicy(aPolicies[i].iId, aPolicies[i].iAction, aPolicies[i].iPolicy);
       
   130 		}
       
   131 	delete aPolicies;
       
   132 	}
       
   133 
       
   134 
       
   135 
       
   136 //---------------------------------
       
   137 // find functions  
       
   138 //---------------------------------
       
   139 TInt CPolicyHandler::FindControlPolicy(TUid aUid)
       
   140 	{
       
   141 	TInt count = iPolicies.Count();
       
   142 	for(TInt i = 0; i < count; i++)
       
   143 		{
       
   144 		if(iPolicies[i]->iUid == aUid)
       
   145 			{
       
   146 			return i;
       
   147 			}
       
   148 		}
       
   149 	return KErrNotFound;
       
   150 	}
       
   151 	
       
   152 TInt CPolicyHandler::FindActionPolicy(CControlPolicy* aControlPolicy, TUint aAction)
       
   153 	{
       
   154 	TInt count = aControlPolicy->iActions.Count();
       
   155 	for(TInt i = 0; i < count; i++)
       
   156 		{
       
   157 		if(aControlPolicy->iActions[i].iAction == aAction)
       
   158 			{
       
   159 			return i;
       
   160 			}
       
   161 		}
       
   162 	return KErrNotFound;
       
   163 	}
       
   164 	
       
   165