Mercurial > hg > audiodb
comparison soap.cpp @ 333:cc3f9d1ca2cd
Ugly hack upon ugly hack:
* extend adb__query() to take a bunch of other arguments that allow
useful functionality through to the SOAP server;
* alter the RadiusQuery reporter so that the count for tracks is
returned through SOAP, punning one of the result fields for the
purpose;
* alter argv construction to be more dynamic, to reflect that the very
presence of some arguments changes audioDB behaviour.
Now test 0020 passes, only some 12 months after it was originally
written, yay. Alter test 0050 also, so that the results are actually
vaguely what would be expected from a radius search; they are not
completely checked for correctness, but are (apart from the last two)
the same as test 0040.
I believe that the modifications are backward compatible; lightly
testing with an old audioDB binary suggests that old-format SOAP queries
continue to work. Currently too baby-encumbered to think of how to test
this fully.
author | mas01cr |
---|---|
date | Mon, 01 Sep 2008 15:35:05 +0000 |
parents | 0c908093082f |
children | 100cf66a5825 |
comparison
equal
deleted
inserted
replaced
332:a0493f861531 | 333:cc3f9d1ca2cd |
---|---|
31 // WS_QUERY (CLIENT SIDE) | 31 // WS_QUERY (CLIENT SIDE) |
32 void audioDB::ws_query(const char*dbName, const char *featureFileName, const char* hostport){ | 32 void audioDB::ws_query(const char*dbName, const char *featureFileName, const char* hostport){ |
33 struct soap soap; | 33 struct soap soap; |
34 adb__queryResponse adbQueryResponse; | 34 adb__queryResponse adbQueryResponse; |
35 VERB_LOG(1, "Calling fileName query on database %s with featureFile=%s\n", dbName, featureFileName); | 35 VERB_LOG(1, "Calling fileName query on database %s with featureFile=%s\n", dbName, featureFileName); |
36 soap_init(&soap); | 36 soap_init(&soap); |
37 if(soap_call_adb__query(&soap,hostport,NULL, | 37 if(soap_call_adb__query(&soap, hostport, NULL, (char *) dbName, |
38 (char*)dbName,(char*)featureFileName,(char*)trackFileName,(char*)timesFileName, | 38 (char *)featureFileName, (char *)trackFileName, |
39 queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResponse)==SOAP_OK){ | 39 (char *)timesFileName, (char *) powerFileName, |
40 //std::std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::std::endl; | 40 queryType, queryPoint, |
41 for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++) | 41 pointNN, trackNN, sequenceLength, |
42 std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i] | 42 radius, absolute_threshold, relative_threshold, |
43 << " " << adbQueryResponse.result.Qpos[i] << " " << adbQueryResponse.result.Spos[i] << std::endl; | 43 !usingQueryPoint, lsh_exact, |
44 } | 44 adbQueryResponse) |
45 else | 45 == SOAP_OK) { |
46 if(radius == 0) { | |
47 for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++) { | |
48 std::cout << adbQueryResponse.result.Rlist[i] << " " | |
49 << adbQueryResponse.result.Dist[i] << " " | |
50 << adbQueryResponse.result.Qpos[i] << " " | |
51 << adbQueryResponse.result.Spos[i] << std::endl; | |
52 } | |
53 } else { | |
54 for(int i = 0; i < adbQueryResponse.result.__sizeRlist; i++) { | |
55 std::cout << adbQueryResponse.result.Rlist[i] << " " | |
56 << adbQueryResponse.result.Spos[i] << std::endl; | |
57 } | |
58 } | |
59 } else { | |
46 soap_print_fault(&soap,stderr); | 60 soap_print_fault(&soap,stderr); |
47 | 61 } |
62 | |
48 soap_destroy(&soap); | 63 soap_destroy(&soap); |
49 soap_end(&soap); | 64 soap_end(&soap); |
50 soap_done(&soap); | 65 soap_done(&soap); |
51 } | 66 } |
52 | 67 |
101 soap_end(&soap); | 116 soap_end(&soap); |
102 soap_done(&soap); | 117 soap_done(&soap); |
103 } | 118 } |
104 | 119 |
105 | 120 |
121 /* handy macros */ | |
122 #define INTSTRINGIFY(val, str) \ | |
123 char str[256]; \ | |
124 snprintf(str, 256, "%d", val); | |
125 #define DOUBLESTRINGIFY(val, str) \ | |
126 char str[256]; \ | |
127 snprintf(str, 256, "%f", val); | |
128 | |
106 /* Server definitions */ | 129 /* Server definitions */ |
107 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){ | 130 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){ |
108 char* const argv[]={"./audioDB",COM_STATUS,"-d",dbName}; | 131 char* const argv[]={"./audioDB",COM_STATUS,"-d",dbName}; |
109 const unsigned argc = 4; | 132 const unsigned argc = 4; |
110 try { | 133 try { |
115 return SOAP_FAULT; | 138 return SOAP_FAULT; |
116 } | 139 } |
117 } | 140 } |
118 | 141 |
119 // Literal translation of command line to web service | 142 // Literal translation of command line to web service |
120 int adb__query(struct soap* soap, xsd__string dbName, xsd__string qKey, xsd__string keyList, xsd__string timesFileName, xsd__int qType, xsd__int qPos, xsd__int pointNN, xsd__int trackNN, xsd__int seqLen, adb__queryResponse &adbQueryResponse){ | 143 int adb__query(struct soap* soap, xsd__string dbName, |
144 xsd__string qKey, xsd__string keyList, | |
145 xsd__string timesFileName, xsd__string powerFileName, | |
146 xsd__int qType, | |
147 xsd__int qPos, xsd__int pointNN, xsd__int trackNN, | |
148 xsd__int seqLen, | |
149 xsd__double radius, | |
150 xsd__double absolute_threshold, xsd__double relative_threshold, | |
151 xsd__int exhaustive, xsd__int lsh_exact, | |
152 adb__queryResponse &adbQueryResponse){ | |
121 char queryType[256]; | 153 char queryType[256]; |
122 | 154 |
123 fprintf(stderr,"Calling fileName query on database %s with featureFile=%s\n", dbName, qKey); | 155 fprintf(stderr,"Calling fileName query on database %s with featureFile=%s\n", dbName, qKey); |
124 | 156 |
125 for(int k=0; k<256; k++) | 157 for(int k=0; k<256; k++) |
138 if(trackNN==0) | 170 if(trackNN==0) |
139 trackNN=10; | 171 trackNN=10; |
140 if(seqLen==0) | 172 if(seqLen==0) |
141 seqLen=16; | 173 seqLen=16; |
142 | 174 |
143 char qPosStr[256]; | 175 INTSTRINGIFY(qPos, qPosStr); |
144 sprintf(qPosStr, "%d", qPos); | 176 INTSTRINGIFY(pointNN, pointNNStr); |
145 char pointNNStr[256]; | 177 INTSTRINGIFY(trackNN, trackNNStr); |
146 sprintf(pointNNStr,"%d",pointNN); | 178 INTSTRINGIFY(seqLen, seqLenStr); |
147 char trackNNStr[256]; | 179 |
148 sprintf(trackNNStr,"%d",trackNN); | 180 /* We don't necessarily use these, but because of scope we do this |
149 char seqLenStr[256]; | 181 anyway. We waste 756 bytes of stack this way. */ |
150 sprintf(seqLenStr,"%d",seqLen); | 182 DOUBLESTRINGIFY(radius, radiusStr); |
151 | 183 DOUBLESTRINGIFY(absolute_threshold, absolute_thresholdStr); |
152 const char* argv[] ={ | 184 DOUBLESTRINGIFY(relative_threshold, relative_thresholdStr); |
153 "./audioDB", | 185 |
154 COM_QUERY, | 186 unsigned int argc = 19; |
155 queryType, // Need to pass a parameter | 187 if (powerFileName) { |
156 COM_DATABASE, | 188 argc += 2; |
157 ENSURE_STRING(dbName), | 189 } |
158 COM_FEATURES, | 190 if (radius != 0) { |
159 ENSURE_STRING(qKey), | 191 argc += 2; |
160 COM_KEYLIST, | 192 } |
161 ENSURE_STRING(keyList), | 193 /* we can't use use_absolute_threshold and friends because we're not |
162 COM_TIMES, | 194 in the audioDB class here. */ |
163 ENSURE_STRING(timesFileName), | 195 if (absolute_threshold != 0) { |
164 COM_QPOINT, | 196 argc += 2; |
165 qPosStr, | 197 } |
166 COM_POINTNN, | 198 if (relative_threshold != 0) { |
167 pointNNStr, | 199 argc += 2; |
168 COM_TRACKNN, | 200 } |
169 trackNNStr, // Need to pass a parameter | 201 if (exhaustive) { |
170 COM_SEQLEN, | 202 argc++; |
171 seqLenStr | 203 } |
172 }; | 204 if (lsh_exact) { |
173 | 205 argc++; |
174 const unsigned argc = 19; | 206 } |
207 | |
208 char **argv = new char*[argc+1]; | |
209 argv[0] = "./audioDB"; | |
210 argv[1] = COM_QUERY; | |
211 argv[2] = queryType; | |
212 argv[3] = COM_DATABASE; | |
213 argv[4] = (char *) (ENSURE_STRING(dbName)); | |
214 argv[5] = COM_FEATURES; | |
215 argv[6] = (char *) (ENSURE_STRING(qKey)); | |
216 argv[7] = COM_KEYLIST; | |
217 argv[8] = (char *) (ENSURE_STRING(keyList)); | |
218 argv[9] = COM_TIMES; | |
219 argv[10] = (char *) (ENSURE_STRING(timesFileName)); | |
220 argv[11] = COM_QPOINT; | |
221 argv[12] = qPosStr; | |
222 argv[13] = COM_POINTNN; | |
223 argv[14] = pointNNStr; | |
224 argv[15] = COM_TRACKNN; | |
225 argv[16] = trackNNStr; | |
226 argv[17] = COM_SEQLEN; | |
227 argv[18] = seqLenStr; | |
228 int argv_counter = 19; | |
229 if (powerFileName) { | |
230 argv[argv_counter++] = COM_QUERYPOWER; | |
231 argv[argv_counter++] = powerFileName; | |
232 } | |
233 if (radius != 0) { | |
234 argv[argv_counter++] = COM_RADIUS; | |
235 argv[argv_counter++] = radiusStr; | |
236 } | |
237 if (absolute_threshold != 0) { | |
238 argv[argv_counter++] = COM_ABSOLUTE_THRESH; | |
239 argv[argv_counter++] = absolute_thresholdStr; | |
240 } | |
241 if (relative_threshold != 0) { | |
242 argv[argv_counter++] = COM_RELATIVE_THRESH; | |
243 argv[argv_counter++] = relative_thresholdStr; | |
244 } | |
245 if (exhaustive) { | |
246 argv[argv_counter++] = COM_EXHAUSTIVE; | |
247 } | |
248 if (lsh_exact) { | |
249 argv[argv_counter++] = COM_LSH_EXACT; | |
250 } | |
251 argv[argv_counter] = NULL; | |
252 | |
253 | |
175 try { | 254 try { |
176 audioDB(argc, (char* const*)argv, &adbQueryResponse); | 255 audioDB(argc, (char* const*)argv, &adbQueryResponse); |
256 delete [] argv; | |
177 return SOAP_OK; | 257 return SOAP_OK; |
178 } catch (char *err) { | 258 } catch (char *err) { |
179 soap_receiver_fault(soap, err, ""); | 259 soap_receiver_fault(soap, err, ""); |
260 delete [] argv; | |
180 return SOAP_FAULT; | 261 return SOAP_FAULT; |
181 } | 262 } |
182 } | 263 } |
183 | 264 |
184 int adb__sequenceQueryByKey(struct soap* soap,xsd__string dbName, | 265 int adb__sequenceQueryByKey(struct soap* soap,xsd__string dbName, |
194 xsd__double radius, | 275 xsd__double radius, |
195 xsd__double absolute_threshold, | 276 xsd__double absolute_threshold, |
196 xsd__int usingQueryPoint, | 277 xsd__int usingQueryPoint, |
197 xsd__int lsh_exact, | 278 xsd__int lsh_exact, |
198 struct adb__queryResponse& adbQueryResponse){ | 279 struct adb__queryResponse& adbQueryResponse){ |
199 char radiusStr[256]; | |
200 char qPosStr[256]; | |
201 char pointNNStr[256]; | |
202 char trackNNStr[256]; | |
203 char seqLenStr[256]; | |
204 char absolute_thresholdStr[256]; | |
205 char qtypeStr[256]; | 280 char qtypeStr[256]; |
206 | 281 |
207 fprintf(stderr, "Calling %s query on database %s with %s=%s\n", (trackKey&&strlen(trackKey))?"KEY":"FILENAME", dbName, (trackKey&&strlen(trackKey))?"KEY":"FILENAME",(trackKey&&strlen(trackKey))?trackKey:featureFileName); | 282 fprintf(stderr, "Calling %s query on database %s with %s=%s\n", (trackKey&&strlen(trackKey))?"KEY":"FILENAME", dbName, (trackKey&&strlen(trackKey))?"KEY":"FILENAME",(trackKey&&strlen(trackKey))?trackKey:featureFileName); |
208 | |
209 /* When the branch is merged, move this to a header and use it | |
210 elsewhere */ | |
211 #define INTSTRINGIFY(val, str) \ | |
212 snprintf(str, 256, "%d", val); | |
213 #define DOUBLESTRINGIFY(val, str) \ | |
214 snprintf(str, 256, "%f", val); | |
215 | 283 |
216 INTSTRINGIFY(queryPoint, qPosStr); | 284 INTSTRINGIFY(queryPoint, qPosStr); |
217 INTSTRINGIFY(pointNN, pointNNStr); | 285 INTSTRINGIFY(pointNN, pointNNStr); |
218 INTSTRINGIFY(trackNN, trackNNStr); | 286 INTSTRINGIFY(trackNN, trackNNStr); |
219 INTSTRINGIFY(sequenceLength, seqLenStr); | 287 INTSTRINGIFY(sequenceLength, seqLenStr); |