Blame source/uds/errors.h

Packit Service 310c69
/*
Packit Service 310c69
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 310c69
 *
Packit Service 310c69
 * This program is free software; you can redistribute it and/or
Packit Service 310c69
 * modify it under the terms of the GNU General Public License
Packit Service 310c69
 * as published by the Free Software Foundation; either version 2
Packit Service 310c69
 * of the License, or (at your option) any later version.
Packit Service 310c69
 * 
Packit Service 310c69
 * This program is distributed in the hope that it will be useful,
Packit Service 310c69
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 310c69
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 310c69
 * GNU General Public License for more details.
Packit Service 310c69
 * 
Packit Service 310c69
 * You should have received a copy of the GNU General Public License
Packit Service 310c69
 * along with this program; if not, write to the Free Software
Packit Service 310c69
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 310c69
 * 02110-1301, USA. 
Packit Service 310c69
 *
Packit Service 310c69
 * $Id: //eng/uds-releases/jasper/src/uds/errors.h#4 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef ERRORS_H
Packit Service 310c69
#define ERRORS_H
Packit Service 310c69
Packit Service 310c69
#include "compiler.h"
Packit Service 310c69
#include "typeDefs.h"
Packit Service 310c69
#include "uds-error.h"
Packit Service 310c69
Packit Service 310c69
enum udsInternalErrorCodes {
Packit Service 310c69
  /** Used as a base value for reporting internal errors */
Packit Service 310c69
  UDS_INTERNAL_ERROR_CODE_BASE = 66560,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_0        = UDS_INTERNAL_ERROR_CODE_BASE + 0,
Packit Service 310c69
  /** Index overflow */
Packit Service 310c69
  UDS_OVERFLOW                 = UDS_INTERNAL_ERROR_CODE_BASE + 1,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_2        = UDS_INTERNAL_ERROR_CODE_BASE + 2,
Packit Service 310c69
  /** Invalid argument passed to internal routine */
Packit Service 310c69
  UDS_INVALID_ARGUMENT         = UDS_INTERNAL_ERROR_CODE_BASE + 3,
Packit Service 310c69
  /** UDS data structures are in an invalid state */
Packit Service 310c69
  UDS_BAD_STATE                = UDS_INTERNAL_ERROR_CODE_BASE + 4,
Packit Service 310c69
  /** Attempt to enter the same name into an internal structure twice */
Packit Service 310c69
  UDS_DUPLICATE_NAME           = UDS_INTERNAL_ERROR_CODE_BASE + 5,
Packit Service 310c69
  /** An internal protocol violation between system components */
Packit Service 310c69
  UDS_UNEXPECTED_RESULT        = UDS_INTERNAL_ERROR_CODE_BASE + 6,
Packit Service 310c69
  /** An error created by test case processing */
Packit Service 310c69
  UDS_INJECTED_ERROR           = UDS_INTERNAL_ERROR_CODE_BASE + 7,
Packit Service 310c69
  /** An assertion failed */
Packit Service 310c69
  UDS_ASSERTION_FAILED         = UDS_INTERNAL_ERROR_CODE_BASE + 8,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_9        = UDS_INTERNAL_ERROR_CODE_BASE + 9,
Packit Service 310c69
  /** Not an actual error, but reporting that the result will be delayed */
Packit Service 310c69
  UDS_QUEUED                   = UDS_INTERNAL_ERROR_CODE_BASE + 10,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_11       = UDS_INTERNAL_ERROR_CODE_BASE + 11,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_12       = UDS_INTERNAL_ERROR_CODE_BASE + 12,
Packit Service 310c69
  /** A problem has occured with a Buffer */
Packit Service 310c69
  UDS_BUFFER_ERROR             = UDS_INTERNAL_ERROR_CODE_BASE + 13,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_14       = UDS_INTERNAL_ERROR_CODE_BASE + 14,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_15       = UDS_INTERNAL_ERROR_CODE_BASE + 15,
Packit Service 310c69
  /** No directory was found where one was expected */
Packit Service 310c69
  UDS_NO_DIRECTORY             = UDS_INTERNAL_ERROR_CODE_BASE + 16,
Packit Service 310c69
  /** Checkpoint not completed */
Packit Service 310c69
  UDS_CHECKPOINT_INCOMPLETE    = UDS_INTERNAL_ERROR_CODE_BASE + 17,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_18       = UDS_INTERNAL_ERROR_CODE_BASE + 18,
Packit Service 310c69
  /** Unused */
Packit Service 310c69
  UDS_INTERNAL_UNUSED_19       = UDS_INTERNAL_ERROR_CODE_BASE + 19,
Packit Service 310c69
  /** This error range has already been registered */
Packit Service 310c69
  UDS_ALREADY_REGISTERED       = UDS_INTERNAL_ERROR_CODE_BASE + 20,
Packit Service 310c69
  /** Either read-only or write-only */
Packit Service 310c69
  UDS_BAD_IO_DIRECTION         = UDS_INTERNAL_ERROR_CODE_BASE + 21,
Packit Service 310c69
  /** Cannot do I/O at this offset */
Packit Service 310c69
  UDS_INCORRECT_ALIGNMENT      = UDS_INTERNAL_ERROR_CODE_BASE + 22,
Packit Service 310c69
  /** Attempt to read or write data outside the bounds established for it */
Packit Service 310c69
  UDS_OUT_OF_RANGE             = UDS_INTERNAL_ERROR_CODE_BASE + 23,
Packit Service 310c69
  /** One more than the last UDS_INTERNAL error code */
Packit Service 310c69
  UDS_INTERNAL_ERROR_CODE_LAST,
Packit Service 310c69
  /** One more than the last error this block will ever use */
Packit Service 310c69
  UDS_INTERNAL_ERROR_CODE_BLOCK_END = UDS_INTERNAL_ERROR_CODE_BASE + 440
Packit Service 310c69
};
Packit Service 310c69
Packit Service 310c69
enum {
Packit Service 310c69
  ERRBUF_SIZE = 128 // default size for buffer passed to stringError
Packit Service 310c69
};
Packit Service 310c69
Packit Service 310c69
// Error attributes - or into top half of error code
Packit Service 310c69
enum { UDS_UNRECOVERABLE = (1 << 17) };
Packit Service 310c69
Packit Service 310c69
const char *stringError(int errnum, char *buf, size_t buflen);
Packit Service 310c69
const char *stringErrorName(int errnum, char *buf, size_t buflen);
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * Identify that an result code is a successful result.
Packit Service 310c69
 *
Packit Service 310c69
 * @param result  A result code
Packit Service 310c69
 *
Packit Service 310c69
 * @return true if the result represents a success.
Packit Service 310c69
 */
Packit Service 310c69
__attribute__((warn_unused_result))
Packit Service 310c69
static INLINE bool isSuccessful(int result)
Packit Service 310c69
{
Packit Service 310c69
  return (result == UDS_SUCCESS) || (result == UDS_QUEUED);
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * Identify that an result code has been marked unrecoverable.
Packit Service 310c69
 *
Packit Service 310c69
 * @param result  A result code
Packit Service 310c69
 *
Packit Service 310c69
 * @return true if the result has been marked unrecoverable.
Packit Service 310c69
 */
Packit Service 310c69
__attribute__((warn_unused_result))
Packit Service 310c69
static INLINE bool isUnrecoverable(int result)
Packit Service 310c69
{
Packit Service 310c69
  return (result & UDS_UNRECOVERABLE) != 0;
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * Mark a result code as unrecoverable.
Packit Service 310c69
 *
Packit Service 310c69
 * @param result  A result code
Packit Service 310c69
 *
Packit Service 310c69
 * @return the result code with the unrecoverable marker added
Packit Service 310c69
 */
Packit Service 310c69
__attribute__((warn_unused_result))
Packit Service 310c69
static INLINE int makeUnrecoverable(int result)
Packit Service 310c69
{
Packit Service 310c69
  return isSuccessful(result) ? result : (result | UDS_UNRECOVERABLE);
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
/*
Packit Service 310c69
 * Remove the unrecoverable marker from a result code.
Packit Service 310c69
 *
Packit Service 310c69
 * @param result  A result code
Packit Service 310c69
 *
Packit Service 310c69
 * @return the result code with the unrecoverable marker removed
Packit Service 310c69
 */
Packit Service 310c69
__attribute__((warn_unused_result))
Packit Service 310c69
static INLINE int sansUnrecoverable(int result)
Packit Service 310c69
{
Packit Service 310c69
  return result & ~UDS_UNRECOVERABLE;
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
typedef struct errorInfo {
Packit Service 310c69
  const char *name;
Packit Service 310c69
  const char *message;
Packit Service 310c69
} ErrorInfo;
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Register an error code block for stringError and stringErrorName.
Packit Service 310c69
 *
Packit Service 310c69
 * @param blockName             the name of the block of error codes
Packit Service 310c69
 * @param firstError            the first error code in the block
Packit Service 310c69
 * @param lastReservedError     one past the highest possible error in the bloc
Packit Service 310c69
 * @param infos                 a pointer to the error info array for the block
Packit Service 310c69
 * @param infoSize              the size of the error info array, which
Packit Service 310c69
 *                              determines the last actual error for which
Packit Service 310c69
 *                              information is available
Packit Service 310c69
 *
Packit Service 310c69
 * @return a success or error code, particularly UDS_DUPLICATE_NAME if the
Packit Service 310c69
 *         block name is already present, or UDS_ALREADY_REGISTERED if a
Packit Service 310c69
 *         block with the specified error code is present
Packit Service 310c69
 **/
Packit Service 310c69
int registerErrorBlock(const char      *blockName,
Packit Service 310c69
                       int              firstError,
Packit Service 310c69
                       int              lastReservedError,
Packit Service 310c69
                       const ErrorInfo *infos,
Packit Service 310c69
                       size_t           infoSize);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Return the first error between result1 and result2.
Packit Service 310c69
 *
Packit Service 310c69
 * @param result1       A success or error code.
Packit Service 310c69
 * @param result2       A success or error code.
Packit Service 310c69
 *
Packit Service 310c69
 * @return result1 if that is an error, else result2
Packit Service 310c69
 **/
Packit Service 310c69
static INLINE int firstError(int result1, int result2)
Packit Service 310c69
{
Packit Service 310c69
  return result1 == UDS_SUCCESS ? result2 : result1;
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
#endif /* ERRORS_H */