2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
27 #ifndef __MCTTOKEN_H__
28 #define __MCTTOKEN_H__
30 #include <ct/tcttokenobjecthandle.h>
31 #include <ct/mcttokenobject.h>
32 #include <ct/tcttokenhandle.h>
33 #include <ct/mcttokentype.h>
35 class MCTTokenInterface;
39 * The base class for a token.
41 * Token types must implement this class. It is created from a MCTTokenType using
42 * MCTTokenType::OpenToken().
44 * A token represents one instance of a particular kind of cryptographic module;
45 * for instance, on a device with two WIMs, each WIM is a token. The token contains
46 * several interfaces, representing particular kinds of functions supported by
47 * the token (e.g. certificate management, key management, etc.)
54 //Functions for opening an interface.
55 //The base class implements the reference counting then calls the corresponding pure virtual Do... methods
57 * Gets a token interface, or NULL if it's not supported by this token.
59 * This is an asynchronous request.
61 * @param aRequiredInterface The UID of the interface that should be returned.
62 * @param aReturnedInterface On success, this will be set to a pointer to the
64 * @param aStatus The request status object; contains the result of the
65 * GetInterface() request when complete. Set to KErrCancel
66 * if an outstanding request is cancelled.
68 IMPORT_C void GetInterface(TUid aRequiredInterface,
69 MCTTokenInterface*& aReturnedInterface,
70 TRequestStatus& aStatus);
73 * Cancels an asynchronous GetInterface() operation.
75 * The operation completes with KErrCancel.
77 IMPORT_C void CancelGetInterface();
80 * Allows the client to add a reference to the token (for
81 * example, when a reference to a token is copied elsewhere).
83 * Does not need to be called if token is referenced through OpenToken().
88 * Destroys the object.
90 * The interface should be destroyed via this method as the destructor is protected.
92 * The token implements reference counting, with one count
93 * for itself and one for every opened interface. Once the count
94 * reaches 0, it releases its count with the token type.
96 IMPORT_C void Release();
98 // Notification of token removal. The base class assumes the token is not removable, and so does nothing. Removable tokens must implement these functions.
100 * Notifies the client when the token has been removed.
102 * The base class assumes the token is not removable, and so does nothing. Removable
103 * tokens must implement these functions.
105 * This is an asynchronous request.
107 * @param aStatus The request status object; contains the result of the
108 * NotifyOnRemoval() request when complete. Set to KErrCancel
109 * if an outstanding request is cancelled.
111 IMPORT_C virtual void NotifyOnRemoval(TRequestStatus& aStatus);
114 * Cancels an asynchronous NotifyOnRemoval() operation.
116 * The operation completes with KErrCancel.
118 IMPORT_C virtual void CancelNotify();
122 * Gets the associated token type.
124 * @return The associated token type.
126 virtual MCTTokenType& TokenType() = 0;
129 * Gets a label for the token.
131 * This should be the same as the descriptor returned by MCTTokenType::List().
133 * @return The label to the token type.
135 virtual const TDesC& Label() = 0;
137 /** Available information strings for the token. */
138 enum TTokenInformation
149 * Gets the token's handle.
151 * This can be used to identify a token to another process.
153 * See the documentation of TCTTokenHandle for an explanation of the use of token
156 * @return The handle of the token.
158 virtual TCTTokenHandle Handle() = 0;
162 * The destructor is protected so that users of the interface
163 * have to use the Release() function.
165 inline virtual ~MCTToken() = 0;
167 // Helper functions for the reference counting
169 * Destroys the token object.
171 * This function is called when Release() has determined that the object is ready
174 * The default implementation just does a 'delete this', but classes can override
175 * that if they want different behaviour.
177 * It should destroy the token; it MUST NOT release the token type, as Release()
180 IMPORT_C virtual void DoRelease();
183 * Gets a reference to the variable used as a reference counter.
185 * The implementer should initialise this to 0. The value of the reference count
186 * should be treated as opaque by the implementer.
188 * @return A reference to the variable used as a reference counter.
190 virtual TInt& ReferenceCount() = 0;
192 // Implementation of GetInterface functionality */
195 * Implementation for getting a token interface.
197 * This is called by GetInterface().
199 * This is an asynchronous request.
202 * @param aRequiredInterface The UID of the interface that should be returned.
203 * @param aReturnedInterface On success, this will be set to a pointer to the
204 * returned interface.
205 * @param aStatus The request status object; contains the result of
206 * the GetInterface() request when complete. Set to
207 * KErrCancel if an outstanding request is cancelled.
209 virtual void DoGetInterface(TUid aRequiredInterface,
210 MCTTokenInterface*& aReturnedInterface,
211 TRequestStatus& aStatus) = 0;
213 * Implements an asynchronous CancelGetInterface() request.
215 * @see CancelGetInterface
216 * @return ETrue if there is an token interface running; EFalse, otherwise.
218 virtual TBool DoCancelGetInterface() = 0;
221 // Used by the token object to increment the reference count
222 void ObjectCreated();
223 // Needed to allow MCTTokenObject to increment the reference count
225 friend class MCTTokenObject;
228 * Gets the specified information string about the token.
229 * The default implementation returns an empty descriptor.
231 virtual const TDesC& Information(TTokenInformation aRequiredInformation) = 0;
237 * Frees all resources owned by the object, prior to its destruction.
239 inline MCTToken::~MCTToken()
243 inline void MCTToken::AddRef()
248 #endif //__MCTTOKEN_H__