diff options
-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: |