Mercurial > hg > audiodb
comparison soap.cpp @ 354:4871a3ed9e36 pre_api
Added serialized feature query Web Service, server-side only, example Python script: QueryADB.py -v
| author | mas01mc |
|---|---|
| date | Fri, 07 Nov 2008 12:48:26 +0000 |
| parents | 30384a82983a |
| children | d72ff5d0292f |
comparison
equal
deleted
inserted
replaced
| 347:0d02bcd74a40 | 354:4871a3ed9e36 |
|---|---|
| 280 if (lsh_exact) { | 280 if (lsh_exact) { |
| 281 argv[argv_counter++] = COM_LSH_EXACT; | 281 argv[argv_counter++] = COM_LSH_EXACT; |
| 282 } | 282 } |
| 283 argv[argv_counter] = NULL; | 283 argv[argv_counter] = NULL; |
| 284 | 284 |
| 285 | |
| 286 try { | 285 try { |
| 287 audioDB(argc, (char* const*)argv, &adbQueryResponse); | 286 audioDB(argc, (char* const*)argv, &adbQueryResponse); |
| 288 delete [] argv; | 287 delete [] argv; |
| 289 return SOAP_OK; | 288 return SOAP_OK; |
| 290 } catch (char *err) { | 289 } catch (char *err) { |
| 357 } catch (char *err) { | 356 } catch (char *err) { |
| 358 soap_receiver_fault(soap, err, ""); | 357 soap_receiver_fault(soap, err, ""); |
| 359 return SOAP_FAULT; | 358 return SOAP_FAULT; |
| 360 } | 359 } |
| 361 } | 360 } |
| 362 | 361 |
| 362 // Query an audioDB database by vector (serialized) | |
| 363 int adb__shingleQuery(struct soap* soap, xsd__string dbName, struct adb__queryVector qVector, xsd__string keyList, xsd__string timesFileName, xsd__int queryType, xsd__int queryPos, xsd__int pointNN, xsd__int trackNN, xsd__int sequenceLength, xsd__double radius, xsd__double absolute_threshold, xsd__double relative_threshold, xsd__int exhaustive, xsd__int lsh_exact, struct adb__queryResponse &adbQueryResponse){ | |
| 364 | |
| 365 // open a tmp file on the server, write shingle, query as a file with query point 0 | |
| 366 // and shingle length l/dim | |
| 367 char tmpFileName[] = "/tmp/adb_XXXXXX"; | |
| 368 int tmpFid = mkstemp(tmpFileName); | |
| 369 if(tmpFid==-1){ | |
| 370 cerr << "Cannot make tmpfile <" << tmpFileName << "> on server" << endl; | |
| 371 return SOAP_FAULT; | |
| 372 } | |
| 373 | |
| 374 FILE* tmpFile = fdopen(tmpFid, "r+b"); | |
| 375 if(!tmpFile){ | |
| 376 cerr << "error opening <" << tmpFileName << "> for write" << endl; | |
| 377 return SOAP_FAULT; | |
| 378 } | |
| 379 | |
| 380 if(fwrite(&qVector.dim, sizeof(int), 1, tmpFile)!=1){ | |
| 381 cerr << "error writing tmp file dim <"<< tmpFileName << ">" << endl; | |
| 382 return SOAP_FAULT; | |
| 383 } | |
| 384 | |
| 385 if(fwrite(qVector.v, sizeof(double), qVector.__sizev, tmpFile)!=(size_t)qVector.__sizev){ | |
| 386 cerr << "error writing tmp file doubles <" << tmpFileName << ">" << endl; | |
| 387 return SOAP_FAULT; | |
| 388 } | |
| 389 | |
| 390 // Close the file so that a new FD can be opened | |
| 391 fclose(tmpFile); | |
| 392 | |
| 393 char tmpFileName2[] = "/tmp/adbP_XXXXXX"; | |
| 394 int tmpFid2 = 0; | |
| 395 FILE* tmpFile2 = NULL; | |
| 396 | |
| 397 // Check if powers have been passed and write accordingly | |
| 398 if(qVector.__sizep){ | |
| 399 tmpFid2 = mkstemp(tmpFileName2); | |
| 400 tmpFile2 = fdopen(tmpFid2, "r+b"); | |
| 401 if(!tmpFile2){ | |
| 402 cerr << "error opening power file <" << tmpFileName2 << "> for write" << endl; | |
| 403 return SOAP_FAULT; | |
| 404 } | |
| 405 int pSize=1; | |
| 406 if(fwrite(&pSize, sizeof(int), 1, tmpFile2)!=1){ | |
| 407 cerr << "error writing tmp power file dim <"<< tmpFileName2 << ">" << endl; | |
| 408 return SOAP_FAULT; | |
| 409 } | |
| 410 | |
| 411 if(fwrite(qVector.p, sizeof(double), qVector.__sizep, tmpFile2)!=(size_t)qVector.__sizep){ | |
| 412 cerr << "error writing tmp power file doubles <" << tmpFileName2 << ">" << endl; | |
| 413 return SOAP_FAULT; | |
| 414 } | |
| 415 fclose(tmpFile2); | |
| 416 } | |
| 417 | |
| 418 // fix up sequenceLength if it isn't provided, we know what the caller wants by the size of the shingle | |
| 419 // and the feature dimensionality | |
| 420 if(!sequenceLength) | |
| 421 sequenceLength = qVector.__sizev/qVector.dim; | |
| 422 | |
| 423 int retVal = adb__query(soap, dbName, tmpFileName, keyList, timesFileName, qVector.__sizep?tmpFileName2:0, | |
| 424 queryType, queryPos, pointNN, trackNN, sequenceLength, radius, | |
| 425 absolute_threshold, relative_threshold, exhaustive, lsh_exact, adbQueryResponse); | |
| 426 | |
| 427 return retVal; | |
| 428 } | |
| 429 | |
| 363 /* Server loop */ | 430 /* Server loop */ |
| 364 void audioDB::startServer(){ | 431 void audioDB::startServer(){ |
| 365 struct soap soap; | 432 struct soap soap; |
| 366 int m, s; // master and slave sockets | 433 int m, s; // master and slave sockets |
| 367 soap_init(&soap); | 434 soap_init(&soap); |
