sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* T_CErrorConverter.CPP
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <s32file.h>
|
sl@0
|
21 |
#include "t_errorconverter.h"
|
sl@0
|
22 |
#include <securityerr.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
class CErrorItem : public CBase
|
sl@0
|
26 |
{
|
sl@0
|
27 |
public:
|
sl@0
|
28 |
static CErrorItem *NewLC(const TDesC &aErrorName, const TInt aError);
|
sl@0
|
29 |
static CErrorItem *NewL(const TDesC &aErrorName, const TInt aError);
|
sl@0
|
30 |
virtual ~CErrorItem(void) { delete iErrorName;};
|
sl@0
|
31 |
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
HBufC8* iErrorName;
|
sl@0
|
34 |
const TInt iError;
|
sl@0
|
35 |
|
sl@0
|
36 |
private:
|
sl@0
|
37 |
void ConstructL(const TDesC &aErrorName);
|
sl@0
|
38 |
CErrorItem(const TInt aError) : iError(aError){}
|
sl@0
|
39 |
};
|
sl@0
|
40 |
|
sl@0
|
41 |
CErrorItem *CErrorItem::NewLC(const TDesC &aErrorName, const TInt aError)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
CErrorItem *errorItem = new (ELeave) CErrorItem(aError);
|
sl@0
|
44 |
CleanupStack::PushL(errorItem);
|
sl@0
|
45 |
errorItem->ConstructL(aErrorName);
|
sl@0
|
46 |
return(errorItem);
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
CErrorItem *CErrorItem::NewL(const TDesC &aErrorName, const TInt aError)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aError);
|
sl@0
|
52 |
CleanupStack::Pop(errorItem);
|
sl@0
|
53 |
return(errorItem);
|
sl@0
|
54 |
};
|
sl@0
|
55 |
|
sl@0
|
56 |
void CErrorItem::ConstructL(const TDesC &aErrorName)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
iErrorName = HBufC8::NewL(aErrorName.Length());
|
sl@0
|
59 |
iErrorName->Des().Copy(aErrorName);
|
sl@0
|
60 |
};
|
sl@0
|
61 |
|
sl@0
|
62 |
EXPORT_C CErrorConverter* CErrorConverter::NewLC(void)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
CErrorConverter *errorConverter = new (ELeave) CErrorConverter();
|
sl@0
|
65 |
CleanupStack::PushL(errorConverter);
|
sl@0
|
66 |
errorConverter->ConstructL();
|
sl@0
|
67 |
return(errorConverter);
|
sl@0
|
68 |
};
|
sl@0
|
69 |
EXPORT_C CErrorConverter* CErrorConverter::NewL(void)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
CErrorConverter *errorConverter = CErrorConverter::NewLC();
|
sl@0
|
72 |
CleanupStack::Pop(errorConverter);
|
sl@0
|
73 |
return(errorConverter);
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
EXPORT_C CErrorConverter::~CErrorConverter()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
iErrorMap.ResetAndDestroy();
|
sl@0
|
79 |
};
|
sl@0
|
80 |
|
sl@0
|
81 |
void CErrorConverter::ConstructL(void)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
CreateErrorMapL();
|
sl@0
|
84 |
};
|
sl@0
|
85 |
|
sl@0
|
86 |
EXPORT_C void CErrorConverter::AddErrorItem(const TDesC& aErrorName, const TInt &aErrorCode)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aErrorCode);
|
sl@0
|
89 |
|
sl@0
|
90 |
User::LeaveIfError(iErrorMap.Append(errorItem));
|
sl@0
|
91 |
CleanupStack::Pop(errorItem);
|
sl@0
|
92 |
};
|
sl@0
|
93 |
|
sl@0
|
94 |
void CErrorConverter::CreateErrorMapL()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
AddErrorItem(_L("KErrNone"), KErrNone);
|
sl@0
|
97 |
AddErrorItem(_L("KErrNotFound"), KErrNotFound);
|
sl@0
|
98 |
AddErrorItem(_L("KErrGeneral"), KErrGeneral);
|
sl@0
|
99 |
AddErrorItem(_L("KErrCancel"), KErrCancel);
|
sl@0
|
100 |
AddErrorItem(_L("KErrNoMemory"), KErrNoMemory);
|
sl@0
|
101 |
AddErrorItem(_L("KErrNotSupported"), KErrNotSupported);
|
sl@0
|
102 |
AddErrorItem(_L("KErrArgument"), KErrArgument);
|
sl@0
|
103 |
AddErrorItem(_L("KErrTotalLossOfPrecision"), KErrTotalLossOfPrecision);
|
sl@0
|
104 |
AddErrorItem(_L("KErrBadHandle"), KErrBadHandle);
|
sl@0
|
105 |
AddErrorItem(_L("KErrOverflow"), KErrOverflow);
|
sl@0
|
106 |
AddErrorItem(_L("KErrUnderflow"), KErrUnderflow);
|
sl@0
|
107 |
AddErrorItem(_L("KErrAlreadyExists"), KErrAlreadyExists);
|
sl@0
|
108 |
AddErrorItem(_L("KErrPathNotFound"), KErrPathNotFound);
|
sl@0
|
109 |
AddErrorItem(_L("KErrDied"), KErrDied);
|
sl@0
|
110 |
AddErrorItem(_L("KErrInUse"), KErrInUse);
|
sl@0
|
111 |
AddErrorItem(_L("KErrServerTerminated"), KErrServerTerminated);
|
sl@0
|
112 |
AddErrorItem(_L("KErrServerBusy"), KErrServerBusy);
|
sl@0
|
113 |
AddErrorItem(_L("KErrCompletion"), KErrCompletion);
|
sl@0
|
114 |
AddErrorItem(_L("KErrNotReady"), KErrNotReady);
|
sl@0
|
115 |
AddErrorItem(_L("KErrUnknown"), KErrUnknown);
|
sl@0
|
116 |
AddErrorItem(_L("KErrCorrupt"), KErrCorrupt);
|
sl@0
|
117 |
AddErrorItem(_L("KErrAccessDenied"), KErrAccessDenied);
|
sl@0
|
118 |
AddErrorItem(_L("KErrLocked"), KErrLocked);
|
sl@0
|
119 |
AddErrorItem(_L("KErrWrite"), KErrWrite);
|
sl@0
|
120 |
AddErrorItem(_L("KErrDisMounted"), KErrDisMounted);
|
sl@0
|
121 |
AddErrorItem(_L("KErrEof"), KErrEof);
|
sl@0
|
122 |
AddErrorItem(_L("KErrDiskFull"), KErrDiskFull);
|
sl@0
|
123 |
AddErrorItem(_L("KErrBadDriver"), KErrBadDriver);
|
sl@0
|
124 |
AddErrorItem(_L("KErrBadName"), KErrBadName);
|
sl@0
|
125 |
AddErrorItem(_L("KErrCommsLineFail"), KErrCommsLineFail);
|
sl@0
|
126 |
AddErrorItem(_L("KErrCommsFrame"), KErrCommsFrame);
|
sl@0
|
127 |
AddErrorItem(_L("KErrCommsOverrun"), KErrCommsOverrun);
|
sl@0
|
128 |
AddErrorItem(_L("KErrCommsParity"), KErrCommsParity);
|
sl@0
|
129 |
AddErrorItem(_L("KErrTimedOut"), KErrTimedOut);
|
sl@0
|
130 |
AddErrorItem(_L("KErrCouldNotConnect"), KErrCouldNotConnect);
|
sl@0
|
131 |
AddErrorItem(_L("KErrCouldNotDisconnect"), KErrCouldNotDisconnect);
|
sl@0
|
132 |
AddErrorItem(_L("KErrDisconnected"), KErrDisconnected);
|
sl@0
|
133 |
AddErrorItem(_L("KErrBadLibraryEntryPoint"), KErrBadLibraryEntryPoint);
|
sl@0
|
134 |
AddErrorItem(_L("KErrBadDescriptor"), KErrBadDescriptor);
|
sl@0
|
135 |
AddErrorItem(_L("KErrAbort"), KErrAbort);
|
sl@0
|
136 |
AddErrorItem(_L("KErrTooBig"), KErrTooBig);
|
sl@0
|
137 |
AddErrorItem(_L("KErrDivideByZero"), KErrDivideByZero);
|
sl@0
|
138 |
AddErrorItem(_L("KErrBadPower"), KErrBadPower);
|
sl@0
|
139 |
AddErrorItem(_L("KErrDirFull"), KErrDirFull);
|
sl@0
|
140 |
AddErrorItem(_L("KErrHardwareNotAvailable"), KErrHardwareNotAvailable);
|
sl@0
|
141 |
AddErrorItem(_L("KErrPrivateKeyNotFound"), KErrPrivateKeyNotFound);
|
sl@0
|
142 |
AddErrorItem(_L("KErrPermissionDenied"), KErrPermissionDenied);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TDesC& aResult /* in */, TInt &aError /* out */)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
HBufC8 *resultBuf = HBufC8::NewLC(aResult.Length());
|
sl@0
|
148 |
resultBuf->Des().Copy(aResult);
|
sl@0
|
149 |
TBool result = EFalse;
|
sl@0
|
150 |
CErrorItem *pError;
|
sl@0
|
151 |
TInt errorPos=0;
|
sl@0
|
152 |
|
sl@0
|
153 |
aError = KErrUnknown;
|
sl@0
|
154 |
|
sl@0
|
155 |
for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
pError = iErrorMap[errorPos];
|
sl@0
|
158 |
if(pError->iErrorName->CompareF(*resultBuf)==0)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
aError = pError->iError;
|
sl@0
|
161 |
result = ETrue;
|
sl@0
|
162 |
};
|
sl@0
|
163 |
}
|
sl@0
|
164 |
CleanupStack::PopAndDestroy(resultBuf);
|
sl@0
|
165 |
|
sl@0
|
166 |
return(result);
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TInt &aError /* in */, HBufC*& aResult /* out */)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TBool result = EFalse;
|
sl@0
|
173 |
TInt errorPos=0;
|
sl@0
|
174 |
CErrorItem *pError;
|
sl@0
|
175 |
|
sl@0
|
176 |
__ASSERT_DEBUG(!result, User::Panic(_L("CErrorConverter::GetExpectedResultL"), 1));
|
sl@0
|
177 |
for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
pError = iErrorMap[errorPos];
|
sl@0
|
180 |
if(pError->iError == aError)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
aResult = HBufC::NewLC(pError->iErrorName->Length());
|
sl@0
|
183 |
aResult->Des().Copy(*pError->iErrorName);
|
sl@0
|
184 |
result = ETrue;
|
sl@0
|
185 |
};
|
sl@0
|
186 |
}
|
sl@0
|
187 |
// just so it always has something to pop even if it didnt find error
|
sl@0
|
188 |
if(!result)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
aResult = HBufC::NewLC(0);
|
sl@0
|
191 |
};
|
sl@0
|
192 |
|
sl@0
|
193 |
return(result);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
|