rtsecuritymanager/rtsecuritymanagerserver/src/rtsecmgrpolicymanager.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2007-2008 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 the License "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:       Definition of policy manager class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <e32debug.h>
       
    24 #include "rtsecmgrpolicymanager.h"
       
    25 #include "rtsecmgrserverdef.h"
       
    26 
       
    27 CPolicyManager* CPolicyManager::NewL(CSecMgrStore* aSecMgrDB)
       
    28 	{
       
    29 	CPolicyManager* self = CPolicyManager::NewLC(aSecMgrDB);
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 CPolicyManager* CPolicyManager::NewLC(CSecMgrStore* aSecMgrDB)
       
    35 	{
       
    36 	CPolicyManager* self = new (ELeave) CPolicyManager(aSecMgrDB);
       
    37 	CleanupStack::PushL (self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 void CPolicyManager::RegisterPolicyL(const CPolicy& aPolicy)
       
    42 	{
       
    43 	//Remove the policy if it already exists
       
    44 	for (TInt idx(0); idx!=iPolicies.Count ();++idx)
       
    45 		{
       
    46 		if ( aPolicy.PolicyID ()==iPolicies[idx]->PolicyID ())
       
    47 			{
       
    48 			delete iPolicies[idx];
       
    49 			iPolicies.Remove (idx);
       
    50 			break;
       
    51 			}
       
    52 		}
       
    53 
       
    54 	//update the cache
       
    55 	iPolicies.AppendL (&aPolicy);
       
    56 
       
    57 	iSecMgrDB->StorePolicyL (aPolicy);
       
    58 	}
       
    59 
       
    60 TInt CPolicyManager::UnRegisterPolicy(TPolicyID aPolicyID)
       
    61 	{
       
    62 	TBool exists(EFalse);
       
    63 	TInt ret(KErrNone);
       
    64 	
       
    65 	for(TInt idx(0);idx<iPolicies.Count();++idx)
       
    66 		{
       
    67 		if(aPolicyID==iPolicies[idx]->PolicyID())
       
    68 			{
       
    69 			if(KErrNone==iSecMgrDB->RemovePolicy(aPolicyID))
       
    70 			{
       
    71 			delete iPolicies[idx];
       
    72 			iPolicies.Remove(idx);
       
    73 			exists=ETrue;
       
    74 			}
       
    75 			}
       
    76 		}
       
    77 
       
    78 		//In case if policyID does not exist in the cache...
       
    79 		if(!exists)
       
    80 			ret = iSecMgrDB->RemovePolicy(aPolicyID);
       
    81 	
       
    82 
       
    83 	return ret;
       
    84 	}
       
    85 
       
    86 CPolicy* CPolicyManager::Policy(TPolicyID aPolicyID) const
       
    87 	{
       
    88 	for (TInt idx(0); idx!=iPolicies.Count ();++idx)
       
    89 		{
       
    90 		if ( aPolicyID==iPolicies[idx]->PolicyID ())
       
    91 			{
       
    92 			return iPolicies[idx];
       
    93 			}
       
    94 		}
       
    95 
       
    96 	return NULL;
       
    97 	}
       
    98 
       
    99 TBool CPolicyManager::HasPolicy(TPolicyID aPolicyID) const
       
   100 	{
       
   101 	for (TInt idx(0); idx!=iPolicies.Count ();++idx)
       
   102 		{
       
   103 		if ( aPolicyID==iPolicies[idx]->PolicyID ())
       
   104 			{
       
   105 			return ETrue;
       
   106 			}
       
   107 		}
       
   108 
       
   109 	return EFalse;
       
   110 	}
       
   111