Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Error module

This module does all error handling. More...

Classes

struct  ERRORTYPEREGISTRATIONFORM

Initialization

CHIPCARD_API void Error_ModuleInit ()
CHIPCARD_API void Error_ModuleFini ()

Error Type Registration

These functions are used to allocate error types. Each module should allocate a type to allow descriptive error messages. Since function pointers are involved you should carefully register and unregister the error types.

CHIPCARD_API int Error_RegisterType (ERRORTYPEREGISTRATIONFORM *tptr)
CHIPCARD_API int Error_UnregisterType (ERRORTYPEREGISTRATIONFORM *tptr)

Error Type Lookup

These functions lookup error types by name or by number.

CHIPCARD_API int Error_FindType (const char *name)
CHIPCARD_API const char * Error_GetTypename (int t)

Getters And Setters

These functions get and set parts of an ERRORCODE.

CHIPCARD_API ERRORCODE Error_New (int iscustom, int severity, int typ, int code)
CHIPCARD_API int Error_IsOk (ERRORCODE c)
CHIPCARD_API int Error_GetSeverity (ERRORCODE c)
CHIPCARD_API void Error_SetSeverity (ERRORCODE *c, int v)
CHIPCARD_API int Error_IsCustom (ERRORCODE c)
CHIPCARD_API void Error_SetIsCustom (ERRORCODE *c, int iscustom)
CHIPCARD_API int Error_GetType (ERRORCODE c)
CHIPCARD_API void Error_SetType (ERRORCODE *c, int v)
CHIPCARD_API int Error_GetCode (ERRORCODE c)
CHIPCARD_API void Error_SetCode (ERRORCODE *c, int v)

Verbosity

Composing error messages.

CHIPCARD_API int Error_ToString (ERRORCODE c, char *buffer, int bsize)

Defines

#define ERROR_SEVERITY_DEBUG   0
#define ERROR_SEVERITY_INFO   1
#define ERROR_SEVERITY_WARN   2
#define ERROR_SEVERITY_ERR   3
#define ERROR_TYPE_ERROR   0
#define ERROR_UNSPECIFIED   1
#define ERROR_COULD_NOT_REGISTER   2
#define ERROR_COULD_NOT_UNREGISTER   3
#define ERROR_INVALID_BUFFERSIZE   4

Variables

CHIPCARD_API typedef const
char *(* 
ERRORMESSAGEPTR )(int c)
CHIPCARD_API typedef unsigned
long 
ERRORCODE

Detailed Description

This module does all error handling.

Author:
Martin Preuss<martin@libchipcard.de>
All errors are grouped into error types. There is no predefined error type, all modules, which want to take advantage of this module should register their own error type. When registering an error type, this module learns about the new error type:

Define Documentation

#define ERROR_COULD_NOT_REGISTER   2
 

#define ERROR_COULD_NOT_UNREGISTER   3
 

#define ERROR_INVALID_BUFFERSIZE   4
 

#define ERROR_SEVERITY_DEBUG   0
 

The error code is a debug level code.

#define ERROR_SEVERITY_ERR   3
 

The error code is a error level code.

#define ERROR_SEVERITY_INFO   1
 

The error code is a information level code.

#define ERROR_SEVERITY_WARN   2
 

The error code is a warning level code.

#define ERROR_TYPE_ERROR   0
 

This class is used for ERROR-related errors ;-)

#define ERROR_UNSPECIFIED   1
 


Function Documentation

CHIPCARD_API int Error_FindType const char *  name  ) 
 

This function returns the type number for the given type name.

Returns:
type number (-1 on error)

CHIPCARD_API int Error_GetCode ERRORCODE  c  ) 
 

Returns the 16 bit error code value.

CHIPCARD_API int Error_GetSeverity ERRORCODE  c  ) 
 

Returns the severity of the error

CHIPCARD_API int Error_GetType ERRORCODE  c  ) 
 

Returns the error type.

CHIPCARD_API const char* Error_GetTypename int  t  ) 
 

Returns the name of the type referenced by the its type number. This function is used when composing a human readable error string.

Returns:
name of the type (0 on error)
Parameters:
t type number

CHIPCARD_API int Error_IsCustom ERRORCODE  c  ) 
 

Checks whether this is a custom error code (which means that the error type and code has to be handled differently. Such a code might be used in programs).

Returns:
!=0 if it is a custom code, 0 otherwise

CHIPCARD_API int Error_IsOk ERRORCODE  c  ) 
 

Checks whether the code really contains an error. If it contains a debug/info/warn code then it will be treaten as "ok".

Returns:
!=0 if ok, 0 if it really is an error

CHIPCARD_API void Error_ModuleFini  ) 
 

Deinitializes this module.

CHIPCARD_API void Error_ModuleInit  ) 
 

Initializes this module.

CHIPCARD_API ERRORCODE Error_New int  iscustom,
int  severity,
int  typ,
int  code
 

Creates an error code based on the arguments given

Returns:
error code based on the given arguments
Parameters:
iscustom if !=0, then this is a custom code. Such an error code can be used by applications. No module of this library will produce errors with this set, so you can use this to take advantage of the ERRORCODE management even without registering you own error type.
severity severity level of this code (might be simply a debug code, a warning, an information or an error)
typ type of this code. As you read above all errors are grouped into error types.
code error code. This needs only to be unique within the error type (in fact that was the reason to introduce the "error type")

CHIPCARD_API int Error_RegisterType ERRORTYPEREGISTRATIONFORM tptr  ) 
 

Register an error type. This function is called by other modules to register a unique type value for itself.

Returns:
0 on error (success otherwise)

CHIPCARD_API void Error_SetCode ERRORCODE c,
int  v
 

Sets the error code.

CHIPCARD_API void Error_SetIsCustom ERRORCODE c,
int  iscustom
 

Sets the custom flag.

CHIPCARD_API void Error_SetSeverity ERRORCODE c,
int  v
 

Sets the severity level.

CHIPCARD_API void Error_SetType ERRORCODE c,
int  v
 

Sets the error type.

CHIPCARD_API int Error_ToString ERRORCODE  c,
char *  buffer,
int  bsize
 

Composes a human readable error string which dumps all parts of an ERRORCODE.

Returns:
1 detailed error message created. If some parts of the ERRORCODE could not be translated (e.g. unassigned type number etc) a 0 is returned.
Parameters:
buffer pointer to a buffer to receive the message
bsize size of that buffer in bytes

CHIPCARD_API int Error_UnregisterType ERRORTYPEREGISTRATIONFORM tptr  ) 
 

When removing a module it should always unregister its assigned error type to avoid segfaultes (due to pointers pointing to nowhere).

Returns:
0 on error (success otherwise)


Variable Documentation

CHIPCARD_API typedef unsigned long ERRORCODE
 

An error code is 32 bits long and has the following bit format:
Bit(s)Meaning
31-30 Severity (0-3)
29 Custom error
28 Reserved
27-16 Type (specifies the type of the error, such as "ERROR_CLASS_SOCKET", "ERROR_CLASS_TIME" etc)
15-0 Code (16 bit error code)

CHIPCARD_API typedef const char*(* ERRORMESSAGEPTR)(int c)
 

A function of this type returns a descriptive string for the given error. So it is supposed to translate a 16 bit error value into a human readable text (please note that this code is PART of a ERRORCODE, not the whole ERRORCODE itself !).


Generated on Wed Jul 28 14:56:50 2004 for libchipcard by doxygen 1.3.7