Mercurial > hg > audiodb
view liszt.cpp @ 395:bc7a821004bb api-inversion
Invert audioDB::status / audiodb_status().
To do that without breaking abstractions, we actually need a new field
in the status structure, storing the size of the data region.
Previously, this was computed in the audioDB::status request from the
database header, but I'm assuming that "user" code doesn't have access
to such internals. While we're at it, name some intermediate values in
audioDB::status() so that I don't get confused.
Here's the thing, though: we need to make sure that the adb_t * that we
have from audiodb_open() or audiodb_create() is propagated all the way
through into the C++ routines that implement library functions -- in
particular those which actually write to the database; otherwise we
won't have a consistent view in memory of the header on-disk (as the adb
header that will have been written to disk won't be the same as the one
in memory).
We can do that, by altering the "API" audioDB constructors to take the
adb_t * argument, and setting the adb field in the audioDB object that
we've already introduced to that. But now we need to be careful a
couple of times: if we have one, then audioDB::initTables() mustn't
stomp on it; also, if we're only constructing an audioDB instance to
fulfil an API request, we mustn't audiodb_close() the one we have when
we destroy the audioDB object, because the adb_t * is the one we have
passed in and are going to reuse in later calls to the API.
The good news is that we can be careful in just these ways with minimal
code. The really good news is that once the inversion is complete, all
of this horribleness will automatically go away (as there will be no
code which constructs audioDB objects to fulfil API functions). Hooray!
It's almost like it was all planned this way.
author | mas01cr |
---|---|
date | Tue, 25 Nov 2008 16:41:01 +0000 |
parents | 4ded52b104e6 |
children | e18843dc0aea |
line wrap: on
line source
#include "audioDB.h" void audioDB::liszt(const char* dbName, unsigned offset, unsigned numLines, adb__lisztResponse* adbLisztResponse){ if(!dbH) { initTables(dbName, 0); } assert(trackTable && fileTable); if(offset>dbH->numFiles){ char tmpStr[MAXSTR]; sprintf(tmpStr, "numFiles=%u, lisztOffset=%u", dbH->numFiles, offset); error("listKeys offset out of range", tmpStr); } if(!adbLisztResponse){ for(Uns32T k=0; k<numLines && offset+k<dbH->numFiles; k++){ fprintf(stdout, "[%d] %s (%d)\n", offset+k, fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE, trackTable[offset+k]); } } else{ adbLisztResponse->result.Rkey = new char*[numLines]; adbLisztResponse->result.Rlen = new unsigned int[numLines]; Uns32T k = 0; for( ; k<numLines && offset+k<dbH->numFiles; k++){ adbLisztResponse->result.Rkey[k] = new char[MAXSTR]; snprintf(adbLisztResponse->result.Rkey[k], O2_MAXFILESTR, "%s", fileTable+(offset+k)*O2_FILETABLE_ENTRY_SIZE); adbLisztResponse->result.Rlen[k] = trackTable[offset+k]; } adbLisztResponse->result.__sizeRkey = k; adbLisztResponse->result.__sizeRlen = k; } }