00001 #ifndef MULTIPART_STREAM_H_ 00002 #define MULTIPART_STREAM_H_ 00003 00004 #include <ros/ros.h> 00005 #include <async_web_server_cpp/http_connection.hpp> 00006 00007 #include <queue> 00008 00009 namespace web_video_server 00010 { 00011 00012 struct PendingFooter { 00013 ros::Time timestamp; 00014 boost::weak_ptr<std::string> contents; 00015 }; 00016 00017 class MultipartStream { 00018 public: 00019 MultipartStream(async_web_server_cpp::HttpConnectionPtr& connection, 00020 const std::string& boundry="boundarydonotcross", 00021 std::size_t max_queue_size=1); 00022 00023 void sendInitialHeader(); 00024 void sendPartHeader(const ros::Time &time, const std::string& type, size_t payload_size); 00025 void sendPartFooter(const ros::Time &time); 00026 void sendPartAndClear(const ros::Time &time, const std::string& type, std::vector<unsigned char> &data); 00027 void sendPart(const ros::Time &time, const std::string& type, const boost::asio::const_buffer &buffer, 00028 async_web_server_cpp::HttpConnection::ResourcePtr resource); 00029 00030 private: 00031 bool isBusy(); 00032 00033 private: 00034 const std::size_t max_queue_size_; 00035 async_web_server_cpp::HttpConnectionPtr connection_; 00036 std::string boundry_; 00037 std::queue<PendingFooter> pending_footers_; 00038 }; 00039 00040 } 00041 00042 #endif