1 /** \file gphoto2-port-log.h
3 * Copyright © 2001 Lutz Müller <lutz@users.sf.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __GPHOTO2_PORT_LOG_H__
22 #define __GPHOTO2_PORT_LOG_H__
27 * \brief Logging level
28 * Specifies the logging severity level.
31 GP_LOG_ERROR = 0, /**< \brief Log message is an error infomation. */
32 GP_LOG_VERBOSE = 1, /**< \brief Log message is an verbose debug infomation. */
33 GP_LOG_DEBUG = 2, /**< \brief Log message is an debug infomation. */
34 GP_LOG_DATA = 3 /**< \brief Log message is a data hex dump. */
40 * Used by frontends if they want to be sure their
41 * callback function receives all messages. Defined
42 * as the highest debug level. Can make frontend code
43 * more understandable and extension of log levels
46 #define GP_LOG_ALL GP_LOG_DATA
49 * \brief Logging function hook
51 * This is the function frontends can use to receive logging information
52 * from the libgphoto2 framework. It is set using gp_log_add_func() and
53 * removed using gp_log_remove_func() and will then receive the logging
54 * messages of the level specified.
56 * \param level the log level of the passed message, as set by the camera driver or libgphoto2
57 * \param domain the logging domain as set by the camera driver, or libgphoto2 function
58 * \param format the printf style format string of the logmessage, without linefeed
59 * \param args the arguments as va_list, depending on the format string
60 * \param data the caller private data that was passed to gp_log_add_func()
62 typedef void (* GPLogFunc) (GPLogLevel level, const char *domain,
63 const char *format, va_list args, void *data)
65 __attribute__((__format__(printf,3,0)))
69 #ifndef DISABLE_DEBUGGING
71 int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data);
72 int gp_log_remove_func (int id);
75 void gp_log (GPLogLevel level, const char *domain,
76 const char *format, ...)
78 __attribute__((__format__(printf,3,4)))
81 void gp_logv (GPLogLevel level, const char *domain, const char *format,
84 __attribute__((__format__(printf,3,0)))
87 void gp_log_data (const char *domain, const char *data, unsigned int size);
93 * params: params to message
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().
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)
110 # warning Disabling GP_DEBUG because variadic macros are not allowed
112 #define GP_DEBUG (void)
114 #endif /* _GPHOTO2_INTERNAL_CODE */
116 #else /* DISABLE_DEBUGGING */
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) /**/
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 */
131 #define GP_DEBUG (void)
133 #endif /* _GPHOTO2_INTERNAL_CODE */
135 #endif /* DISABLE_DEBUGGING */
137 #ifdef _GPHOTO2_INTERNAL_CODE
139 typedef struct StringFlagItem {
144 typedef void (*string_item_func) (const char *str, void *data);
147 gpi_enum_to_string(const unsigned int _enum,
148 const StringFlagItem *map);
151 gpi_string_to_enum(const char *str,
152 unsigned int *result,
153 const StringFlagItem *map);
156 gpi_flags_to_string_list(const unsigned int flags,
157 const StringFlagItem *map,
158 string_item_func func, void *data);
161 gpi_string_or_to_flags(const char *str,
163 const StringFlagItem *map);
166 gpi_string_to_flag(const char *str,
167 const StringFlagItem *map);
170 gpi_string_list_to_flags(const char *str[],
171 const StringFlagItem *map);
173 #endif /* _GPHOTO2_INTERNAL_CODE */
176 #endif /* __GPHOTO2_PORT_LOG_H__ */