javacommons/security/legacysupport/midp2securitypolicyv2/plugins/securitypolicyV2/src/SimpleMapping.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:48:13 +0300
branchRCL_3
changeset 60 6c158198356e
parent 19 04becd199f91
child 83 26b2b12093af
permissions -rw-r--r--
Revision: v2.2.9 Kit: 201033

/*
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/


/**
 *
 * @file SimpleMapping.cpp
 *
 * @internal
 *
 */

#include "SimpleMapping.h"

/*
 *
 * A 'Simple Mapping' is used to represent the mapping between the current
 * interaction mode for a function group and the corresponding interaction
 * mode for a permission within that function group.
 *
 */

namespace MIDP
{

CSimpleMapping* CSimpleMapping::NewLC(const TDesC&                aPermission,
                                      RArray<MPermission::TMode>& aMapping)
{
    CSimpleMapping* sm = new(ELeave) CSimpleMapping;

    CleanupStack::PushL(sm);
    sm->ConstructL(aPermission, aMapping);
    return sm;
}

CSimpleMapping::CSimpleMapping()
{
}

void CSimpleMapping::ConstructL(const TDesC& aPermission, RArray<MPermission::TMode>& aMapping)
{
    iPermission = aPermission.AllocL();

    TInt count = aMapping.Count();

    ASSERT((count % 2) == 0);

    for (TInt i = 0; i < count; i++)
    {
        iMapping.AppendL(aMapping[i]);
    }
}

CSimpleMapping::~CSimpleMapping()
{
    delete iPermission;
    iMapping.Close();
}

/*
 *
 * Returns the name of the permission to which this mapping applies.
 *
 */

const TDesC& CSimpleMapping::Permission(void) const
{
    return *iPermission;
}

/*
 *
 * Returns the interaction mode of the permission to which this mapping
 * applies, given the current interaction mode for the function group.
 *
 */

MPermission::TMode CSimpleMapping::Mapping(MPermission::TMode aCurrent) const
{
    TInt count = iMapping.Count();

    for (TInt i = 0; i < count; i += 2)
    {
        if (iMapping[i] == aCurrent)
        {
            return iMapping[i+1];
        }
    }
    return aCurrent;
}

} // end of namespace MIDP