diff audioDB.cpp @ 167:100b7ba08df3 audiodb-debian

Merge trunk changes -r156:196 to audiodb-debian branch. (+ new debian/changelog version)
author mas01cr
date Tue, 06 Nov 2007 17:16:32 +0000
parents 5bac833c41b5
children 6da72f0e086b
line wrap: on
line diff
--- a/audioDB.cpp	Tue Oct 23 19:57:06 2007 +0000
+++ b/audioDB.cpp	Tue Nov 06 17:16:32 2007 +0000
@@ -42,7 +42,7 @@
     printf("%s\n", gengetopt_args_info_help[1]);
     printf("%s\n", gengetopt_args_info_help[2]);
     printf("%s\n", gengetopt_args_info_help[0]);
-    exit(1);
+    error("No command found");
   }
 
   if(O2_ACTION(COM_SERVER))
@@ -82,8 +82,8 @@
 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
+    isServer = 1; // FIXME: Hack
     processArgs(argc, argv);
-    isServer = 1; // FIXME: Hack
     assert(O2_ACTION(COM_QUERY));
     query(dbName, inFile, adbQueryResponse);
   } catch(char *err) {
@@ -95,8 +95,8 @@
 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResponse *adbStatusResponse): O2_AUDIODB_INITIALIZERS
 {
   try {
+    isServer = 1; // FIXME: Hack
     processArgs(argc, argv);
-    isServer = 1; // FIXME: Hack
     assert(O2_ACTION(COM_STATUS));
     status(dbName, adbStatusResponse);
   } catch(char *err) {
@@ -137,7 +137,7 @@
   }
 
   if (cmdline_parser (argc, argv, &args_info) != 0)
-    exit(1) ;       
+    error("Error parsing command line");
 
   if(args_info.help_given){
     cmdline_parser_print_help();
@@ -153,7 +153,7 @@
   }
 
   if(args_info.size_given) {
-    if (args_info.size_arg < 250 || args_info.size_arg > 4000) {
+    if (args_info.size_arg < 50 || args_info.size_arg > 4000) {
       error("Size out of range", "");
     }
     size = args_info.size_arg * 1000000;
@@ -175,7 +175,7 @@
     port=args_info.SERVER_arg;
     if(port<100 || port > 100000)
       error("port out of range");
-    isServer=1;
+    isServer = 1;
 #if defined(O2_DEBUG)
     struct sigaction sa;
     sa.sa_sigaction = sigterm_action;
@@ -398,6 +398,8 @@
   dbH = new dbTableHeaderT();
   assert(dbH);
 
+  unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE);
+
   // Initialize header
   dbH->magic = O2_MAGIC;
   dbH->version = O2_FORMAT_VERSION;
@@ -406,10 +408,10 @@
   dbH->flags = 0;
   dbH->length = 0;
   dbH->fileTableOffset = ALIGN_UP(O2_HEADERSIZE, 8);
-  dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*O2_MAXFILES, 8);
-  dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8);
-  dbH->l2normTableOffset = ALIGN_DOWN(size - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
-  dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*maxfiles, 8);
+  dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles, 8);
+  dbH->l2normTableOffset = ALIGN_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8);
   dbH->dbSize = size;
 
   memcpy (db, dbH, O2_HEADERSIZE);
@@ -2627,13 +2629,13 @@
     COM_QUERY, 
     queryType, // Need to pass a parameter
     COM_DATABASE,
-    dbName, 
+    ENSURE_STRING(dbName),
     COM_FEATURES,
-    qKey, 
+    ENSURE_STRING(qKey),
     COM_KEYLIST,
-    keyList==0?"":keyList,
+    ENSURE_STRING(keyList),
     COM_TIMES,
-    timesFileName==0?"":timesFileName,
+    ENSURE_STRING(timesFileName),
     COM_QPOINT, 
     qPosStr,
     COM_POINTNN,