os/security/securityanddataprivacytools/securitytools/certapp/encdec/appuidmap.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/securityanddataprivacytools/securitytools/certapp/encdec/appuidmap.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,88 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "appuidmap.h"
    1.23 +#include <map>
    1.24 +
    1.25 +struct AppMapEntry
    1.26 +	{
    1.27 +	std::string iDef;
    1.28 +	TInt32 iLastDefFileIndex;
    1.29 +	};
    1.30 +typedef std::map<TUint32, AppMapEntry> AppMap;
    1.31 +
    1.32 +//
    1.33 +// Local static vars. This avoids including map etc in the header
    1.34 +//
    1.35 +static AppMap sAppMap;
    1.36 +
    1.37 +bool AppUidMap::InsertUidDefinition(TInt32 aUid, const std::string &aDef, TInt32 aInputFileIndex,
    1.38 +									TInt32 &aLastIndex, std::string &aFirstDef)
    1.39 +{
    1.40 +	AppMapEntry val;
    1.41 +	val.iDef = aDef;
    1.42 +	val.iLastDefFileIndex = aInputFileIndex;
    1.43 +	AppMap::value_type e(aUid, val);
    1.44 +	std::pair<AppMap::iterator,bool> result = sAppMap.insert(e);
    1.45 +	if(result.second == true)
    1.46 +		{
    1.47 +		// Inserted new entry
    1.48 +		return true;
    1.49 +		}
    1.50 +	// Duplicate.
    1.51 +	// Save fileIndex of previous definition
    1.52 +	aLastIndex = (result.first)->second.iLastDefFileIndex;
    1.53 +	aFirstDef = (result.first)->second.iDef;
    1.54 +	// Update location of last seen def
    1.55 +	(result.first)->second.iLastDefFileIndex = aInputFileIndex;
    1.56 +
    1.57 +	return false;
    1.58 +}
    1.59 +
    1.60 +
    1.61 +
    1.62 +
    1.63 +
    1.64 +
    1.65 +static EnumEntry *sEnumEntries = 0;
    1.66 +
    1.67 +void AppUidMap::GenerateEnumEntries()
    1.68 +{
    1.69 +	delete [] sEnumEntries;
    1.70 +	sEnumEntries = new EnumEntry[sAppMap.size()+1];
    1.71 +	sEnumEntries[sAppMap.size()].iName=0; // Terminate array
    1.72 +
    1.73 +	AppMap::const_iterator it = sAppMap.begin();
    1.74 +	for(TUint32 i=0; i < sAppMap.size(); ++i)
    1.75 +		{
    1.76 +		sEnumEntries[i].iName = (*it).second.iDef.c_str();
    1.77 +		sEnumEntries[i].iValue = (*it).first;
    1.78 +		++it;
    1.79 +		}
    1.80 +}
    1.81 +
    1.82 +
    1.83 +EnumEntry *AppUidMap::EnumEntries()
    1.84 +{
    1.85 +BULLSEYE_OFF
    1.86 +	if(sEnumEntries == 0) FatalError();
    1.87 +BULLSEYE_RESTORE
    1.88 +	return sEnumEntries;
    1.89 +}
    1.90 +
    1.91 +// End of file