0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "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".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
/**
|
|
19 |
@test
|
|
20 |
@internalComponent
|
|
21 |
|
|
22 |
This contains CT_DriveUnitData
|
|
23 |
*/
|
|
24 |
|
|
25 |
// User includes
|
|
26 |
#include "T_DriveUnitData.h"
|
|
27 |
|
|
28 |
/*@{*/
|
|
29 |
/// Parameters
|
|
30 |
_LIT(KDriveNameType, "driveNameType");
|
|
31 |
_LIT(KDriveName, "driveName");
|
|
32 |
_LIT(KDriveExpValue, "driveExpValue");
|
|
33 |
_LIT(KDriveNameExpValue, "driveNameExpValue");
|
|
34 |
|
|
35 |
/// Commands
|
|
36 |
_LIT(KCmdNew, "new");
|
|
37 |
_LIT(KCmdDestructor, "~");
|
|
38 |
_LIT(KCmdAssign, "=");
|
|
39 |
_LIT(KCmdConvertToInt, "convertToInt");
|
|
40 |
_LIT(KCmdName, "name");
|
|
41 |
/*@}*/
|
|
42 |
|
|
43 |
CT_DriveUnitData* CT_DriveUnitData::NewL()
|
|
44 |
/**
|
|
45 |
* Two phase constructor
|
|
46 |
*/
|
|
47 |
{
|
|
48 |
CT_DriveUnitData* ret = new (ELeave) CT_DriveUnitData();
|
|
49 |
CleanupStack::PushL(ret);
|
|
50 |
ret->ConstructL();
|
|
51 |
CleanupStack::Pop(ret);
|
|
52 |
return ret;
|
|
53 |
}
|
|
54 |
|
|
55 |
CT_DriveUnitData::CT_DriveUnitData()
|
|
56 |
: iDriveUnit(NULL)
|
|
57 |
/**
|
|
58 |
* Protected constructor. First phase construction
|
|
59 |
*/
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
void CT_DriveUnitData::ConstructL()
|
|
64 |
/**
|
|
65 |
* Protected constructor. Second phase construction
|
|
66 |
*/
|
|
67 |
{
|
|
68 |
}
|
|
69 |
|
|
70 |
CT_DriveUnitData::~CT_DriveUnitData()
|
|
71 |
/**
|
|
72 |
* Destructor.
|
|
73 |
*/
|
|
74 |
{
|
|
75 |
DoCleanup();
|
|
76 |
}
|
|
77 |
|
|
78 |
void CT_DriveUnitData::DoCleanup()
|
|
79 |
/**
|
|
80 |
* Contains cleanup implementation
|
|
81 |
*/
|
|
82 |
{
|
|
83 |
if (iDriveUnit)
|
|
84 |
{
|
|
85 |
INFO_PRINTF1(_L("Deleting current TDriveUnit"));
|
|
86 |
delete iDriveUnit;
|
|
87 |
iDriveUnit = NULL;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
TAny* CT_DriveUnitData::GetObject()
|
|
92 |
/**
|
|
93 |
* Return a pointer to the object that the data wraps
|
|
94 |
*
|
|
95 |
* @return pointer to the object that the data wraps
|
|
96 |
*/
|
|
97 |
{
|
|
98 |
return iDriveUnit;
|
|
99 |
}
|
|
100 |
|
|
101 |
TBool CT_DriveUnitData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
|
|
102 |
/**
|
|
103 |
* Process a command read from the ini file
|
|
104 |
*
|
|
105 |
* @param aCommand requiring command to be processed
|
|
106 |
* @param aSection the section in the ini file requiring the command to be processed
|
|
107 |
* @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
|
|
108 |
*
|
|
109 |
* @leave system wide error
|
|
110 |
*
|
|
111 |
* @return ETrue if the command is processed
|
|
112 |
*/
|
|
113 |
{
|
|
114 |
TBool retVal = ETrue;
|
|
115 |
|
|
116 |
if (aCommand == KCmdNew)
|
|
117 |
{
|
|
118 |
DoCmdNewL(aSection);
|
|
119 |
}
|
|
120 |
else if (aCommand == KCmdDestructor)
|
|
121 |
{
|
|
122 |
DoCmdDestructor();
|
|
123 |
}
|
|
124 |
else if (aCommand == KCmdAssign)
|
|
125 |
{
|
|
126 |
DoCmdAssign(aSection);
|
|
127 |
}
|
|
128 |
else if (aCommand == KCmdConvertToInt)
|
|
129 |
{
|
|
130 |
DoCmdConvertToInt(aSection);
|
|
131 |
}
|
|
132 |
else if (aCommand == KCmdName)
|
|
133 |
{
|
|
134 |
DoCmdName(aSection);
|
|
135 |
}
|
|
136 |
else
|
|
137 |
{
|
|
138 |
retVal = EFalse;
|
|
139 |
}
|
|
140 |
return retVal;
|
|
141 |
}
|
|
142 |
|
|
143 |
void CT_DriveUnitData::DoCmdNewL(const TDesC& aSection)
|
|
144 |
/** Creates new TDriveUnit class instance */
|
|
145 |
{
|
|
146 |
//Deletes previous TDriveUnit class instance if it was already created.
|
|
147 |
DoCleanup();
|
|
148 |
|
|
149 |
INFO_PRINTF1(_L("Create new TDriveUnit class instance"));
|
|
150 |
|
|
151 |
TPtrC driveNameType;
|
|
152 |
if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
|
|
153 |
{
|
|
154 |
|
|
155 |
if (driveNameType == _L("number"))
|
|
156 |
{
|
|
157 |
TInt driveNumber;
|
|
158 |
if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
|
|
159 |
{
|
|
160 |
// do create
|
|
161 |
TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveNumber));
|
|
162 |
|
|
163 |
if (err != KErrNone)
|
|
164 |
{
|
|
165 |
ERR_PRINTF2(_L("Error creating TDriveUnit(driveNumber): %d"), err);
|
|
166 |
SetError( err );
|
|
167 |
}
|
|
168 |
}
|
|
169 |
}
|
|
170 |
else if (driveNameType == _L("letter"))
|
|
171 |
{
|
|
172 |
TPtrC driveLetter;
|
|
173 |
if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
|
|
174 |
{
|
|
175 |
// do create
|
|
176 |
TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveLetter));
|
|
177 |
|
|
178 |
if (err != KErrNone)
|
|
179 |
{
|
|
180 |
ERR_PRINTF2(_L("Error creating TDriveUnit(driveLetter): %d"), err);
|
|
181 |
SetError( err );
|
|
182 |
}
|
|
183 |
}
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit());
|
|
188 |
|
|
189 |
if (err != KErrNone)
|
|
190 |
{
|
|
191 |
ERR_PRINTF2(_L("Error creating TDriveUnit(): %d"), err);
|
|
192 |
SetError( err );
|
|
193 |
}
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
void CT_DriveUnitData::DoCmdAssign(const TDesC& aSection)
|
|
199 |
/** Assigns the drive number or letter to the drive unit */
|
|
200 |
{
|
|
201 |
TPtrC driveNameType;
|
|
202 |
if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
|
|
203 |
{
|
|
204 |
if (driveNameType == _L("number"))
|
|
205 |
{
|
|
206 |
TInt driveNumber;
|
|
207 |
if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
|
|
208 |
{
|
|
209 |
INFO_PRINTF1(_L("Assign a new drive number to the drive unit"));
|
|
210 |
*iDriveUnit = iDriveUnit->operator=(driveNumber);
|
|
211 |
|
|
212 |
}
|
|
213 |
}
|
|
214 |
else if (driveNameType == _L("letter"))
|
|
215 |
{
|
|
216 |
TPtrC driveLetter;
|
|
217 |
if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
|
|
218 |
{
|
|
219 |
INFO_PRINTF1(_L("Assign a new drive letter to the drive unit"));
|
|
220 |
*iDriveUnit = iDriveUnit->operator=(driveLetter);
|
|
221 |
}
|
|
222 |
}
|
|
223 |
else
|
|
224 |
{
|
|
225 |
ERR_PRINTF1(_L("Drive name type is not specified!"));
|
|
226 |
SetBlockResult(EFail);
|
|
227 |
}
|
|
228 |
}
|
|
229 |
}
|
|
230 |
|
|
231 |
void CT_DriveUnitData::DoCmdConvertToInt(const TDesC& aSection)
|
|
232 |
/** Converts the drive unit to integer */
|
|
233 |
{
|
|
234 |
INFO_PRINTF1(_L("Convert the drive unit to an integer value"));
|
|
235 |
|
|
236 |
TInt intValue = iDriveUnit->operator TInt();
|
|
237 |
INFO_PRINTF2(_L("Drive unit integer value is %d"), intValue);
|
|
238 |
|
|
239 |
TInt driveExpValue;
|
|
240 |
if (GET_OPTIONAL_INT_PARAMETER(KDriveExpValue(), aSection, driveExpValue))
|
|
241 |
{
|
|
242 |
if ( driveExpValue != intValue )
|
|
243 |
{
|
|
244 |
ERR_PRINTF3(_L("Drive expected integer value does not match! Expected value: %d, actual value: %d"), driveExpValue, intValue);
|
|
245 |
SetBlockResult(EFail);
|
|
246 |
}
|
|
247 |
else
|
|
248 |
{
|
|
249 |
INFO_PRINTF1(_L("Drive expected integer value matches the actual value!"));
|
|
250 |
}
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
|
254 |
void CT_DriveUnitData::DoCmdName(const TDesC& aSection)
|
|
255 |
/** Get the drive unit name as text */
|
|
256 |
{
|
|
257 |
INFO_PRINTF1(_L("Get the drive unit name as text with a colon in the end using Name()"));
|
|
258 |
|
|
259 |
TDriveName driveName = iDriveUnit->Name();
|
|
260 |
|
|
261 |
INFO_PRINTF2(_L("Drive name: %S"), &driveName);
|
|
262 |
|
|
263 |
TPtrC driveNameExpValue;
|
|
264 |
if (GET_OPTIONAL_STRING_PARAMETER(KDriveNameExpValue(), aSection, driveNameExpValue))
|
|
265 |
{
|
|
266 |
if ( driveNameExpValue != driveName )
|
|
267 |
{
|
|
268 |
ERR_PRINTF3(_L("Drive expected name value does not match! Expected value: %S, actual value: %S"), &driveNameExpValue, &driveName);
|
|
269 |
SetBlockResult(EFail);
|
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
273 |
INFO_PRINTF1(_L("Drive expected name value matches the actual value!"));
|
|
274 |
}
|
|
275 |
}
|
|
276 |
}
|
|
277 |
|
|
278 |
void CT_DriveUnitData::DoCmdDestructor()
|
|
279 |
/** Destroy TDriveUnit the object */
|
|
280 |
{
|
|
281 |
DoCleanup();
|
|
282 |
}
|