/****************************************************************************** * * Title : errorHandler.c * Version 0.0 * * Description: errorHandler routines. * * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "globalDefinitions.h" #include "errorHandler.h" #include "fileUtility.h" #include "hostUtility.h" #include "threadUtility.h" #include "mainUir.h" #include "uirUtility.h" #include "errorCodesRcc.h" /****************************************************************************** * Static Function Declarations * ******************************************************************************/ static ERROR_ID saveToErrorFile(const char *errorMessage); static void errorCodeDescription(ERROR_ID errorId, char outputText[100]); /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * hostError() *============================================================================= * * Displays and saves host specific errors to error file. * Pointer to Host struct is passed so any host status information could be * used inside this routine (e.g. current listIndex, thread status info ...). * Error handling dependent on errorId and host status information could be * implemented. * * Input: ->fileName, ->line - name of calling source file(macro __FILE__) and line * number(macro __LINE__); * ->host - pointer to calling >host struct and >errorMessage(any additional * text information, eg. name of the routine, which returned error - * - see macros in errorHandler.h); * ->errorId - is error code valid inside this project * (def. in errorCodes.h). * Note: Don't call hostError() from itself - infinite recursion! * */ void hostError(const char* fileName, int line, ERROR_ID errorId, struct HOST *host, const char *errorMessage){ char string[500]; int status; char outputText[50]; ERROR_ID errorIdLocal; if(global.option.disableVmeError) return; Beep(); /* create errorString */ sprintf(string,"\n========================================================================\n\ Date:%s, Time:%s; CurrentHostListIndex:0x%X\n========================================================================\n", DateStr(), TimeStr(), host->listIndex); errorCodeDescription(errorId, outputText); sprintf(string+strlen(string),"%s (errorId=%d) - file:%s, line:%d, rodSlot#:%d;\nErrorMessage:%s!", outputText, errorId, fileName, line, host->slotNumber, errorMessage); /* send errorString to stdout and errorFile */ errorIdLocal=saveToErrorFile(string); if(errorIdLocal!=SUCCESS){ printf("FILE ERROR - file:%s, line:%d, errorID=%d,\n- Function: saveToErrorFile()", __FILE__, __LINE__, errorIdLocal); } if(errorIdfileName, ->line - name of calling source file(macro __FILE__) and line * number(macro __LINE__); * ->functionName - name of the function which returned * ->functionStatus; ->errorId - is error code valid inside this project * (def. in errorCodes.h). * * ->host - pointer to calling host struct and ->errorMessage(any additional * text information - see macro examples in errorHandler.h). * Note: Don't call programError() from itself - infinite recursion! * */ void programError(const char* fileName, int line, ERROR_ID errorId, const char *functionName, int functionStatus, const char *errorMessage){ char string[500]; int status; char outputText[50]; ERROR_ID errorIdLocal; if(global.option.disableVmeError) return; Beep(); /* create errorString */ sprintf(string,"\n========================================================================\n\ Date:%s, Time:%s\n========================================================================\n", DateStr(), TimeStr()); errorCodeDescription(errorId, outputText); sprintf(string+strlen(string),"%s (errorId=%d) - file:%s, line:%d,\n- Function: %s, status=%d\nErrorMessage: %s!", outputText, errorId, fileName, line, functionName, functionStatus, errorMessage); /* send errorString to stdout and errorFile */ errorIdLocal=saveToErrorFile(string); if(errorIdLocal!=SUCCESS){ printf("FILE ERROR - file:%s, line:%d, errorID=%d;\n- Function: saveToErrorFile()", __FILE__, __LINE__, errorIdLocal); } if(errorId!\n", __FILE__, __LINE__, errorId, global.errorFileName); puts("############################################################################\n"); /* show error window */ status = SetCtrlAttribute (global.panel.main, MAIN_ERROR_TIMER, ATTR_ENABLED, 1); UIR_STATUS_CHECK(status, SetCtrlAttribute()); } /* "unlock" routine */ LEAVE_CRITICAL_SECTION(&global.saveToErrorFileCriticalSection); return(errorId); } /*============================================================================= * errorCodeDescription() *============================================================================= * * Input: errorId, * Output: error type string. * The error codes are defined in errorCodes.h * */ #define COPY_TEXT(errorId) \ case errorId: strcpy(outputText, #errorId); break; static void errorCodeDescription(ERROR_ID errorId, char outputText[100]){ switch(errorId){ COPY_TEXT(SUCCESS ); COPY_TEXT(FATAL_ERROR ); COPY_TEXT(PROGRAM_WARNING ); COPY_TEXT(PROGRAM_ERROR ); COPY_TEXT(HOST_ERROR ); COPY_TEXT(TIMEOUT_ERROR ); COPY_TEXT(PRIMLIST_ERROR ); COPY_TEXT(REPLIST_ERROR ); COPY_TEXT(HPI_ERROR ); COPY_TEXT(FILE_ERROR ); COPY_TEXT(UIR_ERROR ); COPY_TEXT(VME_ERROR ); COPY_TEXT(TEXT_BUFFER_OVERFLOW ); COPY_TEXT(TEXT_BUFFER_ERROR ); COPY_TEXT(COMMAND_ERROR ); COPY_TEXT(COMMAND_LIST_ERROR ); COPY_TEXT(FLASH_ERROR ); COPY_TEXT(FLASH_TIMEOUT_ERROR ); default: strcpy(outputText,"UNKNOWN ERROR"); break; } return; } /******************************************************************************/