2004-05-15 Lutz Mueller <lutz@users.sourceforge.net>
[platform/upstream/libexif.git] / libexif / exif-log.c
1 /* exif-log.c
2  *
3  * Copyright © 2004 Lutz Müller <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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22 #include <libexif/exif-log.h>
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 struct _ExifLog {
28         unsigned int ref_count;
29
30         ExifLogFunc func;
31         void *data;
32 };
33
34 ExifLog *
35 exif_log_new (void)
36 {
37         ExifLog *log;
38
39         log = malloc (sizeof (ExifLog));
40         if (!log) return NULL;
41         memset (log, 0, sizeof (ExifLog));
42         log->ref_count = 1;
43
44         return log;
45 }
46
47 void
48 exif_log_ref (ExifLog *log)
49 {
50         if (!log) return;
51         log->ref_count++;
52 }
53
54 void
55 exif_log_unref (ExifLog *log)
56 {
57         if (!log) return;
58         if (log->ref_count > 0) log->ref_count--;
59         if (!log->ref_count) exif_log_free (log);
60 }
61
62 void
63 exif_log_free (ExifLog *log)
64 {
65         if (!log) return;
66         memset (log, 0, sizeof (log));
67         free (log);
68 }
69
70 void
71 exif_log_set_func (ExifLog *log, ExifLogFunc func, void *data)
72 {
73         if (!log) return;
74         log->func = func;
75         log->data = data;
76 }
77
78 void
79 exif_log (ExifLog *log, ExifLogCode code, const char *domain,
80           const char *format, ...)
81 {
82         va_list args;
83
84         va_start (args, format);
85         exif_logv (log, code, domain, format, args);
86         va_end (args);
87 }
88
89 void
90 exif_logv (ExifLog *log, ExifLogCode code, const char *domain,
91            const char *format, va_list args)
92 {
93         if (!log) return;
94         if (!log->func) return;
95         log->func (log, code, domain, format, args, log->data);
96 }