EXIF library (libexif) Internals 0.6.26
exif-log.c
Go to the documentation of this file.
1/* exif-log.c
2 *
3 * Copyright (c) 2004 Lutz Mueller <lutz@users.sourceforge.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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA.
19 *
20 * SPDX-License-Identifier: LGPL-2.0-or-later
21 */
22
23#include <config.h>
24
25#include <libexif/exif-log.h>
26#include <libexif/i18n.h>
27
28#include <stdlib.h>
29#include <string.h>
30
31struct _ExifLog {
32 unsigned int ref_count;
33
35 void *data;
36
38};
39
40static const struct {
42 const char *title;
43 const char *message;
44} codes[] = {
45 { EXIF_LOG_CODE_DEBUG, N_("Debugging information"),
46 N_("Debugging information is available.") },
47 { EXIF_LOG_CODE_NO_MEMORY, N_("Not enough memory"),
48 N_("The system cannot provide enough memory.") },
49 { EXIF_LOG_CODE_CORRUPT_DATA, N_("Corrupt data"),
50 N_("The data provided does not follow the specification.") },
51 { 0, NULL, NULL }
52};
53
54const char *
56{
57 unsigned int i;
58
59 for (i = 0; codes[i].title; i++) if (codes[i].code == code) break;
60 return _(codes[i].title);
61}
62
63const char *
65{
66 unsigned int i;
67
68 for (i = 0; codes[i].message; i++) if (codes[i].code == code) break;
69 return _(codes[i].message);
70}
71
72ExifLog *
74{
75 ExifLog *log;
76
77 log = exif_mem_alloc (mem, sizeof (ExifLog));
78 if (!log) return NULL;
79 log->ref_count = 1;
80
81 log->mem = mem;
82 exif_mem_ref (mem);
83
84 return log;
85}
86
87ExifLog *
89{
91 ExifLog *log = exif_log_new_mem (mem);
92
93 exif_mem_unref (mem);
94
95 return log;
96}
97
98void
100{
101 if (!log) return;
102 log->ref_count++;
103}
104
105void
107{
108 if (!log) return;
109 if (log->ref_count > 0) log->ref_count--;
110 if (!log->ref_count) exif_log_free (log);
111}
112
113void
115{
116 ExifMem *mem = log ? log->mem : NULL;
117
118 if (!log) return;
119
120 exif_mem_free (mem, log);
121 exif_mem_unref (mem);
122}
123
124void
125exif_log_set_func (ExifLog *log, ExifLogFunc func, void *data)
126{
127 if (!log) return;
128 log->func = func;
129 log->data = data;
130}
131
132#ifdef NO_VERBOSE_TAG_STRINGS
133/* exif_log forms part of the API and can't be commented away */
134#undef exif_log
135#endif
136void
137exif_log (ExifLog *log, ExifLogCode code, const char *domain,
138 const char *format, ...)
139{
140 va_list args;
141
142 va_start (args, format);
143 exif_logv (log, code, domain, format, args);
144 va_end (args);
145}
146
147void
148exif_logv (ExifLog *log, ExifLogCode code, const char *domain,
149 const char *format, va_list args)
150{
151 if (!log) return;
152 if (!log->func) return;
153 log->func (log, code, domain, format, args, log->data);
154}
ExifFormat format
Definition exif-format.c:35
ExifLog * exif_log_new(void)
Create a new logging instance.
Definition exif-log.c:88
void exif_log(ExifLog *log, ExifLogCode code, const char *domain, const char *format,...)
Definition exif-log.c:137
ExifLogCode code
Definition exif-log.c:41
const char * message
Definition exif-log.c:43
const char * exif_log_code_get_title(ExifLogCode code)
Return a textual description of the given class of error log.
Definition exif-log.c:55
ExifLog * exif_log_new_mem(ExifMem *mem)
Definition exif-log.c:73
void exif_log_set_func(ExifLog *log, ExifLogFunc func, void *data)
Register log callback function.
Definition exif-log.c:125
void exif_log_unref(ExifLog *log)
Definition exif-log.c:106
const char * title
Definition exif-log.c:42
void exif_logv(ExifLog *log, ExifLogCode code, const char *domain, const char *format, va_list args)
Definition exif-log.c:148
void exif_log_ref(ExifLog *log)
Definition exif-log.c:99
static const struct @9 codes[]
void exif_log_free(ExifLog *log)
Delete instance of ExifLog.
Definition exif-log.c:114
const char * exif_log_code_get_message(ExifLogCode code)
Return a verbose description of the given class of error log.
Definition exif-log.c:64
Log message infrastructure.
ExifLogCode
Definition exif-log.h:56
@ EXIF_LOG_CODE_NO_MEMORY
Definition exif-log.h:59
@ EXIF_LOG_CODE_CORRUPT_DATA
Definition exif-log.h:60
@ EXIF_LOG_CODE_DEBUG
Definition exif-log.h:58
void(* ExifLogFunc)(ExifLog *log, ExifLogCode, const char *domain, const char *format, va_list args, void *data)
Log callback function prototype.
Definition exif-log.h:79
void exif_mem_free(ExifMem *mem, void *d)
Definition exif-mem.c:91
void exif_mem_unref(ExifMem *mem)
Unrefcount an ExifMem.
Definition exif-mem.c:83
void * exif_mem_alloc(ExifMem *mem, ExifLong ds)
Definition exif-mem.c:101
ExifMem * exif_mem_new_default(void)
Create a new ExifMem with default values for your convenience.
Definition exif-mem.c:117
void exif_mem_ref(ExifMem *mem)
Refcount an ExifMem.
Definition exif-mem.c:76
#define _(String)
Definition i18n.h:50
#define N_(String)
Definition i18n.h:51
ExifMem * mem
Definition exif-log.c:37
ExifLogFunc func
Definition exif-log.c:34
unsigned int ref_count
Definition exif-log.c:32
void * data
Definition exif-log.c:35

libexif Generated by doxygen