epoc32/include/ct/mcttoken.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/ct/mcttoken.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,248 @@
     1.4 +/*
     1.5 +* Copyright (c) 2001-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 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 + @publishedPartner
    1.27 + @released
    1.28 +*/
    1.29 +
    1.30 +#ifndef __MCTTOKEN_H__
    1.31 +#define __MCTTOKEN_H__
    1.32 +
    1.33 +#include <ct/tcttokenobjecthandle.h>
    1.34 +#include <ct/mcttokenobject.h>
    1.35 +#include <ct/tcttokenhandle.h>
    1.36 +#include <ct/mcttokentype.h>
    1.37 +
    1.38 +class MCTTokenInterface;
    1.39 +
    1.40 +
    1.41 +/** 
    1.42 + * The base class for a token.
    1.43 + * 
    1.44 + * Token types must implement this class. It is created from a MCTTokenType using 
    1.45 + * MCTTokenType::OpenToken().
    1.46 + * 
    1.47 + * A token represents one instance of a particular kind of cryptographic module; 
    1.48 + * for instance, on a device with two WIMs, each WIM is a token. The token contains 
    1.49 + * several interfaces, representing particular kinds of functions supported by 
    1.50 + * the token (e.g. certificate management, key management, etc.) 
    1.51 + * 
    1.52 + * @since v7.0 
    1.53 + */
    1.54 +class MCTToken
    1.55 +	{
    1.56 + public:
    1.57 +  //Functions for opening an interface. 
    1.58 +  //The base class implements the reference counting then calls the corresponding pure virtual Do... methods	
    1.59 +	/** 
    1.60 +	 * Gets a token interface, or NULL if it's not supported by this token.
    1.61 +	 *
    1.62 +	 * This is an asynchronous request.
    1.63 +	 *
    1.64 +	 * @param aRequiredInterface	The UID of the interface that should be returned.
    1.65 +	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
    1.66 +	 * 								returned interface.
    1.67 +	 * @param aStatus				The request status object; contains the result of the 
    1.68 +	 * 								GetInterface() request when complete. Set to KErrCancel 
    1.69 +	 * 								if an outstanding request is cancelled. 
    1.70 +	 */
    1.71 +	IMPORT_C void GetInterface(TUid aRequiredInterface,
    1.72 +							  MCTTokenInterface*& aReturnedInterface, 
    1.73 +							  TRequestStatus& aStatus);
    1.74 +
    1.75 +	/** 
    1.76 +	 * Cancels an asynchronous GetInterface() operation.
    1.77 +	 *
    1.78 +	 * The operation completes with KErrCancel. 
    1.79 +	 */
    1.80 +	IMPORT_C void CancelGetInterface();
    1.81 +	
    1.82 +	/**
    1.83 +	 * Allows the client to add a reference to the token (for
    1.84 +	 * example, when a reference to a token is copied elsewhere).  
    1.85 +	 * 
    1.86 +	 * Does not need to be called if token is referenced through OpenToken().
    1.87 +	 */
    1.88 +	inline void AddRef();
    1.89 +	
    1.90 +	/** 
    1.91 +	 * Destroys the object.
    1.92 +	 *	
    1.93 +	 * The interface should be destroyed via this method as the destructor is protected.
    1.94 +	 *
    1.95 +	 * The token implements reference counting, with one count
    1.96 +	 * for itself and one for every opened interface. Once the count
    1.97 +	 * reaches 0, it releases its count with the token type.
    1.98 +	 */
    1.99 +	IMPORT_C void Release();
   1.100 +
   1.101 +	// Notification of token removal. The base class assumes the token is not removable, and so does nothing. Removable tokens must implement these functions.
   1.102 +	/** 
   1.103 +	 * Notifies the client when the token has been removed.
   1.104 +	 *	
   1.105 +	 * The base class assumes the token is not removable, and so does nothing. Removable 
   1.106 +	 * tokens must implement these functions.
   1.107 +	 *
   1.108 +	 * This is an asynchronous request.	
   1.109 +	 *
   1.110 +	 * @param aStatus	The request status object; contains the result of the 
   1.111 +	 * 					NotifyOnRemoval() request when complete. Set to KErrCancel 
   1.112 +	 * 					if an outstanding request is cancelled. 
   1.113 +	 */
   1.114 +	IMPORT_C virtual void NotifyOnRemoval(TRequestStatus& aStatus);
   1.115 +
   1.116 +	/** 
   1.117 +	 * Cancels an asynchronous NotifyOnRemoval() operation.
   1.118 +	 *
   1.119 +	 * The operation completes with KErrCancel. 
   1.120 +	 */
   1.121 +	IMPORT_C virtual void CancelNotify();
   1.122 +	
   1.123 +
   1.124 +	/** 
   1.125 +	 * Gets the associated token type.	
   1.126 +	 *
   1.127 +	 * @return	The associated token type. 
   1.128 +	 */
   1.129 +	virtual MCTTokenType& TokenType() = 0;
   1.130 +
   1.131 +	/** 
   1.132 +	 * Gets a label for the token.
   1.133 +	 *
   1.134 +	 * This should be the same as the descriptor returned by MCTTokenType::List().
   1.135 +	 *
   1.136 +	 * @return	The label to the token type. 
   1.137 +	 */
   1.138 +	virtual const TDesC& Label() = 0;
   1.139 +
   1.140 +	/** Available information strings for the token. */
   1.141 +	enum TTokenInformation
   1.142 +		{
   1.143 +		/** Version */
   1.144 +		EVersion,
   1.145 +		/** Serial number */
   1.146 +		ESerialNo,
   1.147 +		/** Manufacturer */
   1.148 +		EManufacturer
   1.149 +		};
   1.150 +	
   1.151 +	/** 
   1.152 +	 * Gets the token's handle.
   1.153 +	 *
   1.154 +	 * This can be used to identify a token to another process.
   1.155 +	 *
   1.156 +	 * See the documentation of TCTTokenHandle for an explanation of the use of token 
   1.157 +	 * handles.
   1.158 +	 *
   1.159 +	 * @return	The handle of the token. 
   1.160 +	 */
   1.161 +	virtual TCTTokenHandle Handle() = 0;
   1.162 +
   1.163 + protected:
   1.164 + 	 /** 
   1.165 + 	  * The destructor is protected so that users of the interface
   1.166 +	  * have to use the Release() function. 
   1.167 +	  */
   1.168 +	inline virtual ~MCTToken() = 0;
   1.169 +
   1.170 +	// Helper functions for the reference counting
   1.171 +	/** 
   1.172 +	 * Destroys the token object.
   1.173 +	 *
   1.174 +	 * This function is called when Release() has determined that the object is ready 
   1.175 +	 * to be destroyed.
   1.176 +	 *
   1.177 +	 * The default implementation just does a 'delete this', but classes can override 
   1.178 +	 * that if they want different behaviour.
   1.179 +	 *
   1.180 +	 * It should destroy the token; it MUST NOT release the token type, as Release() 
   1.181 +	 * will do that. 
   1.182 +	 */
   1.183 +	IMPORT_C virtual void DoRelease();
   1.184 +
   1.185 +	/** 
   1.186 +	 * Gets a reference to the variable used as a reference counter.
   1.187 +	 *
   1.188 +	 * The implementer should initialise this to 0. The value of the reference count 
   1.189 +	 * should be treated as opaque by the implementer.
   1.190 +	 *
   1.191 +	 * @return	A reference to the variable used as a reference counter. 
   1.192 +	 */
   1.193 +	virtual TInt& ReferenceCount() = 0;
   1.194 +	
   1.195 +	// Implementation of GetInterface functionality */
   1.196 +			
   1.197 +	/** 
   1.198 +	 * Implementation for getting a token interface.
   1.199 +	 *
   1.200 +	 * This is called by GetInterface().
   1.201 +	 *
   1.202 +	 * This is an asynchronous request.
   1.203 +	 *
   1.204 +	 * @see GetInterface
   1.205 +	 * @param aRequiredInterface	The UID of the interface that should be returned.
   1.206 +	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
   1.207 +	 * 								returned interface.
   1.208 +	 * @param aStatus				The request status object; contains the result of 
   1.209 +	 * 								the GetInterface() request when complete. Set to 
   1.210 +	 * 								KErrCancel if an outstanding request is cancelled. 
   1.211 +	 */
   1.212 +	virtual void DoGetInterface(TUid aRequiredInterface,
   1.213 +							  MCTTokenInterface*& aReturnedInterface, 
   1.214 +							  TRequestStatus& aStatus) = 0;
   1.215 +	/** 
   1.216 +	 * Implements an asynchronous CancelGetInterface() request.
   1.217 +	 * 
   1.218 +	 * @see	CancelGetInterface
   1.219 +	 * @return	ETrue if there is an token interface running; EFalse, otherwise. 
   1.220 +	 */
   1.221 +	virtual TBool DoCancelGetInterface() = 0;
   1.222 +	
   1.223 + private:
   1.224 +	// Used by the token object to increment the reference count
   1.225 +	void ObjectCreated();
   1.226 +	// Needed to allow MCTTokenObject to increment the reference count
   1.227 +	// of the token
   1.228 +	friend class MCTTokenObject;
   1.229 + public:
   1.230 +	/**
   1.231 +	 * Gets the specified information string about the token.
   1.232 +	 * The default implementation returns an empty descriptor.
   1.233 +	 */
   1.234 +	virtual const TDesC& Information(TTokenInformation aRequiredInformation) = 0;
   1.235 +	};
   1.236 +
   1.237 +/** 
   1.238 + * Destructor.
   1.239 + *
   1.240 + * Frees all resources owned by the object, prior to its destruction. 
   1.241 + */
   1.242 +inline MCTToken::~MCTToken()
   1.243 +	{
   1.244 +	}
   1.245 +
   1.246 +inline void MCTToken::AddRef()
   1.247 +	{
   1.248 +	++ReferenceCount();
   1.249 +	}
   1.250 +
   1.251 +#endif //__MCTTOKEN_H__