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

libexif Generated by doxygen