comparison insert.cpp @ 580:633614461994

API for retrieving a track's data. A new function, audiodb_retrieve_datum() fills a provided adb_datum_t structure with the data corresponding to a given database key; the companion audiodb_free_datum() function frees the data in a given datum appropriately. Just in case, I continue to require passing in the adb_t * as the first argument to audiodb_free_datum(), even though it's not currently used: I couldn't convince myself that _all_ possible implementations could free a datum without reference to the adb_t. This meant rewriting the internal code to use a new internal audiodb_really_free_datum() function, which audiodb_free_datum() also calls. Sanity-checked by implementing a binding in sb-alien to this function, lightly-tested. All this fixes ticket:20 in Trac.
author mas01cr
date Tue, 14 Jul 2009 15:35:36 +0000
parents cc2b97d020b1
children c850f3433454
comparison
equal deleted inserted replaced
579:81053b8bdb51 580:633614461994
270 } 270 }
271 return 1; 271 return 1;
272 } 272 }
273 } 273 }
274 274
275 int audiodb_free_datum(adb_datum_t *datum) { 275 int audiodb_really_free_datum(adb_datum_t *datum) {
276 if(datum->data) { 276 if(datum->data) {
277 free(datum->data); 277 free(datum->data);
278 datum->data = NULL; 278 datum->data = NULL;
279 } 279 }
280 if(datum->power) { 280 if(datum->power) {
396 close(fd); 396 close(fd);
397 } 397 }
398 if(file) { 398 if(file) {
399 fclose(file); 399 fclose(file);
400 } 400 }
401 audiodb_free_datum(datum); 401 audiodb_really_free_datum(datum);
402 return 1; 402 return 1;
403 } 403 }
404 404
405 int audiodb_insert(adb_t *adb, adb_insert_t *insert) { 405 int audiodb_insert(adb_t *adb, adb_insert_t *insert) {
406 if(adb->header->flags & ADB_HEADER_FLAG_REFERENCES) { 406 if(adb->header->flags & ADB_HEADER_FLAG_REFERENCES) {
419 419
420 if(audiodb_insert_create_datum(insert, &datum)) { 420 if(audiodb_insert_create_datum(insert, &datum)) {
421 return 1; 421 return 1;
422 } 422 }
423 err = audiodb_insert_datum(adb, &datum); 423 err = audiodb_insert_datum(adb, &datum);
424 audiodb_free_datum(&datum); 424 audiodb_really_free_datum(&datum);
425 425
426 if(err == 2) { 426 if(err == 2) {
427 return 0; 427 return 0;
428 } else { 428 } else {
429 return err; 429 return err;