• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*! \file exif-log.h
2  *  \brief Log message infrastructure
3  */
4 /*
5  * Copyright (c) 2004 Lutz Mueller <lutz@users.sourceforge.net>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA  02110-1301  USA.
21  *
22  * SPDX-License-Identifier: LGPL-2.0-or-later
23  */
24 
25 #ifndef LIBEXIF_EXIF_LOG_H
26 #define LIBEXIF_EXIF_LOG_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 
32 #include <libexif/exif-mem.h>
33 #include <stdarg.h>
34 
35 /*! State maintained by the logging interface */
36 typedef struct _ExifLog        ExifLog;
37 
38 /*! Create a new logging instance.
39  * \see exif_log_free
40  *
41  * \return new instance of #ExifLog
42  */
43 ExifLog *exif_log_new     (void);
44 ExifLog *exif_log_new_mem (ExifMem *);
45 void     exif_log_ref     (ExifLog *log);
46 void     exif_log_unref   (ExifLog *log);
47 
48 /*! Delete instance of #ExifLog.
49  * \see exif_log_new
50  *
51  * \param[in] log #ExifLog
52  * \return new instance of #ExifLog
53  */
54 void     exif_log_free    (ExifLog *log);
55 
56 typedef enum {
57 	EXIF_LOG_CODE_NONE,
58 	EXIF_LOG_CODE_DEBUG,
59 	EXIF_LOG_CODE_NO_MEMORY,
60 	EXIF_LOG_CODE_CORRUPT_DATA
61 } ExifLogCode;
62 
63 /*! Return a textual description of the given class of error log.
64  *
65  * \param[in] code logging message class
66  * \return textual description of the log class, or NULL if unknown
67  */
68 const char *exif_log_code_get_title   (ExifLogCode code);
69 
70 /*! Return a verbose description of the given class of error log.
71  *
72  * \param[in] code logging message class
73  * \return verbose description of the log class, or NULL if unknown
74  */
75 const char *exif_log_code_get_message (ExifLogCode code);
76 
77 /*! Log callback function prototype.
78  */
79 typedef void (* ExifLogFunc) (ExifLog *log, ExifLogCode, const char *domain,
80 			      const char *format, va_list args, void *data);
81 
82 /*! Register log callback function.
83  * Calls to the log callback function are purely for diagnostic purposes.
84  *
85  * \param[in] log logging state variable
86  * \param[in] func callback function to set
87  * \param[in] data data to pass into callback function
88  */
89 void     exif_log_set_func (ExifLog *log, ExifLogFunc func, void *data);
90 
91 #ifndef NO_VERBOSE_TAG_STRINGS
92 void     exif_log  (ExifLog *log, ExifLogCode, const char *domain,
93 		    const char *format, ...)
94 #ifdef __GNUC__
95 			__attribute__((__format__(printf,4,5)))
96 #endif
97 ;
98 #else
99 #if defined(__STDC_VERSION__) &&  __STDC_VERSION__ >= 199901L
100 #define exif_log(...) do { } while (0)
101 #elif defined(__GNUC__)
102 #define exif_log(x...) do { } while (0)
103 #else
104 #define exif_log (void)
105 #endif
106 #endif
107 
108 void     exif_logv (ExifLog *log, ExifLogCode, const char *domain,
109 		    const char *format, va_list args);
110 
111 /* For your convenience */
112 #define EXIF_LOG_NO_MEMORY(l,d,s) exif_log ((l), EXIF_LOG_CODE_NO_MEMORY, (d), "Could not allocate %lu byte(s).", (unsigned long)(s))
113 
114 #ifdef __cplusplus
115 }
116 #endif /* __cplusplus */
117 
118 #endif /* !defined(LIBEXIF_EXIF_LOG_H) */
119