sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "MTestInterface.h" sl@0: sl@0: _LIT(KToken5Info, "Test Token 5"); sl@0: _LIT(KToken6Info, "Test Token 6"); sl@0: sl@0: sl@0: class CTestObject : public MTestObject sl@0: { sl@0: public: sl@0: CTestObject(MCTToken& aToken) : MTestObject(aToken), iToken(aToken) {}; sl@0: sl@0: virtual const TDesC& Label() const; sl@0: virtual MCTToken& Token() const; sl@0: virtual TUid Type() const; sl@0: virtual TCTTokenObjectHandle Handle() const; sl@0: sl@0: private: sl@0: MCTToken& iToken; sl@0: }; sl@0: sl@0: class CTestInterface : public MTestInterface sl@0: { sl@0: public: sl@0: CTestInterface(const TDesC& aLabel, MCTToken& aToken) sl@0: : iLabel(aLabel), iToken(aToken) {}; sl@0: sl@0: virtual MCTToken& Token(); sl@0: sl@0: virtual const TDesC& Label(); sl@0: sl@0: MTestObject* ObjectL(); sl@0: sl@0: private: sl@0: const TDesC& iLabel; sl@0: MCTToken& iToken; sl@0: }; sl@0: sl@0: class CTestToken : public CBase, public MCTToken sl@0: { sl@0: public: sl@0: CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType); sl@0: sl@0: virtual void DoGetInterface(TUid aRequiredInterface, sl@0: MCTTokenInterface*& aReturnedInterface, sl@0: TRequestStatus& aStatus); sl@0: virtual TBool DoCancelGetInterface(); sl@0: sl@0: virtual const TDesC& Label(); sl@0: sl@0: virtual MCTTokenType& TokenType(); sl@0: sl@0: virtual TCTTokenHandle Handle(); sl@0: virtual const TDesC& Information(TTokenInformation aRequiredInformation); sl@0: protected: sl@0: virtual TInt& ReferenceCount(); sl@0: sl@0: private: sl@0: MCTTokenType& iTokenType; sl@0: const TDesC& iLabel; sl@0: TInt iCount; sl@0: TBool iAsyncGetInterfaceRunning; sl@0: }; sl@0: sl@0: CTestToken::CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType) sl@0: : iTokenType(aTokenType), iLabel(aLabel) sl@0: { sl@0: } sl@0: sl@0: const TDesC& CTestToken::Label() sl@0: { sl@0: return iLabel; sl@0: } sl@0: sl@0: const TDesC& CTestToken::Information(TTokenInformation aRequiredInformation) sl@0: { sl@0: _LIT(KVersion, "The Ultimate Version"); sl@0: _LIT(KSerial, "Serial No. 1"); sl@0: _LIT(KManufacturer, "ACME Corporation"); sl@0: switch (aRequiredInformation) sl@0: { sl@0: case EVersion: sl@0: return KVersion; sl@0: case ESerialNo: sl@0: return KSerial; sl@0: case EManufacturer: sl@0: default: sl@0: return KManufacturer; sl@0: } sl@0: } sl@0: sl@0: MCTTokenType& CTestToken::TokenType() sl@0: { sl@0: return iTokenType; sl@0: } sl@0: sl@0: MCTToken& CTestInterface::Token() sl@0: { sl@0: return iToken; sl@0: } sl@0: const TDesC& CTestInterface::Label() sl@0: { sl@0: return iLabel; sl@0: } sl@0: sl@0: MTestObject* CTestInterface::ObjectL() sl@0: { sl@0: return new (ELeave) CTestObject(Token()); sl@0: } sl@0: sl@0: const TDesC& CTestObject::Label() const sl@0: { sl@0: return Token().Label(); sl@0: } sl@0: sl@0: MCTToken& CTestObject::Token() const sl@0: { sl@0: return iToken; sl@0: } sl@0: sl@0: TUid CTestObject::Type() const sl@0: { sl@0: TUid uid = {0}; sl@0: return uid; sl@0: } sl@0: sl@0: TCTTokenObjectHandle CTestObject::Handle() const sl@0: { sl@0: return TCTTokenObjectHandle(Token().Handle(), 1); sl@0: } sl@0: sl@0: TCTTokenHandle CTestToken::Handle() sl@0: { sl@0: return TCTTokenHandle(TokenType().Type(), 1); sl@0: } sl@0: sl@0: void CTestToken::DoGetInterface(TUid aRequiredInterface, sl@0: MCTTokenInterface*& aReturnedInterface, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: // InterfaceC is returned. InterfaceB (actually anything else) is sl@0: // used to test async behaviour and never returns anything. sl@0: TUid uid = {0x101f4e52}; sl@0: if (aRequiredInterface != uid) sl@0: { sl@0: iAsyncGetInterfaceRunning = ETrue; sl@0: return; sl@0: } sl@0: aReturnedInterface = new CTestInterface(iLabel, *this); sl@0: TRequestStatus* r = &aStatus; sl@0: if (aReturnedInterface) sl@0: User::RequestComplete(r, KErrNone); sl@0: else sl@0: User::RequestComplete(r, KErrNoMemory); sl@0: } sl@0: sl@0: TBool CTestToken::DoCancelGetInterface() sl@0: { sl@0: if (iAsyncGetInterfaceRunning) sl@0: { sl@0: iAsyncGetInterfaceRunning = EFalse; sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: sl@0: TInt& CTestToken::ReferenceCount() sl@0: { sl@0: return iCount; sl@0: } sl@0: sl@0: class CTokenTypeImplementation : public CCTTokenType sl@0: { sl@0: public: sl@0: static CTokenTypeImplementation* NewL5(); sl@0: static CTokenTypeImplementation* NewL6(); sl@0: sl@0: virtual void List(RCPointerArray& aTokens, sl@0: TRequestStatus& aStatus); sl@0: virtual void CancelList(); sl@0: virtual void OpenToken(const TDesC& aTokenInfo, MCTToken*& aToken, sl@0: TRequestStatus& aStatus); sl@0: virtual void OpenToken(TCTTokenHandle aHandle, MCTToken*& aToken, sl@0: TRequestStatus& aStatus); sl@0: virtual void CancelOpenToken(); sl@0: sl@0: virtual ~CTokenTypeImplementation(); sl@0: protected: sl@0: HBufC* iMyInfo; sl@0: }; sl@0: sl@0: void CTokenTypeImplementation::List(RCPointerArray& aTokens, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* r = &aStatus; sl@0: HBufC* name = iMyInfo->Alloc(); sl@0: if (name) sl@0: User::RequestComplete(r, aTokens.Append(name)); sl@0: else sl@0: User::RequestComplete(r, KErrNoMemory); sl@0: } sl@0: sl@0: void CTokenTypeImplementation::CancelList() sl@0: { sl@0: } sl@0: sl@0: void CTokenTypeImplementation::OpenToken(const TDesC& /*aTokenInfo*/, MCTToken*& aToken, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: aToken = new CTestToken(*iMyInfo, *this); sl@0: TRequestStatus* r = &aStatus; sl@0: User::RequestComplete(r, KErrNone); sl@0: IncReferenceCount(); sl@0: } sl@0: sl@0: void CTokenTypeImplementation::OpenToken(TCTTokenHandle /*aHandle*/, sl@0: MCTToken*& aToken, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: aToken = new CTestToken(*iMyInfo, *this); sl@0: TRequestStatus* r = &aStatus; sl@0: User::RequestComplete(r, KErrNone); sl@0: IncReferenceCount(); sl@0: } sl@0: sl@0: void CTokenTypeImplementation::CancelOpenToken() sl@0: { sl@0: } sl@0: sl@0: sl@0: CTokenTypeImplementation::~CTokenTypeImplementation() sl@0: { sl@0: delete iMyInfo; sl@0: } sl@0: sl@0: CTokenTypeImplementation* CTokenTypeImplementation::NewL5() sl@0: { sl@0: CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation; sl@0: CleanupStack::PushL(that); sl@0: that->iMyInfo = KToken5Info().AllocL(); sl@0: CleanupStack::Pop(that); sl@0: return that; sl@0: } sl@0: sl@0: CTokenTypeImplementation* CTokenTypeImplementation::NewL6() sl@0: { sl@0: CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation; sl@0: CleanupStack::PushL(that); sl@0: that->iMyInfo = KToken6Info().AllocL(); sl@0: CleanupStack::Pop(that); sl@0: return that; sl@0: } sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: IMPLEMENTATION_PROXY_ENTRY(0x101F4E4D, CTokenTypeImplementation::NewL5), sl@0: IMPLEMENTATION_PROXY_ENTRY(0x101F4E4C, CTokenTypeImplementation::NewL6), sl@0: }; sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: sl@0: return ImplementationTable; sl@0: } sl@0: