exif-log.c

Go to the documentation of this file.
00001 /* exif-log.c
00002  *
00003  * Copyright © 2004 Lutz Müller <lutz@users.sourceforge.net>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <libexif/exif-log.h>
00024 #include <libexif/i18n.h>
00025 
00026 #include <stdlib.h>
00027 #include <string.h>
00028 
00029 struct _ExifLog {
00030         unsigned int ref_count;
00031 
00032         ExifLogFunc func;
00033         void *data;
00034 
00035         ExifMem *mem;
00036 };
00037 
00038 static struct {
00039         ExifLogCode code;
00040         const char *title;
00041         const char *message;
00042 } codes[] = {
00043         { EXIF_LOG_CODE_DEBUG, N_("Debugging information"),
00044           N_("Debugging information is available.") },
00045         { EXIF_LOG_CODE_NO_MEMORY, N_("Not enough memory"),
00046           N_("The system cannot provide enough memory.") },
00047         { EXIF_LOG_CODE_CORRUPT_DATA, N_("Corrupt data"),
00048           N_("The data provided does not follow the specification.") },
00049         { 0, NULL, NULL }
00050 };
00051 
00052 const char *
00053 exif_log_code_get_title (ExifLogCode code)
00054 {
00055         unsigned int i;
00056 
00057         for (i = 0; codes[i].title; i++) if (codes[i].code == code) break;
00058         return _(codes[i].title);
00059 }
00060 
00061 const char *
00062 exif_log_code_get_message (ExifLogCode code)
00063 {
00064         unsigned int i;
00065 
00066         for (i = 0; codes[i].message; i++) if (codes[i].code == code) break;
00067         return _(codes[i].message);
00068 }
00069 
00070 ExifLog *
00071 exif_log_new_mem (ExifMem *mem)
00072 {
00073         ExifLog *log;
00074 
00075         log = exif_mem_alloc (mem, sizeof (ExifLog));
00076         if (!log) return NULL;
00077         log->ref_count = 1;
00078 
00079         log->mem = mem;
00080         exif_mem_ref (mem);
00081 
00082         return log;
00083 }
00084 
00085 ExifLog *
00086 exif_log_new (void)
00087 {
00088         ExifMem *mem = exif_mem_new_default ();
00089         ExifLog *log = exif_log_new_mem (mem);
00090 
00091         exif_mem_unref (mem);
00092 
00093         return log;
00094 }
00095 
00096 void
00097 exif_log_ref (ExifLog *log)
00098 {
00099         if (!log) return;
00100         log->ref_count++;
00101 }
00102 
00103 void
00104 exif_log_unref (ExifLog *log)
00105 {
00106         if (!log) return;
00107         if (log->ref_count > 0) log->ref_count--;
00108         if (!log->ref_count) exif_log_free (log);
00109 }
00110 
00111 void
00112 exif_log_free (ExifLog *log)
00113 {
00114         ExifMem *mem = log ? log->mem : NULL;
00115 
00116         if (!log) return;
00117 
00118         exif_mem_free (mem, log);
00119         exif_mem_unref (mem);
00120 }
00121 
00122 void
00123 exif_log_set_func (ExifLog *log, ExifLogFunc func, void *data)
00124 {
00125         if (!log) return;
00126         log->func = func;
00127         log->data = data;
00128 }
00129 
00130 void
00131 exif_log (ExifLog *log, ExifLogCode code, const char *domain,
00132           const char *format, ...)
00133 {
00134         va_list args;
00135 
00136         va_start (args, format);
00137         exif_logv (log, code, domain, format, args);
00138         va_end (args);
00139 }
00140 
00141 void
00142 exif_logv (ExifLog *log, ExifLogCode code, const char *domain,
00143            const char *format, va_list args)
00144 {
00145         if (!log) return;
00146         if (!log->func) return;
00147         log->func (log, code, domain, format, args, log->data);
00148 }

Generated on Tue Dec 19 14:33:53 2006 for EXIF library (libexif) Internals by  doxygen 1.5.1