GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

GATErrors.h

Go to the documentation of this file.
00001 /** @file GATErrors.h
00002  * Header file defining various GAT error codes.
00003  * 
00004  * We need a consistent naming of errors.  This file defines constants
00005  * for possible error codes.
00006  * 
00007  * @date Tue Sep 23 2003
00008  * 
00009  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATErrors.h,v 1.37 2004/04/28 10:50:10 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Tom Goodale
00012  *  This file is part of the GAT Engine.
00013  *  Contributed by Tom Goodale <goodale@aei.mpg.de>.
00014  *
00015  *  Use, modification and distribution is subject to the Gridlab Software
00016  *  License. (See accompanying file GLlicense.txt or copy at
00017  *  http://www.gridlab.org/GLlicense.txt)
00018  */
00019 
00020 #ifndef _GATERRORS_H_
00021 #define _GATERRORS_H_ 1
00022 
00023 #include "xds.h"
00024 #include "GATType.h"
00025 #include "GATStatus.h"
00026 
00027 /*
00028  * GATResult values are 32 bit values layed out as follows:
00029  *
00030  *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
00031  * +---+-+-+-----------------------+-------------------------------+
00032  * |Sev|C|R|     Facility          |             Code              |
00033  * +---+-+-+-----------------------+-------------------------------+
00034  *
00035  * where
00036  *
00037  *     Sev - is the severity code
00038  *
00039  *         00 - Success
00040  *         01 - Informational
00041  *         10 - Warning
00042  *         11 - Error
00043  *
00044  *     C - is the Customer code flag (may be used by client code)
00045  *
00046  *     R - is a reserved bit
00047  *
00048  *     Facility - is the facility code
00049  *
00050  *     Code - is the facility's status code
00051  */
00052 
00053 /* Severity values */
00054 #define GAT_SEVERITY_SUCCESS              0x0
00055 #define GAT_SEVERITY_INFORMATIONAL        0x1
00056 #define GAT_SEVERITY_WARNING              0x2
00057 #define GAT_SEVERITY_ERROR                0x3
00058 
00059 /* Facility codes */
00060 #define GAT_FACILITY_ENGINE               0
00061 #define GAT_FACILITY_ENGINE_XDS           1     /* xds error codes */
00062 #define GAT_FACILITY_ENGINE_UUID          2     /* uuid error codes */
00063 #define GAT_FACILITY_ENGINE_REGEX         3     /* regex error codes */
00064 #define GAT_FACILITY_POSIX                4     /* errno based error codes */
00065 #define GAT_FACILITY_SQLITE               5     /* sqlite error codes */
00066 
00067 #define GAT_FACILITY_FILE_CPI            10
00068 #define GAT_FACILITY_LOGICALFILE_CPI     11
00069 
00070 
00071 /* Helper macros for the handling of error values */
00072 #define GAT_SUCCEEDED(Status) ((GATResult)(Status) >= 0)  /* success */
00073 #define GAT_FAILED(Status)    ((GATResult)(Status) < 0)   /* inverse */
00074 
00075 /* access parts of the result code */
00076 #define GAT_RESULT_CODE(rc)      ((rc) & 0xFFFF)
00077 #define GAT_RESULT_FACILITY(rc)  (((rc) >> 16) & 0x0FFF)
00078 #define GAT_RESULT_SEVERITY(rc)  (((rc) >> 30) & 0x0003)
00079 
00080 /* construct a result code */
00081 #define MAKE_GAT_RESULT(sev,fac,code)                                         \
00082   ((GATResult) (                                                              \
00083     ((unsigned long)(sev & 0x0003) << 30) |                                   \
00084     ((unsigned long)(fac & 0x0FFF) << 16) |                                   \
00085     ((unsigned long)(code & 0xFFFF)) ) )                                      \
00086   /**/
00087 
00088 /* Helper macros for constructing result values for the engine */
00089 #define GAT_ENGINE_ERROR(rc)                                                  \
00090   MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_ENGINE, (rc))              \
00091   /**/
00092   
00093 /* map a XDS error code to the corresponding GAT error code */
00094 #define XDS_TO_GAT(rc)                                                        \
00095   ((XDS_OK == (rc)) ? GAT_SUCCESS :                                           \
00096     MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_ENGINE_XDS, -(rc)))      \
00097   /**/
00098 
00099 /* map uuid error code to the corresponding GAT error code */
00100 #define UUID_TO_GAT(rc)                                                       \
00101   ((UUID_RC_OK == (rc)) ? GAT_SUCCESS :                                       \
00102     MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_ENGINE_UUID, (rc)))      \
00103   /**/
00104   
00105 /* map regex error code to the corresponding GAT error code */
00106 #define REGEX_TO_GAT(rc)                                                      \
00107   ((REG_NOERROR == (rc)) ? GAT_SUCCESS :                                      \
00108     MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_ENGINE_REGEX, (rc)))     \
00109   /**/
00110   
00111 /* map sqlite error code to the corresponding GAT error code */
00112 #define SQLITE_TO_GAT(rc)                                                     \
00113   ((SQLITE_OK == (rc)) ? GAT_SUCCESS :                                        \
00114     MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_SQLITE, (rc)))           \
00115   /**/
00116   
00117 /* map POSIX error code to the corresponding GAT error code */
00118 #define POSIX_TO_GAT(rc)                                                      \
00119   ((0 == (rc)) ? GAT_SUCCESS :                                                \
00120     MAKE_GAT_RESULT(GAT_SEVERITY_ERROR, GAT_FACILITY_POSIX, (rc)))            \
00121   /**/
00122   
00123 /* Error codes used in the GAT engine (FACILITY_ENGINE) */
00124 #define GAT_FALSE                         /* not GAT_SUCCESS, but no error */ \
00125   MAKE_GAT_RESULT(GAT_SEVERITY_SUCCESS, GAT_FACILITY_ENGINE, 1)               \
00126   /**/
00127   
00128 #define GAT_SUCCESS                                                           \
00129   MAKE_GAT_RESULT(GAT_SEVERITY_SUCCESS, GAT_FACILITY_ENGINE, 0)               \
00130   /**/
00131 
00132 /* Error codes used by the GAT engine */
00133 #define GAT_FAIL                         GAT_ENGINE_ERROR(1)
00134 #define GAT_NOTIMPL                      GAT_ENGINE_ERROR(2)
00135 #define GAT_MEMORYFAILURE                GAT_ENGINE_ERROR(3)
00136 #define GAT_DUPLICATE_ADAPTOR            GAT_ENGINE_ERROR(4)
00137 #define GAT_FAILED_TO_LOAD_ADAPTOR       GAT_ENGINE_ERROR(5)
00138 #define GAT_NO_ADAPTOR_REGISTRATION_FUNC GAT_ENGINE_ERROR(6)
00139 #define GAT_DUPLICATE_CONFIG             GAT_ENGINE_ERROR(7)
00140 #define GAT_FILEOPEN_ERROR               GAT_ENGINE_ERROR(8)
00141 #define GAT_KEY_NOT_FOUND                GAT_ENGINE_ERROR(9)
00142 #define GAT_KEY_TYPE_ERROR               GAT_ENGINE_ERROR(10)
00143 #define GAT_INVALID_HANDLE               GAT_ENGINE_ERROR(11)
00144 #define GAT_INVALID_PARAMETER            GAT_ENGINE_ERROR(12)
00145 #define GAT_UNKNOWN_VERSION              GAT_ENGINE_ERROR(13)
00146 #define GAT_NO_REGISTERED_CPI            GAT_ENGINE_ERROR(14)
00147 #define GAT_INVALID_ENCODING             GAT_ENGINE_ERROR(15)
00148 #define GAT_INCOMPLETE_ENCODING          GAT_ENGINE_ERROR(16)
00149 #define GAT_NO_MATCHING_CPI              GAT_ENGINE_ERROR(17)
00150 #define GAT_NO_MATCHING_RESOURCE         GAT_ENGINE_ERROR(18)
00151 #define GAT_NO_INTERFACE                 GAT_ENGINE_ERROR(19)
00152 #define GAT_UNKNOWN_FORMAT               GAT_ENGINE_ERROR(20)
00153 #define GAT_KEY_ALREADY_EXISTS           GAT_ENGINE_ERROR(21)
00154 #define GAT_REMOTE_CALL_FAILED           GAT_ENGINE_ERROR(22)
00155 #define GAT_IO_ERROR                     GAT_ENGINE_ERROR(23)
00156 #define GAT_INVALID_STATE                GAT_ENGINE_ERROR(24)
00157 #define GAT_TYPE_MISMATCH                GAT_ENGINE_ERROR(25)
00158 #define GAT_BUFFER_TOO_SMALL             GAT_ENGINE_ERROR(26)
00159 #define GAT_BAD_OBJECT_CONVERSION        GAT_ENGINE_ERROR(27)
00160 #define GAT_INVALID_CONFIG_FORMAT        GAT_ENGINE_ERROR(28)
00161 #define GAT_ERROR_CONTEXT_ONLY           GAT_ENGINE_ERROR(29)
00162 
00163 /* Helper macros to simplify error diagnostics and error propagation */
00164 
00165 /* 
00166  *  GAT_USES_STATUS is to be used as the first statement inside of every 
00167  *  function, which has to handle GATStatus based errors/diagnostics.
00168  */
00169 #define GAT_USES_STATUS(ctx, name)                                            \
00170   GATStatus __status = NULL;                                                  \
00171   GATContext __ctx = (ctx);                                                   \
00172   char const *__name = (name);                                                \
00173   GATResult __retval = GAT_SUCCESS                                            \
00174   /**/
00175 
00176 /* 
00177  *  GAT_STATUS_APIENTRY is essentially equivalent to GAT_USES_STATUS, except
00178  *  that it will initialise the current status to zero, thus this macro should
00179  *  be used on any high level API entry point only.
00180  */
00181 #define GAT_STATUS_APIENTRY(ctx, name)                                        \
00182   GATStatus __status = NULL;                                                  \
00183   GATContext __ctx = (ctx);                                                   \
00184   char const *__name = (name);                                                \
00185   GATResult __retval = GATContext_SetCurrentStatus((ctx), 0)                  \
00186   /**/
00187 
00188 #define GAT_CREATE_STATUS(f)                                                  \
00189   {                                                                           \
00190     if (GAT_SUCCEEDED(__retval))                                              \
00191     {                                                                         \
00192       if (GAT_FAILED(__retval = (f)))                                         \
00193       { __retval = GATCreateStatus(__name, &__status, __retval, __ctx,        \
00194           __FILE__, __LINE__); }                                              \
00195     }                                                                         \
00196   }                                                                           \
00197   /**/
00198 
00199 #define GAT_CREATE_STATUS_UNCOND(f)                                           \
00200   {                                                                           \
00201     if (GAT_FAILED(__retval = (f)))                                           \
00202     { __retval = GATCreateStatus(__name, &__status, __retval, __ctx,          \
00203         __FILE__, __LINE__); }                                                \
00204   }                                                                           \
00205   /**/
00206 
00207 #define GAT_CREATE_STATUS_MSG(rc, msg)                                        \
00208   {                                                                           \
00209     if (GAT_SUCCEEDED(__retval))                                              \
00210     {                                                                         \
00211       __retval = GATCreateStatus(__name, &__status, (rc), __ctx,              \
00212         __FILE__, __LINE__);                                                  \
00213       GATStatus_AddMessage(__status, msg);                                    \
00214     }                                                                         \
00215   }                                                                           \
00216   /**/
00217 
00218 #define GAT_CREATE_STATUS_IF(cond, rc)                                        \
00219   {                                                                           \
00220     if (GAT_SUCCEEDED(__retval))                                              \
00221     {                                                                         \
00222       if (cond) { __retval = GATCreateStatus(__name, &__status, (rc), __ctx,  \
00223                     __FILE__, __LINE__); }                                    \
00224       else { __retval = GAT_SUCCESS; }                                        \
00225     }                                                                         \
00226   }                                                                           \
00227   /**/
00228 
00229 #define GAT_CREATE_STATUS_IF_MSG(cond, rc, msg)                               \
00230   {                                                                           \
00231     if (GAT_SUCCEEDED(__retval))                                              \
00232     {                                                                         \
00233       if (cond) {                                                             \
00234         __retval = GATCreateStatus(__name, &__status, (rc), __ctx,            \
00235           __FILE__, __LINE__);                                                \
00236         GATStatus_AddMessage(__status, msg);                                  \
00237       }                                                                       \
00238       else { __retval = GAT_SUCCESS; }                                        \
00239     }                                                                         \
00240   }                                                                           \
00241   /**/
00242 
00243 #define GAT_STATUS_ADD_MESSAGE(msg)                                           \
00244     GATStatus_AddMessage(__status, msg)                                       \
00245   /**/
00246   
00247 #ifdef GAT_ENABLE_PROPAGATE_STATUS_MACROS
00248 #define GAT_PROPAGATE_STATUS(f)                                               \
00249   {                                                                           \
00250     if (GAT_SUCCEEDED(__retval))                                              \
00251     {                                                                         \
00252       if (GAT_FAILED(__retval = (f)))                                         \
00253       { __retval = GATPropagateStatus(__name, &__status, __retval, __ctx); }  \
00254     }                                                                         \
00255   }                                                                           \
00256   /**/
00257   
00258 #define GAT_PROPAGATE_STATUS_UNCOND(f)                                        \
00259   {                                                                           \
00260     if (GAT_FAILED(__retval = (f)))                                           \
00261     { __retval = GATPropagateStatus(__name, &__status, __retval, __ctx); }    \
00262   }                                                                           \
00263   /**/
00264   
00265 #define GAT_PROPAGATE_STATUS_IF(cond, rc)                                     \
00266   {                                                                           \
00267     if (GAT_SUCCEEDED(__retval))                                              \
00268     {                                                                         \
00269       if (cond)                                                               \
00270       { __retval = GATPropagateStatus(__name, &__status, rc, __ctx); }        \
00271     }                                                                         \
00272   }                                                                           \
00273   /**/
00274 #endif /* GAT_ENABLE_PROPAGATE_STATUS_MACROS */
00275   
00276 #define GAT_RETURN_STATUS()                                                   \
00277   (NULL != __status) ?                                                        \
00278     GATContext_SetCurrentStatus(__ctx, &__status), __retval : __retval;       \
00279   /**/
00280 
00281 #define GAT_STORE_STATUS()                                                    \
00282   {                                                                           \
00283     if (NULL != __status)                                                     \
00284     {                                                                         \
00285       GATContext_SetCurrentStatus(__ctx, &__status);                          \
00286     }                                                                         \
00287   }                                                                           \
00288   /**/
00289 
00290 #define GAT_CURRENT_STATUS()  __retval
00291   
00292 #endif /* _GATERRORS_H_ */