1 /* exif-mnote-data.c 2 * 3 * Copyright (C) 2003 Lutz Mueller <lutz (at) 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.1 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-mnote-data.h> 24 #include <libexif/exif-mnote-data-priv.h> 25 26 #include <stdlib.h> 27 #include <string.h> 28 29 struct _ExifMnoteDataPriv 30 { 31 unsigned int ref_count; 32 }; 33 34 void 35 exif_mnote_data_construct (ExifMnoteData *d, ExifMem *mem) 36 { 37 if (!d || !mem) return; 38 if (d->priv) return; 39 d->priv = exif_mem_alloc (mem, sizeof (ExifMnoteDataPriv)); 40 if (!d->priv) return; 41 42 d->priv->ref_count = 1; 43 44 d->mem = mem; 45 exif_mem_ref (mem); 46 } 47 48 void 49 exif_mnote_data_ref (ExifMnoteData *d) 50 { 51 if (d && d->priv) d->priv->ref_count++; 52 } 53 54 static void 55 exif_mnote_data_free (ExifMnoteData *d) 56 { 57 ExifMem *mem = d ? d->mem : NULL; 58 59 if (!d) return; 60 if (d->priv) { 61 if (d->methods.free) d->methods.free (d); 62 exif_mem_free (mem, d->priv); 63 d->priv = NULL; 64 } 65 exif_log_unref (d->log); 66 exif_mem_free (mem, d); 67 exif_mem_unref (mem); 68 } 69 70 void 71 exif_mnote_data_unref (ExifMnoteData *d) 72 { 73 if (!d || !d->priv) return; 74 if (d->priv->ref_count > 0) d->priv->ref_count--; 75 if (!d->priv->ref_count) 76 exif_mnote_data_free (d); 77 } 78 79 void 80 exif_mnote_data_load (ExifMnoteData *d, const unsigned char *buf, 81 unsigned int buf_size) 82 { 83 if (!d || !d->methods.load) return; 84 d->methods.load (d, buf, buf_size); 85 } 86 87 void 88 exif_mnote_data_save (ExifMnoteData *d, unsigned char **buf, 89 unsigned int *buf_size) 90 { 91 if (!d || !d->methods.save) return; 92 d->methods.save (d, buf, buf_size); 93 } 94 95 void 96 exif_mnote_data_set_byte_order (ExifMnoteData *d, ExifByteOrder o) 97 { 98 if (!d || !d->methods.set_byte_order) return; 99 d->methods.set_byte_order (d, o); 100 } 101 102 void 103 exif_mnote_data_set_offset (ExifMnoteData *d, unsigned int o) 104 { 105 if (!d || !d->methods.set_offset) return; 106 d->methods.set_offset (d, o); 107 } 108 109 unsigned int 110 exif_mnote_data_count (ExifMnoteData *d) 111 { 112 if (!d || !d->methods.count) return 0; 113 return d->methods.count (d); 114 } 115 116 unsigned int 117 exif_mnote_data_get_id (ExifMnoteData *d, unsigned int n) 118 { 119 if (!d || !d->methods.get_id) return 0; 120 return d->methods.get_id (d, n); 121 } 122 123 const char * 124 exif_mnote_data_get_name (ExifMnoteData *d, unsigned int n) 125 { 126 if (!d || !d->methods.get_name) return NULL; 127 return d->methods.get_name (d, n); 128 } 129 130 const char * 131 exif_mnote_data_get_title (ExifMnoteData *d, unsigned int n) 132 { 133 if (!d || !d->methods.get_title) return NULL; 134 return d->methods.get_title (d, n); 135 } 136 137 const char * 138 exif_mnote_data_get_description (ExifMnoteData *d, unsigned int n) 139 { 140 if (!d || !d->methods.get_description) return NULL; 141 return d->methods.get_description (d, n); 142 } 143 144 char * 145 exif_mnote_data_get_value (ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen) 146 { 147 if (!d || !d->methods.get_value) return NULL; 148 return d->methods.get_value (d, n, val, maxlen); 149 } 150 151 void 152 exif_mnote_data_log (ExifMnoteData *d, ExifLog *log) 153 { 154 if (!d) return; 155 exif_log_unref (d->log); 156 d->log = log; 157 exif_log_ref (log); 158 } 159