changeset 350:8ff9d4d83222 serializedQuery

serialized shingle query added to WS, compiles but not tested
author mas01mc
date Thu, 06 Nov 2008 08:54:40 +0000
parents d1afecc71781
children af3bc78e0f77
files audioDBws.h soap.cpp
diffstat 2 files changed, 81 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/audioDBws.h	Mon Oct 27 11:09:34 2008 +0000
+++ b/audioDBws.h	Thu Nov 06 08:54:40 2008 +0000
@@ -48,8 +48,9 @@
 };
 
 struct adb__queryVector {
-  int __sizeQvector;
-  double *Qvector;
+  int __sizeQvector; // l x d :
+  double *Qvector;   // pointer to query data
+  int dim; // dimensionality of the feature (d)
 };
 
 struct adb__lisztResponse {
--- a/soap.cpp	Mon Oct 27 11:09:34 2008 +0000
+++ b/soap.cpp	Thu Nov 06 08:54:40 2008 +0000
@@ -360,11 +360,87 @@
 
 // Query an audioDB database by vector (serialized)
 int adb__shingleQuery(struct soap* soap, xsd__string dbName, struct adb__queryVector qVector, xsd__int queryType,xsd__int pointNN,xsd__int trackNN,xsd__int sequenceLength,xsd__double radius,xsd__double absolute_threshold,xsd__int lsh_exact,struct adb__queryResponse &adbQueryResponse){
-  cout << "qvector[" << qVector.__sizeQvector << "]: ";
+
+  cout << "qvector[" << qVector.dim << " x " << qVector.__sizeQvector/qVector.dim << "]: ";
   for(int k=0; k < qVector.__sizeQvector ; k++)
     cout << qVector.Qvector[k] << " ";
   cout.flush();
-  return SOAP_OK;
+
+  // open a tmp file on the server, write shingle, query as a file with query point 0
+  // and shingle length l/dim
+  char tmpFileName[] = "adbXXXXXX";
+  int fid = mkstemp(tmpFileName);
+  if(fid==-1){
+    cerr << "Cannot open tmpfile on server";
+    return SOAP_FAULT;
+  }
+  
+  FILE* tmpFile = fdopen(fid, "r+b");
+
+  if(fwrite(&qVector.dim, 1, sizeof(int), tmpFile)!=1){
+    cerr << "error writing tmp file dim";
+    return SOAP_FAULT;
+  }
+
+  if(fwrite(qVector.Qvector, qVector.__sizeQvector,sizeof(double), tmpFile)!=(size_t)qVector.__sizeQvector){
+    cerr << "error writing tmp file doubles";
+    return SOAP_FAULT;
+  }
+    
+  // Call adb query with tmpQueryFile name as a the query file parameter
+  char qtypeStr[256];
+
+  fprintf(stderr, "Calling %s query on database %s with %s=%s\n", "FILENAME", dbName, "FILENAME",tmpFileName);
+
+  // fix up sequenceLength if it isn't provided, we know what the caller wants by the size of the shingle
+  // and the feature dimensionality
+  if(!sequenceLength)
+    sequenceLength = qVector.__sizeQvector/qVector.dim;
+
+  INTSTRINGIFY(0, qPosStr); // query position is 0
+  INTSTRINGIFY(pointNN, pointNNStr);
+  INTSTRINGIFY(trackNN, trackNNStr);
+  INTSTRINGIFY(sequenceLength, seqLenStr);
+  DOUBLESTRINGIFY(absolute_threshold, absolute_thresholdStr);
+  DOUBLESTRINGIFY(radius, radiusStr);
+
+  snprintf(qtypeStr, 256, "nsequence");
+  const char *argv[]={
+    "./audioDB",
+    COM_QUERY,
+    qtypeStr,
+    COM_DATABASE,
+    dbName, 
+    COM_FEATURES,
+    ENSURE_STRING(tmpFileName),
+    COM_KEYLIST,
+    ENSURE_STRING(""),
+    COM_QPOINT,
+    qPosStr,
+    COM_POINTNN,
+    pointNNStr,
+    COM_TRACKNN,
+    trackNNStr,
+    COM_RADIUS,
+    radiusStr,
+    COM_SEQLEN,
+    seqLenStr,
+    COM_ABSOLUTE_THRESH,
+    absolute_thresholdStr,
+    lsh_exact?COM_LSH_EXACT:""
+  };
+
+  const unsigned argc = 22;
+ 
+  try {
+    audioDB(argc, (char* const*)argv, &adbQueryResponse);
+    fclose(tmpFile);
+    return SOAP_OK;
+  } catch (char *err) {
+    soap_receiver_fault(soap, err, "");
+    fclose(tmpFile);
+    return SOAP_FAULT;
+  }  
 }
 
 /* Server loop */