Mercurial > hg > audiodb
changeset 496:8fb85fbcaba6 api-inversion
Mostly disentangle API from command-line binary.
Now audioDB.cpp doesn't need to be included in the library, because
nothing the library does creates an audioDB instance. Hooray. We can't
disentangle the other way, because there's still plenty in the
command-line binary that isn't implemented in terms of the API, so the
audioDB binary code needs to know naughty stuff about the library's
internals (e.g. what the file header looks like).
Remove liszt.o and sample.o from the library, even though they'll
probably make a reapparance soon (for scare-quoted values of "soon")
Remove cmdline.o and common.o from the library, not scheduled to make a
reapparence ever (hooray!). Separate out the bits that are used in the
library -- locks and PointPairs -- into their own files.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 15:33:25 +0000 |
parents | c291e9201a3c |
children | 9d8aee621afb |
files | Makefile audioDB.cpp audioDB.h audioDB_API.h common.cpp lock.cpp pointpair.cpp |
diffstat | 7 files changed, 70 insertions(+), 242 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sat Jan 10 15:33:21 2009 +0000 +++ b/Makefile Sat Jan 10 15:33:25 2009 +0000 @@ -8,8 +8,8 @@ SHARED_LIB_FLAGS=-shared -Wl,-soname, -LIBOBJS=query.o index.o insert.o create.o common.o open.o close.o status.o dump.o power.o l2norm.o liszt.o sample.o lshlib.o cmdline.o -OBJS=$(LIBOBJS) soap.o audioDB.o +LIBOBJS=query.o index.o insert.o create.o common.o open.o close.o status.o dump.o power.o l2norm.o lshlib.o lock.o pointpair.o +OBJS=$(LIBOBJS) soap.o liszt.o sample.o cmdline.o audioDB.o common.o EXECUTABLE=audioDB @@ -54,14 +54,10 @@ cmdline.o: cmdline.c cmdline.h gcc -c $(CFLAGS) $< -audioDB_library.o: audioDB.cpp - g++ -c -o $@ $(CFLAGS) $(GSOAP_INCLUDE) -Wall -DLIBRARY $< - $(EXECUTABLE): $(OBJS) soapServer.cpp soapClient.cpp soapC.cpp g++ -o $(EXECUTABLE) $(CFLAGS) $^ $(LIBGSL) $(GSOAP_INCLUDE) $(GSOAP_CPP) - -$(LIBRARY): $(LIBOBJS) audioDB_library.o +$(LIBRARY): $(LIBOBJS) g++ $(SHARED_LIB_FLAGS)$(LIBRARY) -o $(LIBRARY) $(CFLAGS) $(LIBGSL) $^ tags: @@ -77,7 +73,7 @@ -rm xthresh -sh -c "cd tests && sh ./clean.sh" -sh -c "cd libtests && sh ./clean.sh" - -rm $(LIBRARY) audioDB_library.o + -rm $(LIBRARY) -rm tags distclean: clean @@ -97,4 +93,3 @@ ln -sf /usr/local/lib/lib$(EXECUTABLE).so.$(SOVERSION) /usr/local/lib/lib$(EXECUTABLE).so ldconfig cp audioDB_API.h /usr/local/include/ -
--- a/audioDB.cpp Sat Jan 10 15:33:21 2009 +0000 +++ b/audioDB.cpp Sat Jan 10 15:33:25 2009 +0000 @@ -8,24 +8,6 @@ char* SERVER_ADB_ROOT; char* SERVER_ADB_FEATURE_ROOT; -PointPair::PointPair(Uns32T a, Uns32T b, Uns32T c):trackID(a),qpos(b),spos(c){}; - -bool operator<(const PointPair& a, const PointPair& b){ - return ( (a.trackID<b.trackID) || - ( (a.trackID==b.trackID) && - ( (a.spos<b.spos) || ( (a.spos==b.spos) && (a.qpos < b.qpos) )) ) ); -} - -bool operator>(const PointPair& a, const PointPair& b){ - return ( (a.trackID>b.trackID) || - ( (a.trackID==b.trackID) && - ( (a.spos>b.spos) || ( (a.spos==b.spos) && (a.qpos > b.qpos) )) ) ); -} - -bool operator==(const PointPair& a, const PointPair& b){ - return ( (a.trackID==b.trackID) && (a.qpos==b.qpos) && (a.spos==b.spos) ); -} - audioDB::audioDB(const unsigned argc, const char *argv[]): O2_AUDIODB_INITIALIZERS { if(processArgs(argc, argv)<0){ @@ -45,11 +27,7 @@ prefix_name((char** const)&dbName, adb_root); if(O2_ACTION(COM_SERVER)) -#ifdef LIBRARY - ; -#else startServer(); -#endif else if(O2_ACTION(COM_CREATE)) create(dbName); @@ -62,9 +40,6 @@ else if(O2_ACTION(COM_QUERY)) if(isClient){ -#ifdef LIBRARY - ; -#else if(query_from_key){ VERB_LOG(1, "Calling web services query %s on database %s, query=%s\n", radius>0?"(Radius)":"(NN)", dbName, (key&&strlen(key))?key:inFile); ws_query_by_key(dbName, key, inFile, (char*)hostport); @@ -73,18 +48,13 @@ VERB_LOG(1, "Calling web services query on database %s, query=%s\n", dbName, (key&&strlen(key))?key:inFile); ws_query(dbName, inFile, (char*)hostport); } -#endif } else query(dbName, inFile); else if(O2_ACTION(COM_STATUS)) if(isClient) -#ifdef LIBRARY - ; -#else ws_status(dbName,(char*)hostport); -#endif else status(dbName); @@ -102,11 +72,7 @@ else if(O2_ACTION(COM_LISZT)) if(isClient) -#ifdef LIBRARY - ; -#else ws_liszt(dbName, (char*) hostport); -#endif else liszt(dbName, lisztOffset, lisztLength); @@ -165,38 +131,6 @@ } } -//for API query -audioDB::audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror, adb_t *a): O2_AUDIODB_INITIALIZERS -{ - - try { - UseApiError=1; - adb = a; - - if(processArgs(argc, argv)<0){ - printf("No command found.\n"); - cmdline_parser_print_version (); - if (strlen(gengetopt_args_info_purpose) > 0) - printf("%s\n", gengetopt_args_info_purpose); - printf("%s\n", gengetopt_args_info_usage); - printf("%s\n", gengetopt_args_info_help[1]); - printf("%s\n", gengetopt_args_info_help[2]); - printf("%s\n", gengetopt_args_info_help[0]); - error("No command found"); - } - - query(dbName, inFile, adbQueryResponse); - - } catch(int a) { - *apierror=a; - return; - - } - *apierror=apierrortemp; - return; - -} - void audioDB::cleanup() { cmdline_parser_free(&args_info); if(fileTable) @@ -221,7 +155,7 @@ gsl_rng_free(rng); if(infid>0) close(infid); - if(adb && !UseApiError) { + if(adb) { audiodb_close(adb); adb = NULL; } @@ -1008,121 +942,3 @@ SERVER_ADB_FEATURE_ROOT = 0; // Server-side features root prefix audioDB(argc, argv); } - - -extern "C" { - -/* for API questions contact - * Christophe Rhodes c.rhodes@gold.ac.uk - * Ian Knopke mas01ik@gold.ac.uk, ian.knopke@gmail.com */ - - int audiodb_query(adb_ptr mydb, adb_query_ptr adbq, adb_queryresult_ptr adbqr){ - - const char *argv[32]; - int argvctr=0; - char tempstr1[200]; - char tempstr2[200]; - char tempstr3[200]; - int apierror=0; - - adb__queryResponse adbQueryResponse; - - /* TODO: may need error checking here */ - /* currently counting on audioDB binary to fail for me */ - argv[argvctr++]="audioDB"; - - if(adbq->querytype){ - argv[argvctr++]="-Q"; - argv[argvctr++]=adbq->querytype; - } - - if(mydb->path){ - argv[argvctr++]="-d"; - argv[argvctr++]=mydb->path; - } - - if (adbq->feature){ - argv[argvctr++]="-f"; - argv[argvctr++]=adbq->feature; - } - - if (adbq->power){ - argv[argvctr++]="-w"; - argv[argvctr++]=adbq->power; - } - - if (adbq->qpoint){ - argv[argvctr++]="-p"; - argv[argvctr++]=adbq->qpoint; - } - if (adbq->numpoints){ - argv[argvctr++]="-n"; - argv[argvctr++]=adbq->numpoints; - } - if (adbq->radius){ - argv[argvctr++]="-R"; - argv[argvctr++]=adbq->radius; - } - if(adbq->resultlength){ - argv[argvctr++]="-r"; - argv[argvctr++]=adbq->resultlength; - } - if(adbq->sequencelength){ - argv[argvctr++]="-l"; - argv[argvctr++]=adbq->sequencelength; - } - if(adbq->sequencehop){ - argv[argvctr++]="-h"; - argv[argvctr++]=adbq->sequencehop; - } - - if (adbq->absolute_threshold){ - argv[argvctr++]="--absolute-threshold"; - snprintf(tempstr1,sizeof(tempstr1),"%f",adbq->absolute_threshold); - argv[argvctr++]=tempstr1; - } - - if (adbq->relative_threshold){ - argv[argvctr++]="--relative-threshold"; - snprintf(tempstr2,sizeof(tempstr2),"%f",adbq->relative_threshold); - argv[argvctr++]=tempstr2; - } - - if (adbq->exhaustive){ - argv[argvctr++]="--exhaustive"; - } - - if (adbq->expandfactor){ - argv[argvctr++]="--expandfactor"; - snprintf(tempstr3,sizeof(tempstr3),"%f",adbq->expandfactor); - argv[argvctr++]=tempstr3; - } - - if (adbq->rotate){ - argv[argvctr++]="--rotate"; - } - - if (adbq->keylist){ - argv[argvctr++]="-K"; - argv[argvctr++]=adbq->keylist; - } - argv[argvctr]='\0'; - - /* debugging */ - - audioDB::audioDB(argvctr,argv, &adbQueryResponse, &apierror,mydb); - - //copy data over here from adbQueryResponse to adbqr - adbqr->sizeRlist=adbQueryResponse.result.__sizeRlist; - adbqr->sizeDist=adbQueryResponse.result.__sizeDist; - adbqr->sizeQpos=adbQueryResponse.result.__sizeQpos; - adbqr->sizeSpos=adbQueryResponse.result.__sizeSpos; - adbqr->Rlist=adbQueryResponse.result.Rlist; - adbqr->Dist=adbQueryResponse.result.Dist; - adbqr->Qpos=adbQueryResponse.result.Qpos; - adbqr->Spos=adbQueryResponse.result.Spos; - - return apierror; - } -} -
--- a/audioDB.h Sat Jan 10 15:33:21 2009 +0000 +++ b/audioDB.h Sat Jan 10 15:33:25 2009 +0000 @@ -296,10 +296,6 @@ unsigned lisztOffset; unsigned lisztLength; - //for lib / API - int apierrortemp; - unsigned UseApiError; - // private methods void error(const char* a, const char* b = "", const char *sysFunc = 0); @@ -316,8 +312,6 @@ audioDB(const unsigned argc, const char *argv[], adb__queryResponse *adbQueryResponse); audioDB(const unsigned argc, const char *argv[], adb__statusResponse *adbStatusResponse); audioDB(const unsigned argc, const char *argv[], adb__lisztResponse *adbLisztResponse); - audioDB(const unsigned argc, const char *argv[],adb__queryResponse *adbQueryResponse, int * apierror, struct adb *a); - void cleanup(); ~audioDB(); @@ -435,8 +429,6 @@ reporter(0), \ lisztOffset(0), \ lisztLength(0), \ - apierrortemp(0), \ - UseApiError(0), \ lsh(0), \ lsh_in_core(false), \ lsh_use_u_functions(false), \
--- a/audioDB_API.h Sat Jan 10 15:33:21 2009 +0000 +++ b/audioDB_API.h Sat Jan 10 15:33:25 2009 +0000 @@ -11,6 +11,7 @@ /* Temporary workarounds */ typedef struct dbTableHeader adb_header_t; int acquire_lock(int, bool); +int divest_lock(int); /*******************************************************************/
--- a/common.cpp Sat Jan 10 15:33:21 2009 +0000 +++ b/common.cpp Sat Jan 10 15:33:25 2009 +0000 @@ -14,42 +14,6 @@ } #endif -int acquire_lock(int fd, bool exclusive) { - struct flock lock; - int status; - - lock.l_type = exclusive ? F_WRLCK : F_RDLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; /* "the whole file" */ - - retry: - do { - status = fcntl(fd, F_SETLKW, &lock); - } while (status != 0 && errno == EINTR); - - if (status) { - if (errno == EAGAIN) { - sleep(1); - goto retry; - } else { - return status; - } - } - return 0; -} - -int divest_lock(int fd) { - struct flock lock; - - lock.l_type = F_UNLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - - return fcntl(fd, F_SETLKW, &lock); -} - void audioDB::get_lock(int fd, bool exclusive) { if(acquire_lock(fd, exclusive)) { error("fcntl lock error", "", "fcntl"); @@ -76,9 +40,6 @@ structured type, so that we can throw separate faultstring and details. -- CSR, 2007-10-01 */ throw(err); - } else if (UseApiError){ - apierrortemp=-1; - throw(apierrortemp); } else { std::cerr << a << ": " << b << std::endl; if (sysFunc) { @@ -86,7 +47,6 @@ } exit(1); } - } void audioDB::initRNG() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lock.cpp Sat Jan 10 15:33:25 2009 +0000 @@ -0,0 +1,37 @@ +#include "audioDB.h" + +int acquire_lock(int fd, bool exclusive) { + struct flock lock; + int status; + + lock.l_type = exclusive ? F_WRLCK : F_RDLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; /* "the whole file" */ + + retry: + do { + status = fcntl(fd, F_SETLKW, &lock); + } while (status != 0 && errno == EINTR); + + if (status) { + if (errno == EAGAIN) { + sleep(1); + goto retry; + } else { + return status; + } + } + return 0; +} + +int divest_lock(int fd) { + struct flock lock; + + lock.l_type = F_UNLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; + + return fcntl(fd, F_SETLKW, &lock); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pointpair.cpp Sat Jan 10 15:33:25 2009 +0000 @@ -0,0 +1,27 @@ +#include "audioDB.h" +extern "C" { +#include "audioDB_API.h" +#include "audioDB-internals.h" +} + +PointPair::PointPair(Uns32T a, Uns32T b, Uns32T c) : + trackID(a), qpos(b), spos(c) { +}; + +bool operator<(const PointPair& a, const PointPair& b) { + return ((a.trackID < b.trackID) || + ((a.trackID == b.trackID) && + ((a.spos < b.spos) || ((a.spos == b.spos) && (a.qpos < b.qpos))))); +} + +bool operator>(const PointPair& a, const PointPair& b) { + return ((a.trackID > b.trackID) || + ((a.trackID == b.trackID) && + ((a.spos > b.spos) || ((a.spos == b.spos) && (a.qpos > b.qpos))))); +} + +bool operator==(const PointPair& a, const PointPair& b) { + return ((a.trackID == b.trackID) && + (a.qpos == b.qpos) && + (a.spos == b.spos)); +}