Mercurial > hg > audiodb
comparison audioDB.cpp @ 97:69424e77621f
Clean up a bit better when a server audioDB constructor throws an
exception (or even a char*, as currently).
New cleanup() function, called from the destructor and from catch blocks
in the server constructors.
author | mas01cr |
---|---|
date | Wed, 03 Oct 2007 15:16:47 +0000 |
parents | caf4ec67ddaf |
children | 97107ee61dba |
comparison
equal
deleted
inserted
replaced
96:8f7d0ae0ede4 | 97:69424e77621f |
---|---|
107 error("Unrecognized command",command); | 107 error("Unrecognized command",command); |
108 } | 108 } |
109 | 109 |
110 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS | 110 audioDB::audioDB(const unsigned argc, char* const argv[], adb__queryResult *adbQueryResult): O2_AUDIODB_INITIALIZERS |
111 { | 111 { |
112 processArgs(argc, argv); | 112 try { |
113 isServer = 1; // FIXME: Hack | 113 processArgs(argc, argv); |
114 assert(O2_ACTION(COM_QUERY)); | 114 isServer = 1; // FIXME: Hack |
115 query(dbName, inFile, adbQueryResult); | 115 assert(O2_ACTION(COM_QUERY)); |
116 query(dbName, inFile, adbQueryResult); | |
117 } catch(char *err) { | |
118 cleanup(); | |
119 throw(err); | |
120 } | |
116 } | 121 } |
117 | 122 |
118 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS | 123 audioDB::audioDB(const unsigned argc, char* const argv[], adb__statusResult *adbStatusResult): O2_AUDIODB_INITIALIZERS |
119 { | 124 { |
120 processArgs(argc, argv); | 125 try { |
121 isServer = 1; // FIXME: Hack | 126 processArgs(argc, argv); |
122 assert(O2_ACTION(COM_STATUS)); | 127 isServer = 1; // FIXME: Hack |
123 status(dbName, adbStatusResult); | 128 assert(O2_ACTION(COM_STATUS)); |
124 } | 129 status(dbName, adbStatusResult); |
125 | 130 } catch(char *err) { |
126 audioDB::~audioDB(){ | 131 cleanup(); |
127 // Clean up | 132 throw(err); |
133 } | |
134 } | |
135 | |
136 void audioDB::cleanup() { | |
128 if(indata) | 137 if(indata) |
129 munmap(indata,statbuf.st_size); | 138 munmap(indata,statbuf.st_size); |
130 if(db) | 139 if(db) |
131 munmap(db,O2_DEFAULTDBSIZE); | 140 munmap(db,O2_DEFAULTDBSIZE); |
132 if(dbfid>0) | 141 if(dbfid>0) |
133 close(dbfid); | 142 close(dbfid); |
134 if(infid>0) | 143 if(infid>0) |
135 close(infid); | 144 close(infid); |
136 if(dbH) | 145 if(dbH) |
137 delete dbH; | 146 delete dbH; |
147 } | |
148 | |
149 audioDB::~audioDB(){ | |
150 cleanup(); | |
138 } | 151 } |
139 | 152 |
140 int audioDB::processArgs(const unsigned argc, char* const argv[]){ | 153 int audioDB::processArgs(const unsigned argc, char* const argv[]){ |
141 | 154 |
142 if(argc<2){ | 155 if(argc<2){ |