Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 This contains CT_DriveUnitData
27 #include "T_DriveUnitData.h"
31 _LIT(KDriveNameType, "driveNameType");
32 _LIT(KDriveName, "driveName");
33 _LIT(KDriveExpValue, "driveExpValue");
34 _LIT(KDriveNameExpValue, "driveNameExpValue");
38 _LIT(KCmdDestructor, "~");
39 _LIT(KCmdAssign, "=");
40 _LIT(KCmdConvertToInt, "convertToInt");
41 _LIT(KCmdName, "name");
44 CT_DriveUnitData* CT_DriveUnitData::NewL()
46 * Two phase constructor
49 CT_DriveUnitData* ret = new (ELeave) CT_DriveUnitData();
50 CleanupStack::PushL(ret);
52 CleanupStack::Pop(ret);
56 CT_DriveUnitData::CT_DriveUnitData()
59 * Protected constructor. First phase construction
64 void CT_DriveUnitData::ConstructL()
66 * Protected constructor. Second phase construction
71 CT_DriveUnitData::~CT_DriveUnitData()
79 void CT_DriveUnitData::DoCleanup()
81 * Contains cleanup implementation
86 INFO_PRINTF1(_L("Deleting current TDriveUnit"));
92 TAny* CT_DriveUnitData::GetObject()
94 * Return a pointer to the object that the data wraps
96 * @return pointer to the object that the data wraps
102 TBool CT_DriveUnitData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
104 * Process a command read from the ini file
106 * @param aCommand requiring command to be processed
107 * @param aSection the section in the ini file requiring the command to be processed
108 * @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
110 * @leave system wide error
112 * @return ETrue if the command is processed
115 TBool retVal = ETrue;
117 if (aCommand == KCmdNew)
121 else if (aCommand == KCmdDestructor)
125 else if (aCommand == KCmdAssign)
127 DoCmdAssign(aSection);
129 else if (aCommand == KCmdConvertToInt)
131 DoCmdConvertToInt(aSection);
133 else if (aCommand == KCmdName)
144 void CT_DriveUnitData::DoCmdNewL(const TDesC& aSection)
145 /** Creates new TDriveUnit class instance */
147 //Deletes previous TDriveUnit class instance if it was already created.
150 INFO_PRINTF1(_L("Create new TDriveUnit class instance"));
153 if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
156 if (driveNameType == _L("number"))
159 if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
162 TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveNumber));
166 ERR_PRINTF2(_L("Error creating TDriveUnit(driveNumber): %d"), err);
171 else if (driveNameType == _L("letter"))
174 if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
177 TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveLetter));
181 ERR_PRINTF2(_L("Error creating TDriveUnit(driveLetter): %d"), err);
188 TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit());
192 ERR_PRINTF2(_L("Error creating TDriveUnit(): %d"), err);
199 void CT_DriveUnitData::DoCmdAssign(const TDesC& aSection)
200 /** Assigns the drive number or letter to the drive unit */
203 if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
205 if (driveNameType == _L("number"))
208 if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
210 INFO_PRINTF1(_L("Assign a new drive number to the drive unit"));
211 *iDriveUnit = iDriveUnit->operator=(driveNumber);
215 else if (driveNameType == _L("letter"))
218 if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
220 INFO_PRINTF1(_L("Assign a new drive letter to the drive unit"));
221 *iDriveUnit = iDriveUnit->operator=(driveLetter);
226 ERR_PRINTF1(_L("Drive name type is not specified!"));
227 SetBlockResult(EFail);
232 void CT_DriveUnitData::DoCmdConvertToInt(const TDesC& aSection)
233 /** Converts the drive unit to integer */
235 INFO_PRINTF1(_L("Convert the drive unit to an integer value"));
237 TInt intValue = iDriveUnit->operator TInt();
238 INFO_PRINTF2(_L("Drive unit integer value is %d"), intValue);
241 if (GET_OPTIONAL_INT_PARAMETER(KDriveExpValue(), aSection, driveExpValue))
243 if ( driveExpValue != intValue )
245 ERR_PRINTF3(_L("Drive expected integer value does not match! Expected value: %d, actual value: %d"), driveExpValue, intValue);
246 SetBlockResult(EFail);
250 INFO_PRINTF1(_L("Drive expected integer value matches the actual value!"));
255 void CT_DriveUnitData::DoCmdName(const TDesC& aSection)
256 /** Get the drive unit name as text */
258 INFO_PRINTF1(_L("Get the drive unit name as text with a colon in the end using Name()"));
260 TDriveName driveName = iDriveUnit->Name();
262 INFO_PRINTF2(_L("Drive name: %S"), &driveName);
264 TPtrC driveNameExpValue;
265 if (GET_OPTIONAL_STRING_PARAMETER(KDriveNameExpValue(), aSection, driveNameExpValue))
267 if ( driveNameExpValue != driveName )
269 ERR_PRINTF3(_L("Drive expected name value does not match! Expected value: %S, actual value: %S"), &driveNameExpValue, &driveName);
270 SetBlockResult(EFail);
274 INFO_PRINTF1(_L("Drive expected name value matches the actual value!"));
279 void CT_DriveUnitData::DoCmdDestructor()
280 /** Destroy TDriveUnit the object */