diff options
author | Mauro Sardara <msardara+fdio@cisco.com> | 2017-07-12 11:13:31 +0200 |
---|---|---|
committer | Mauro Sardara <msardara+fdio@cisco.com> | 2017-07-12 11:13:31 +0200 |
commit | 5bae941c8b65a177f84adcbbb6f8643055ba002d (patch) | |
tree | 800135f92a08c9ce52ce68e24291f652fadb8366 | |
parent | 98a3c9497b4bebbc18092b468ea5929afde65b81 (diff) |
Avoid attaching HTTP publisher to the forwarder at creation time: create a method for it.
Change-Id: Ibe93696e3e2bf8acaf3dbe736db511436dca8f71
Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
-rw-r--r-- | icnet/http/icnet_http_server_publisher.cc | 20 | ||||
-rw-r--r-- | 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<transport::ProducerSocket>(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<transport::ProducerSocket>(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<core::Name &>(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: |