Source code upload
[framework/connectivity/libgphoto2.git] / libgphoto2_port / gphoto2 / gphoto2-port-log.h
1 /** \file gphoto2-port-log.h
2  *
3  * Copyright © 2001 Lutz Müller <lutz@users.sf.net>
4  *
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.
9  *
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. 
14  *
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.
19  */
20
21 #ifndef __GPHOTO2_PORT_LOG_H__
22 #define __GPHOTO2_PORT_LOG_H__
23
24 #include <stdarg.h>
25
26 /**
27  * \brief Logging level
28  * Specifies the logging severity level.
29  */
30 typedef enum {
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. */
35 } GPLogLevel;
36
37 /**
38  * GP_LOG_ALL:
39  * 
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
44  * easier.
45  **/
46 #define GP_LOG_ALL GP_LOG_DATA
47
48 /**
49  * \brief Logging function hook
50  * 
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.
55  *
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()
61  */
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__ */