sl@0: // Copyright (c) 1997-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 Suicidal class 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 "TestUtilities.h" // For __FILE__LINE__ sl@0: #include "Interface.h" sl@0: #include "ImplementationProxy.h" sl@0: 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, and then commits suicide. 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 CSuicidalImplementation : public CExampleInterface sl@0: { sl@0: // Methods sl@0: public: sl@0: /** sl@0: @fn NewL() 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: @return CSuicidalImplementation* The class instance. sl@0: @pre None sl@0: @post CSuicidalImplementation has been constructed, sl@0: and initialised. sl@0: */ sl@0: static CSuicidalImplementation* NewL(); sl@0: sl@0: /** sl@0: @fn ~CSuicidalImplementation() sl@0: Intended Usage : Default Destructor sl@0: Error Condition : None sl@0: @since 7.0 sl@0: @pre CSuicidalImplementation has been constructed sl@0: @post CSuicidalImplementation has been completely destroyed, sl@0: and is no longer registered with the scheduler. sl@0: */ sl@0: virtual ~CSuicidalImplementation(); sl@0: sl@0: /** sl@0: @fn DoMethodL() sl@0: Intended Usage : Overload of the pure interface method sl@0: Representative of some 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 CSuicidalImplementation 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 CSuicidalImplementation has been constructed sl@0: @post CSuicidalImplementation is active with a status of KRequestPending. 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 CSuicidalImplementation() 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 CSuicidalImplementation has been constructed sl@0: */ sl@0: CSuicidalImplementation(); sl@0: sl@0: /** sl@0: @fn ConstructL() sl@0: Intended Usage : Completes the safe construction of the CSuicidalImplementation object sl@0: Error Condition : Leaves with the error code. sl@0: @leave KErrNoMemory. sl@0: @since 7.0 sl@0: @pre CSuicidalImplementation has been constructed sl@0: @post CSuicidalImplementation has been fully initialised. sl@0: */ sl@0: void ConstructL(); sl@0: sl@0: // Provide the CActive overloads sl@0: /** sl@0: @fn RunL() sl@0: Intended Usage : When the object activates commit suicide. sl@0: Error Condition : Not enough memory available to complete the scan. sl@0: @leave KErrNoMemory sl@0: @since 7.0 sl@0: @pre CSuicidalImplementation is fully constructed. sl@0: @post CSuicidalImplementation has committed suicide, sl@0: and deleted itself. sl@0: */ sl@0: void RunL(); sl@0: /** sl@0: @fn DoCancel() sl@0: Intended Usage : The cancel action called by CActive::Cancel(). sl@0: Error Condition : None sl@0: @since 7.0 sl@0: @pre CSuicidalImplementation is fully constructed. sl@0: @post CSuicidalImplementation behaviour is cancelled and sl@0: it is no longer active on the current scheduler. sl@0: */ sl@0: void DoCancel(); sl@0: sl@0: /** sl@0: @fn RunError(TInt aError) sl@0: Intended Usage : Called by the RunL leaving. sl@0: @since 7.0 sl@0: @param aError The error code that the RunL left with. sl@0: @return TInt KErrNone. sl@0: @pre CSuicidalImplementation is fully constructed. sl@0: @post CSuicidalImplementation is returned to a sl@0: sensible active state. sl@0: */ sl@0: TInt RunError(TInt aError); sl@0: sl@0: }; // End of CSuicidalImplementation definition sl@0: sl@0: // __________________________________________________________________________ sl@0: // Implementation sl@0: const TInt KDefaultTestAllocSize = 8; sl@0: sl@0: CSuicidalImplementation* CSuicidalImplementation::NewL() 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 CSuicidalImplementation* a pointer to the fully instantiated CSuicidalImplementation object sl@0: // @pre None sl@0: // @post The object has been fully instantiated sl@0: // Static member sl@0: { sl@0: CSuicidalImplementation* self=new(ELeave) CSuicidalImplementation(); // calls c'tor sl@0: CleanupStack::PushL(self); // Make the construction safe by using the cleanup stack sl@0: self->ConstructL(); // Complete the 'construction'. sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CSuicidalImplementation::~CSuicidalImplementation() sl@0: // Default virtual d'tor sl@0: { sl@0: // Do Nothing sl@0: } sl@0: sl@0: CSuicidalImplementation::CSuicidalImplementation() 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 CSuicidalImplementation::ConstructL() 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 CSuicidalImplementation has been constructed sl@0: // @post The CSuicidalImplementation object has been fully instantiated sl@0: // sl@0: { sl@0: // Allocate and delete some memory sl@0: // so that leave testing can check sl@0: // for the correct handling. sl@0: HBufC* temp = HBufC::NewL(KDefaultTestAllocSize); sl@0: delete temp; sl@0: } sl@0: sl@0: void CSuicidalImplementation::DoMethodL() sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: TInt CSuicidalImplementation::FireAndForget() sl@0: { sl@0: TInt error = KErrNone; sl@0: TRAP(error,DoMethodL()); sl@0: if(!IsActive()) sl@0: { sl@0: SetActive(); sl@0: iStatus = KRequestPending; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, error); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: // Provide the CActive overloads sl@0: void CSuicidalImplementation::RunL() sl@0: { sl@0: User::LeaveIfError(iStatus.Int()); sl@0: delete this; // AAARGH : Scary self deletion!!!! sl@0: } sl@0: sl@0: void CSuicidalImplementation::DoCancel() sl@0: { sl@0: // Do nothing sl@0: } sl@0: sl@0: TInt CSuicidalImplementation::RunError(TInt) sl@0: { sl@0: delete this; // AAARGH : Scary self deletion!!!! sl@0: return KErrNone; // Don't Panic sl@0: } sl@0: sl@0: TUid CSuicidalImplementation::ImplId() sl@0: { sl@0: TUid idVal = {0x10009DC5}; sl@0: return (idVal); 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(0x10009DC5, CSuicidalImplementation::NewL) // SuicidalImplementationClass 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: }