Update contrib.
2 * Copyright (c) 2005-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.
24 #include <ecom/ecom.h>
25 #include <ecom/implementationproxy.h>
27 #include "MTestInterface.h"
29 _LIT(KToken5Info, "Test Token 5");
30 _LIT(KToken6Info, "Test Token 6");
33 class CTestObject : public MTestObject
36 CTestObject(MCTToken& aToken) : MTestObject(aToken), iToken(aToken) {};
38 virtual const TDesC& Label() const;
39 virtual MCTToken& Token() const;
40 virtual TUid Type() const;
41 virtual TCTTokenObjectHandle Handle() const;
47 class CTestInterface : public MTestInterface
50 CTestInterface(const TDesC& aLabel, MCTToken& aToken)
51 : iLabel(aLabel), iToken(aToken) {};
53 virtual MCTToken& Token();
55 virtual const TDesC& Label();
57 MTestObject* ObjectL();
64 class CTestToken : public CBase, public MCTToken
67 CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType);
69 virtual void DoGetInterface(TUid aRequiredInterface,
70 MCTTokenInterface*& aReturnedInterface,
71 TRequestStatus& aStatus);
72 virtual TBool DoCancelGetInterface();
74 virtual const TDesC& Label();
76 virtual MCTTokenType& TokenType();
78 virtual TCTTokenHandle Handle();
79 virtual const TDesC& Information(TTokenInformation aRequiredInformation);
81 virtual TInt& ReferenceCount();
84 MCTTokenType& iTokenType;
87 TBool iAsyncGetInterfaceRunning;
90 CTestToken::CTestToken(const TDesC& aLabel, MCTTokenType& aTokenType)
91 : iTokenType(aTokenType), iLabel(aLabel)
95 const TDesC& CTestToken::Label()
100 const TDesC& CTestToken::Information(TTokenInformation aRequiredInformation)
102 _LIT(KVersion, "The Ultimate Version");
103 _LIT(KSerial, "Serial No. 1");
104 _LIT(KManufacturer, "ACME Corporation");
105 switch (aRequiredInformation)
113 return KManufacturer;
117 MCTTokenType& CTestToken::TokenType()
122 MCTToken& CTestInterface::Token()
126 const TDesC& CTestInterface::Label()
131 MTestObject* CTestInterface::ObjectL()
133 return new (ELeave) CTestObject(Token());
136 const TDesC& CTestObject::Label() const
138 return Token().Label();
141 MCTToken& CTestObject::Token() const
146 TUid CTestObject::Type() const
152 TCTTokenObjectHandle CTestObject::Handle() const
154 return TCTTokenObjectHandle(Token().Handle(), 1);
157 TCTTokenHandle CTestToken::Handle()
159 return TCTTokenHandle(TokenType().Type(), 1);
162 void CTestToken::DoGetInterface(TUid aRequiredInterface,
163 MCTTokenInterface*& aReturnedInterface,
164 TRequestStatus& aStatus)
166 // InterfaceC is returned. InterfaceB (actually anything else) is
167 // used to test async behaviour and never returns anything.
168 TUid uid = {0x101f4e52};
169 if (aRequiredInterface != uid)
171 iAsyncGetInterfaceRunning = ETrue;
174 aReturnedInterface = new CTestInterface(iLabel, *this);
175 TRequestStatus* r = &aStatus;
176 if (aReturnedInterface)
177 User::RequestComplete(r, KErrNone);
179 User::RequestComplete(r, KErrNoMemory);
182 TBool CTestToken::DoCancelGetInterface()
184 if (iAsyncGetInterfaceRunning)
186 iAsyncGetInterfaceRunning = EFalse;
193 TInt& CTestToken::ReferenceCount()
198 class CTokenTypeImplementation : public CCTTokenType
201 static CTokenTypeImplementation* NewL5();
202 static CTokenTypeImplementation* NewL6();
204 virtual void List(RCPointerArray<HBufC>& aTokens,
205 TRequestStatus& aStatus);
206 virtual void CancelList();
207 virtual void OpenToken(const TDesC& aTokenInfo, MCTToken*& aToken,
208 TRequestStatus& aStatus);
209 virtual void OpenToken(TCTTokenHandle aHandle, MCTToken*& aToken,
210 TRequestStatus& aStatus);
211 virtual void CancelOpenToken();
213 virtual ~CTokenTypeImplementation();
218 void CTokenTypeImplementation::List(RCPointerArray<HBufC>& aTokens,
219 TRequestStatus& aStatus)
221 TRequestStatus* r = &aStatus;
222 HBufC* name = iMyInfo->Alloc();
224 User::RequestComplete(r, aTokens.Append(name));
226 User::RequestComplete(r, KErrNoMemory);
229 void CTokenTypeImplementation::CancelList()
233 void CTokenTypeImplementation::OpenToken(const TDesC& /*aTokenInfo*/, MCTToken*& aToken,
234 TRequestStatus& aStatus)
236 aToken = new CTestToken(*iMyInfo, *this);
237 TRequestStatus* r = &aStatus;
238 User::RequestComplete(r, KErrNone);
242 void CTokenTypeImplementation::OpenToken(TCTTokenHandle /*aHandle*/,
244 TRequestStatus& aStatus)
246 aToken = new CTestToken(*iMyInfo, *this);
247 TRequestStatus* r = &aStatus;
248 User::RequestComplete(r, KErrNone);
252 void CTokenTypeImplementation::CancelOpenToken()
257 CTokenTypeImplementation::~CTokenTypeImplementation()
262 CTokenTypeImplementation* CTokenTypeImplementation::NewL5()
264 CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation;
265 CleanupStack::PushL(that);
266 that->iMyInfo = KToken5Info().AllocL();
267 CleanupStack::Pop(that);
271 CTokenTypeImplementation* CTokenTypeImplementation::NewL6()
273 CTokenTypeImplementation* that = new (ELeave) CTokenTypeImplementation;
274 CleanupStack::PushL(that);
275 that->iMyInfo = KToken6Info().AllocL();
276 CleanupStack::Pop(that);
280 const TImplementationProxy ImplementationTable[] =
282 IMPLEMENTATION_PROXY_ENTRY(0x101F4E4D, CTokenTypeImplementation::NewL5),
283 IMPLEMENTATION_PROXY_ENTRY(0x101F4E4C, CTokenTypeImplementation::NewL6),
286 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
288 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
290 return ImplementationTable;