libgphoto2 photo camera library (libgphoto2) API  2.4.11
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 
62 typedef void (* GPLogFunc) (GPLogLevel level, const char *domain,
63  const char *format, va_list args, void *data)
64 #if (__GNUC__ >= 3)
65  __attribute__((__format__(printf,3,0)))
66 #endif
67 ;
68 
69 #ifndef DISABLE_DEBUGGING
70 
71 int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data);
72 int gp_log_remove_func (int id);
73 
74 /* Logging */
75 void gp_log (GPLogLevel level, const char *domain,
76  const char *format, ...)
77 #ifdef __GNUC__
78  __attribute__((__format__(printf,3,4)))
79 #endif
80 ;
81 void gp_logv (GPLogLevel level, const char *domain, const char *format,
82  va_list args)
83 #ifdef __GNUC__
84  __attribute__((__format__(printf,3,0)))
85 #endif
86 ;
87 void gp_log_data (const char *domain, const char *data, unsigned int size);
88 
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 #else
109 # ifdef __GNUC__
110 # warning Disabling GP_DEBUG because variadic macros are not allowed
111 # endif
112 #define GP_DEBUG (void)
113 #endif
114 #endif /* _GPHOTO2_INTERNAL_CODE */
115 
116 #else /* DISABLE_DEBUGGING */
117 
118 /* Stub these functions out if debugging is disabled */
119 #define gp_log_add_func(level, func, data) (0)
120 #define gp_log_remove_func(id) (0)
121 #define gp_log(level, domain, format, args...)
122 #define gp_logv(level, domain, format, args)
123 #define gp_log_data(domain, data, size)
124 
125 #ifdef _GPHOTO2_INTERNAL_CODE
126 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
127 #define GP_DEBUG(...) /* no-op */
128 #elif defined(__GNUC__)
129 #define GP_DEBUG(msg, params...) /* no-op */
130 #else
131 #define GP_DEBUG (void)
132 #endif
133 #endif /* _GPHOTO2_INTERNAL_CODE */
134 
135 #endif /* DISABLE_DEBUGGING */
136 
137 #ifdef _GPHOTO2_INTERNAL_CODE
138 
139  typedef struct StringFlagItem {
140  char *str;
141  unsigned int flag;
142  } StringFlagItem;
143 
144  typedef void (*string_item_func) (const char *str, void *data);
145 
146  const char *
147  gpi_enum_to_string(const unsigned int _enum,
148  const StringFlagItem *map);
149 
150  int
151  gpi_string_to_enum(const char *str,
152  unsigned int *result,
153  const StringFlagItem *map);
154 
155  void
156  gpi_flags_to_string_list(const unsigned int flags,
157  const StringFlagItem *map,
158  string_item_func func, void *data);
159 
160  int
161  gpi_string_or_to_flags(const char *str,
162  unsigned int *flags,
163  const StringFlagItem *map);
164 
165  unsigned int
166  gpi_string_to_flag(const char *str,
167  const StringFlagItem *map);
168 
169  unsigned int
170  gpi_string_list_to_flags(const char *str[],
171  const StringFlagItem *map);
172 
173 #endif /* _GPHOTO2_INTERNAL_CODE */
174 
175 
176 #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:260
void(* GPLogFunc)(GPLogLevel level, const char *domain, const char *format, va_list args, void *data)
Logging function hook.
Definition: gphoto2-port-log.h:62
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:80
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:293
void gp_log_data(const char *domain, const char *data, unsigned int size)
Log data.
Definition: gphoto2-port-log.c:178
int gp_log_remove_func(int id)
Remove a logging receiving function.
Definition: gphoto2-port-log.c:115