Avoid attaching HTTP publisher to the forwarder at creation time: create a method... 27/7527/1
authorMauro Sardara <[email protected]>
Wed, 12 Jul 2017 09:13:31 +0000 (11:13 +0200)
committerMauro Sardara <[email protected]>
Wed, 12 Jul 2017 09:13:31 +0000 (11:13 +0200)
Change-Id: Ibe93696e3e2bf8acaf3dbe736db511436dca8f71
Signed-off-by: Mauro Sardara <[email protected]>
icnet/http/icnet_http_server_publisher.cc
icnet/http/icnet_http_server_publisher.h

index 8ff8645..93c19df 100644 (file)
@@ -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
+}
index 933d20c..c914b7f 100644 (file)
@@ -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: