sl@0: // Copyright (c) 2007-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 "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: // The implementation of a classe
sl@0: // to be provided by ECom.
sl@0: // 1. Using the CExampleInterface class as a base.
sl@0: // 
sl@0: //
sl@0: 
sl@0: #include "Interface.h"
sl@0: #include "ImplementationProxy.h"
sl@0: #include "TestUtilities.h"	// For __FILE__LINE__
sl@0: 
sl@0: // ____________________________________________________________________________
sl@0: // 
sl@0: /**	Intended usage: This class implements the functionality promised by 
sl@0: 	the CExampleInterface defintion class. It does little apart from provides a test instance
sl@0: 	which may be retrieved and run for testing purposes.
sl@0: 	Its resolution is based upon its registered default data string that
sl@0: 	advertises this class as being able to handle 'text\wml' data.
sl@0: 	@since 7.0
sl@0:  */
sl@0: class CImplementationClassOne : public CExampleInterface
sl@0: {
sl@0: // Methods
sl@0: public:
sl@0: /**
sl@0: 	@fn				NewL(TAny* aInitParams)
sl@0: 	Intended Usage	: Standardised safe construction which leaves nothing the cleanup stack.
sl@0: 	Error Condition	: Leaves with error code.
sl@0: 	@leave          	KErrNoMemory.
sl@0: 	@since			7.0
sl@0: 	@param			aInitParams The parameter struct used for initialising this object
sl@0: 	@return			CImplementationClassOne* The class instance.
sl@0: 	@pre 			None
sl@0: 	@post			CImplementationClassOne has been constructed,
sl@0: 					and initialised.
sl@0:  */
sl@0: 	static CImplementationClassOne* NewL(TAny* aInitParams);
sl@0: 
sl@0: /**
sl@0: 	@fn				~CImplementationClassOne()
sl@0: 	Intended Usage	: Default Destructor	
sl@0: 	Error Condition	: None	
sl@0: 	@since			7.0
sl@0: 	@pre 			CImplementationClassOne has been constructed
sl@0: 	@post			CImplementationClassOne has been completely destroyed.
sl@0:  */
sl@0: 	virtual ~CImplementationClassOne();
sl@0: 
sl@0: /**
sl@0: 	@fn				DoMethodL()
sl@0: 	Intended Usage	: Overload of the pure interface method
sl@0: 					Representative of a method provided on 
sl@0: 					the interface by the interface definer.
sl@0: 	Error Condition	: Leaves with an error code.
sl@0: 	@leave  		KErrNoMemory, KErrNotSupported.
sl@0: 	@since			7.0
sl@0: 	@return			None
sl@0: 	@pre 			CImplementationClassOne has been constructed
sl@0: 	@post			Unspecified
sl@0:  */	
sl@0: 	void DoMethodL();
sl@0: 
sl@0: /**
sl@0: 	@fn				FireAndForget()
sl@0: 	Intended Usage	: Overload of the pure interface method
sl@0: 					asynchronous function which 
sl@0: 					an interface definer could specify.  
sl@0: 					It allows the client to call the function in the knowledge 
sl@0: 					that the object will commit suicide when the 
sl@0: 					function completes.
sl@0: 	Error Condition	: None.
sl@0: 	@since			7.0
sl@0: 	@return			TInt KErrNone for success.
sl@0: 	@pre 			CImplementationClassOne has been constructed
sl@0: 	@post			Unspecified
sl@0:  */
sl@0: 	TInt FireAndForget();
sl@0: 
sl@0:  /**
sl@0: 	@fn				ImplId()
sl@0: 	Intended Usage	: To verify the object returned by ECOM.
sl@0: 	Error Condition	: None.
sl@0: 	@since			7.0s
sl@0: 	@return			TUid (ECOM's Implementation Uid for this class.)
sl@0: 	@pre 			CImplementationClassThree has been constructed
sl@0: 	@post			Unspecified
sl@0:  */
sl@0: 	TUid ImplId();
sl@0: 
sl@0: private:
sl@0: /**
sl@0: 	@fn				CImplementationClassOne()
sl@0: 	Intended Usage	: Default Constructor : usable only by derived classes	
sl@0: 	Error Condition	: None	
sl@0: 	@since			7.0
sl@0: 	@pre 			None
sl@0: 	@post			CImplementationClassOne has been constructed
sl@0:  */
sl@0: 	CImplementationClassOne();
sl@0: 
sl@0: /**
sl@0: 	@fn				ConstructL(TAny* aInitParams)
sl@0: 	Intended Usage	: Completes the safe construction of the CImplementationClassOne object
sl@0: 	Error Condition	: Leaves with the error code.	
sl@0: 	@leave          	KErrNoMemory.	
sl@0: 	@since			7.0
sl@0: 	@param			aInitParams The parameter struct used for initialising this object
sl@0: 	@pre 			CImplementationClassOne has been constructed
sl@0: 	@post			CImplementationClassOne has been fully initialised.
sl@0:  */
sl@0: 	void ConstructL(TAny* aInitParams);
sl@0: 
sl@0: // Provide the CActive overloads
sl@0: 	void RunL();
sl@0: 	void DoCancel();
sl@0: 	TInt RunError(TInt aError);
sl@0: 
sl@0: private:
sl@0: /** A place for allocating some memory in the ConstructL */
sl@0: 	HBufC*	iInternalDescriptor;
sl@0: /** An int to be stored in TLS to test its useage */	
sl@0: 	TInt	iTLSInt;
sl@0: 
sl@0: };  // End of CImplementationClassOne definition
sl@0: 
sl@0: // __________________________________________________________________________
sl@0: // Implementation
sl@0: 
sl@0: CImplementationClassOne* CImplementationClassOne::NewL(TAny* aInitParams)
sl@0: // Intended Usage	: Safe construction which leaves nothing upon the cleanup stack	
sl@0: // Error Condition	: Will leave with an appropriate error code	
sl@0: // Dependencies	: CBase
sl@0: // @param			" "
sl@0: // @return			CImplementationClassOne* a pointer to the fully instantiated CImplementationClassOne object
sl@0: // @pre 			None
sl@0: // @post			The object has been fully instantiated
sl@0: // Static member
sl@0: 	{
sl@0: 	CImplementationClassOne* self=new(ELeave) CImplementationClassOne();  // calls c'tor
sl@0: 	CleanupStack::PushL(self);	// Make the construction safe by using the cleanup stack
sl@0: 	self->ConstructL(aInitParams); // Complete the 'construction'.
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: CImplementationClassOne::~CImplementationClassOne()
sl@0: // Default virtual d'tor
sl@0: 	{
sl@0: 	delete iInternalDescriptor;
sl@0: 	}
sl@0: 
sl@0: CImplementationClassOne::CImplementationClassOne()
sl@0: // Default c'tor for use by derived and 
sl@0: // static construction methods only
sl@0: : CExampleInterface()
sl@0: 	{
sl@0: 	// Deliberately do nothing here : See ConstructL() for initialisation completion.
sl@0: 	}
sl@0: 
sl@0: void CImplementationClassOne::ConstructL(TAny* aInitParams)
sl@0: // Intended Usage	: Safely complete the initialization of the constructed object	
sl@0: // Error Condition	: Will leave with an appropriate error code	
sl@0: // Dependencies	: CBase
sl@0: // @return			void
sl@0: // @pre 			CImplementationClassOne has been constructed
sl@0: // @post			The CImplementationClassOne object has been fully instantiated
sl@0: //
sl@0: 	{
sl@0: 	TExampleInterfaceInitParams* params = REINTERPRET_CAST(TExampleInterfaceInitParams*,
sl@0: 														   aInitParams);
sl@0: 	if(params->descriptor)
sl@0: 		iInternalDescriptor = params->descriptor->AllocL();
sl@0: 
sl@0: 	Dll::SetTls(&iTLSInt);
sl@0: 	}
sl@0: 
sl@0: void CImplementationClassOne::DoMethodL()
sl@0: 	{
sl@0: 	// Access TLS to ensure it has been set properly
sl@0: 	REINTERPRET_CAST(TInt*, Dll::Tls());
sl@0: 	}
sl@0: 
sl@0: TInt CImplementationClassOne::FireAndForget()
sl@0: 	{
sl@0: 	TRAPD(error,DoMethodL());
sl@0: 	return error;			// Always KErrNotSupported
sl@0: 	}
sl@0: 
sl@0: // Provide the CActive overloads
sl@0: void CImplementationClassOne::RunL()
sl@0: 	{
sl@0: 	// Do nothing : should never be called
sl@0: 	__ASSERT_DEBUG(EFalse,User::Invariant());
sl@0: 	}
sl@0: 
sl@0: void CImplementationClassOne::DoCancel()
sl@0: 	{
sl@0: 	// Do nothing
sl@0: 	}
sl@0: 
sl@0: TInt CImplementationClassOne::RunError(TInt aError)
sl@0: 	{
sl@0: 	return aError;
sl@0: 	}
sl@0: 
sl@0: TUid CImplementationClassOne::ImplId()
sl@0: 	{
sl@0: 	TUid idVal = {0x10009DDA};
sl@0: 	return (idVal);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // __________________________________________________________________________
sl@0: // Exported proxy for instantiation method resolution
sl@0: // Define the interface UIDs
sl@0: const TImplementationProxy ImplementationTable[] = 
sl@0: 	{
sl@0: 		IMPLEMENTATION_PROXY_ENTRY(0x10009DDA,	CImplementationClassOne::NewL),
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: