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 "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: #include "T_EComSessionData.h" sl@0: #include "T_ImplementationInformationData.h" sl@0: #include "TestEComInterface.h" sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KUid, "uid"); sl@0: _LIT(KResolver, "resolver"); sl@0: _LIT(KExpectedResult, "expected"); sl@0: _LIT(KResolverUid, "resolver_uid"); sl@0: _LIT(KOffset, "offset"); sl@0: _LIT(KInteger, "integer"); sl@0: _LIT(KDescriptor, "descriptor"); sl@0: _LIT(KEmpty, "empty"); sl@0: _LIT(KSaveTo, "saveto"); sl@0: _LIT(KSaveIndex, "saveindex"); sl@0: sl@0: /// REComSession sl@0: _LIT(KCmdOpenL, "OpenL"); sl@0: _LIT(KCmdClose, "Close"); sl@0: _LIT(KCmdFinalClose, "FinalClose"); sl@0: _LIT(KCmdNotifyOnChange, "NotifyOnChange"); sl@0: _LIT(KCmdCancelNotifyOnChange, "CancelNotifyOnChange"); sl@0: _LIT(KCmdListImplementationsL, "ListImplementationsL"); sl@0: _LIT(KCmdCreateImplementationL, "CreateImplementationL"); sl@0: _LIT(KCmdDestroyedImplementation, "DestroyedImplementation"); sl@0: _LIT(KCmdClean, "~"); sl@0: sl@0: _LIT(KEmptyString, ""); sl@0: _LIT(KDefault, "default"); sl@0: /*@}*/ sl@0: sl@0: ////////////////////////////////////////////////////////////////////// sl@0: // Construction/Destruction sl@0: ////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: CT_EComSessionData* CT_EComSessionData::NewL() sl@0: { sl@0: CT_EComSessionData* ret=new (ELeave) CT_EComSessionData(); sl@0: CleanupStack::PushL(ret); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop(ret); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Constructor. First phase construction sl@0: */ sl@0: CT_EComSessionData::CT_EComSessionData() sl@0: : iActiveNotifyOnChange(NULL) sl@0: , iImplementationInterface(NULL) sl@0: { sl@0: iInitParams.iInteger=0; sl@0: iInitParams.iDescriptor=&iInterfaceDesc; sl@0: } sl@0: sl@0: /** sl@0: * Second phase construction sl@0: */ sl@0: void CT_EComSessionData::ConstructL() sl@0: { sl@0: iInterfaceDesc=KEmptyString; sl@0: iDTorKey=TUid::Uid(0); sl@0: iActiveNotifyOnChange=CActiveCallback::NewL(*this); sl@0: } sl@0: sl@0: /** sl@0: * Public destructor sl@0: */ sl@0: CT_EComSessionData::~CT_EComSessionData() sl@0: { sl@0: DestroyData(); sl@0: iInfoArray.ResetAndDestroy(); sl@0: iInfoArray.Close(); sl@0: delete iActiveNotifyOnChange; sl@0: iActiveNotifyOnChange=NULL; sl@0: } sl@0: sl@0: TAny* CT_EComSessionData::GetObject() sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return Pointer to the object that the data wraps sl@0: */ sl@0: { sl@0: return &iSession; sl@0: } sl@0: sl@0: void CT_EComSessionData::DestroyData() sl@0: { sl@0: if (iImplementationInterface) sl@0: { sl@0: delete static_cast(iImplementationInterface); sl@0: iImplementationInterface=NULL; sl@0: }; sl@0: } sl@0: sl@0: ////////////////////////////////////////////////////////////////////// sl@0: // Read data from INI file sl@0: ////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CT_EComSessionData::GetUid(const TDesC& aSection, TUid& aUid) sl@0: { sl@0: TInt uidValue=0; sl@0: sl@0: GetHexFromConfig(aSection, KUid(), uidValue ); sl@0: aUid = TUid::Uid(uidValue); sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetResolver(const TDesC& aSection, TPtrC& aResolver) sl@0: { sl@0: return GetStringFromConfig(aSection, KResolver(), aResolver); sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetResolverUid(const TDesC& aSection, TUid& aUid) sl@0: { sl@0: TInt uidValue=0; sl@0: TBool ret=GetHexFromConfig(aSection, KResolverUid(), uidValue ); sl@0: aUid = TUid::Uid(uidValue); sl@0: return ret; sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetEmpty(const TDesC& aSection, TBool& aEmpty) sl@0: { sl@0: aEmpty = EFalse; sl@0: return GetBoolFromConfig(aSection, KEmpty(), aEmpty ); sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetExpectedResult(const TDesC& aSection, TInt& aExpectedResult) sl@0: { sl@0: aExpectedResult = 0; sl@0: return GetIntFromConfig(aSection, KExpectedResult(), aExpectedResult ); sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetOffset(const TDesC& aSection, TInt& aOffset) sl@0: { sl@0: aOffset=_FOFF(CTestEComInterface, iDtor_ID_Key); sl@0: sl@0: TPtrC offset; sl@0: TBool ret=GetStringFromConfig(aSection, KOffset(), offset); sl@0: if ( ret ) sl@0: { sl@0: if ( offset == KDefault ) sl@0: { sl@0: INFO_PRINTF2(_L("Default offset %d"), aOffset); sl@0: } sl@0: else sl@0: { sl@0: ret=GetIntFromConfig(aSection, KOffset(), aOffset); sl@0: } sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetDescriptor(const TDesC& aSection, TPtrC& aDescriptor) sl@0: { sl@0: aDescriptor.Set(KEmptyString); sl@0: return GetStringFromConfig(aSection, KDescriptor(), aDescriptor ); sl@0: } sl@0: sl@0: TBool CT_EComSessionData::GetInteger(const TDesC& aSection, TInt& aInt) sl@0: { sl@0: return GetIntFromConfig(aSection, KInteger(), aInt ); sl@0: } sl@0: sl@0: sl@0: TBool CT_EComSessionData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand The command to process sl@0: * @param aSection The section in the ini containing data for the command sl@0: * @param aAsyncErrorIndex Command index for async calls to return errors to sl@0: * sl@0: * @return ETrue if the command is processed sl@0: * @pre N/A sl@0: * @post N/A sl@0: * sl@0: * @leave System wide error sl@0: */ sl@0: { sl@0: TBool retVal=ETrue; sl@0: sl@0: if ( aCommand==KCmdOpenL ) sl@0: { sl@0: DoCmdOpenL(); sl@0: } sl@0: else if ( aCommand==KCmdClose ) sl@0: { sl@0: DoCmdClose(); sl@0: } sl@0: else if ( aCommand==KCmdFinalClose ) sl@0: { sl@0: DoCmdFinalClose(); sl@0: } sl@0: else if ( aCommand==KCmdNotifyOnChange ) sl@0: { sl@0: DoCmdNotifyOnChange(aAsyncErrorIndex); sl@0: } sl@0: else if ( aCommand==KCmdCancelNotifyOnChange ) sl@0: { sl@0: DoCmdCancelNotifyOnChange(); sl@0: } sl@0: else if ( aCommand==KCmdListImplementationsL ) sl@0: { sl@0: DoCmdListImplementationsL(aSection); sl@0: } sl@0: else if ( aCommand==KCmdCreateImplementationL ) sl@0: { sl@0: DoCmdCreateImplementationL(aSection); sl@0: } sl@0: else if ( aCommand==KCmdDestroyedImplementation ) sl@0: { sl@0: DoCmdDestroyedImplementation(aSection); sl@0: } sl@0: else if ( aCommand==KCmdClean ) sl@0: { sl@0: DestroyData(); sl@0: } sl@0: else sl@0: { sl@0: retVal=EFalse; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdOpenL() sl@0: { sl@0: INFO_PRINTF1(_L("OpenL Call")); sl@0: TRAPD ( err, iSession = REComSession::OpenL() ); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("OpenL Error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Session opened")); sl@0: } sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdClose() sl@0: { sl@0: INFO_PRINTF1(_L("Close")); sl@0: iSession.Close(); sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdFinalClose() sl@0: { sl@0: INFO_PRINTF1(_L("Final Close")); sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdNotifyOnChange(const TInt aIndex) sl@0: { sl@0: INFO_PRINTF1(_L("NotifyOnChange")); sl@0: iSession.NotifyOnChange(iActiveNotifyOnChange->iStatus); sl@0: iActiveNotifyOnChange->Activate(aIndex); sl@0: IncOutstanding(); sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdCancelNotifyOnChange() sl@0: { sl@0: INFO_PRINTF1(_L("CancelNotifyOnChange")); sl@0: iSession.CancelNotifyOnChange(iActiveNotifyOnChange->iStatus); sl@0: } sl@0: sl@0: // Found defects: sl@0: // 1. ListImplementationsL with impossible aResolutionParameters argument don't leave sl@0: // Status: possible defect sl@0: void CT_EComSessionData::DoCmdListImplementationsL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Getting Implementnation List")); sl@0: sl@0: TUid impUid; sl@0: GetUid(aSection, impUid); sl@0: sl@0: TUid resolverUid; sl@0: TBool hasResolverUid=GetResolverUid(aSection, resolverUid); sl@0: sl@0: TInt err = KErrNone; sl@0: sl@0: TPtrC resolver; sl@0: TBool hasResolver=GetResolver(aSection, resolver); sl@0: if ( hasResolver ) sl@0: { sl@0: TEComResolverParams* resolverParams=static_cast(GetDataObjectL(resolver)); sl@0: if ( hasResolverUid ) sl@0: { sl@0: INFO_PRINTF1(_L("Getting Implementnation List(3) by Uid, ResolverParams as a filter params && Resolver Uid as a filter")); sl@0: TRAP(err, REComSession::ListImplementationsL(impUid, *resolverParams, resolverUid, iInfoArray)); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Getting Implementnation List(1) by Uid && ResolverParams as a filter")); sl@0: TRAP(err, REComSession::ListImplementationsL(impUid, *resolverParams, iInfoArray)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Getting Implementnation List(2) by Uid")); sl@0: TRAP(err, REComSession::ListImplementationsL(impUid, iInfoArray)); sl@0: } sl@0: sl@0: if ( err==KErrNone ) sl@0: { sl@0: // Check to see if we the data object has to be set in a CT_ImplementationInformationData sl@0: TPtrC saveTo; sl@0: if ( GetStringFromConfig(aSection, KSaveTo(), saveTo) ) sl@0: { sl@0: TInt index=0; sl@0: GetIntFromConfig(aSection, KSaveIndex(), index); sl@0: CDataWrapper* wrapper=static_cast(GetDataWrapperL(saveTo)); sl@0: wrapper->SetObjectL(iInfoArray[index]); sl@0: } sl@0: } sl@0: sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get implementation list with error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: TInt expectedResult; sl@0: if ( GetExpectedResult(aSection, expectedResult) ) sl@0: { sl@0: if (iInfoArray.Count() != expectedResult) sl@0: { sl@0: ERR_PRINTF3(_L("List retrieved. Found %d imlementations, expected %d"), sl@0: iInfoArray.Count(), expectedResult ); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: for (TInt i = 0; i < iInfoArray.Count(); i++) sl@0: { sl@0: const TDesC8& name8=iInfoArray[i]->DataType(); sl@0: TBuf name16; sl@0: name16.Copy(name8); sl@0: INFO_PRINTF3(_L("Implementation UID %d: - \"%S\""), iInfoArray[i]->ImplementationUid().iUid, &(iInfoArray[i]->DisplayName())); sl@0: INFO_PRINTF2(_L("Data Type is \"%S\""), &name16); sl@0: }; sl@0: } sl@0: } sl@0: sl@0: // Found defects: sl@0: // 1. CreateImplementationL with any aKeyOffset argument - aKeyOffset can have any value (-1, 0, 10000, ...) sl@0: // but CreateImplementationL returns no error and generates memory leak. sl@0: // Status: possible defects sl@0: // 2. CreateImplementationL with impossible aResolutionParameters argument - returns KErrnotFound, but in documentation sl@0: // CreateImplementationL levaes only with KErrNoMemory, KErrNotConnected, KErrArgument or KErrPermissionDenied error sl@0: // Status: documentation defect sl@0: void CT_EComSessionData::DoCmdCreateImplementationL(const TDesC& aSection) sl@0: { sl@0: DestroyData(); sl@0: sl@0: TUid impUid; sl@0: GetUid(aSection,impUid); sl@0: sl@0: TInt offset; sl@0: TBool hasOffset=GetOffset(aSection,offset); sl@0: sl@0: TUid resolverUid; sl@0: TBool hasResolverUid=GetResolverUid(aSection, resolverUid); sl@0: sl@0: TBool hasIntegerValue=GetInteger(aSection, iInitParams.iInteger); sl@0: sl@0: TBool emptyArgs; sl@0: TBool hasEmptyArgs=GetEmpty(aSection, emptyArgs); sl@0: sl@0: TBool hasInitParams=hasIntegerValue || hasEmptyArgs; sl@0: TAny* initParamsPtr=NULL; sl@0: if (hasInitParams) sl@0: { sl@0: if (!emptyArgs) sl@0: { sl@0: initParamsPtr=&iInitParams; sl@0: } sl@0: } sl@0: sl@0: TInt err = KErrNone; sl@0: TBool getKeyFromOffset=EFalse; sl@0: sl@0: TPtrC resolver; sl@0: if ( GetResolver(aSection, resolver) ) sl@0: { sl@0: TEComResolverParams* resolverParams=static_cast(GetDataObjectL(resolver)); sl@0: if (hasResolverUid && hasInitParams && hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(12) by Interface Uid, Offset, Init Params, ResolverParams as a filter params && Resolver Uid as a filter")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset, initParamsPtr, *resolverParams, resolverUid)); sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else if (hasResolverUid && hasInitParams) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(11) by Interface Uid, Init Params, ResolverParams as a filter params && Resolver Uid as a filter")); sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr, *resolverParams, resolverUid)); sl@0: } sl@0: else if (hasResolverUid && hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(10) by Interface Uid, Offset, ResolverParams as a filter params && Resolver Uid as a filter")); sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset, *resolverParams, resolverUid)); sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else if (hasResolverUid) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(9) by Interface Uid, ResolverParams as a filter params && Resolver Uid as a filter")); sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey, *resolverParams, resolverUid)); sl@0: } sl@0: else if (hasInitParams && hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(8) by Interface Uid, Offset, Init Params && Resolver Parameters as a filter")); sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset, initParamsPtr, *resolverParams)); sl@0: sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else if (hasInitParams) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(7) by Interface Uid, Init Params && Resolver Parameters as a filter")); sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr, *resolverParams)); sl@0: } sl@0: else if (hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(6) by Interface Uid, Offset && Resolver Parameters as a filter")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset, *resolverParams)); sl@0: sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(5) by Interface Uid && Resolver Parameters as a filter")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey, *resolverParams)); sl@0: sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (hasInitParams && hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(4) by Uid, Offset && Construction Parameters")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset, initParamsPtr)); sl@0: sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else if (hasInitParams) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(3) by Uid && Construction Parameters")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr)); sl@0: sl@0: } sl@0: else if (hasOffset) sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(2) by Uid && offset defined by interface")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, offset)); sl@0: sl@0: getKeyFromOffset=(err==KErrNone); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Creating Implementnation(1) by Uid")); sl@0: sl@0: TRAP( err, iImplementationInterface = sl@0: REComSession::CreateImplementationL(impUid, iDTorKey )); sl@0: sl@0: } sl@0: } sl@0: sl@0: if ( getKeyFromOffset ) sl@0: { sl@0: TUint8* uidPtr=REINTERPRET_CAST(TUint8*, iImplementationInterface) + offset; sl@0: TUid* uid=REINTERPRET_CAST(TUid*, uidPtr); sl@0: iDTorKey=*uid; sl@0: *uid=TUid::Null(); sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("Implementation created successfully. iDTorKey is %d"), iDTorKey.iUid); sl@0: if (BlockResult()==EPass) sl@0: { sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to create implementation with error %d"), err); sl@0: SetError(err); sl@0: if (iImplementationInterface != NULL) sl@0: { sl@0: SetBlockResult(EFail); sl@0: ERR_PRINTF1(_L("Data verification failed: CreateImplementationL returns an error, but implementation was created")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Data verification succcess: CreateImplementationL returns an error and implementation was not created as expected")); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EComSessionData::DoCmdDestroyedImplementation(const TDesC& aSection) sl@0: { sl@0: TInt uidValue; sl@0: if ( GetIntFromConfig(aSection, KUid(), uidValue) ) sl@0: { sl@0: iDTorKey = TUid::Uid(uidValue); sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("Destroy Interface Implementation. UID is %d"), iDTorKey.iUid); sl@0: REComSession::DestroyedImplementation(iDTorKey); sl@0: INFO_PRINTF1(_L("REComSession::DestroyedImplementation(iDTorKey) completed")); sl@0: DestroyData(); sl@0: INFO_PRINTF1(_L("Interface implementation destroyed")); sl@0: } sl@0: sl@0: /** sl@0: Virtual RunL - Called on completion of an asynchronous command sl@0: @internalComponent sl@0: @see MTPActiveCallback sl@0: @param aActive Active Object that RunL has been called on sl@0: @pre N/A sl@0: @post N/A sl@0: @leave system wide error code sl@0: */ sl@0: void CT_EComSessionData::RunL(CActive* aActive, const TInt aIndex) sl@0: { sl@0: if ( aActive==iActiveNotifyOnChange ) sl@0: { sl@0: RunNotifyOnChangeL( aIndex ); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Stray signal")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: RunNotifyOnChangeL - Process RunL for iActiveNotifyOnChange sl@0: @internalComponent sl@0: @pre N/A sl@0: @post N/A sl@0: @leave system wide error code sl@0: */ sl@0: void CT_EComSessionData::RunNotifyOnChangeL(const TInt aIndex) sl@0: { sl@0: TInt err=iActiveNotifyOnChange->iStatus.Int(); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("RunL Error %d"), err); sl@0: SetAsyncError(aIndex, err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("RunNotifyOnChangeL OK")); sl@0: } sl@0: sl@0: DecOutstanding(); sl@0: } sl@0: