libgphoto2 photo camera library (libgphoto2) API
2.5.13
|
00001 00021 #ifndef __GPHOTO2_PORT_LOG_H__ 00022 #define __GPHOTO2_PORT_LOG_H__ 00023 00024 #include <stdarg.h> 00025 00030 typedef enum { 00031 GP_LOG_ERROR = 0, 00032 GP_LOG_VERBOSE = 1, 00033 GP_LOG_DEBUG = 2, 00034 GP_LOG_DATA = 3 00035 } GPLogLevel; 00036 00046 #define GP_LOG_ALL GP_LOG_DATA 00047 00061 typedef void (* GPLogFunc) (GPLogLevel level, const char *domain, const char *str, void *data); 00062 00063 #ifndef DISABLE_DEBUGGING 00064 00065 int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data); 00066 int gp_log_remove_func (int id); 00067 00068 /* Logging */ 00069 void gp_log (GPLogLevel level, const char *domain, 00070 const char *format, ...) 00071 #ifdef __GNUC__ 00072 __attribute__((__format__(printf,3,4))) 00073 #endif 00074 ; 00075 void gp_log_with_source_location( 00076 GPLogLevel level, const char *file, int line, const char *func, 00077 const char *format, ...) 00078 #ifdef __GNUC__ 00079 __attribute__((__format__(printf,5,6))) 00080 #endif 00081 ; 00082 void gp_logv (GPLogLevel level, const char *domain, const char *format, 00083 va_list args) 00084 #ifdef __GNUC__ 00085 __attribute__((__format__(printf,3,0))) 00086 #endif 00087 ; 00088 void gp_log_data (const char *domain, const char *data, unsigned int size, 00089 const char *format, ...) 00090 #ifdef __GNUC__ 00091 __attribute__((__format__(printf,4,5))) 00092 #endif 00093 ; 00094 00095 /* 00096 * GP_DEBUG: 00097 * msg: message to log 00098 * params: params to message 00099 * 00100 * Logs message at log level #GP_LOG_DEBUG by calling #gp_log() with 00101 * an automatically generated domain 00102 * You have to define GP_MODULE as "mymod" for your module 00103 * mymod before using #GP_DEBUG(). 00104 */ 00105 00106 #ifdef _GPHOTO2_INTERNAL_CODE 00107 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 00108 #define GP_DEBUG(...) \ 00109 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, __VA_ARGS__) 00110 00111 /* 00112 * GP_LOG_D/E: 00113 * simple helper macros for convenient and consistent logging of error 00114 * and debug messages including information about the source location. 00115 */ 00116 #define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__) 00117 #define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) 00118 #define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__) 00119 00120 #elif defined(__GNUC__) && __GNUC__ >= 2 00121 #define GP_DEBUG(msg, params...) \ 00122 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, msg, ##params) 00123 /* 00124 * GP_LOG_D/E: 00125 * simple helper macros for convenient and consistent logging of error 00126 * and debug messages including information about the source location. 00127 */ 00128 #define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__) 00129 #define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) 00130 #define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__) 00131 00132 #else 00133 # ifdef __GNUC__ 00134 # warning Disabling GP_DEBUG because variadic macros are not allowed 00135 # endif 00136 #define GP_DEBUG (void) 00137 #define GP_LOG_D(...) /* no-op */ 00138 #define GP_LOG_E(...) /* no-op */ 00139 #define GP_LOG_DATA(DATA, SIZE, ...) /* no-op */ 00140 #endif 00141 #endif /* _GPHOTO2_INTERNAL_CODE */ 00142 00143 #else /* DISABLE_DEBUGGING */ 00144 00145 /* Stub these functions out if debugging is disabled */ 00146 #define gp_log_add_func(level, func, data) (0) 00147 #define gp_log_remove_func(id) (0) 00148 #define gp_log(level, domain, format, args...) 00149 #define gp_log_with_source_location(level, file, line, func, format, ...) 00150 #define gp_logv(level, domain, format, args) 00151 #define gp_log_data(domain, data, size) 00152 00153 #ifdef _GPHOTO2_INTERNAL_CODE 00154 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 00155 #define GP_DEBUG(...) /* no-op */ 00156 #define GP_LOG_D(...) /* no-op */ 00157 #define GP_LOG_E(...) /* no-op */ 00158 #define GP_LOG_DATA(DATA, SIZE, ...) /* no-op */ 00159 00160 #elif defined(__GNUC__) 00161 #define GP_DEBUG(msg, params...) /* no-op */ 00162 #define GP_LOG_D(...) /* no-op */ 00163 #define GP_LOG_E(...) /* no-op */ 00164 #define GP_LOG_DATA(DATA, SIZE, ...) /* no-op */ 00165 #else 00166 #define GP_DEBUG (void) 00167 #define GP_LOG_D (void /* no-op */ 00168 #define GP_LOG_E (void) /* no-op */ 00169 #define GP_LOG_DATA(void) /* no-op */ 00170 #endif 00171 #endif /* _GPHOTO2_INTERNAL_CODE */ 00172 00173 #endif /* DISABLE_DEBUGGING */ 00174 00175 #ifdef _GPHOTO2_INTERNAL_CODE 00176 00177 typedef struct StringFlagItem { 00178 char *str; 00179 unsigned int flag; 00180 } StringFlagItem; 00181 00182 typedef void (*string_item_func) (const char *str, void *data); 00183 00184 const char * 00185 gpi_enum_to_string(const unsigned int _enum, 00186 const StringFlagItem *map); 00187 00188 int 00189 gpi_string_to_enum(const char *str, 00190 unsigned int *result, 00191 const StringFlagItem *map); 00192 00193 void 00194 gpi_flags_to_string_list(const unsigned int flags, 00195 const StringFlagItem *map, 00196 string_item_func func, void *data); 00197 00198 int 00199 gpi_string_or_to_flags(const char *str, 00200 unsigned int *flags, 00201 const StringFlagItem *map); 00202 00203 unsigned int 00204 gpi_string_to_flag(const char *str, 00205 const StringFlagItem *map); 00206 00207 unsigned int 00208 gpi_string_list_to_flags(const char *str[], 00209 const StringFlagItem *map); 00210 00211 /* Allocates a sufficiently large buffer and interpolates the format 00212 * string with the proveded va_list args. The returned memory has to 00213 * be freed by the caller. */ 00214 char* 00215 gpi_vsnprintf (const char* format, va_list args); 00216 00217 #define C_MEM(MEM) do {\ 00218 if ((MEM) == NULL) {\ 00219 GP_LOG_E ("Out of memory: '%s' failed.", #MEM);\ 00220 return GP_ERROR_NO_MEMORY;\ 00221 }\ 00222 } while(0) 00223 00224 #define C_PARAMS(PARAMS) do {\ 00225 if (!(PARAMS)) {\ 00226 GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\ 00227 return GP_ERROR_BAD_PARAMETERS;\ 00228 }\ 00229 } while(0) 00230 00231 #define C_PARAMS_MSG(PARAMS, MSG, ...) do {\ 00232 if (!(PARAMS)) {\ 00233 GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\ 00234 return GP_ERROR_BAD_PARAMETERS;\ 00235 }\ 00236 } while(0) 00237 00238 #endif /* _GPHOTO2_INTERNAL_CODE */ 00239 00240 #endif /* __GPHOTO2_PORT_LOG_H__ */