21 #ifndef __GPHOTO2_PORT_LOG_H__ 22 #define __GPHOTO2_PORT_LOG_H__ 46 #define GP_LOG_ALL GP_LOG_DATA 63 #ifndef DISABLE_DEBUGGING 70 const char *format, ...)
72 __attribute__((__format__(printf,3,4)))
75 void gp_log_with_source_location(
76 GPLogLevel level,
const char *file,
int line,
const char *func,
77 const char *format, ...)
79 __attribute__((__format__(printf,5,6)))
85 __attribute__((__format__(printf,3,0)))
88 void gp_log_data (
const char *domain,
const char *data,
unsigned int size,
89 const char *format, ...)
91 __attribute__((__format__(printf,4,5)))
106 #ifdef _GPHOTO2_INTERNAL_CODE 107 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 108 #define GP_DEBUG(...) \ 109 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, __VA_ARGS__) 116 #define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__) 117 #define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) 118 #define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__) 120 #elif defined(__GNUC__) && __GNUC__ >= 2 121 #define GP_DEBUG(msg, params...) \ 122 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, msg, ##params) 128 #define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__) 129 #define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) 130 #define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__) 134 # warning Disabling GP_DEBUG because variadic macros are not allowed 136 #define GP_DEBUG (void) 137 #define GP_LOG_D(...) 138 #define GP_LOG_E(...) 139 #define GP_LOG_DATA(DATA, SIZE, ...) 146 #define gp_log_add_func(level, func, data) (0) 147 #define gp_log_remove_func(id) (0) 148 #define gp_log(level, domain, format, args...) 149 #define gp_log_with_source_location(level, file, line, func, format, ...) 150 #define gp_logv(level, domain, format, args) 151 #define gp_log_data(domain, data, size) 153 #ifdef _GPHOTO2_INTERNAL_CODE 154 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 155 #define GP_DEBUG(...) 156 #define GP_LOG_D(...) 157 #define GP_LOG_E(...) 158 #define GP_LOG_DATA(DATA, SIZE, ...) 160 #elif defined(__GNUC__) 161 #define GP_DEBUG(msg, params...) 162 #define GP_LOG_D(...) 163 #define GP_LOG_E(...) 164 #define GP_LOG_DATA(DATA, SIZE, ...) 166 #define GP_DEBUG (void) 167 #define GP_LOG_D (void 168 #define GP_LOG_E (void) 169 #define GP_LOG_DATA(void) 175 #ifdef _GPHOTO2_INTERNAL_CODE 177 typedef struct StringFlagItem {
182 typedef void (*string_item_func) (
const char *str,
void *data);
185 gpi_enum_to_string(
const unsigned int _enum,
186 const StringFlagItem *map);
189 gpi_string_to_enum(
const char *str,
190 unsigned int *result,
191 const StringFlagItem *map);
194 gpi_flags_to_string_list(
const unsigned int flags,
195 const StringFlagItem *map,
196 string_item_func func,
void *data);
199 gpi_string_or_to_flags(
const char *str,
201 const StringFlagItem *map);
204 gpi_string_to_flag(
const char *str,
205 const StringFlagItem *map);
208 gpi_string_list_to_flags(
const char *str[],
209 const StringFlagItem *map);
215 gpi_vsnprintf (
const char* format, va_list args);
217 #define C_MEM(MEM) do {\ 218 if ((MEM) == NULL) {\ 219 GP_LOG_E ("Out of memory: '%s' failed.", #MEM);\ 220 return GP_ERROR_NO_MEMORY;\ 224 #define C_PARAMS(PARAMS) do {\ 226 GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\ 227 return GP_ERROR_BAD_PARAMETERS;\ 231 #define C_PARAMS_MSG(PARAMS, MSG, ...) do {\ 233 GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\ 234 return GP_ERROR_BAD_PARAMETERS;\ void(* GPLogFunc)(GPLogLevel level, const char *domain, const char *str, void *data)
Logging function hook.
Definition: gphoto2-port-log.h:61
Log message is a data hex dump.
Definition: gphoto2-port-log.h:34
void gp_log_data(const char *domain, const char *data, unsigned int size, const char *format,...)
Log data.
Definition: gphoto2-port-log.c:205
void gp_logv(GPLogLevel level, const char *domain, const char *format, va_list args)
Log a debug or error message with va_list.
Definition: gphoto2-port-log.c:299
Log message is an verbose debug infomation.
Definition: gphoto2-port-log.h:32
int gp_log_add_func(GPLogLevel level, GPLogFunc func, void *data)
Add a function to get logging information.
Definition: gphoto2-port-log.c:82
Log message is an debug infomation.
Definition: gphoto2-port-log.h:33
GPLogLevel
Logging level Specifies the logging severity level.
Definition: gphoto2-port-log.h:30
Log message is an error infomation.
Definition: gphoto2-port-log.h:31
void gp_log(GPLogLevel level, const char *domain, const char *format,...)
Log a debug or error message.
Definition: gphoto2-port-log.c:331
int gp_log_remove_func(int id)
Remove a logging receiving function.
Definition: gphoto2-port-log.c:138