lowlevellibsandfws/pluginfw/Framework/Example/ExampleOne.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The implementation of a some classes
       
    15 // to be provided by ECom.
       
    16 // 1. Using the CExampleInterface class as a base.
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "Interface.h"
       
    21 #include "ImplementationProxy.h"
       
    22 #include "TestUtilities.h"	// For __FILE__LINE__
       
    23 
       
    24 // ____________________________________________________________________________
       
    25 // 
       
    26 /**
       
    27 	Intended usage: This class implements the functionality promised by 
       
    28 	the CExampleInterface defintion class. It does little apart from provides a test instance
       
    29 	which may be retrieved and run for testing purposes.
       
    30 	Its resolution is based upon its registered default data string that
       
    31 	advertises this class as being able to handle 'text\wml' data.
       
    32 	@since 7.0
       
    33 	
       
    34  */
       
    35 class CImplementationClassThree : public CExampleInterface
       
    36 {
       
    37 // Methods
       
    38 public:
       
    39 /**
       
    40 	@fn				NewL(TAny* aInitParams)
       
    41 	Intended Usage	: Standardised safe construction which leaves nothing the cleanup stack.
       
    42 	Error Condition	: Leaves with error code.
       
    43 	@leave          KErrNoMemory.
       
    44 	@since			7.0
       
    45 	@param			aInitParams The parameter struct used for initialising this object
       
    46 	@return			CImplementationClassThree* The class instance.
       
    47 	@pre 			None
       
    48 	@post			CImplementationClassThree has been constructed,
       
    49 					and initialised.
       
    50  */
       
    51 	static CImplementationClassThree* NewL(TAny* aInitParams);
       
    52 
       
    53 /**
       
    54 	@fn				~CImplementationClassThree()
       
    55 	Intended Usage	: Default Destructor	
       
    56 	Error Condition	: None	
       
    57 	@since			7.0
       
    58 	@pre 			CImplementationClassThree has been constructed
       
    59 	@post			CImplementationClassThree has been completely destroyed.
       
    60  */
       
    61 	virtual ~CImplementationClassThree();
       
    62 
       
    63 /**
       
    64 	@fn				DoMethodL()
       
    65 	Intended Usage	: Overload of the pure interface method
       
    66 					Representative of a method provided on 
       
    67 					the interface by the interface definer.
       
    68 	Error Condition	: Leaves with an error code.
       
    69 	@leave  		KErrNoMemory, KErrNotSupported.
       
    70 	@since			7.0
       
    71 	@return			None
       
    72 	@pre 			CImplementationClassThree has been constructed
       
    73 	@post			Unspecified
       
    74  */	
       
    75 	void DoMethodL();
       
    76 
       
    77 /**
       
    78 	@fn				FireAndForget()
       
    79 	Intended Usage	: Overload of the pure interface method
       
    80 					asynchronous function which 
       
    81 					an interface definer could specify.  
       
    82 					It allows the client to call the function in the knowledge 
       
    83 					that the object will commit suicide when the 
       
    84 					function completes.
       
    85 	Error Condition	: None.
       
    86 	@since			7.0
       
    87 	@return			TInt KErrNone for success.
       
    88 	@pre 			CImplementationClassThree has been constructed
       
    89 	@post			Unspecified
       
    90  */
       
    91 	TInt FireAndForget();
       
    92 
       
    93  /**
       
    94 	@fn				ImplId()
       
    95 	Intended Usage	: To verify the object returned by ECOM.
       
    96 	Error Condition	: None.
       
    97 	@since			7.0
       
    98 	@return			TUid (ECOM's Implementation Uid for this class.)
       
    99 	@pre 			CImplementationClassThree has been constructed
       
   100 	@post			Unspecified
       
   101  */
       
   102 	TUid ImplId();
       
   103 
       
   104 private:
       
   105 /**
       
   106 	@fn				CImplementationClassThree()
       
   107 	Intended Usage	: Default Constructor : usable only by derived classes	
       
   108 	Error Condition	: None	
       
   109 	@since			7.0
       
   110 	@pre 			None
       
   111 	@post			CImplementationClassThree has been constructed
       
   112  */
       
   113 	CImplementationClassThree();
       
   114 
       
   115 /**
       
   116 	@fn				ConstructL(TAny* aInitParams)
       
   117 	Intended Usage	: Completes the safe construction of the CImplementationClassThree object
       
   118 	Error Condition	: Leaves with the error code.	
       
   119 	@leave          KErrNoMemory.	
       
   120 	@since			7.0
       
   121 	@param			aInitParams The parameter struct used for initialising this object
       
   122 	@pre 			CImplementationClassThree has been constructed
       
   123 	@post			CImplementationClassThree has been fully initialised.
       
   124  */
       
   125 	void ConstructL(TAny* aInitParams);
       
   126 
       
   127 // Provide the CActive overloads
       
   128 	void RunL();
       
   129 	void DoCancel();
       
   130 	TInt RunError(TInt aError);
       
   131 
       
   132 
       
   133 
       
   134 private:
       
   135 /** A place for allocating some memory in the ConstructL */
       
   136 	HBufC*	iInternalDescriptor;
       
   137 /** An int to be stored in TLS to test its useage */	
       
   138 	TInt	iTLSInt;
       
   139 
       
   140 };  // End of CImplementationClassThree definition
       
   141 
       
   142 // __________________________________________________________________________
       
   143 // Implementation
       
   144 
       
   145 CImplementationClassThree* CImplementationClassThree::NewL(TAny* aInitParams)
       
   146 // Intended Usage	: Safe construction which leaves nothing upon the cleanup stack	
       
   147 // Error Condition	: Will leave with an appropriate error code	
       
   148 // Dependencies	: CBase
       
   149 // @param			" "
       
   150 // @return			CImplementationClassThree* a pointer to the fully instantiated CImplementationClassThree object
       
   151 // @pre 			None
       
   152 // @post			The object has been fully instantiated
       
   153 // Static member
       
   154 	{
       
   155 	CImplementationClassThree* self=new(ELeave) CImplementationClassThree();  // calls c'tor
       
   156 	CleanupStack::PushL(self);	// Make the construction safe by using the cleanup stack
       
   157 	self->ConstructL(aInitParams); // Complete the 'construction'.
       
   158 	CleanupStack::Pop(self);
       
   159 	return self;
       
   160 	}
       
   161 
       
   162 CImplementationClassThree::~CImplementationClassThree()
       
   163 // Default virtual d'tor
       
   164 	{
       
   165 	delete iInternalDescriptor;
       
   166 	}
       
   167 
       
   168 CImplementationClassThree::CImplementationClassThree()
       
   169 // Default c'tor for use by derived and 
       
   170 // static construction methods only
       
   171 : CExampleInterface()
       
   172 	{
       
   173 	// Deliberately do nothing here : See ConstructL() for initialisation completion.
       
   174 	}
       
   175 
       
   176 void CImplementationClassThree::ConstructL(TAny* aInitParams)
       
   177 // Intended Usage	: Safely complete the initialization of the constructed object	
       
   178 // Error Condition	: Will leave with an appropriate error code	
       
   179 // Dependencies	: CBase
       
   180 // @return			void
       
   181 // @pre 			CImplementationClassThree has been constructed
       
   182 // @post			The CImplementationClassThree object has been fully instantiated
       
   183 //
       
   184 	{
       
   185 	TExampleInterfaceInitParams* params = REINTERPRET_CAST(TExampleInterfaceInitParams*,
       
   186 														   aInitParams);
       
   187 	if(params->descriptor)
       
   188 		iInternalDescriptor = params->descriptor->AllocL();
       
   189 
       
   190 	Dll::SetTls(&iTLSInt);
       
   191 	}
       
   192 
       
   193 void CImplementationClassThree::DoMethodL()
       
   194 	{
       
   195 	// Access TLS to ensure it has been set properly
       
   196 	REINTERPRET_CAST(TInt*, Dll::Tls());
       
   197 	}
       
   198 
       
   199 TInt CImplementationClassThree::FireAndForget()
       
   200 	{
       
   201 	TRAPD(error,DoMethodL());
       
   202 	return error;			// Always KErrNotSupported
       
   203 	}
       
   204 
       
   205 // Provide the CActive overloads
       
   206 void CImplementationClassThree::RunL()
       
   207 	{
       
   208 	// Do nothing : should never be called
       
   209 	__ASSERT_DEBUG(EFalse,User::Invariant());
       
   210 	}
       
   211 
       
   212 void CImplementationClassThree::DoCancel()
       
   213 	{
       
   214 	// Do nothing
       
   215 	}
       
   216 
       
   217 TInt CImplementationClassThree::RunError(TInt /*aError*/)
       
   218 	{
       
   219 	return KErrNone;
       
   220 	}
       
   221 
       
   222 TUid CImplementationClassThree::ImplId()
       
   223 	{
       
   224 	TUid idVal = {0x101F8478};
       
   225 	return (idVal);
       
   226 	}
       
   227 // __________________________________________________________________________
       
   228 // Exported proxy for instantiation method resolution
       
   229 // Define the interface UIDs
       
   230 const TImplementationProxy ImplementationTable[] = 
       
   231 	{
       
   232 		IMPLEMENTATION_PROXY_ENTRY(0x101F8478,	CImplementationClassThree::NewL)
       
   233 	};
       
   234 
       
   235 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   236 	{
       
   237 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   238 	return ImplementationTable;
       
   239 	}
       
   240