00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 const 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 #ifdef NO_VERBOSE_TAG_STRINGS
00131
00132 #undef exif_log
00133 #endif
00134 void
00135 exif_log (ExifLog *log, ExifLogCode code, const char *domain,
00136 const char *format, ...)
00137 {
00138 va_list args;
00139
00140 va_start (args, format);
00141 exif_logv (log, code, domain, format, args);
00142 va_end (args);
00143 }
00144
00145 void
00146 exif_logv (ExifLog *log, ExifLogCode code, const char *domain,
00147 const char *format, va_list args)
00148 {
00149 if (!log) return;
00150 if (!log->func) return;
00151 log->func (log, code, domain, format, args, log->data);
00152 }