diff audioDB.cpp @ 548:e18843dc0aea

Implement a rudimentary API for audioDB::liszt The API is rudimentary because we've dropped support for the incremental retrieval of tracks and their number of vectors (at the API level; the SOAP and command-line support is still there -- no changes should be visible). This is potentially bad for the large-scale databases, of course; one million tracks will take of the order of 16MB of RAM, more if I'm unlucky about how std::string.c_str() is implemented. Both this liszt operation and querying (and sampling, forthcoming...) would benefit from a `cursor-like' interface to retrieval results: for an API like that, instead of getting a struct with the data there, you get a cookie with which you can ask the database for successive results. This would be neat for all sorts of reasons. In the meantime, at least this change fixes SOAP memory leaks related to liszt. Make liszt.o part of LIBOBJS rather than ordinary OBJS, so that the liszt functionality is actually compiled into the library. Add a test for this library functionality; also modify the command-line test file to run the SOAP server on its own port.
author mas01cr
date Wed, 11 Feb 2009 12:38:03 +0000
parents 5da228727a2d
children 048688d47697
line wrap: on
line diff
--- a/audioDB.cpp	Wed Feb 11 10:42:23 2009 +0000
+++ b/audioDB.cpp	Wed Feb 11 12:38:03 2009 +0000
@@ -111,7 +111,7 @@
   }
 }
 
-audioDB::audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse): O2_AUDIODB_INITIALIZERS
+audioDB::audioDB(const unsigned argc, const char *argv[], struct soap *soap, adb__lisztResponse *adbLisztResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
     isServer = 1; // Set to make errors report over SOAP
@@ -120,7 +120,7 @@
     if(dbName && adb_root)
       prefix_name((char** const)&dbName, adb_root);
     assert(O2_ACTION(COM_LISZT));
-    liszt(dbName, lisztOffset, lisztLength, adbLisztResponse);
+    liszt(dbName, lisztOffset, lisztLength, soap, adbLisztResponse);
   } catch(char *err) {
     cleanup();
     throw(err);
@@ -950,6 +950,44 @@
   reporter->report(adb, soap, adbQueryResponse);
 }
 
+void audioDB::liszt(const char* dbName, unsigned offset, unsigned numLines, struct soap *soap, adb__lisztResponse* adbLisztResponse) {
+  if(!adb) {
+    if(!(adb = audiodb_open(dbName, O_RDONLY))) {
+      error("failed to open database", dbName);
+    }
+  }
+
+  adb_liszt_results_t *results = audiodb_liszt(adb);
+  if(!results) {
+    error("audiodb_liszt() failed");
+  }
+
+  if(offset > results->nresults) {
+    audiodb_liszt_free_results(adb, results);
+    error("listKeys offset out of range");
+  }
+
+  if(!adbLisztResponse){
+    for(uint32_t k = 0; k < numLines && offset + k < results->nresults; k++) {
+      uint32_t index = offset + k;
+      printf("[%d] %s (%d)\n", index, results->entries[index].key, results->entries[index].nvectors);
+    }
+  } else {
+    adbLisztResponse->result.Rkey = (char **) soap_malloc(soap, numLines * sizeof(char *));
+    adbLisztResponse->result.Rlen = (unsigned int *) soap_malloc(soap, numLines * sizeof(unsigned int));
+    uint32_t k;
+    for(k = 0; k < numLines && offset + k < results->nresults; k++) {
+      uint32_t index = offset + k;
+      adbLisztResponse->result.Rkey[k] = (char *) soap_malloc(soap, O2_MAXFILESTR);
+      snprintf(adbLisztResponse->result.Rkey[k], O2_MAXFILESTR, "%s", results->entries[index].key);
+      adbLisztResponse->result.Rlen[k] = results->entries[index].nvectors;
+    }
+    adbLisztResponse->result.__sizeRkey = k;
+    adbLisztResponse->result.__sizeRlen = k;
+  }
+  audiodb_liszt_free_results(adb, results);  
+}
+
 // This entry point is visited once per instance
 // so it is a good place to set any global state variables
 int main(const int argc, const char* argv[]){