Implement local_discovery_enabled setting
Implementation will reset entire privet::Manager component if setting was
changed to false, and recreate component if it was changed into true.
Additionally removing of HTTP callback was added.
BUG: 27480269
Change-Id: Ieea91057fc0bdbd5f12c439b791250c9cf6c3741
Reviewed-on: https://weave-review.googlesource.com/2833
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/examples/provider/event_http_server.cc b/examples/provider/event_http_server.cc
index 48faab1..3d64d15 100644
--- a/examples/provider/event_http_server.cc
+++ b/examples/provider/event_http_server.cc
@@ -143,7 +143,7 @@
void HttpServerImpl::ProcessRequest(evhtp_request_t* req) {
std::unique_ptr<RequestImpl> request{new RequestImpl{EventPtr<evhtp_request_t>{req}}};
std::string path = request->GetPath();
- auto it = handlers_.find(path);
+ auto it = handlers_.find(std::make_pair(path, req->htp));
if (it != handlers_.end()) {
return it->second.Run(std::move(request));
}
@@ -157,17 +157,27 @@
void HttpServerImpl::AddHttpRequestHandler(
const std::string& path,
const RequestHandlerCallback& callback) {
- handlers_.insert(std::make_pair(path, callback));
+ handlers_[std::make_pair(path, httpd_.get())] = callback;
evhtp_set_cb(httpd_.get(), path.c_str(), &ProcessRequestCallback, this);
}
void HttpServerImpl::AddHttpsRequestHandler(
const std::string& path,
const RequestHandlerCallback& callback) {
- handlers_.insert(std::make_pair(path, callback));
+ handlers_[std::make_pair(path, httpsd_.get())] = callback;
evhtp_set_cb(httpsd_.get(), path.c_str(), &ProcessRequestCallback, this);
}
+void HttpServerImpl::RemoveHttpRequestHandler(const std::string& path) {
+ handlers_.erase(std::make_pair(path, httpd_.get()));
+ evhtp_set_cb(httpd_.get(), path.c_str(), nullptr, nullptr);
+}
+
+void HttpServerImpl::RemoveHttpsRequestHandler(const std::string& path) {
+ handlers_.erase(std::make_pair(path, httpsd_.get()));
+ evhtp_set_cb(httpsd_.get(), path.c_str(), nullptr, nullptr);
+}
+
void HttpServerImpl::ProcessReply(std::shared_ptr<RequestImpl> request,
int status_code,
const std::string& data,