Fixing regression and rewrote portions of the memory handling of registered server plugins

This commit is contained in:
Dennis Luxen 2011-03-14 13:35:16 +00:00
parent 50373d0a94
commit da3789f2ce
3 changed files with 16 additions and 11 deletions

View File

@ -53,8 +53,9 @@ public:
}
void EraseAll() {
if(table.size() > 0)
table.clear();
table.clear();
}
private:
MyHashTable table;
};

View File

@ -34,10 +34,15 @@ namespace http {
class RequestHandler : private boost::noncopyable {
public:
explicit RequestHandler() { }
explicit RequestHandler() : _pluginCount(0) { }
~RequestHandler() {
pluginMap.EraseAll();
for(unsigned i = 0; i < _pluginVector.size(); i++) {
BasePlugin * tempPointer = _pluginVector[i];
delete tempPointer;
}
}
void handle_request(const Request& req, Reply& rep){
@ -59,7 +64,7 @@ public:
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
rep.status = Reply::ok;
pluginMap.Find(command)->HandleRequest(parameters, rep );
_pluginVector[pluginMap.Find(command)]->HandleRequest(parameters, rep );
} else {
rep = Reply::stockReply(Reply::badRequest);
}
@ -73,12 +78,15 @@ public:
void RegisterPlugin(BasePlugin * plugin) {
std::cout << "[handler] registering plugin " << plugin->GetDescriptor() << std::endl;
pluginMap.Add(plugin->GetDescriptor(), plugin);
pluginMap.Add(plugin->GetDescriptor(), _pluginCount);
_pluginVector.push_back(plugin);
_pluginCount++;
}
private:
boost::mutex pluginMutex;
HashTable<std::string, BasePlugin *> pluginMap;
HashTable<std::string, unsigned> pluginMap;
std::vector<BasePlugin *> _pluginVector;
unsigned _pluginCount;
};
} // namespace http

View File

@ -89,10 +89,6 @@ int main (int argc, char *argv[])
std::cout << std::endl << "[server] shutting down" << std::endl;
s->Stop();
t.join();
delete helloWorld;
delete locate;
delete route;
delete h;
delete s;
} catch (std::exception& e) {
std::cerr << "[fatal error] exception: " << e.what() << std::endl;