sl@0: /* sl@0: * Copyright (c) 1998-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 the License "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: * T_CErrorConverter.CPP sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "t_errorconverter.h" sl@0: #include sl@0: sl@0: sl@0: class CErrorItem : public CBase sl@0: { sl@0: public: sl@0: static CErrorItem *NewLC(const TDesC &aErrorName, const TInt aError); sl@0: static CErrorItem *NewL(const TDesC &aErrorName, const TInt aError); sl@0: virtual ~CErrorItem(void) { delete iErrorName;}; sl@0: sl@0: public: sl@0: HBufC8* iErrorName; sl@0: const TInt iError; sl@0: sl@0: private: sl@0: void ConstructL(const TDesC &aErrorName); sl@0: CErrorItem(const TInt aError) : iError(aError){} sl@0: }; sl@0: sl@0: CErrorItem *CErrorItem::NewLC(const TDesC &aErrorName, const TInt aError) sl@0: { sl@0: CErrorItem *errorItem = new (ELeave) CErrorItem(aError); sl@0: CleanupStack::PushL(errorItem); sl@0: errorItem->ConstructL(aErrorName); sl@0: return(errorItem); sl@0: } sl@0: sl@0: CErrorItem *CErrorItem::NewL(const TDesC &aErrorName, const TInt aError) sl@0: { sl@0: CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aError); sl@0: CleanupStack::Pop(errorItem); sl@0: return(errorItem); sl@0: }; sl@0: sl@0: void CErrorItem::ConstructL(const TDesC &aErrorName) sl@0: { sl@0: iErrorName = HBufC8::NewL(aErrorName.Length()); sl@0: iErrorName->Des().Copy(aErrorName); sl@0: }; sl@0: sl@0: EXPORT_C CErrorConverter* CErrorConverter::NewLC(void) sl@0: { sl@0: CErrorConverter *errorConverter = new (ELeave) CErrorConverter(); sl@0: CleanupStack::PushL(errorConverter); sl@0: errorConverter->ConstructL(); sl@0: return(errorConverter); sl@0: }; sl@0: EXPORT_C CErrorConverter* CErrorConverter::NewL(void) sl@0: { sl@0: CErrorConverter *errorConverter = CErrorConverter::NewLC(); sl@0: CleanupStack::Pop(errorConverter); sl@0: return(errorConverter); sl@0: }; sl@0: sl@0: EXPORT_C CErrorConverter::~CErrorConverter() sl@0: { sl@0: iErrorMap.ResetAndDestroy(); sl@0: }; sl@0: sl@0: void CErrorConverter::ConstructL(void) sl@0: { sl@0: CreateErrorMapL(); sl@0: }; sl@0: sl@0: EXPORT_C void CErrorConverter::AddErrorItem(const TDesC& aErrorName, const TInt &aErrorCode) sl@0: { sl@0: CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aErrorCode); sl@0: sl@0: User::LeaveIfError(iErrorMap.Append(errorItem)); sl@0: CleanupStack::Pop(errorItem); sl@0: }; sl@0: sl@0: void CErrorConverter::CreateErrorMapL() sl@0: { sl@0: AddErrorItem(_L("KErrNone"), KErrNone); sl@0: AddErrorItem(_L("KErrNotFound"), KErrNotFound); sl@0: AddErrorItem(_L("KErrGeneral"), KErrGeneral); sl@0: AddErrorItem(_L("KErrCancel"), KErrCancel); sl@0: AddErrorItem(_L("KErrNoMemory"), KErrNoMemory); sl@0: AddErrorItem(_L("KErrNotSupported"), KErrNotSupported); sl@0: AddErrorItem(_L("KErrArgument"), KErrArgument); sl@0: AddErrorItem(_L("KErrTotalLossOfPrecision"), KErrTotalLossOfPrecision); sl@0: AddErrorItem(_L("KErrBadHandle"), KErrBadHandle); sl@0: AddErrorItem(_L("KErrOverflow"), KErrOverflow); sl@0: AddErrorItem(_L("KErrUnderflow"), KErrUnderflow); sl@0: AddErrorItem(_L("KErrAlreadyExists"), KErrAlreadyExists); sl@0: AddErrorItem(_L("KErrPathNotFound"), KErrPathNotFound); sl@0: AddErrorItem(_L("KErrDied"), KErrDied); sl@0: AddErrorItem(_L("KErrInUse"), KErrInUse); sl@0: AddErrorItem(_L("KErrServerTerminated"), KErrServerTerminated); sl@0: AddErrorItem(_L("KErrServerBusy"), KErrServerBusy); sl@0: AddErrorItem(_L("KErrCompletion"), KErrCompletion); sl@0: AddErrorItem(_L("KErrNotReady"), KErrNotReady); sl@0: AddErrorItem(_L("KErrUnknown"), KErrUnknown); sl@0: AddErrorItem(_L("KErrCorrupt"), KErrCorrupt); sl@0: AddErrorItem(_L("KErrAccessDenied"), KErrAccessDenied); sl@0: AddErrorItem(_L("KErrLocked"), KErrLocked); sl@0: AddErrorItem(_L("KErrWrite"), KErrWrite); sl@0: AddErrorItem(_L("KErrDisMounted"), KErrDisMounted); sl@0: AddErrorItem(_L("KErrEof"), KErrEof); sl@0: AddErrorItem(_L("KErrDiskFull"), KErrDiskFull); sl@0: AddErrorItem(_L("KErrBadDriver"), KErrBadDriver); sl@0: AddErrorItem(_L("KErrBadName"), KErrBadName); sl@0: AddErrorItem(_L("KErrCommsLineFail"), KErrCommsLineFail); sl@0: AddErrorItem(_L("KErrCommsFrame"), KErrCommsFrame); sl@0: AddErrorItem(_L("KErrCommsOverrun"), KErrCommsOverrun); sl@0: AddErrorItem(_L("KErrCommsParity"), KErrCommsParity); sl@0: AddErrorItem(_L("KErrTimedOut"), KErrTimedOut); sl@0: AddErrorItem(_L("KErrCouldNotConnect"), KErrCouldNotConnect); sl@0: AddErrorItem(_L("KErrCouldNotDisconnect"), KErrCouldNotDisconnect); sl@0: AddErrorItem(_L("KErrDisconnected"), KErrDisconnected); sl@0: AddErrorItem(_L("KErrBadLibraryEntryPoint"), KErrBadLibraryEntryPoint); sl@0: AddErrorItem(_L("KErrBadDescriptor"), KErrBadDescriptor); sl@0: AddErrorItem(_L("KErrAbort"), KErrAbort); sl@0: AddErrorItem(_L("KErrTooBig"), KErrTooBig); sl@0: AddErrorItem(_L("KErrDivideByZero"), KErrDivideByZero); sl@0: AddErrorItem(_L("KErrBadPower"), KErrBadPower); sl@0: AddErrorItem(_L("KErrDirFull"), KErrDirFull); sl@0: AddErrorItem(_L("KErrHardwareNotAvailable"), KErrHardwareNotAvailable); sl@0: AddErrorItem(_L("KErrPrivateKeyNotFound"), KErrPrivateKeyNotFound); sl@0: AddErrorItem(_L("KErrPermissionDenied"), KErrPermissionDenied); sl@0: } sl@0: sl@0: EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TDesC& aResult /* in */, TInt &aError /* out */) sl@0: { sl@0: HBufC8 *resultBuf = HBufC8::NewLC(aResult.Length()); sl@0: resultBuf->Des().Copy(aResult); sl@0: TBool result = EFalse; sl@0: CErrorItem *pError; sl@0: TInt errorPos=0; sl@0: sl@0: aError = KErrUnknown; sl@0: sl@0: for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++) sl@0: { sl@0: pError = iErrorMap[errorPos]; sl@0: if(pError->iErrorName->CompareF(*resultBuf)==0) sl@0: { sl@0: aError = pError->iError; sl@0: result = ETrue; sl@0: }; sl@0: } sl@0: CleanupStack::PopAndDestroy(resultBuf); sl@0: sl@0: return(result); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TInt &aError /* in */, HBufC*& aResult /* out */) sl@0: { sl@0: TBool result = EFalse; sl@0: TInt errorPos=0; sl@0: CErrorItem *pError; sl@0: sl@0: __ASSERT_DEBUG(!result, User::Panic(_L("CErrorConverter::GetExpectedResultL"), 1)); sl@0: for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++) sl@0: { sl@0: pError = iErrorMap[errorPos]; sl@0: if(pError->iError == aError) sl@0: { sl@0: aResult = HBufC::NewLC(pError->iErrorName->Length()); sl@0: aResult->Des().Copy(*pError->iErrorName); sl@0: result = ETrue; sl@0: }; sl@0: } sl@0: // just so it always has something to pop even if it didnt find error sl@0: if(!result) sl@0: { sl@0: aResult = HBufC::NewLC(0); sl@0: }; sl@0: sl@0: return(result); sl@0: } sl@0: sl@0: