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