epoc32/include/ct/mcttoken.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     5
* under the terms of the License "Eclipse Public License v1.0"
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description: 
williamr@2
    15
*
williamr@2
    16
*/
williamr@2
    17
williamr@2
    18
williamr@2
    19
/**
williamr@2
    20
 @file
williamr@4
    21
 @publishedAll
williamr@2
    22
 @released
williamr@2
    23
*/
williamr@2
    24
williamr@2
    25
#ifndef __MCTTOKEN_H__
williamr@2
    26
#define __MCTTOKEN_H__
williamr@2
    27
williamr@2
    28
#include <ct/tcttokenobjecthandle.h>
williamr@2
    29
#include <ct/mcttokenobject.h>
williamr@2
    30
#include <ct/tcttokenhandle.h>
williamr@2
    31
#include <ct/mcttokentype.h>
williamr@2
    32
williamr@2
    33
class MCTTokenInterface;
williamr@2
    34
williamr@2
    35
williamr@2
    36
/** 
williamr@2
    37
 * The base class for a token.
williamr@2
    38
 * 
williamr@2
    39
 * Token types must implement this class. It is created from a MCTTokenType using 
williamr@2
    40
 * MCTTokenType::OpenToken().
williamr@2
    41
 * 
williamr@2
    42
 * A token represents one instance of a particular kind of cryptographic module; 
williamr@2
    43
 * for instance, on a device with two WIMs, each WIM is a token. The token contains 
williamr@2
    44
 * several interfaces, representing particular kinds of functions supported by 
williamr@2
    45
 * the token (e.g. certificate management, key management, etc.) 
williamr@2
    46
 * 
williamr@2
    47
 * @since v7.0 
williamr@2
    48
 */
williamr@2
    49
class MCTToken
williamr@2
    50
	{
williamr@2
    51
 public:
williamr@2
    52
  //Functions for opening an interface. 
williamr@2
    53
  //The base class implements the reference counting then calls the corresponding pure virtual Do... methods	
williamr@2
    54
	/** 
williamr@2
    55
	 * Gets a token interface, or NULL if it's not supported by this token.
williamr@2
    56
	 *
williamr@2
    57
	 * This is an asynchronous request.
williamr@2
    58
	 *
williamr@2
    59
	 * @param aRequiredInterface	The UID of the interface that should be returned.
williamr@2
    60
	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
williamr@2
    61
	 * 								returned interface.
williamr@2
    62
	 * @param aStatus				The request status object; contains the result of the 
williamr@2
    63
	 * 								GetInterface() request when complete. Set to KErrCancel 
williamr@2
    64
	 * 								if an outstanding request is cancelled. 
williamr@2
    65
	 */
williamr@2
    66
	IMPORT_C void GetInterface(TUid aRequiredInterface,
williamr@2
    67
							  MCTTokenInterface*& aReturnedInterface, 
williamr@2
    68
							  TRequestStatus& aStatus);
williamr@2
    69
williamr@2
    70
	/** 
williamr@2
    71
	 * Cancels an asynchronous GetInterface() operation.
williamr@2
    72
	 *
williamr@2
    73
	 * The operation completes with KErrCancel. 
williamr@2
    74
	 */
williamr@2
    75
	IMPORT_C void CancelGetInterface();
williamr@2
    76
	
williamr@2
    77
	/**
williamr@2
    78
	 * Allows the client to add a reference to the token (for
williamr@2
    79
	 * example, when a reference to a token is copied elsewhere).  
williamr@2
    80
	 * 
williamr@2
    81
	 * Does not need to be called if token is referenced through OpenToken().
williamr@2
    82
	 */
williamr@2
    83
	inline void AddRef();
williamr@2
    84
	
williamr@2
    85
	/** 
williamr@2
    86
	 * Destroys the object.
williamr@2
    87
	 *	
williamr@2
    88
	 * The interface should be destroyed via this method as the destructor is protected.
williamr@2
    89
	 *
williamr@2
    90
	 * The token implements reference counting, with one count
williamr@2
    91
	 * for itself and one for every opened interface. Once the count
williamr@2
    92
	 * reaches 0, it releases its count with the token type.
williamr@2
    93
	 */
williamr@2
    94
	IMPORT_C void Release();
williamr@2
    95
williamr@2
    96
	// Notification of token removal. The base class assumes the token is not removable, and so does nothing. Removable tokens must implement these functions.
williamr@2
    97
	/** 
williamr@2
    98
	 * Notifies the client when the token has been removed.
williamr@2
    99
	 *	
williamr@2
   100
	 * The base class assumes the token is not removable, and so does nothing. Removable 
williamr@2
   101
	 * tokens must implement these functions.
williamr@2
   102
	 *
williamr@2
   103
	 * This is an asynchronous request.	
williamr@2
   104
	 *
williamr@2
   105
	 * @param aStatus	The request status object; contains the result of the 
williamr@2
   106
	 * 					NotifyOnRemoval() request when complete. Set to KErrCancel 
williamr@2
   107
	 * 					if an outstanding request is cancelled. 
williamr@2
   108
	 */
williamr@2
   109
	IMPORT_C virtual void NotifyOnRemoval(TRequestStatus& aStatus);
williamr@2
   110
williamr@2
   111
	/** 
williamr@2
   112
	 * Cancels an asynchronous NotifyOnRemoval() operation.
williamr@2
   113
	 *
williamr@2
   114
	 * The operation completes with KErrCancel. 
williamr@2
   115
	 */
williamr@2
   116
	IMPORT_C virtual void CancelNotify();
williamr@2
   117
	
williamr@2
   118
williamr@2
   119
	/** 
williamr@2
   120
	 * Gets the associated token type.	
williamr@2
   121
	 *
williamr@2
   122
	 * @return	The associated token type. 
williamr@2
   123
	 */
williamr@2
   124
	virtual MCTTokenType& TokenType() = 0;
williamr@2
   125
williamr@2
   126
	/** 
williamr@2
   127
	 * Gets a label for the token.
williamr@2
   128
	 *
williamr@2
   129
	 * This should be the same as the descriptor returned by MCTTokenType::List().
williamr@2
   130
	 *
williamr@2
   131
	 * @return	The label to the token type. 
williamr@2
   132
	 */
williamr@2
   133
	virtual const TDesC& Label() = 0;
williamr@2
   134
williamr@2
   135
	/** Available information strings for the token. */
williamr@2
   136
	enum TTokenInformation
williamr@2
   137
		{
williamr@2
   138
		/** Version */
williamr@2
   139
		EVersion,
williamr@2
   140
		/** Serial number */
williamr@2
   141
		ESerialNo,
williamr@2
   142
		/** Manufacturer */
williamr@2
   143
		EManufacturer
williamr@2
   144
		};
williamr@2
   145
	
williamr@2
   146
	/** 
williamr@2
   147
	 * Gets the token's handle.
williamr@2
   148
	 *
williamr@2
   149
	 * This can be used to identify a token to another process.
williamr@2
   150
	 *
williamr@2
   151
	 * See the documentation of TCTTokenHandle for an explanation of the use of token 
williamr@2
   152
	 * handles.
williamr@2
   153
	 *
williamr@2
   154
	 * @return	The handle of the token. 
williamr@2
   155
	 */
williamr@2
   156
	virtual TCTTokenHandle Handle() = 0;
williamr@2
   157
williamr@2
   158
 protected:
williamr@2
   159
 	 /** 
williamr@2
   160
 	  * The destructor is protected so that users of the interface
williamr@2
   161
	  * have to use the Release() function. 
williamr@2
   162
	  */
williamr@2
   163
	inline virtual ~MCTToken() = 0;
williamr@2
   164
williamr@2
   165
	// Helper functions for the reference counting
williamr@2
   166
	/** 
williamr@2
   167
	 * Destroys the token object.
williamr@2
   168
	 *
williamr@2
   169
	 * This function is called when Release() has determined that the object is ready 
williamr@2
   170
	 * to be destroyed.
williamr@2
   171
	 *
williamr@2
   172
	 * The default implementation just does a 'delete this', but classes can override 
williamr@2
   173
	 * that if they want different behaviour.
williamr@2
   174
	 *
williamr@2
   175
	 * It should destroy the token; it MUST NOT release the token type, as Release() 
williamr@2
   176
	 * will do that. 
williamr@2
   177
	 */
williamr@2
   178
	IMPORT_C virtual void DoRelease();
williamr@2
   179
williamr@2
   180
	/** 
williamr@2
   181
	 * Gets a reference to the variable used as a reference counter.
williamr@2
   182
	 *
williamr@2
   183
	 * The implementer should initialise this to 0. The value of the reference count 
williamr@2
   184
	 * should be treated as opaque by the implementer.
williamr@2
   185
	 *
williamr@2
   186
	 * @return	A reference to the variable used as a reference counter. 
williamr@2
   187
	 */
williamr@2
   188
	virtual TInt& ReferenceCount() = 0;
williamr@2
   189
	
williamr@2
   190
	// Implementation of GetInterface functionality */
williamr@2
   191
			
williamr@2
   192
	/** 
williamr@2
   193
	 * Implementation for getting a token interface.
williamr@2
   194
	 *
williamr@2
   195
	 * This is called by GetInterface().
williamr@2
   196
	 *
williamr@2
   197
	 * This is an asynchronous request.
williamr@2
   198
	 *
williamr@2
   199
	 * @see GetInterface
williamr@2
   200
	 * @param aRequiredInterface	The UID of the interface that should be returned.
williamr@2
   201
	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
williamr@2
   202
	 * 								returned interface.
williamr@2
   203
	 * @param aStatus				The request status object; contains the result of 
williamr@2
   204
	 * 								the GetInterface() request when complete. Set to 
williamr@2
   205
	 * 								KErrCancel if an outstanding request is cancelled. 
williamr@2
   206
	 */
williamr@2
   207
	virtual void DoGetInterface(TUid aRequiredInterface,
williamr@2
   208
							  MCTTokenInterface*& aReturnedInterface, 
williamr@2
   209
							  TRequestStatus& aStatus) = 0;
williamr@2
   210
	/** 
williamr@2
   211
	 * Implements an asynchronous CancelGetInterface() request.
williamr@2
   212
	 * 
williamr@2
   213
	 * @see	CancelGetInterface
williamr@2
   214
	 * @return	ETrue if there is an token interface running; EFalse, otherwise. 
williamr@2
   215
	 */
williamr@2
   216
	virtual TBool DoCancelGetInterface() = 0;
williamr@2
   217
	
williamr@2
   218
 private:
williamr@2
   219
	// Used by the token object to increment the reference count
williamr@2
   220
	void ObjectCreated();
williamr@2
   221
	// Needed to allow MCTTokenObject to increment the reference count
williamr@2
   222
	// of the token
williamr@2
   223
	friend class MCTTokenObject;
williamr@2
   224
 public:
williamr@2
   225
	/**
williamr@2
   226
	 * Gets the specified information string about the token.
williamr@2
   227
	 * The default implementation returns an empty descriptor.
williamr@2
   228
	 */
williamr@2
   229
	virtual const TDesC& Information(TTokenInformation aRequiredInformation) = 0;
williamr@2
   230
	};
williamr@2
   231
williamr@2
   232
/** 
williamr@2
   233
 * Destructor.
williamr@2
   234
 *
williamr@2
   235
 * Frees all resources owned by the object, prior to its destruction. 
williamr@2
   236
 */
williamr@2
   237
inline MCTToken::~MCTToken()
williamr@2
   238
	{
williamr@2
   239
	}
williamr@2
   240
williamr@2
   241
inline void MCTToken::AddRef()
williamr@2
   242
	{
williamr@2
   243
	++ReferenceCount();
williamr@2
   244
	}
williamr@2
   245
williamr@2
   246
#endif //__MCTTOKEN_H__