Go to the documentation of this file.00001
00024 #ifndef __COMMON_HEADER_H__
00025 #define __COMMON_HEADER_H__
00026
00027 #include <stdio.h>
00028 #include <stdint.h>
00029 #include <stdlib.h>
00030 #include <stdbool.h>
00031 #include <stddef.h>
00032 #include <string.h>
00033
00038 #define CT_ASSERT(e) extern char (*CT_ASSERT(void)) [sizeof(char[1 - 2*!(e)])]
00039
00043 #define NELEMS(x) (sizeof(x) / sizeof(x[0]))
00044
00048 #define LOG_ERR(fmt, ...) \
00049 do { \
00050 printf("(%s:%u) ERROR: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
00051 } while (0)
00052
00059 #define VALIDATE_VTABLE_FN(obj_h, private_h, vtable, fn, rc) \
00060 do { \
00061 if (NULL == obj_h) { \
00062 LOG_ERR("Invalid input, " #obj_h "(%p)", obj_h); \
00063 rc = MY_RC_E_EINVAL; \
00064 break; \
00065 } \
00066 \
00067 if (NULL == obj_h->private_h) { \
00068 LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p)", obj_h, \
00069 obj_h->private_h); \
00070 rc = MY_RC_E_EINVAL; \
00071 break; \
00072 } \
00073 \
00074 if (NULL == obj_h->private_h->vtable) { \
00075 LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p) " #vtable \
00076 "(%p)", obj_h, obj_h->private_h, obj_h->private_h->vtable); \
00077 rc = MY_RC_E_EINVAL; \
00078 break; \
00079 } \
00080 \
00081 if (NULL == obj_h->private_h->vtable->fn) { \
00082 LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p) " #vtable \
00083 "(%p) " #fn "(%p)", obj_h, obj_h->private_h, \
00084 obj_h->private_h->vtable, obj_h->private_h->vtable->fn); \
00085 rc = MY_RC_E_EINVAL; \
00086 break; \
00087 } \
00088 } while (0)
00089
00097 #define INHERIT_VTABLE_FN(parent_vtable, child_vtable, fn, do_null_check, rc) \
00098 do { \
00099 if (NULL == child_vtable->fn) { \
00100 child_vtable->fn = parent_vtable->fn; \
00101 if (do_null_check && (NULL == child_vtable->fn)) { \
00102 LOG_ERR("Invalid input, " #fn "(%p)", child_vtable->fn); \
00103 rc = MY_RC_E_EINVAL; \
00104 goto err_exit; \
00105 } \
00106 } \
00107 } while (0)
00108
00112 typedef enum my_rc_e_ {
00114 MY_RC_E_INVALID,
00116 MY_RC_E_SUCCESS,
00118 MY_RC_E_EINVAL,
00120 MY_RC_E_ENOMEM,
00122 MY_RC_E_MAX,
00123 } my_rc_e;
00124
00125
00126
00127 extern bool
00128 my_rc_e_is_notok(my_rc_e rc);
00129
00130 extern bool
00131 my_rc_e_is_ok(my_rc_e rc);
00132
00133 extern bool
00134 my_rc_e_is_valid(my_rc_e rc);
00135
00136 extern const char *
00137 my_rc_e_get_string(my_rc_e rc);
00138
00139 #endif