/****************************************************************************
**
**  Name:  hosterrs.h
**
**  Description:
**     Host system errors are #defined here, along with typical masks.
**
**  Status:  (PRELIMINARY | CODED)
**  Copyright (C) 1991 Microtek International.  All rights reserved.
**
*****************************************************************************/

#define _HOSTERRS_

                       /****************************
                        *                          *
                        *       INCLUDE FILES      *
                        *                          *
                        ****************************/

                       /****************************
                        *                          *
                        *        DEFINITIONS       *
                        *                          *
                        ****************************/

/*
 * ERROR NUMBER COMPONENTS
 */

/* Severity flag composed of bits 0..2 */
#define E_SEVERITY_MASK    0xE0000000L
#define E_NO_ERROR         0x00000000L
#define E_INFORMATIVE      0x20000000L
#define E_WARNING          0x40000000L
#define E_SEVERE           0x80000000L
#define E_FATAL            0xA0000000L
#define E_CATASTROPHIC     0xC0000000L
#define E_SEVERITYID(x) (((x) & E_SEVERITY_MASK) >> 29)

/* Internal flag is bit 3 */
#define INTERNAL_ERROR_MASK 0x10000000L
#define INTERNAL_ERROR_ON   0x10000000L
#define INTERNAL_ERROR_OFF  0x00000000L
#define INTERNAL_ERROR(x)   (((U32)(((U32)x) & INTERNAL_ERROR_MASK)) == INTERNAL_ERROR_ON)

/* detecting component id is upper 2 bytes less top 4 bits */
#define E_COMPONENT_MASK   0x0FFF0000L
#define E_MODULEID(x)  (((x) & E_COMPONENT_MASK) >> 16)

/* error number is lower 2 bytes */
#define E_ERROR_NUMBER_MASK   0x0000FFFFL
#define E_ERRORID(x)  ((x) & E_ERROR_NUMBER_MASK)

/*
 *  Module component IDs : range 0x0000..0x0FFF (left shifted)
 */

/* Windows, DOS, or generic errors */
#define MODULE_GENERIC      0x0FFF0000L
#define MODULE_SYSTEM      0x00000000L

/* server modules */
/* note: these module id's now correspond to entries in the errtext.dll
    server GetErrorText routine table.  Do not change one without a
    corresponding change to the other!
*/
#define MODULE_HEAP                   0x00010000L
#define MODULE_SYMBOLS                0x00020000L
#define MODULE_ADDRESS                0x00030000L
#define MODULE_BREAKPOINT             0x00040000L
#define MODULE_CPU                    0x00050000L
#define MODULE_DISASSEMBLY            0x00060000L
#define MODULE_EVENT                  0x00070000L
#define MODULE_EVENT_TEMPLATE         0x00080000L
#define MODULE_LOADER_ELF             0x00090000L
#define MODULE_GENERIC_LDR            MODULE_LOADER_ELF
#define MODULE_LOADER_OMF             0x000A0000L
#define MODULE_MEMORY                 0x000B0000L
#define MODULE_SHARED_DATA            0x000C0000L
#define MODULE_STACK                  0x000D0000L
#define MODULE_SWAT                   0x000E0000L
#define MODULE_TRACE                  0x000F0000L
#define MODULE_TRIGGER                0x00100000L
#define MODULE_VAR                    0x00110000L
#define MODULE_LOADER_SREC            0x00120000L
#define MODULE_LOADER_TEK             0x00130000L
#define MODULE_MAP                    0x00140000L
#define MODULE_ENLIB                  0x00150000L
#define MODULE_WSCOM                  0x00160000L
#define MODULE_BKROOT                 0x00170000L
#define MODULE_CLIULIB                0x00180000L
#define MODULE_PROC                   0x00190000L
#define MODULE_PERI                   0x001A0000L
#define MODULE_PVTEST                 0x001B0000L
#define MODULE_LAST_SVR               MODULE_PVTEST    /* note dependency
                                                        on previous line */

/* presenter modules */
#define MODULE_CLI                    0x00200000L
#define MODULE_SOURCE                 0x00300000L
#define MODULE_SWATP                  0x00400000L

#define MAX_MODULES  32    /* need to recheck size when DLL added */

#ifndef _ERRCODEC_
#include "errcodec.h"
#endif


/* macros */
#define IS_GENERICID(x) (((x) & E_COMPONENT_MASK) == MODULE_GENERIC)
#define IS_SERVERID(x)  ((((x) & E_COMPONENT_MASK) >= MODULE_SYSTEM) \
                      && (((x) & E_COMPONENT_MASK) <= MODULE_LAST_SVR))
#define IS_VALIDMODULE(x)  (IS_SERVERID(x) || IS_GENERICID(x))
/* check for alternate loaders */
#define IS_LOADERID(x)  (x == (MODULE_LOADER_SREC >> 16))

/* SAMPLE: Heap Module specific error */
/* define ER_HEAP_CORRUPT   (MODULE_HEAP   | E_FATAL   | 0x00000001L) */


#define E_MODNAME_OFFSET     99     /* offset in server stringtable for
                                       printable module name */
#define E_ERRTEXT_OFFSET    100     /* offset within server stringtable for
                                        error text */
#define E_ERRSIZE           255     /* maximum size of error text */


                       /**************************
                        *                        *
                        *    TYPE DEFINITIONS    *
                        *                        *
                        **************************/
/* These types are allowed in the 'mode' parameter for calls */
typedef enum { CHECK_MODE, FORCE_POPUP, FORCE_CLI, HERR_DUMMY = 0x7fff }
   HANDLE_ERROR;

/* Types allowed in the 'msgBoxStyle' parameter for calls */
typedef enum {MB_TYPE_OK, MB_TYPE_OKCANCEL, MB_TYPE_ABORTRETRYIGNORE,
    MB_TYPE_YESNOCANCEL, MB_TYPE_YESNO, MB_TYPE_RETRYCANCEL, MB_TYPE_TYPEMASK,
    MB_DUMMY=0x7fff } MB_TYPE;

                       /****************************
                        *                          *
                        *        PROTOTYPES        *
                        *                          *
                        ****************************/
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************************
**
**  ErrInitDLL
**
**  Description:
**     Each server needs to register with the Error Text Server
**     (from its LibMain).
**
**  Parameters:
**     input:
**        moduleID      Handle to server DLL
**        dllName       Name of DLL file on disk
**     output:
**        none.
**
*****************************************************************************/
RETCODE EXPORT ErrInitDLL(U32 moduleID, LPSTR dllName);

/****************************************************************************
**
**  ErrGetErrorText
**
**  Description:
**     Retrieve the error text corresponding to the given errorCode.
**
**  Parameters:
**     input:
**        errorCode         retcode returned from Server call
**     output:
**        lperrString       text of error message obtained from .rc file
**
*****************************************************************************/
RETCODE EXPORT ErrGetErrorText(RETCODE errorCode, LPSTR lperrString);

/****************************************************************************
**
**  ErrDisplayString
**
**  Description:
**     For use with server- and presenter- formatted strings.  Additional
**     information can be tacked onto the end of the string retrieved
**     from the resource file.  The additional string will be in 'lpErrText'.
**
**  Parameters:
**     input:
**        errCode        retcode returned from Server call
**        lpErrText      additional text to tack on
**        mode           display mode (CLI vs. popup)
**     output:
**        none.
**
*****************************************************************************/
RETCODE EXPORT ErrDisplayString(RETCODE errCode, LPSTR lpErrText,
   HANDLE_ERROR mode);

/****************************************************************************
**
**  ErrDisplayErrorEx
**
**  Description:
**     Obtain and display the error text corresponding to the given
**     error code.
**
**  Parameters:
**     input:
**        errNumber     retcode returned from Server call
**        mode          display mode (CLI vs. popup)
**        msgBoxStyle   if popup, style of message box
**     output:
**        buttonID      button user clicked (value are ID* in Windows.h),
**                         e.g., IDCANCEL, IDOK, etc.
**
*****************************************************************************/
RETCODE EXPORT ErrDisplayErrorEx(RETCODE errNumber, HANDLE_ERROR mode,
    MB_TYPE msgBoxStyle, S16 FAR *buttonID);

/****************************************************************************
**
**  ErrDisplayError
**
**  Description:
**     Obtain and display the error text corresponding to the given
**     error code.
**
**  Parameters:
**     input:
**        errNumber     retcode returned from Server call
**        mode          display mode (CLI vs. popup)
**     output:
**        none.
**
*****************************************************************************/
RETCODE EXPORT ErrDisplayError(RETCODE errNumber, HANDLE_ERROR mode);

/****************************************************************************
**
**  ErrDisplayFormattedError
**
**  Description:
**     Obtain and display the error text corresponding to the given
**     error code, and provide a help button for context-sensitive help.
**
**  Parameters:
**     input:
**        errNumber     retcode returned from Server call
**        displayMode   display mode (CLI vs. popup)
**        arg1          first optional argument
**        arg2          second optional argument
**        arg3          third optional argument
**        style         MB_OK, MB_RETRYCANCEL, etc or 0 (defaults to MB_OK)
**     output:
**        buttonID      the id of the button (OK, Retry, Cancel, ...) pushed
**
*****************************************************************************/
RETCODE EXPORT ErrDisplayFormattedError(RETCODE errCode, 
   HANDLE_ERROR displayMode, LPSTR arg1, LPSTR arg2, LPSTR arg3,
   U16 style, S16 FAR *buttonID);

/*****************************************************************************
** ErrGetFormattedErrorText
**
** Description:
**   Retrieve error text and plug in optional arguments.  The *caller* is 
**   expected to have allocated storage for the return string of size 
**   E_ERRSIZE.
** Parameters:
**   errCode (in): encoded module, error type, and error number
**   lperrString (in): caller-allocated buffer
**   arg1 (in): optional sprintf argument
**   arg2 (in): optional sprintf argument
**   arg3 (in): optional sprintf argument
*****************************************************************************/
RETCODE EXPORT ErrGetFormattedErrorText(RETCODE errorCode, LPSTR lperrString,
   LPSTR arg1, LPSTR arg2, LPSTR arg3);

/*****************************************************************************
**
** ErrMessageBox
**
** Description:
**   Bring up a message box (including a help button) using the provided
**   caption, text, and style (buttons), and pass back the ID of the button
**   that was pressed.
**
** Parameters:
**   caption (in): caption of the dialog box
**   text (in): text of the message
**   style (in): which buttons (besides Help) to use
**   helpEntry (in): the entry point into pwrviews.hlp
**   buttonID (out): the ID of the button that was pressed
**
**
*****************************************************************************/
RETCODE EXPORT ErrMessageBox(LPSTR caption, LPSTR text, U16 style,
                             DWORD helpEntry, S16 FAR *buttonID);

/****************************************************************************
**
**  ErrGetErrorCLI
**
**  Description:
**     Print the error text corresponding to the given errorCode.
**
**  Parameters:
**     input:
**        cmdString         array of strings (two expected)
**        argc              count strings (one command, one arg)
**        argv              offset in cmdString
**
*****************************************************************************/
RETCODE EXPORT  ErrGetErrorCLI(LPSTR cmdString, U32 argc, U32 argv[]);

/***************************************************************************
**
**  ErrSaveMemoryVerifyInfo
**
**  Status:  TESTED
**
**  description:
**     Save memory verification text for later display.
**
**  input:
**     memoryVerifyString:  memory verification text string.
**
**  output:
**     none
**
*****************************************************************************/
RETCODE EXPORT ErrSaveMemoryVerifyInfo(LPSTR memoryVerifyString);

#ifdef __cplusplus
}
#endif
/******************************** E O F ***********************************/
