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: #include "T_MmcSDSessionData.h" sl@0: sl@0: //MMCSD Commands index sl@0: /*@{*/ sl@0: _LIT(KCmdConstructor, "NewL"); sl@0: _LIT(KCmdLoadDriver, "LoadDriver"); sl@0: _LIT(KCmdUnLoadDriver, "UnLoadDriver"); sl@0: _LIT(KCmdDriverOpen, "DriverOpen"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: sl@0: _LIT(KLDDName, "LDD"); sl@0: _LIT(KStackNumber, "stacknumber"); sl@0: /*@}*/ sl@0: sl@0: sl@0: sl@0: /** sl@0: * Create a new Socket Driver Data wrapper sl@0: * sl@0: * @return A Socket Driver Data wrapper sl@0: * sl@0: * @leave System wide error sl@0: */ sl@0: CT_MmcSDSessionData* CT_MmcSDSessionData::NewL() sl@0: { sl@0: CT_MmcSDSessionData* ret=new (ELeave) CT_MmcSDSessionData(); 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: * Construction sl@0: * sl@0: * @return N/A sl@0: */ sl@0: CT_MmcSDSessionData::CT_MmcSDSessionData() sl@0: : CT_RBusLogicalChannelData() sl@0: , iMmcSDController(NULL) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Second phase construction sl@0: * sl@0: * @return void sl@0: * sl@0: * @leave System wide error sl@0: */ sl@0: void CT_MmcSDSessionData::ConstructL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Public destructor sl@0: * sl@0: * @return N/A sl@0: */ sl@0: CT_MmcSDSessionData::~CT_MmcSDSessionData() sl@0: { sl@0: } sl@0: 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: TAny* CT_MmcSDSessionData::GetObject() sl@0: { sl@0: return iMmcSDController; sl@0: } sl@0: sl@0: /** sl@0: * Return a pointer to the handle sl@0: * sl@0: * @return pointer to the MMC/SD Controller sl@0: */ sl@0: RHandleBase* CT_MmcSDSessionData::GetHandleBase() sl@0: { sl@0: return iMmcSDController; sl@0: } sl@0: sl@0: /** sl@0: * Return a pointer to the logical channel sl@0: * sl@0: * @return pointer to the MMC/SD Controller sl@0: */ sl@0: RBusLogicalChannel* CT_MmcSDSessionData::GetBusLogicalChannel() sl@0: { sl@0: return iMmcSDController; sl@0: } sl@0: sl@0: /** sl@0: * Close and clean sl@0: * sl@0: * @return void sl@0: */ sl@0: void CT_MmcSDSessionData::DestroyData() sl@0: { sl@0: delete iMmcSDController; sl@0: iMmcSDController=NULL; sl@0: } sl@0: sl@0: /** sl@0: * Process a command read from the script 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: * sl@0: * @leave System wide error sl@0: */ sl@0: TBool CT_MmcSDSessionData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) sl@0: { sl@0: TBool ret=ETrue; sl@0: sl@0: if ( aCommand==KCmdConstructor ) sl@0: { sl@0: DoCmdConstructor(); sl@0: } sl@0: else if ( aCommand==KCmdLoadDriver ) sl@0: { sl@0: DoCmdLoadDriver(aSection); sl@0: } sl@0: else if ( aCommand==KCmdDriverOpen ) sl@0: { sl@0: DoCmdDriverOpen(aSection); sl@0: } sl@0: else if ( aCommand==KCmdUnLoadDriver ) sl@0: { sl@0: DoCmdUnLoadDriver(aSection); sl@0: } sl@0: else if ( aCommand==KCmdDestructor ) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else sl@0: { sl@0: ret=CT_RBusLogicalChannelData::DoCommandL(aCommand, aSection, aAsyncErrorIndex); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Creates the RBusLogicalChannel derived interface sl@0: * sl@0: * @param aCommand None sl@0: * sl@0: * @return None sl@0: */ sl@0: void CT_MmcSDSessionData::DoCmdConstructor() sl@0: { sl@0: delete iMmcSDController; sl@0: iMmcSDController=NULL; sl@0: TRAPD(err, iMmcSDController=new (ELeave) RMMCSDTestControllerInterface()); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("RMMCSDTestControllerInterface Creation Error %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Loads the Device Driver sl@0: * sl@0: * @param aSection The section in the ini containing data for the command sl@0: * sl@0: * @return void sl@0: */ sl@0: void CT_MmcSDSessionData::DoCmdLoadDriver(const TDesC& aSection) sl@0: { sl@0: TPtrC lddname; sl@0: if(!GetStringFromConfig(aSection, KLDDName(), lddname)) sl@0: { sl@0: ERR_PRINTF1(_L("Error in Reading Driver Name from INI file -Load")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: User::LoadLogicalDevice(lddname); sl@0: } sl@0: sl@0: /** sl@0: * Unloads the Device Driver sl@0: * sl@0: * @param aSection The section in the ini containing data for the command sl@0: * sl@0: * @return void sl@0: */ sl@0: void CT_MmcSDSessionData::DoCmdUnLoadDriver(const TDesC& aSection) sl@0: { sl@0: TPtrC lddname; sl@0: if(!GetStringFromConfig(aSection, KLDDName(), lddname)) sl@0: { sl@0: ERR_PRINTF1(_L("Error in Reading Driver Name from INI file-UnLoad")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: User::FreeLogicalDevice(lddname); sl@0: } sl@0: sl@0: /** sl@0: * Opens the Driver Call sl@0: * sl@0: * @param aSection The section in the ini containing data for the command sl@0: * sl@0: * @return void sl@0: */ sl@0: void CT_MmcSDSessionData::DoCmdDriverOpen(const TDesC& aSection) sl@0: { sl@0: TInt err; sl@0: TInt stackNumber = 0; sl@0: GetIntFromConfig(aSection, KStackNumber(), stackNumber); sl@0: err=iMmcSDController->Open(stackNumber,iMmcSDController->VersionRequired()); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Driver Open Call Failure %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("iMmcSDController = %x"), iMmcSDController); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Destroys the objects sl@0: * sl@0: * @return void sl@0: */ sl@0: void CT_MmcSDSessionData::DoCmdDestructor() sl@0: { sl@0: INFO_PRINTF1(_L("CT_MmcSDSessionData::DoCmdDestructor()")); sl@0: DestroyData(); sl@0: } sl@0: