CTextResolver Class Reference

class CTextResolver : public CBase

Class offers functionality for resolving corresponding error texts for error codes. Text Resolver API provides operations with which a specific error code can be resolved to a human readable text. Descriptions for the different error codes must be defined in the resource files of this component.

Text Resolver uses the CCoeEnv environment class to access the resource files if the CCoeEnv environment is available. If the CCoeEnv environment is not available, the files are accessed through the RResourceFile API.

The API consist of the CTextResolver class which is used together with Text Resolver flags defined in textresolver.hrh file. The flags are used to tell the priority of the error to the client:

  • EErrorResBlankErrorFlag is used to tell that error has no proper explanation.

  • EErrorResUnknownErrorFlag indicates that Text Resolver does not support the error.

  • EErrorResOOMFlag Flag is returned while processing KErrNoMemory error code.

Usage:

        #include <textresolver.h>

  // Typically used as an instance variable.
  
  // Call the factory method NewLC() to create a new instance of CTextResolver.
  // NewLC() method leaves the instance of the object on the cleanup stack.	
  // The passed CCoeEnv instance is needed to access the resource files.
  CTextResolver* iTextResolver = CTextResolver::NewLC(*iCoeEnv); 

  // // Error Resolving, simple:

  // Get error code to be resolved.
  // TInt err1 = MyMethod(KInvalidValue);
  TInt err1 = KErrNoMemory;
    
  TPtrC buf1;  // For returned error text
    
  if (err1 != KErrNone)
      {
      // Resolve the given error code. 
      // The operation returns the error text for the resolved error.
      // There's no limit how long the resolved string can be.
      // Add context to 2nd param if needed.
      buf1.Set(iTextResolver->ResolveErrorString(err)); 
      }
  else
      {
      // Do something.
      }
        
  // Note that buf1 will only be valid as long as CTextResolver 
  // instance is alive and no new error is resolved by the same instance.
  // If for some reason you need to store the resolved error
  // beyond immediate use, make a copy of it.

  // Error Resolving, advanced:
 
  // Get error code to be resolved.
  // TInt err2 = MyMethod(KInvalidValue);
  TInt err2 = KErrNotSupported;
        
  TInt textId(0);    // ID of the returned text
  TUint flags(0);    // Priority of the returned error 
  TPtrC buf2;      // For returned error text
   
  if (err2 != KErrNone)
      {
      // Resolve the given error code.
      // The operation returns the error text for the resolved error.
      // There's no limit on how long the resolved string can be.
      // Add Context to 4th param if needed.
      buf2.Set(iTextResolver->ResolveErrorString(err, textId, flags)); 

      if (flags & EErrorResUnknownErrorFlag)
          {
          // The flag indicates that Text Resolver does not support
          // the error code. 
          // Do something.
          }
      }
  else
      {
      // Do something.
      }
    
  // Note that buf2 will only be valid as long as CTextResolver 
  // instance is alive and no new error is resolved by the same instance.
  // If for some reason you need to store the resolved error
  // beyond immediate use, make a copy of it.

  // iTextResolver, Free loaded resources
  CleanupStack::PopAndDestroy();
       
commonengine.lib
Since
S60 2.0

Inherits from

Public Member Functions
~CTextResolver ()
IMPORT_C CTextResolver * NewL ( CCoeEnv &)
IMPORT_C CTextResolver * NewL ()
IMPORT_C CTextResolver * NewLC ( CCoeEnv &)
IMPORT_C CTextResolver * NewLC ()
IMPORT_C const TDesC & ResolveErrorString ( TInt , TInt &, TUint &, TErrorContext )
IMPORT_C const TDesC & ResolveErrorString ( TInt , TErrorContext )
Private Member Functions
CTextResolver ( CCoeEnv &)
CTextResolver ()
TBool AddContextAndSeparator ( TErrorContext )
void AllocBuffersL ()
HBufC * AllocReadUnicodeString (RResourceFile &, TInt )
void ConstructL ()
void DoRawReadOfSystemErrorResourcesToArraysL ( TInt &, TInt &)
void DoResolveErrorStringL ( TInt , TInt &, TUint &)
void LoadResourceFilesL ()
void ReadLocalizedSeparatorCharacterFromResourceAndPrepareResourceReaderLC ( TResourceReader &)
void ReadLocalizedSeparatorCharacterFromResourceL ( CCoeEnv &)
void Reset ()
TInt ResourceForError ( TInt )
Inherited Functions
CBase::CBase()
CBase::Delete(CBase *)
CBase::Extension_(TUint,TAny *&,TAny *)
CBase::operator new(TUint)
CBase::operator new(TUint,TAny *)
CBase::operator new(TUint,TLeave)
CBase::operator new(TUint,TLeave,TUint)
CBase::operator new(TUint,TUint)
CBase::~CBase()
Public Member Enumerations
enum TErrorContext { ECtxAutomatic  = 0, ECtxNoCtx  = 1, ECtxNoCtxNoSeparator  = 2 }
Private Attributes
CArrayFix < TInt > * iAppTexts
TInt iBaseResourceFileOffset
CCoeEnv * iCoe
HBufC * iContextSeparator
CArrayPtr < CErrorResourceIdArray > * iErrorTexts
CArrayPtr < CErrorResourceFlagArray > * iFlags
RFs iFs
TInt iRDSupport
RResourceFile iResFile
CArrayFix < TInt > * iStartError
HBufC * iTextBuffer
HBufC * iTitleText
TPtrC iTruncatedTextPointer

Constructor & Destructor Documentation

CTextResolver(CCoeEnv &)

CTextResolver ( CCoeEnv & aEnv ) [private]

Parameters

CCoeEnv & aEnv

CTextResolver()

CTextResolver ( ) [private]

~CTextResolver()

IMPORT_C ~CTextResolver ( )

Destructor

Member Functions Documentation

AddContextAndSeparator(TErrorContext)

TBool AddContextAndSeparator ( TErrorContext aContext ) [private]

Returns false if any memory allocation fails or initial values of necessary pointers are NULL, indicating alloc failure earlier.

Parameters

TErrorContext aContext

AllocBuffersL()

void AllocBuffersL ( ) [private]

AllocReadUnicodeString(RResourceFile &, TInt)

HBufC * AllocReadUnicodeString ( RResourceFile & aResFile,
TInt aTextId
) [private, static]

Parameters

RResourceFile & aResFile
TInt aTextId

ConstructL()

void ConstructL ( ) [private]

DoRawReadOfSystemErrorResourcesToArraysL(TInt &, TInt &)

void DoRawReadOfSystemErrorResourcesToArraysL ( TInt & aError,
TInt & aTextId
) [private]

Read the system error texts from errorres.rss only, without using the Uikon CEikErrorResolver. This will not pick up any appliation specific errors.

Parameters

TInt & aError
TInt & aTextId

DoResolveErrorStringL(TInt, TInt &, TUint &)

void DoResolveErrorStringL ( TInt aError,
TInt & aTextId,
TUint & aFlags
) [private]

Parameters

TInt aError
TInt & aTextId
TUint & aFlags

LoadResourceFilesL()

void LoadResourceFilesL ( ) [private, inline, virtual]

NewL(CCoeEnv &)

IMPORT_C CTextResolver * NewL ( CCoeEnv & aEnv ) [static]

Two-phase constructor method that is used to create a new instance of the CTextResolver class. The implementation uses the passed CCoeEnv instance to access the resource files.

Parameters

CCoeEnv & aEnv the CCoeEnv instance to be used to access the resource files.

NewL()

IMPORT_C CTextResolver * NewL ( ) [static]

Constructor creates a new instance of CTextResolver . Resource files are accessed through the RResourceFile API.

NewLC(CCoeEnv &)

IMPORT_C CTextResolver * NewLC ( CCoeEnv & aEnv ) [static]

Constructor creates a new instance of CTextResolver . The implementation uses the passed CCoeEnv instance to access the resource files. Leaves the object on the cleanup stack.

Parameters

CCoeEnv & aEnv the CCoeEnv instance to be used to access the resource files.

NewLC()

IMPORT_C CTextResolver * NewLC ( ) [static]

Constructor creates a new instance of CTextResolver.Resource files are accessed through the RResourceFile API. Leaves the object on the cleanup stack.

ReadLocalizedSeparatorCharacterFromResourceAndPrepareResourceReaderLC(TResourceReader &)

void ReadLocalizedSeparatorCharacterFromResourceAndPrepareResourceReaderLC ( TResourceReader & aResReader ) [private]

ErrorResolver resource files in the ?:/resource/errors/ folder must always begin with an array of error texts. The Nokia-specific version of the errorres.rss file also contains the localized titel/text separator character at the end of the file. This method reads the separator character from file WITHOUT using a CCoeEnv .

Parameters

TResourceReader & aResReader

ReadLocalizedSeparatorCharacterFromResourceL(CCoeEnv &)

void ReadLocalizedSeparatorCharacterFromResourceL ( CCoeEnv & aCoeEnv ) [private]

ErrorResolver resource files in the ?:/resource/errors/ folder must always begin with an array of error texts. The Nokia-specific version of the errorres.rss file also contains the localized titel/text separator character at the end of the file. This method reads the separator character from file using the CCoeEnv provided.

Parameters

CCoeEnv & aCoeEnv

Reset()

void Reset ( ) [private]

ResolveErrorString(TInt, TInt &, TUint &, TErrorContext)

IMPORT_C const TDesC & ResolveErrorString ( TInt aError,
TInt & aTextId,
TUint & aFlags,
TErrorContext aContext = ECtxAutomatic
)

Resolves the given error code and returns the error text for the resolved error. Resolved text can be of any length. This version is for advanced use

Parameters

TInt aError The error code to be resolved.
TInt & aTextId ID of the returned text.
TUint & aFlags The priority of the returned error. The priority is defined by the this module! Flags are defined in textresolver.hrh.
TErrorContext aContext = ECtxAutomatic Optional context for error numbers. If the aContext parameter is not passed to the function, it uses the default value ECtxAutomatic.

ResolveErrorString(TInt, TErrorContext)

IMPORT_C const TDesC & ResolveErrorString ( TInt aError,
TErrorContext aContext = ECtxAutomatic
)

Resolves the given error code and returns the error text for the resolved error. Resolved text can be of any length. This version is for "normal" use.

Parameters

TInt aError The error code to be resolved.
TErrorContext aContext = ECtxAutomatic Optional context for error numbers. If the aContext parameter is not passed to the function, it uses the default value ECtxAutomatic.

ResourceForError(TInt)

TInt ResourceForError ( TInt aError ) [private, virtual]

Parameters

TInt aError

Member Enumerations Documentation

Enum TErrorContext

Defines used error contexts. Optional error contexes for aiding the mapping of error codes to texts in a unique way. If no context is given the assumption is that error codes are unique.

Enumerators

ECtxAutomatic = 0

Context is defined automatically from error code value. Here it is assumed that each error code is unique and in own range. This is a default value when resolving errors.

ECtxNoCtx = 1

Context text is not added to the beginning of the resolved error text, just context separator ':' and newline are added.

ECtxNoCtxNoSeparator = 2

No context text, context separator ':' or newline added to the beginning of the resolved error text.

Member Data Documentation

CArrayFix< TInt > * iAppTexts

CArrayFix < TInt > * iAppTexts [private]

TInt iBaseResourceFileOffset

TInt iBaseResourceFileOffset [private]

CCoeEnv * iCoe

CCoeEnv * iCoe [private]

HBufC * iContextSeparator

HBufC * iContextSeparator [private]

CArrayPtr< CErrorResourceIdArray > * iErrorTexts

CArrayPtr < CErrorResourceIdArray > * iErrorTexts [private]

CArrayPtr< CErrorResourceFlagArray > * iFlags

CArrayPtr < CErrorResourceFlagArray > * iFlags [private]

RFs iFs

RFs iFs [private]

TInt iRDSupport

TInt iRDSupport [private]

RResourceFile iResFile

RResourceFile iResFile [private]

CArrayFix< TInt > * iStartError

CArrayFix < TInt > * iStartError [private]

HBufC * iTextBuffer

HBufC * iTextBuffer [private]

HBufC * iTitleText

HBufC * iTitleText [private]

TPtrC iTruncatedTextPointer

TPtrC iTruncatedTextPointer [private]