Fixing regression and rewrote portions of the memory handling of registered server plugins
This commit is contained in:
parent
50373d0a94
commit
da3789f2ce
@ -53,8 +53,9 @@ public:
|
|||||||
}
|
}
|
||||||
void EraseAll() {
|
void EraseAll() {
|
||||||
if(table.size() > 0)
|
if(table.size() > 0)
|
||||||
table.clear();
|
table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MyHashTable table;
|
MyHashTable table;
|
||||||
};
|
};
|
||||||
|
@ -34,10 +34,15 @@ namespace http {
|
|||||||
|
|
||||||
class RequestHandler : private boost::noncopyable {
|
class RequestHandler : private boost::noncopyable {
|
||||||
public:
|
public:
|
||||||
explicit RequestHandler() { }
|
explicit RequestHandler() : _pluginCount(0) { }
|
||||||
|
|
||||||
~RequestHandler() {
|
~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){
|
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] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
||||||
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
||||||
rep.status = Reply::ok;
|
rep.status = Reply::ok;
|
||||||
pluginMap.Find(command)->HandleRequest(parameters, rep );
|
_pluginVector[pluginMap.Find(command)]->HandleRequest(parameters, rep );
|
||||||
} else {
|
} else {
|
||||||
rep = Reply::stockReply(Reply::badRequest);
|
rep = Reply::stockReply(Reply::badRequest);
|
||||||
}
|
}
|
||||||
@ -73,12 +78,15 @@ public:
|
|||||||
|
|
||||||
void RegisterPlugin(BasePlugin * plugin) {
|
void RegisterPlugin(BasePlugin * plugin) {
|
||||||
std::cout << "[handler] registering plugin " << plugin->GetDescriptor() << std::endl;
|
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:
|
private:
|
||||||
boost::mutex pluginMutex;
|
HashTable<std::string, unsigned> pluginMap;
|
||||||
HashTable<std::string, BasePlugin *> pluginMap;
|
std::vector<BasePlugin *> _pluginVector;
|
||||||
|
unsigned _pluginCount;
|
||||||
};
|
};
|
||||||
} // namespace http
|
} // namespace http
|
||||||
|
|
||||||
|
@ -89,10 +89,6 @@ int main (int argc, char *argv[])
|
|||||||
std::cout << std::endl << "[server] shutting down" << std::endl;
|
std::cout << std::endl << "[server] shutting down" << std::endl;
|
||||||
s->Stop();
|
s->Stop();
|
||||||
t.join();
|
t.join();
|
||||||
delete helloWorld;
|
|
||||||
delete locate;
|
|
||||||
delete route;
|
|
||||||
delete h;
|
|
||||||
delete s;
|
delete s;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::cerr << "[fatal error] exception: " << e.what() << std::endl;
|
std::cerr << "[fatal error] exception: " << e.what() << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user