Avis Client Library: avis/errors.h Source File

- Main Page
- Data Structures
- Files

# avis/errors.h

Go to the documentation of this file.

    00001 /*
    00002  *  Avis Elvin client library for C.
    00003  *
    00004  *  Copyright (C) 2008 Matthew Phillips <avis@mattp.name>
    00005  *
    00006  *  This program is free software; you can redistribute it and/or
    00007  *  modify it under the terms of version 3 of the GNU Lesser General
    00008  *  Public License as published by the Free Software Foundation.
    00009  *
    00010  *  This program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00013  *  General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
    00017  */
    00021 #ifndef AVIS_ERRORS_H_
    00022 #define AVIS_ERRORS_H_
    00023
    00024 #include <stdlib.h>
    00025
    00026 #include <avis/stdtypes.h>
    00027 #include <avis/defs.h>
    00028
    00058 typedef struct
    00059 {
    00060   int    code;
    00061   char * message;
    00062 } ElvinError;
    00063
    00064 #define ELVIN_ERROR_BASE       0
    00065 #define ELVIN_ERRNO_BASE       10000
    00066 #define ELVIN_HOST_ERROR_BASE  20000
    00067
    00068 #define ELVIN_ERROR_NONE                0
    00069 #define ELVIN_ERROR_INTERNAL            (ELVIN_ERROR_BASE + 1)
    00070 #define ELVIN_ERROR_PROTOCOL            (ELVIN_ERROR_BASE + 2)
    00071 #define ELVIN_ERROR_CONNECTION_CLOSED   (ELVIN_ERROR_BASE + 3)
    00072 #define ELVIN_ERROR_INVALID_URI         (ELVIN_ERROR_BASE + 4)
    00073 #define ELVIN_ERROR_SYNTAX              (ELVIN_ERROR_BASE + 5)
    00074 #define ELVIN_ERROR_TRIVIAL_EXPRESSION  (ELVIN_ERROR_BASE + 6)
    00075 #define ELVIN_ERROR_NACK                (ELVIN_ERROR_BASE + 7)
    00076 #define ELVIN_ERROR_USAGE               (ELVIN_ERROR_BASE + 8)
    00077 #define ELVIN_ERROR_TIMEOUT             (ELVIN_ERROR_BASE + 9)
    00078 #define ELVIN_ERROR_ROUTER_FAILURE      (ELVIN_ERROR_BASE + 10)
    00079
    00080 AVIS_PUBLIC
    00081 void *do_avis_emalloc (size_t size, const char *file, int line);
    00082
    00083 AVIS_PUBLIC
    00084 char *do_avis_estrdup (const char *str, const char *file, int line);
    00085
    00086 #define avis_emalloc(size) do_avis_emalloc ((size), __FILE__, __LINE__)
    00087
    00088 #define avis_estrdup(str) do_avis_estrdup ((str), __FILE__, __LINE__)
    00089
    00096 #define ELVIN_EMPTY_ERROR {ELVIN_ERROR_NONE, NULL}
    00097
    00104 AVIS_PUBLIC
    00105 void elvin_error_free (ElvinError *error);
    00106
    00113 AVIS_PUBLIC
    00114 void elvin_error_init (ElvinError *error);
    00115
    00119 #define elvin_error_reset(error) (elvin_error_free (error))
    00120
    00129 #define on_error_return_false(stat) on_error_return (stat, false)
    00130
    00140 #define on_error_return(stat, retval) \
    00141   {stat; if (elvin_error_occurred (error)) return (retval);}
    00142
    00147 #define host_to_elvin_error(code) (ELVIN_HOST_ERROR_BASE + (code))
    00148
    00153 #define errno_to_elvin_error(code) (ELVIN_ERRNO_BASE + (code))
    00154
    00158 AVIS_PUBLIC
    00159 void elvin_perror (const char *tag, ElvinError *error);
    00160
    00169 AVIS_PUBLIC
    00170 bool elvin_error_from_errno (ElvinError *error);
    00171
    00191 AVIS_PUBLIC
    00192 bool elvin_error_set (ElvinError *error, int code, const char *message, ...);
    00193
    00197 #define elvin_error_ok(error) ((error)->code == ELVIN_ERROR_NONE)
    00198
    00202 #define elvin_error_occurred(error) (!elvin_error_ok (error))
    00203
    00204 #endif /*AVIS_ERRORS_H_*/