Mercurial > hg > audiodb
comparison audioDB.cpp @ 508:23c47e118bc6
Better soap memory correctness.
Pass the struct soap down through audioDB::query into Reporter::report
methods.
We go through the audioDB constructor and do everything on the stack.
We'll eventually also need to add a pointer member within the audioDB
object, so that non-local transfers of control (particularly
audioDB::error) can still allocate soap-specific memory.
Then use soap_malloc() not new[] for memory allocation of
adbQueryResponse data structures.
author | mas01cr |
---|---|
date | Tue, 13 Jan 2009 21:37:14 +0000 |
parents | e7fd50483311 |
children | cc2b97d020b1 |
comparison
equal
deleted
inserted
replaced
507:e7fd50483311 | 508:23c47e118bc6 |
---|---|
81 | 81 |
82 else | 82 else |
83 error("Unrecognized command",command); | 83 error("Unrecognized command",command); |
84 } | 84 } |
85 | 85 |
86 audioDB::audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS | 86 audioDB::audioDB(const unsigned argc, const char *argv[], struct soap *soap, adb__queryResponse *adbQueryResponse): O2_AUDIODB_INITIALIZERS |
87 { | 87 { |
88 try { | 88 try { |
89 isServer = 1; // Set to make errors report over SOAP | 89 isServer = 1; // Set to make errors report over SOAP |
90 processArgs(argc, argv); | 90 processArgs(argc, argv); |
91 // Perform database prefix substitution | 91 // Perform database prefix substitution |
92 if(dbName && adb_root) | 92 if(dbName && adb_root) |
93 prefix_name((char** const)&dbName, adb_root); | 93 prefix_name((char** const)&dbName, adb_root); |
94 assert(O2_ACTION(COM_QUERY)); | 94 assert(O2_ACTION(COM_QUERY)); |
95 query(dbName, inFile, adbQueryResponse); | 95 query(dbName, inFile, soap, adbQueryResponse); |
96 } catch(char *err) { | 96 } catch(char *err) { |
97 cleanup(); | 97 cleanup(); |
98 throw(err); | 98 throw(err); |
99 } | 99 } |
100 } | 100 } |
755 | 755 |
756 // Report status | 756 // Report status |
757 status(dbName); | 757 status(dbName); |
758 } | 758 } |
759 | 759 |
760 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse) { | 760 void audioDB::query(const char* dbName, const char* inFile, struct soap *soap, adb__queryResponse *adbQueryResponse) { |
761 | 761 |
762 if(!adb) { | 762 if(!adb) { |
763 if(!(adb = audiodb_open(dbName, O_RDWR))) { | 763 if(!(adb = audiodb_open(dbName, O_RDWR))) { |
764 error("failed to open database", dbName); | 764 error("failed to open database", dbName); |
765 } | 765 } |
949 adb_result_t r = rs->results[k]; | 949 adb_result_t r = rs->results[k]; |
950 reporter->add_point(audiodb_key_index(adb, r.key), r.qpos, r.ipos, r.dist); | 950 reporter->add_point(audiodb_key_index(adb, r.key), r.qpos, r.ipos, r.dist); |
951 } | 951 } |
952 audiodb_query_free_results(adb, &qspec, rs); | 952 audiodb_query_free_results(adb, &qspec, rs); |
953 | 953 |
954 reporter->report(adb, adbQueryResponse); | 954 reporter->report(adb, soap, adbQueryResponse); |
955 } | 955 } |
956 | 956 |
957 // This entry point is visited once per instance | 957 // This entry point is visited once per instance |
958 // so it is a good place to set any global state variables | 958 // so it is a good place to set any global state variables |
959 int main(const int argc, const char* argv[]){ | 959 int main(const int argc, const char* argv[]){ |