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: @test sl@0: @internalComponent sl@0: sl@0: This contains CT_DriveUnitData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_DriveUnitData.h" sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KDriveNameType, "driveNameType"); sl@0: _LIT(KDriveName, "driveName"); sl@0: _LIT(KDriveExpValue, "driveExpValue"); sl@0: _LIT(KDriveNameExpValue, "driveNameExpValue"); sl@0: sl@0: /// Commands sl@0: _LIT(KCmdNew, "new"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdAssign, "="); sl@0: _LIT(KCmdConvertToInt, "convertToInt"); sl@0: _LIT(KCmdName, "name"); sl@0: /*@}*/ sl@0: sl@0: CT_DriveUnitData* CT_DriveUnitData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_DriveUnitData* ret = new (ELeave) CT_DriveUnitData(); sl@0: CleanupStack::PushL(ret); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop(ret); sl@0: return ret; sl@0: } sl@0: sl@0: CT_DriveUnitData::CT_DriveUnitData() sl@0: : iDriveUnit(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_DriveUnitData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_DriveUnitData::~CT_DriveUnitData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_DriveUnitData::DoCleanup() sl@0: /** sl@0: * Contains cleanup implementation sl@0: */ sl@0: { sl@0: if (iDriveUnit) sl@0: { sl@0: INFO_PRINTF1(_L("Deleting current TDriveUnit")); sl@0: delete iDriveUnit; sl@0: iDriveUnit = NULL; sl@0: } sl@0: } sl@0: sl@0: TAny* CT_DriveUnitData::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 iDriveUnit; sl@0: } sl@0: sl@0: TBool CT_DriveUnitData::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 requiring command to be processed sl@0: * @param aSection the section in the ini file requiring the command to be processed sl@0: * @param aAsyncErrorIndex the index of asynchronous command error code belongs to. sl@0: * sl@0: * @leave system wide error sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if (aCommand == KCmdNew) sl@0: { sl@0: DoCmdNewL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if (aCommand == KCmdAssign) sl@0: { sl@0: DoCmdAssign(aSection); sl@0: } sl@0: else if (aCommand == KCmdConvertToInt) sl@0: { sl@0: DoCmdConvertToInt(aSection); sl@0: } sl@0: else if (aCommand == KCmdName) sl@0: { sl@0: DoCmdName(aSection); 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_DriveUnitData::DoCmdNewL(const TDesC& aSection) sl@0: /** Creates new TDriveUnit class instance */ sl@0: { sl@0: //Deletes previous TDriveUnit class instance if it was already created. sl@0: DoCleanup(); sl@0: sl@0: INFO_PRINTF1(_L("Create new TDriveUnit class instance")); sl@0: sl@0: TPtrC driveNameType; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType)) sl@0: { sl@0: sl@0: if (driveNameType == _L("number")) sl@0: { sl@0: TInt driveNumber; sl@0: if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber)) sl@0: { sl@0: // do create sl@0: TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveNumber)); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error creating TDriveUnit(driveNumber): %d"), err); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: else if (driveNameType == _L("letter")) sl@0: { sl@0: TPtrC driveLetter; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter)) sl@0: { sl@0: // do create sl@0: TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveLetter)); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error creating TDriveUnit(driveLetter): %d"), err); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit()); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error creating TDriveUnit(): %d"), err); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DriveUnitData::DoCmdAssign(const TDesC& aSection) sl@0: /** Assigns the drive number or letter to the drive unit */ sl@0: { sl@0: TPtrC driveNameType; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType)) sl@0: { sl@0: if (driveNameType == _L("number")) sl@0: { sl@0: TInt driveNumber; sl@0: if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber)) sl@0: { sl@0: INFO_PRINTF1(_L("Assign a new drive number to the drive unit")); sl@0: *iDriveUnit = iDriveUnit->operator=(driveNumber); sl@0: sl@0: } sl@0: } sl@0: else if (driveNameType == _L("letter")) sl@0: { sl@0: TPtrC driveLetter; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter)) sl@0: { sl@0: INFO_PRINTF1(_L("Assign a new drive letter to the drive unit")); sl@0: *iDriveUnit = iDriveUnit->operator=(driveLetter); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Drive name type is not specified!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DriveUnitData::DoCmdConvertToInt(const TDesC& aSection) sl@0: /** Converts the drive unit to integer */ sl@0: { sl@0: INFO_PRINTF1(_L("Convert the drive unit to an integer value")); sl@0: sl@0: TInt intValue = iDriveUnit->operator TInt(); sl@0: INFO_PRINTF2(_L("Drive unit integer value is %d"), intValue); sl@0: sl@0: TInt driveExpValue; sl@0: if (GET_OPTIONAL_INT_PARAMETER(KDriveExpValue(), aSection, driveExpValue)) sl@0: { sl@0: if ( driveExpValue != intValue ) sl@0: { sl@0: ERR_PRINTF3(_L("Drive expected integer value does not match! Expected value: %d, actual value: %d"), driveExpValue, intValue); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Drive expected integer value matches the actual value!")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DriveUnitData::DoCmdName(const TDesC& aSection) sl@0: /** Get the drive unit name as text */ sl@0: { sl@0: INFO_PRINTF1(_L("Get the drive unit name as text with a colon in the end using Name()")); sl@0: sl@0: TDriveName driveName = iDriveUnit->Name(); sl@0: sl@0: INFO_PRINTF2(_L("Drive name: %S"), &driveName); sl@0: sl@0: TPtrC driveNameExpValue; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KDriveNameExpValue(), aSection, driveNameExpValue)) sl@0: { sl@0: if ( driveNameExpValue != driveName ) sl@0: { sl@0: ERR_PRINTF3(_L("Drive expected name value does not match! Expected value: %S, actual value: %S"), &driveNameExpValue, &driveName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Drive expected name value matches the actual value!")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DriveUnitData::DoCmdDestructor() sl@0: /** Destroy TDriveUnit the object */ sl@0: { sl@0: DoCleanup(); sl@0: }