os/security/cryptomgmtlibs/cryptotokenfw/tframework/TestPlugin.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include <e32base.h>
sl@0
    24
#include <ecom/ecom.h>
sl@0
    25
#include <ecom/implementationproxy.h>
sl@0
    26
#include <ct.h>
sl@0
    27
#include "MTestInterface.h"
sl@0
    28
sl@0
    29
_LIT(KToken5Info, "Test Token 5");
sl@0
    30
_LIT(KToken6Info, "Test Token 6");
sl@0
    31
sl@0
    32
sl@0
    33
class CTestObject : public MTestObject
sl@0
    34
	{
sl@0
    35
public:
sl@0
    36
	CTestObject(MCTToken& aToken) : MTestObject(aToken), iToken(aToken) {};
sl@0
    37
sl@0
    38
	virtual const TDesC& Label() const;
sl@0
    39
	virtual MCTToken& Token() const;
sl@0
    40
	virtual TUid Type() const;
sl@0
    41
	virtual TCTTokenObjectHandle Handle() const;
sl@0
    42
sl@0
    43
private:
sl@0
    44
	MCTToken& iToken;
sl@0
    45
	};
sl@0
    46
sl@0
    47
class CTestInterface : public MTestInterface
sl@0
    48
	{
sl@0
    49
public:
sl@0
    50
	CTestInterface(const TDesC& aLabel, MCTToken& aToken)
sl@0
    51
			: iLabel(aLabel), iToken(aToken) {};
sl@0
    52
sl@0
    53
	virtual MCTToken& Token();
sl@0
    54
sl@0
    55
	virtual const TDesC& Label();
sl@0
    56
sl@0
    57
	MTestObject* ObjectL();
sl@0
    58
sl@0
    59
private:
sl@0
    60
	const TDesC& iLabel;
sl@0
    61
	MCTToken& iToken;
sl@0
    62
	};
sl@0
    63
sl@0
    64
class CTestToken : public CBase, public MCTToken
sl@0
    65
	{
sl@0
    66
public:
sl@0
    67
	CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType);
sl@0
    68
sl@0
    69
	virtual void DoGetInterface(TUid aRequiredInterface,
sl@0
    70
							  MCTTokenInterface*& aReturnedInterface, 
sl@0
    71
							  TRequestStatus& aStatus);
sl@0
    72
	virtual TBool DoCancelGetInterface();
sl@0
    73
sl@0
    74
	virtual const TDesC& Label();
sl@0
    75
sl@0
    76
	virtual MCTTokenType& TokenType();
sl@0
    77
sl@0
    78
	virtual TCTTokenHandle Handle();
sl@0
    79
	virtual const TDesC& Information(TTokenInformation aRequiredInformation);
sl@0
    80
protected:
sl@0
    81
	virtual TInt& ReferenceCount();
sl@0
    82
sl@0
    83
private:
sl@0
    84
	MCTTokenType& iTokenType;
sl@0
    85
	const TDesC& iLabel;
sl@0
    86
	TInt iCount;
sl@0
    87
	TBool iAsyncGetInterfaceRunning;
sl@0
    88
	};
sl@0
    89
sl@0
    90
CTestToken::CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType)
sl@0
    91
		: iTokenType(aTokenType), iLabel(aLabel)
sl@0
    92
	{
sl@0
    93
	}
sl@0
    94
sl@0
    95
const TDesC& CTestToken::Label()
sl@0
    96
	{
sl@0
    97
	return iLabel;
sl@0
    98
	}
sl@0
    99
sl@0
   100
const TDesC& CTestToken::Information(TTokenInformation aRequiredInformation)
sl@0
   101
	{
sl@0
   102
	_LIT(KVersion, "The Ultimate Version");
sl@0
   103
	_LIT(KSerial, "Serial No. 1");
sl@0
   104
	_LIT(KManufacturer, "ACME Corporation");
sl@0
   105
	switch (aRequiredInformation)
sl@0
   106
		{
sl@0
   107
	case EVersion:
sl@0
   108
		return KVersion;
sl@0
   109
	case ESerialNo:
sl@0
   110
		return KSerial;
sl@0
   111
	case EManufacturer:
sl@0
   112
	default:
sl@0
   113
		return KManufacturer;
sl@0
   114
		}
sl@0
   115
	}
sl@0
   116
sl@0
   117
MCTTokenType& CTestToken::TokenType()
sl@0
   118
	{
sl@0
   119
	return iTokenType;
sl@0
   120
	}
sl@0
   121
sl@0
   122
MCTToken& CTestInterface::Token()
sl@0
   123
	{
sl@0
   124
	return iToken;
sl@0
   125
	}
sl@0
   126
const TDesC& CTestInterface::Label()
sl@0
   127
	{
sl@0
   128
	return iLabel;
sl@0
   129
	}
sl@0
   130
sl@0
   131
MTestObject* CTestInterface::ObjectL()
sl@0
   132
	{
sl@0
   133
	return new (ELeave) CTestObject(Token());
sl@0
   134
	}
sl@0
   135
sl@0
   136
const TDesC& CTestObject::Label() const
sl@0
   137
	{
sl@0
   138
	return Token().Label();
sl@0
   139
	}
sl@0
   140
sl@0
   141
MCTToken& CTestObject::Token() const
sl@0
   142
	{
sl@0
   143
	return iToken;
sl@0
   144
	}
sl@0
   145
sl@0
   146
TUid CTestObject::Type() const
sl@0
   147
	{
sl@0
   148
	TUid uid = {0};
sl@0
   149
	return uid;
sl@0
   150
	}
sl@0
   151
sl@0
   152
TCTTokenObjectHandle CTestObject::Handle() const
sl@0
   153
	{
sl@0
   154
	return TCTTokenObjectHandle(Token().Handle(), 1);
sl@0
   155
	}
sl@0
   156
sl@0
   157
TCTTokenHandle CTestToken::Handle()
sl@0
   158
	{
sl@0
   159
	return TCTTokenHandle(TokenType().Type(), 1);
sl@0
   160
	}
sl@0
   161
sl@0
   162
void CTestToken::DoGetInterface(TUid aRequiredInterface,
sl@0
   163
							  MCTTokenInterface*& aReturnedInterface, 
sl@0
   164
							  TRequestStatus& aStatus)
sl@0
   165
	{
sl@0
   166
	// InterfaceC is returned. InterfaceB (actually anything else) is
sl@0
   167
	// used to test async behaviour and never returns anything.
sl@0
   168
	TUid uid = {0x101f4e52};
sl@0
   169
	if (aRequiredInterface != uid)
sl@0
   170
		{
sl@0
   171
		iAsyncGetInterfaceRunning = ETrue;
sl@0
   172
		return;
sl@0
   173
		}
sl@0
   174
	aReturnedInterface = new CTestInterface(iLabel, *this);
sl@0
   175
	TRequestStatus* r = &aStatus;
sl@0
   176
	if (aReturnedInterface)
sl@0
   177
		User::RequestComplete(r, KErrNone);
sl@0
   178
	else
sl@0
   179
		User::RequestComplete(r, KErrNoMemory);
sl@0
   180
	}
sl@0
   181
sl@0
   182
TBool CTestToken::DoCancelGetInterface()
sl@0
   183
	{
sl@0
   184
	if (iAsyncGetInterfaceRunning)
sl@0
   185
		{
sl@0
   186
		iAsyncGetInterfaceRunning = EFalse;
sl@0
   187
		return ETrue;
sl@0
   188
		}
sl@0
   189
	return EFalse;
sl@0
   190
	}
sl@0
   191
sl@0
   192
sl@0
   193
TInt& CTestToken::ReferenceCount()
sl@0
   194
	{
sl@0
   195
	return iCount;
sl@0
   196
	}
sl@0
   197
sl@0
   198
class CTokenTypeImplementation : public CCTTokenType
sl@0
   199
	{
sl@0
   200
public:
sl@0
   201
	static CTokenTypeImplementation* NewL5();
sl@0
   202
	static CTokenTypeImplementation* NewL6();
sl@0
   203
sl@0
   204
	virtual void List(RCPointerArray<HBufC>& aTokens, 
sl@0
   205
					  TRequestStatus& aStatus);
sl@0
   206
	virtual void CancelList();
sl@0
   207
	virtual void OpenToken(const TDesC& aTokenInfo, MCTToken*& aToken, 
sl@0
   208
						   TRequestStatus& aStatus);
sl@0
   209
	virtual void OpenToken(TCTTokenHandle aHandle, MCTToken*& aToken, 
sl@0
   210
						   TRequestStatus& aStatus);
sl@0
   211
	virtual void CancelOpenToken();
sl@0
   212
sl@0
   213
	virtual ~CTokenTypeImplementation();
sl@0
   214
protected:
sl@0
   215
	HBufC* iMyInfo;
sl@0
   216
	};
sl@0
   217
sl@0
   218
void CTokenTypeImplementation::List(RCPointerArray<HBufC>& aTokens, 
sl@0
   219
							   TRequestStatus& aStatus)
sl@0
   220
	{
sl@0
   221
	TRequestStatus* r = &aStatus;
sl@0
   222
	HBufC* name = iMyInfo->Alloc();
sl@0
   223
	if (name)
sl@0
   224
		User::RequestComplete(r, aTokens.Append(name));
sl@0
   225
	else
sl@0
   226
		User::RequestComplete(r, KErrNoMemory);
sl@0
   227
	}
sl@0
   228
sl@0
   229
void CTokenTypeImplementation::CancelList()
sl@0
   230
	{
sl@0
   231
	}
sl@0
   232
sl@0
   233
void CTokenTypeImplementation::OpenToken(const TDesC& /*aTokenInfo*/, MCTToken*& aToken,
sl@0
   234
						   TRequestStatus& aStatus)
sl@0
   235
	{
sl@0
   236
	aToken = new CTestToken(*iMyInfo, *this);
sl@0
   237
	TRequestStatus* r = &aStatus;
sl@0
   238
	User::RequestComplete(r, KErrNone);
sl@0
   239
	IncReferenceCount();
sl@0
   240
	}
sl@0
   241
sl@0
   242
void CTokenTypeImplementation::OpenToken(TCTTokenHandle /*aHandle*/,
sl@0
   243
										 MCTToken*& aToken,
sl@0
   244
										 TRequestStatus& aStatus)
sl@0
   245
	{
sl@0
   246
	aToken = new CTestToken(*iMyInfo, *this);
sl@0
   247
	TRequestStatus* r = &aStatus;
sl@0
   248
	User::RequestComplete(r, KErrNone);
sl@0
   249
	IncReferenceCount();
sl@0
   250
	}
sl@0
   251
sl@0
   252
void CTokenTypeImplementation::CancelOpenToken()
sl@0
   253
	{
sl@0
   254
	}
sl@0
   255
sl@0
   256
sl@0
   257
CTokenTypeImplementation::~CTokenTypeImplementation()
sl@0
   258
	{
sl@0
   259
	delete iMyInfo;
sl@0
   260
	}
sl@0
   261
sl@0
   262
CTokenTypeImplementation* CTokenTypeImplementation::NewL5()
sl@0
   263
	{
sl@0
   264
	CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation;
sl@0
   265
	CleanupStack::PushL(that);
sl@0
   266
	that->iMyInfo = KToken5Info().AllocL();
sl@0
   267
	CleanupStack::Pop(that);
sl@0
   268
	return that;
sl@0
   269
	}
sl@0
   270
sl@0
   271
CTokenTypeImplementation* CTokenTypeImplementation::NewL6()
sl@0
   272
	{
sl@0
   273
	CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation;
sl@0
   274
	CleanupStack::PushL(that);
sl@0
   275
	that->iMyInfo = KToken6Info().AllocL();
sl@0
   276
	CleanupStack::Pop(that);
sl@0
   277
	return that;
sl@0
   278
	}
sl@0
   279
sl@0
   280
const TImplementationProxy ImplementationTable[] = 
sl@0
   281
	{
sl@0
   282
		IMPLEMENTATION_PROXY_ENTRY(0x101F4E4D,	CTokenTypeImplementation::NewL5),
sl@0
   283
		IMPLEMENTATION_PROXY_ENTRY(0x101F4E4C,	CTokenTypeImplementation::NewL6),
sl@0
   284
	};
sl@0
   285
sl@0
   286
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
   287
	{
sl@0
   288
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
   289
sl@0
   290
	return ImplementationTable;
sl@0
   291
	}
sl@0
   292