Mercurial > hg > audiodb
comparison open.cpp @ 509:cc2b97d020b1
Code rearrangements to tease apart library code from C++ audioDB code.
There should be precisely no functional changes in this commit.
Instead, the only thing that has happened is that all the abstraction
violation and other horribleness is concentrated in one place: the
include of "audioDB-internals.h" in audioDB.h -- the separation will be
complete once that include can be removed.
This include is necessary because the command-line binary / SOAP server
still does some things directly rather than through an API: not least of
which the operations that have not yet been integrated into the API yet,
but also some messing around with constants, flags and nominally
internal functions. The intent is to remove as many of these as
possible and think quite hard about the rest.
In the meantime, the library is now much more self-contained: the only
things it uses are in the audioDB_API.h and audioDB-internals.h headers;
thus there are fewer nasty surprises lurking for readers of the code.
The Makefile has been adjusted to take advantage of this rearrangement
in the dependencies.
author | mas01cr |
---|---|
date | Thu, 15 Jan 2009 13:57:33 +0000 |
parents | 342822c2d49a |
children | cfa74bcc1249 |
comparison
equal
deleted
inserted
replaced
508:23c47e118bc6 | 509:cc2b97d020b1 |
---|---|
1 #include "audioDB.h" | |
2 extern "C" { | 1 extern "C" { |
3 #include "audioDB_API.h" | 2 #include "audioDB_API.h" |
3 } | |
4 #include "audioDB-internals.h" | 4 #include "audioDB-internals.h" |
5 } | |
6 | 5 |
7 static bool audiodb_check_header(adb_header_t *header) { | 6 static bool audiodb_check_header(adb_header_t *header) { |
8 /* FIXME: use syslog() or write to stderr or something to give the | 7 /* FIXME: use syslog() or write to stderr or something to give the |
9 poor user some diagnostics. */ | 8 poor user some diagnostics. */ |
10 if(header->magic == O2_OLD_MAGIC) { | 9 if(header->magic == ADB_OLD_MAGIC) { |
11 return false; | 10 return false; |
12 } | 11 } |
13 if(header->magic != O2_MAGIC) { | 12 if(header->magic != ADB_MAGIC) { |
14 return false; | 13 return false; |
15 } | 14 } |
16 if(header->version != O2_FORMAT_VERSION) { | 15 if(header->version != ADB_FORMAT_VERSION) { |
17 return false; | 16 return false; |
18 } | 17 } |
19 if(header->headerSize != O2_HEADERSIZE) { | 18 if(header->headerSize != ADB_HEADER_SIZE) { |
20 return false; | 19 return false; |
21 } | 20 } |
22 return true; | 21 return true; |
23 } | 22 } |
24 | 23 |
26 char *key_table = 0; | 25 char *key_table = 0; |
27 size_t key_table_length = 0; | 26 size_t key_table_length = 0; |
28 | 27 |
29 if(adb->header->length > 0) { | 28 if(adb->header->length > 0) { |
30 unsigned nfiles = adb->header->numFiles; | 29 unsigned nfiles = adb->header->numFiles; |
31 key_table_length = ALIGN_PAGE_UP(nfiles * O2_FILETABLE_ENTRY_SIZE); | 30 key_table_length = align_page_up(nfiles * ADB_FILETABLE_ENTRY_SIZE); |
32 mmap_or_goto_error(char *, key_table, adb->header->fileTableOffset, key_table_length); | 31 mmap_or_goto_error(char *, key_table, adb->header->fileTableOffset, key_table_length); |
33 for (unsigned int k = 0; k < nfiles; k++) { | 32 for (unsigned int k = 0; k < nfiles; k++) { |
34 adb->keys->push_back(key_table + k*O2_FILETABLE_ENTRY_SIZE); | 33 adb->keys->push_back(key_table + k*ADB_FILETABLE_ENTRY_SIZE); |
35 (*adb->keymap)[(key_table + k*O2_FILETABLE_ENTRY_SIZE)] = k; | 34 (*adb->keymap)[(key_table + k*ADB_FILETABLE_ENTRY_SIZE)] = k; |
36 } | 35 } |
37 munmap(key_table, key_table_length); | 36 munmap(key_table, key_table_length); |
38 } | 37 } |
39 | 38 |
40 return 0; | 39 return 0; |
47 static int audiodb_collect_track_lengths(adb_t *adb) { | 46 static int audiodb_collect_track_lengths(adb_t *adb) { |
48 uint32_t *track_table = 0; | 47 uint32_t *track_table = 0; |
49 size_t track_table_length = 0; | 48 size_t track_table_length = 0; |
50 if(adb->header->length > 0) { | 49 if(adb->header->length > 0) { |
51 unsigned nfiles = adb->header->numFiles; | 50 unsigned nfiles = adb->header->numFiles; |
52 track_table_length = ALIGN_PAGE_UP(nfiles * O2_TRACKTABLE_ENTRY_SIZE); | 51 track_table_length = align_page_up(nfiles * ADB_TRACKTABLE_ENTRY_SIZE); |
53 mmap_or_goto_error(uint32_t *, track_table, adb->header->trackTableOffset, track_table_length); | 52 mmap_or_goto_error(uint32_t *, track_table, adb->header->trackTableOffset, track_table_length); |
54 off_t offset = 0; | 53 off_t offset = 0; |
55 for (unsigned int k = 0; k < nfiles; k++) { | 54 for (unsigned int k = 0; k < nfiles; k++) { |
56 uint32_t track_length = track_table[k]; | 55 uint32_t track_length = track_table[k]; |
57 adb->track_lengths->push_back(track_length); | 56 adb->track_lengths->push_back(track_length); |
95 | 94 |
96 adb->header = (adb_header_t *) malloc(sizeof(adb_header_t)); | 95 adb->header = (adb_header_t *) malloc(sizeof(adb_header_t)); |
97 if(!(adb->header)) { | 96 if(!(adb->header)) { |
98 goto error; | 97 goto error; |
99 } | 98 } |
100 if(read(fd, (char *) adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { | 99 if(read(fd, (char *) adb->header, ADB_HEADER_SIZE) != ADB_HEADER_SIZE) { |
101 goto error; | 100 goto error; |
102 } | 101 } |
103 if(!audiodb_check_header(adb->header)) { | 102 if(!audiodb_check_header(adb->header)) { |
104 goto error; | 103 goto error; |
105 } | 104 } |