From 5bae941c8b65a177f84adcbbb6f8643055ba002d Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Wed, 12 Jul 2017 11:13:31 +0200 Subject: Avoid attaching HTTP publisher to the forwarder at creation time: create a method for it. Change-Id: Ibe93696e3e2bf8acaf3dbe736db511436dca8f71 Signed-off-by: Mauro Sardara --- icnet/http/icnet_http_server_publisher.cc | 20 +++++++++++++++----- icnet/http/icnet_http_server_publisher.h | 8 +------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/icnet/http/icnet_http_server_publisher.cc b/icnet/http/icnet_http_server_publisher.cc index 8ff86459..93c19df8 100644 --- a/icnet/http/icnet_http_server_publisher.cc +++ b/icnet/http/icnet_http_server_publisher.cc @@ -21,13 +21,19 @@ namespace http { HTTPServerPublisher::HTTPServerPublisher(const transport::Name &content_name) : content_name_(content_name) { - // Create a new publisher - producer_ = std::unique_ptr(new transport::ProducerSocket(content_name)); - producer_->attach(); } HTTPServerPublisher::~HTTPServerPublisher() { - this->timer_->cancel(); + if (this->timer_) { + this->timer_->cancel(); + } +} + +HTTPServerPublisher& HTTPServerPublisher::attachPublisher() { + // Create a new publisher + producer_ = std::unique_ptr(new transport::ProducerSocket(content_name_)); + producer_->attach(); + return *this; } HTTPServerPublisher &HTTPServerPublisher::setTimeout(uint32_t timeout) { @@ -59,7 +65,11 @@ HTTPServerPublisher &HTTPServerPublisher::setTimeout(uint32_t timeout) { void HTTPServerPublisher::publishContent(const uint8_t *buf, size_t buffer_size, const int response_id, bool is_last) { if (producer_) { +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_DEBUG, "HTTP_SERVER_PUBLISHER", "Replying to %s", const_cast(content_name_).toString().c_str()); +#else std::cout << "Replying to " << content_name_ << std::endl; +#endif producer_->produce(content_name_, buf, buffer_size, response_id, is_last); } } @@ -76,4 +86,4 @@ void HTTPServerPublisher::stop() { } -} \ No newline at end of file +} diff --git a/icnet/http/icnet_http_server_publisher.h b/icnet/http/icnet_http_server_publisher.h index 933d20c8..c914b7f7 100644 --- a/icnet/http/icnet_http_server_publisher.h +++ b/icnet/http/icnet_http_server_publisher.h @@ -48,13 +48,7 @@ class HTTPServerPublisher { HTTPServerPublisher &setTimeout(uint32_t timeout); -// HttpRequest&& request(); - -// void sendResponse(); - -// HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {}); -// -// HTTPResponse&& response(); + HTTPServerPublisher &attachPublisher(); private: -- cgit 1.2.3-korg