Mercurial > hg > audiodb
comparison soap.cpp @ 239:2cc06e5b05a5
Merge refactoring branch.
Bug fixes:
* 64-bit powertable bug;
* -inf - -inf bug;
* use new times information;
* plus short track, O2_MAXFILES and structure padding ABI fixes (already
backported)
Major code changes:
* split source into functional units, known as 'files';
* Reporter class for accumulating and reporting on query results;
* much OAOOization, mostly from above: net 800 LOC (25%) shorter.
author | mas01cr |
---|---|
date | Thu, 13 Dec 2007 14:23:32 +0000 |
parents | |
children | d1b8b2dec37e |
comparison
equal
deleted
inserted
replaced
224:3a81da6fb1d7 | 239:2cc06e5b05a5 |
---|---|
1 #include "audioDB.h" | |
2 #include "adb.nsmap" | |
3 | |
4 /* Command-line client definitions */ | |
5 | |
6 // FIXME: this can't propagate the sequence length argument (used for | |
7 // dudCount). See adb__status() definition for the other half of | |
8 // this. -- CSR, 2007-10-01 | |
9 void audioDB::ws_status(const char*dbName, char* hostport){ | |
10 struct soap soap; | |
11 adb__statusResponse adbStatusResponse; | |
12 | |
13 // Query an existing adb database | |
14 soap_init(&soap); | |
15 if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResponse)==SOAP_OK) { | |
16 std::cout << "numFiles = " << adbStatusResponse.result.numFiles << std::endl; | |
17 std::cout << "dim = " << adbStatusResponse.result.dim << std::endl; | |
18 std::cout << "length = " << adbStatusResponse.result.length << std::endl; | |
19 std::cout << "dudCount = " << adbStatusResponse.result.dudCount << std::endl; | |
20 std::cout << "nullCount = " << adbStatusResponse.result.nullCount << std::endl; | |
21 std::cout << "flags = " << adbStatusResponse.result.flags << std::endl; | |
22 } else { | |
23 soap_print_fault(&soap,stderr); | |
24 } | |
25 | |
26 soap_destroy(&soap); | |
27 soap_end(&soap); | |
28 soap_done(&soap); | |
29 } | |
30 | |
31 void audioDB::ws_query(const char*dbName, const char *trackKey, const char* hostport){ | |
32 struct soap soap; | |
33 adb__queryResponse adbQueryResponse; | |
34 | |
35 soap_init(&soap); | |
36 if(soap_call_adb__query(&soap,hostport,NULL, | |
37 (char*)dbName,(char*)trackKey,(char*)trackFileName,(char*)timesFileName, | |
38 queryType, queryPoint, pointNN, trackNN, sequenceLength, adbQueryResponse)==SOAP_OK){ | |
39 //std::std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::std::endl; | |
40 for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++) | |
41 std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i] | |
42 << " " << adbQueryResponse.result.Qpos[i] << " " << adbQueryResponse.result.Spos[i] << std::endl; | |
43 } | |
44 else | |
45 soap_print_fault(&soap,stderr); | |
46 | |
47 soap_destroy(&soap); | |
48 soap_end(&soap); | |
49 soap_done(&soap); | |
50 } | |
51 | |
52 /* Server definitions */ | |
53 int adb__status(struct soap* soap, xsd__string dbName, adb__statusResponse &adbStatusResponse){ | |
54 char* const argv[]={"audioDB",COM_STATUS,"-d",dbName}; | |
55 const unsigned argc = 4; | |
56 try { | |
57 audioDB(argc, argv, &adbStatusResponse); | |
58 return SOAP_OK; | |
59 } catch(char *err) { | |
60 soap_receiver_fault(soap, err, ""); | |
61 return SOAP_FAULT; | |
62 } | |
63 } | |
64 | |
65 // Literal translation of command line to web service | |
66 | |
67 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){ | |
68 char queryType[256]; | |
69 for(int k=0; k<256; k++) | |
70 queryType[k]='\0'; | |
71 if(qType == O2_POINT_QUERY) | |
72 strncpy(queryType, "point", strlen("point")); | |
73 else if (qType == O2_SEQUENCE_QUERY) | |
74 strncpy(queryType, "sequence", strlen("sequence")); | |
75 else if(qType == O2_TRACK_QUERY) | |
76 strncpy(queryType,"track", strlen("track")); | |
77 else | |
78 strncpy(queryType, "", strlen("")); | |
79 | |
80 if(pointNN==0) | |
81 pointNN=10; | |
82 if(trackNN==0) | |
83 trackNN=10; | |
84 if(seqLen==0) | |
85 seqLen=16; | |
86 | |
87 char qPosStr[256]; | |
88 sprintf(qPosStr, "%d", qPos); | |
89 char pointNNStr[256]; | |
90 sprintf(pointNNStr,"%d",pointNN); | |
91 char trackNNStr[256]; | |
92 sprintf(trackNNStr,"%d",trackNN); | |
93 char seqLenStr[256]; | |
94 sprintf(seqLenStr,"%d",seqLen); | |
95 | |
96 const char* argv[] ={ | |
97 "./audioDB", | |
98 COM_QUERY, | |
99 queryType, // Need to pass a parameter | |
100 COM_DATABASE, | |
101 ENSURE_STRING(dbName), | |
102 COM_FEATURES, | |
103 ENSURE_STRING(qKey), | |
104 COM_KEYLIST, | |
105 ENSURE_STRING(keyList), | |
106 COM_TIMES, | |
107 ENSURE_STRING(timesFileName), | |
108 COM_QPOINT, | |
109 qPosStr, | |
110 COM_POINTNN, | |
111 pointNNStr, | |
112 COM_TRACKNN, | |
113 trackNNStr, // Need to pass a parameter | |
114 COM_SEQLEN, | |
115 seqLenStr | |
116 }; | |
117 | |
118 const unsigned argc = 19; | |
119 try { | |
120 audioDB(argc, (char* const*)argv, &adbQueryResponse); | |
121 return SOAP_OK; | |
122 } catch (char *err) { | |
123 soap_receiver_fault(soap, err, ""); | |
124 return SOAP_FAULT; | |
125 } | |
126 } | |
127 | |
128 int adb__sequenceQuery(struct soap* soap, xsd__string dbName, xsd__string qKey, | |
129 adb__sequenceQueryParms *parms, | |
130 adb__queryResponse &adbQueryResponse) { | |
131 | |
132 char qPosStr[256]; | |
133 char pointNNStr[256]; | |
134 char trackNNStr[256]; | |
135 char seqLenStr[256]; | |
136 char relative_thresholdStr[256]; | |
137 char absolute_thresholdStr[256]; | |
138 | |
139 /* When the branch is merged, move this to a header and use it | |
140 elsewhere */ | |
141 #define INTSTRINGIFY(val, str) \ | |
142 snprintf(str, 256, "%d", val); | |
143 #define DOUBLESTRINGIFY(val, str) \ | |
144 snprintf(str, 256, "%f", val); | |
145 | |
146 INTSTRINGIFY(parms->qPos, qPosStr); | |
147 INTSTRINGIFY(parms->pointNN, pointNNStr); | |
148 INTSTRINGIFY(parms->segNN, trackNNStr); | |
149 /* FIXME: decide which of segLen and seqLen should live */ | |
150 INTSTRINGIFY(parms->segLen, seqLenStr); | |
151 | |
152 DOUBLESTRINGIFY(parms->relative_threshold, relative_thresholdStr); | |
153 DOUBLESTRINGIFY(parms->absolute_threshold, absolute_thresholdStr); | |
154 | |
155 const char *argv[] = { | |
156 "./audioDB", | |
157 COM_QUERY, | |
158 "sequence", | |
159 COM_DATABASE, | |
160 dbName, | |
161 COM_FEATURES, | |
162 qKey, | |
163 COM_KEYLIST, | |
164 /* FIXME: when this branch is merged, use ENSURE_STRING */ | |
165 parms->keyList==0?"":parms->keyList, | |
166 COM_TIMES, | |
167 parms->timesFileName==0?"":parms->timesFileName, | |
168 COM_QUERYPOWER, | |
169 parms->powerFileName==0?"":parms->powerFileName, | |
170 COM_QPOINT, | |
171 qPosStr, | |
172 COM_POINTNN, | |
173 pointNNStr, | |
174 COM_TRACKNN, | |
175 trackNNStr, | |
176 COM_SEQLEN, | |
177 seqLenStr, | |
178 COM_RELATIVE_THRESH, | |
179 relative_thresholdStr, | |
180 COM_ABSOLUTE_THRESH, | |
181 absolute_thresholdStr | |
182 }; | |
183 | |
184 const unsigned argc = 25; | |
185 | |
186 try { | |
187 audioDB(argc, (char* const*)argv, &adbQueryResponse); | |
188 return SOAP_OK; | |
189 } catch (char *err) { | |
190 soap_receiver_fault(soap, err, ""); | |
191 return SOAP_FAULT; | |
192 } | |
193 } | |
194 | |
195 /* Server loop */ | |
196 void audioDB::startServer(){ | |
197 struct soap soap; | |
198 int m, s; // master and slave sockets | |
199 soap_init(&soap); | |
200 // FIXME: largely this use of SO_REUSEADDR is to make writing (and | |
201 // running) test cases more convenient, so that multiple test runs | |
202 // in close succession don't fail because of a bin() error. | |
203 // Investigate whether there are any potential drawbacks in this, | |
204 // and also whether there's a better way to write the tests. -- | |
205 // CSR, 2007-10-03 | |
206 soap.bind_flags |= SO_REUSEADDR; | |
207 m = soap_bind(&soap, NULL, port, 100); | |
208 if (m < 0) | |
209 soap_print_fault(&soap, stderr); | |
210 else | |
211 { | |
212 fprintf(stderr, "Socket connection successful: master socket = %d\n", m); | |
213 for (int i = 1; ; i++) | |
214 { | |
215 s = soap_accept(&soap); | |
216 if (s < 0) | |
217 { | |
218 soap_print_fault(&soap, stderr); | |
219 break; | |
220 } | |
221 /* FIXME: find a way to play nice with logging when run from | |
222 /etc/init.d scripts: at present this just goes nowhere */ | |
223 fprintf(stderr, "%d: accepted connection from IP=%lu.%lu.%lu.%lu socket=%d\n", i, | |
224 (soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF, s); | |
225 if (soap_serve(&soap) != SOAP_OK) // process RPC request | |
226 soap_print_fault(&soap, stderr); // print error | |
227 fprintf(stderr, "request served\n"); | |
228 soap_destroy(&soap); // clean up class instances | |
229 soap_end(&soap); // clean up everything and close socket | |
230 } | |
231 } | |
232 soap_done(&soap); // close master socket and detach environment | |
233 } |