21#ifndef LIBGPHOTO2_GPHOTO2_PORT_LOG_H
22#define LIBGPHOTO2_GPHOTO2_PORT_LOG_H
50#define GP_LOG_ALL GP_LOG_DATA
67#ifndef DISABLE_DEBUGGING
74 const char *format, ...)
76 __attribute__((__format__(printf,3,4)))
79void gp_log_with_source_location(
80 GPLogLevel level,
const char *file,
int line,
const char *func,
81 const char *format, ...)
83 __attribute__((__format__(printf,5,6)))
89 __attribute__((__format__(printf,3,0)))
92void gp_log_data (
const char *domain,
const char *data,
unsigned int size,
93 const char *format, ...)
95__attribute__((__format__(printf,4,5)))
110#ifdef _GPHOTO2_INTERNAL_CODE
111#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
112#define GP_DEBUG(...) \
113 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, __VA_ARGS__)
120#define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__)
121#define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
122#define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__)
124#elif defined(__GNUC__) && __GNUC__ >= 2
125#define GP_DEBUG(msg, params...) \
126 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, msg, ##params)
132#define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__)
133#define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
134#define GP_LOG_DATA(DATA, SIZE, MSG, ...) gp_log_data(__func__, DATA, SIZE, MSG, ##__VA_ARGS__)
138# warning Disabling GP_DEBUG because variadic macros are not allowed
140#define GP_DEBUG (void)
143#define GP_LOG_DATA(DATA, SIZE, ...)
150#define gp_log_add_func(level, func, data) (0)
151#define gp_log_remove_func(id) (0)
152#define gp_log(level, domain, format, args...)
153#define gp_log_with_source_location(level, file, line, func, format, ...)
154#define gp_logv(level, domain, format, args)
155#define gp_log_data(domain, data, size)
157#ifdef _GPHOTO2_INTERNAL_CODE
158#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
162#define GP_LOG_DATA(DATA, SIZE, ...)
164#elif defined(__GNUC__)
165#define GP_DEBUG(msg, params...)
168#define GP_LOG_DATA(DATA, SIZE, ...)
170#define GP_DEBUG (void)
171#define GP_LOG_D (void
172#define GP_LOG_E (void)
173#define GP_LOG_DATA(void)
179#ifdef _GPHOTO2_INTERNAL_CODE
181 typedef struct StringFlagItem {
186 typedef void (*string_item_func) (
const char *str,
void *data);
189 gpi_enum_to_string(
const unsigned int _enum,
190 const StringFlagItem *map);
193 gpi_string_to_enum(
const char *str,
194 unsigned int *result,
195 const StringFlagItem *map);
198 gpi_flags_to_string_list(
const unsigned int flags,
199 const StringFlagItem *map,
200 string_item_func func,
void *data);
203 gpi_string_or_to_flags(
const char *str,
205 const StringFlagItem *map);
208 gpi_string_to_flag(
const char *str,
209 const StringFlagItem *map);
212 gpi_string_list_to_flags(
const char *str[],
213 const StringFlagItem *map);
219 gpi_vsnprintf (
const char* format, va_list args);
221#define C_MEM(MEM) do {\
222 if ((MEM) == NULL) {\
223 GP_LOG_E ("Out of memory: '%s' failed.", #MEM);\
224 return GP_ERROR_NO_MEMORY;\
228#define C_PARAMS(PARAMS) do {\
230 GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\
231 return GP_ERROR_BAD_PARAMETERS;\
235#define C_PARAMS_MSG(PARAMS, MSG, ...) do {\
237 GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\
238 return GP_ERROR_BAD_PARAMETERS;\
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:287
int gp_log_remove_func(int id)
Remove a logging receiving function.
Definition: gphoto2-port-log.c:126
void(* GPLogFunc)(GPLogLevel level, const char *domain, const char *str, void *data)
Logging function hook.
Definition: gphoto2-port-log.h:65
void gp_log(GPLogLevel level, const char *domain, const char *format,...)
Log a debug or error message.
Definition: gphoto2-port-log.c:319
int gp_log_add_func(GPLogLevel level, GPLogFunc func, void *data)
Add a function to get logging information.
Definition: gphoto2-port-log.c:70
GPLogLevel
Logging level Specifies the logging severity level.
Definition: gphoto2-port-log.h:34
@ GP_LOG_VERBOSE
Log message is an verbose debug information.
Definition: gphoto2-port-log.h:36
@ GP_LOG_ERROR
Log message is an error information.
Definition: gphoto2-port-log.h:35
@ GP_LOG_DATA
Log message is a data hex dump.
Definition: gphoto2-port-log.h:38
@ GP_LOG_DEBUG
Log message is an debug information.
Definition: gphoto2-port-log.h:37
void gp_log_data(const char *domain, const char *data, unsigned int size, const char *format,...)
Log data.
Definition: gphoto2-port-log.c:193