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);
101 #ifdef _GPHOTO2_INTERNAL_CODE
102 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
103 #define GP_DEBUG(...) \
104 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, __VA_ARGS__)
105 #elif defined(__GNUC__) && __GNUC__ >= 2
106 #define GP_DEBUG(msg, params...) \
107 gp_log(GP_LOG_DEBUG, GP_MODULE "/" __FILE__, msg, ##params)
113 #define GP_LOG_D(...) gp_log(GP_LOG_DEBUG, __func__, __VA_ARGS__)
114 #define GP_LOG_E(...) gp_log_with_source_location(GP_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
115 #define GP_LOG_DATA(DATA, SIZE) gp_log_data(__func__, DATA, SIZE)
119 # warning Disabling GP_DEBUG because variadic macros are not allowed
121 #define GP_DEBUG (void)
122 #define GP_LOG_D(...)
123 #define GP_LOG_E(...)
124 #define GP_LOG_DATA(DATA, SIZE)
131 #define gp_log_add_func(level, func, data) (0)
132 #define gp_log_remove_func(id) (0)
133 #define gp_log(level, domain, format, args...)
134 #define gp_log_with_source_location(level, file, line, func, format, ...)
135 #define gp_logv(level, domain, format, args)
136 #define gp_log_data(domain, data, size)
138 #ifdef _GPHOTO2_INTERNAL_CODE
139 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
140 #define GP_DEBUG(...)
141 #define GP_LOG_D(...)
142 #define GP_LOG_E(...)
143 #define GP_LOG_DATA(DATA, SIZE)
145 #elif defined(__GNUC__)
146 #define GP_DEBUG(msg, params...)
147 #define GP_LOG_D(...)
148 #define GP_LOG_E(...)
149 #define GP_LOG_DATA(DATA, SIZE)
151 #define GP_DEBUG (void)
152 #define GP_LOG_D (void
153 #define GP_LOG_E (void)
154 #define GP_LOG_DATA(DATA, SIZE)
160 #ifdef _GPHOTO2_INTERNAL_CODE
162 typedef struct StringFlagItem {
167 typedef void (*string_item_func) (
const char *str,
void *data);
170 gpi_enum_to_string(
const unsigned int _enum,
171 const StringFlagItem *map);
174 gpi_string_to_enum(
const char *str,
175 unsigned int *result,
176 const StringFlagItem *map);
179 gpi_flags_to_string_list(
const unsigned int flags,
180 const StringFlagItem *map,
181 string_item_func func,
void *data);
184 gpi_string_or_to_flags(
const char *str,
186 const StringFlagItem *map);
189 gpi_string_to_flag(
const char *str,
190 const StringFlagItem *map);
193 gpi_string_list_to_flags(
const char *str[],
194 const StringFlagItem *map);
196 #define C_MEM(MEM) do {\
197 if ((MEM) == NULL) {\
198 GP_LOG_E ("Out of memory: '%s' failed.", #MEM);\
199 return GP_ERROR_NO_MEMORY;\
203 #define C_PARAMS(PARAMS) do {\
205 GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\
206 return GP_ERROR_BAD_PARAMETERS;\
210 #define C_PARAMS_MSG(PARAMS, MSG, ...) do {\
212 GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\
213 return GP_ERROR_BAD_PARAMETERS;\
Log message is a data hex dump.
Definition: gphoto2-port-log.h:34
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:251
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:310
void(* GPLogFunc)(GPLogLevel level, const char *domain, const char *str, void *data)
Logging function hook.
Definition: gphoto2-port-log.h:61
void gp_log_data(const char *domain, const char *data, unsigned int size)
Log data.
Definition: gphoto2-port-log.c:170
int gp_log_remove_func(int id)
Remove a logging receiving function.
Definition: gphoto2-port-log.c:107