authenticationservices/authenticationserver/source/common/plugindesc.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2005-2009 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: 
       
    15 * CPluginDesc class definition
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22 */
       
    23 
       
    24 #include "authcommon_impl.h"
       
    25 
       
    26 using namespace AuthServer;
       
    27 
       
    28 
       
    29 // -------- factory functions --------
       
    30 
       
    31 
       
    32 /**
       
    33 	Factory function allocates a new instance of CPluginDesc
       
    34 	from the supplied arguments.
       
    35 
       
    36 	The supplied values are arbitrary and need not correlate with
       
    37 	the actual plugins on the device.
       
    38 	
       
    39 	@param	aId				The plugin's ID.  This value is used
       
    40 							to specify the plugin in an authentication
       
    41 							expression.
       
    42 							actually available on the system.
       
    43 	@param	aName			The plugin's name.  The newly-created
       
    44 							description object allocates its own copy
       
    45 							of this name, so aName does not have to remain
       
    46 							in scope after the object has been created.
       
    47 	@param	aType			The plugin's type.
       
    48 	@param	aTrainingStatus	The plugin's training status.
       
    49 	@param	aMinEntropy		The plugin's minimum entropy as a percentage.
       
    50 	@param	aFalsePositiveRate	The plugin's false positive rate as a
       
    51 							percentage.
       
    52 	@param	aFalseNegativeRate	The plugin's false negative rate as a
       
    53 							percentage.
       
    54  */
       
    55 EXPORT_C CPluginDesc* CPluginDesc::NewL(
       
    56 	TPluginId aId, const TDesC& aName,
       
    57 	TAuthPluginType aType, TAuthTrainingStatus aTrainingStatus,
       
    58 	TEntropy aMinEntropy, TPercentage aFalsePositiveRate,
       
    59 	TPercentage aFalseNegativeRate)
       
    60 
       
    61 	{
       
    62 	CPluginDesc* self = new(ELeave) CPluginDesc(
       
    63 		aId, aType, aTrainingStatus, aMinEntropy,
       
    64 		aFalsePositiveRate, aFalseNegativeRate);
       
    65 	
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL(aName);
       
    68 	CleanupStack::Pop(self);
       
    69 	
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 /**
       
    74 	Record supplied information in this new object,
       
    75 	See NewL for argument descriptions.
       
    76 	
       
    77 	@see NewL
       
    78  */
       
    79 CPluginDesc::CPluginDesc(
       
    80 	TPluginId aId, TAuthPluginType aType,
       
    81 	TAuthTrainingStatus aTrainingStatus, TEntropy aMinEntropy,
       
    82 	TPercentage aFalsePositiveRate, TPercentage aFalseNegativeRate)
       
    83 :	iId(aId),
       
    84 	iType(aType),
       
    85 	iTrainingStatus(aTrainingStatus),
       
    86 	iMinEntropy(aMinEntropy),
       
    87 	iFalsePositiveRate(aFalsePositiveRate),
       
    88 	iFalseNegativeRate(aFalseNegativeRate)
       
    89 	{
       
    90 	// empty.
       
    91 	}
       
    92 
       
    93 
       
    94 /**
       
    95 	Allocate a copy of the supplied name.  The
       
    96 	copy is freed in the destructor.
       
    97 	
       
    98 	@param	aName			This plugin's name.
       
    99  */
       
   100 void CPluginDesc::ConstructL(const TDesC& aName)
       
   101 	{
       
   102 	iName = aName.AllocL();
       
   103 	}
       
   104 
       
   105 
       
   106 /**
       
   107 	Free resources allocated in ConstructL.
       
   108 	
       
   109 	@see ConstructL
       
   110  */
       
   111 CPluginDesc::~CPluginDesc()
       
   112     {
       
   113     delete iName;
       
   114     }
       
   115 
       
   116 
       
   117 // -------- persistence --------
       
   118 
       
   119 /**
       
   120 	Recreate an instance of CPluginDesc from the supplied
       
   121 	stream.  On success the object is placed on the cleanup stack.
       
   122 	
       
   123 	@param	aIn				Stream containing persisted plugin
       
   124 							description.
       
   125 	@return					New instance of CPluginDesc, created
       
   126 							from information in the supplied stream.
       
   127  */
       
   128 EXPORT_C CPluginDesc* CPluginDesc::NewLC(RReadStream& aIn)
       
   129 	{
       
   130 	CPluginDesc* self = new(ELeave) CPluginDesc;
       
   131 	CleanupStack::PushL(self);
       
   132 	self->InternalizeL(aIn);
       
   133 	return self;
       
   134 	}
       
   135 
       
   136 /**
       
   137 	Initialize this object from the supplied stream.
       
   138 	This function is used to copy plugin descriptions
       
   139 	across IPC boundaries.
       
   140 	
       
   141 	@param	aIn				Stream which contains externalized
       
   142 							plugin descriptor.
       
   143 	@see ExternalizeL
       
   144  */
       
   145 void CPluginDesc::InternalizeL(RReadStream& aIn)
       
   146 	{
       
   147 	iId = aIn.ReadUint32L();
       
   148 	iName = HBufC::NewL(aIn, KMaxNameLength);
       
   149 	iType = static_cast<TAuthPluginType>(aIn.ReadUint32L());
       
   150 	iTrainingStatus = static_cast<TAuthTrainingStatus>(aIn.ReadUint32L());
       
   151 	iMinEntropy = aIn.ReadUint32L();
       
   152 	iFalsePositiveRate = aIn.ReadUint32L();
       
   153 	iFalseNegativeRate = aIn.ReadUint32L();
       
   154 	}
       
   155 
       
   156 
       
   157 /**
       
   158 	Write information about this object to the supplied stream
       
   159 	so it can be reconstructed later.
       
   160 	
       
   161 	This function is used to copy plugin descriptions
       
   162 	across IPC boundaries.
       
   163 	
       
   164 	@see InternalizeL
       
   165  */
       
   166 EXPORT_C void CPluginDesc::ExternalizeL(RWriteStream& aOut) const
       
   167 	{
       
   168 	aOut << iId;
       
   169 	aOut << *iName;
       
   170 	aOut.WriteInt32L(iType);
       
   171 	aOut.WriteInt32L(iTrainingStatus);
       
   172 	aOut << iMinEntropy;
       
   173 	aOut << iFalsePositiveRate;
       
   174 	aOut << iFalseNegativeRate;
       
   175 	}
       
   176 
       
   177 
       
   178 // -------- accessors --------
       
   179 
       
   180     
       
   181 /**
       
   182  * The plugin id.
       
   183  * @return The plugin id
       
   184  **/
       
   185 EXPORT_C TPluginId CPluginDesc::Id() const
       
   186   {
       
   187   return iId;
       
   188   }
       
   189 
       
   190 /**
       
   191  * The plugin name.
       
   192  *
       
   193  * @return The plugin name, ownership of the returned pointer remains the
       
   194  * plugin description
       
   195  **/
       
   196 EXPORT_C const TDesC* CPluginDesc::Name() const
       
   197   {
       
   198   return iName;
       
   199   }
       
   200 
       
   201 /**
       
   202  * The plugin type.
       
   203  * @return the plugin type
       
   204  **/
       
   205 EXPORT_C TAuthPluginType CPluginDesc::Type() const
       
   206   {
       
   207   return iType;
       
   208   }
       
   209 	
       
   210 /**
       
   211  * Indicates whether the plugin is trained for none, some or all known
       
   212  * identities.
       
   213  *
       
   214  * @return the training status
       
   215  **/
       
   216 EXPORT_C TAuthTrainingStatus CPluginDesc::TrainingStatus() const
       
   217   {
       
   218   return iTrainingStatus;
       
   219   }
       
   220 
       
   221 /**
       
   222  * How many unique identities the plugin supports.
       
   223  * @return The minumum entropy provided by the plugin.
       
   224  **/
       
   225 EXPORT_C TEntropy CPluginDesc::MinEntropy() const
       
   226   {
       
   227   return iMinEntropy;
       
   228   }
       
   229 	
       
   230 /**
       
   231  * The percentage of times an device holder is falsely identified as an
       
   232  * known identity.
       
   233  *
       
   234  * @return The false positive rate of the plugin
       
   235  **/
       
   236 EXPORT_C TPercentage CPluginDesc::FalsePositiveRate() const
       
   237   {
       
   238   return iFalsePositiveRate;
       
   239   }
       
   240 
       
   241 /**
       
   242  * The percentage of times a known identity is not identified. 
       
   243  *
       
   244  * @return The false negative rate of the plugin.
       
   245  **/
       
   246 EXPORT_C TPercentage CPluginDesc::FalseNegativeRate() const
       
   247   {
       
   248   return iFalseNegativeRate;
       
   249   }
       
   250 
       
   251