libgphoto2 photo camera library (libgphoto2) API  2.5.5.1
gphoto2-port-log.h
Go to the documentation of this file.
1 
21 #ifndef __GPHOTO2_PORT_LOG_H__
22 #define __GPHOTO2_PORT_LOG_H__
23 
24 #include <stdarg.h>
25 
30 typedef enum {
35 } GPLogLevel;
36 
46 #define GP_LOG_ALL GP_LOG_DATA
47 
61 typedef void (* GPLogFunc) (GPLogLevel level, const char *domain, const char *str, void *data);
62 
63 #ifndef DISABLE_DEBUGGING
64 
65 int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data);
66 int gp_log_remove_func (int id);
67 
68 /* Logging */
69 void gp_log (GPLogLevel level, const char *domain,
70  const char *format, ...)
71 #ifdef __GNUC__
72  __attribute__((__format__(printf,3,4)))
73 #endif
74 ;
75 void gp_log_with_source_location(
76  GPLogLevel level, const char *file, int line, const char *func,
77  const char *format, ...)
78 #ifdef __GNUC__
79  __attribute__((__format__(printf,5,6)))
80 #endif
81 ;
82 void gp_logv (GPLogLevel level, const char *domain, const char *format,
83  va_list args)
84 #ifdef __GNUC__
85  __attribute__((__format__(printf,3,0)))
86 #endif
87 ;
88 void gp_log_data (const char *domain, const char *data, unsigned int size);
89 
90 /*
91  * GP_DEBUG:
92  * msg: message to log
93  * params: params to message
94  *
95  * Logs message at log level #GP_LOG_DEBUG by calling #gp_log() with
96  * an automatically generated domain
97  * You have to define GP_MODULE as "mymod" for your module
98  * mymod before using #GP_DEBUG().
99  */
100 
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)
108 /*
109  * GP_LOG_D/E:
110  * simple helper macros for convenient and consistent logging of error
111  * and debug messages including information about the source location.
112  */
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)
116 
117 #else
118 # ifdef __GNUC__
119 # warning Disabling GP_DEBUG because variadic macros are not allowed
120 # endif
121 #define GP_DEBUG (void)
122 #define GP_LOG_D(...) /* no-op */
123 #define GP_LOG_E(...) /* no-op */
124 #define GP_LOG_DATA(DATA, SIZE) /* no-op */
125 #endif
126 #endif /* _GPHOTO2_INTERNAL_CODE */
127 
128 #else /* DISABLE_DEBUGGING */
129 
130 /* Stub these functions out if debugging is disabled */
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)
137 
138 #ifdef _GPHOTO2_INTERNAL_CODE
139 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
140 #define GP_DEBUG(...) /* no-op */
141 #define GP_LOG_D(...) /* no-op */
142 #define GP_LOG_E(...) /* no-op */
143 #define GP_LOG_DATA(DATA, SIZE) /* no-op */
144 
145 #elif defined(__GNUC__)
146 #define GP_DEBUG(msg, params...) /* no-op */
147 #define GP_LOG_D(...) /* no-op */
148 #define GP_LOG_E(...) /* no-op */
149 #define GP_LOG_DATA(DATA, SIZE) /* no-op */
150 #else
151 #define GP_DEBUG (void)
152 #define GP_LOG_D (void /* no-op */
153 #define GP_LOG_E (void) /* no-op */
154 #define GP_LOG_DATA(DATA, SIZE) /* no-op */
155 #endif
156 #endif /* _GPHOTO2_INTERNAL_CODE */
157 
158 #endif /* DISABLE_DEBUGGING */
159 
160 #ifdef _GPHOTO2_INTERNAL_CODE
161 
162  typedef struct StringFlagItem {
163  char *str;
164  unsigned int flag;
165  } StringFlagItem;
166 
167  typedef void (*string_item_func) (const char *str, void *data);
168 
169  const char *
170  gpi_enum_to_string(const unsigned int _enum,
171  const StringFlagItem *map);
172 
173  int
174  gpi_string_to_enum(const char *str,
175  unsigned int *result,
176  const StringFlagItem *map);
177 
178  void
179  gpi_flags_to_string_list(const unsigned int flags,
180  const StringFlagItem *map,
181  string_item_func func, void *data);
182 
183  int
184  gpi_string_or_to_flags(const char *str,
185  unsigned int *flags,
186  const StringFlagItem *map);
187 
188  unsigned int
189  gpi_string_to_flag(const char *str,
190  const StringFlagItem *map);
191 
192  unsigned int
193  gpi_string_list_to_flags(const char *str[],
194  const StringFlagItem *map);
195 
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;\
200  }\
201 } while(0)
202 
203 #define C_PARAMS(PARAMS) do {\
204  if (!(PARAMS)) {\
205  GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\
206  return GP_ERROR_BAD_PARAMETERS;\
207  }\
208 } while(0)
209 
210 #define C_PARAMS_MSG(PARAMS, MSG, ...) do {\
211  if (!(PARAMS)) {\
212  GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\
213  return GP_ERROR_BAD_PARAMETERS;\
214  }\
215 } while(0)
216 
217 #endif /* _GPHOTO2_INTERNAL_CODE */
218 
219 #endif /* __GPHOTO2_PORT_LOG_H__ */
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