|
| 1 | +#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_ASYNC_MESSAGE_HPP_20100622 |
| 2 | +#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_ASYNC_MESSAGE_HPP_20100622 |
| 3 | + |
| 4 | +// Copyright 2010 (c) Dean Michael Berris |
| 5 | +// Copyright 2010 (c) Sinefunc, Inc. |
| 6 | +// Distributed under the Boost Software License, Version 1.0. |
| 7 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 9 | + |
| 10 | +#include <boost/thread/future.hpp> |
| 11 | +#include <boost/cstdint.hpp> |
| 12 | + |
| 13 | +namespace boost { namespace network { namespace http { |
| 14 | + |
| 15 | + template <class Tag> |
| 16 | + struct async_message { |
| 17 | + |
| 18 | + typedef typename string<Tag>::type string_type; |
| 19 | + typedef typename headers_container<Tag>::type headers_container_type; |
| 20 | + |
| 21 | + async_message() |
| 22 | + : status_message_(), |
| 23 | + status_(), |
| 24 | + version_(), |
| 25 | + source_(), |
| 26 | + destination_(), |
| 27 | + headers_(), |
| 28 | + body_() |
| 29 | + {} |
| 30 | + |
| 31 | + async_message(async_message const & other) |
| 32 | + : status_message_(other.status_message_), |
| 33 | + status_(other.status_), |
| 34 | + version_(other.version_), |
| 35 | + source_(other.source_), |
| 36 | + destination_(other.destination_), |
| 37 | + headers_(other.destination_), |
| 38 | + body_(other.body_) |
| 39 | + {} |
| 40 | + |
| 41 | + string_type const status_message() const { |
| 42 | + return status_message_.get(); |
| 43 | + } |
| 44 | + |
| 45 | + void status_message(boost::shared_future<string_type> const & future) const { |
| 46 | + status_message_ = future; |
| 47 | + } |
| 48 | + |
| 49 | + string_type const version() const { |
| 50 | + return version_.get(); |
| 51 | + } |
| 52 | + |
| 53 | + void version(boost::shared_future<string_type> const & future) const { |
| 54 | + version_ = future; |
| 55 | + } |
| 56 | + |
| 57 | + boost::uint16_t const status() const { |
| 58 | + return status_.get(); |
| 59 | + } |
| 60 | + |
| 61 | + void status(boost::shared_future<string_type> const & future) const { |
| 62 | + status_ = future; |
| 63 | + } |
| 64 | + |
| 65 | + string_type const source() const { |
| 66 | + return source_.get(); |
| 67 | + } |
| 68 | + |
| 69 | + void source(boost::shared_future<string_type> const & future) const { |
| 70 | + source_ = future; |
| 71 | + } |
| 72 | + |
| 73 | + string_type const destination() const { |
| 74 | + return destination_.get(); |
| 75 | + } |
| 76 | + |
| 77 | + void destination(boost::shared_future<string_type> const & future) const { |
| 78 | + destination_ = future; |
| 79 | + } |
| 80 | + |
| 81 | + headers_container_type const headers() const { |
| 82 | + return headers_.get(); |
| 83 | + } |
| 84 | + |
| 85 | + void headers(boost::shared_future<headers_container_type> const & future) const { |
| 86 | + headers_ = future; |
| 87 | + } |
| 88 | + |
| 89 | + string_type const body() const { |
| 90 | + return body_.get(); |
| 91 | + } |
| 92 | + |
| 93 | + void body(boost::shared_future<string_type> const & future) const { |
| 94 | + body_ = future; |
| 95 | + } |
| 96 | + |
| 97 | + void swap(async_message & other) { |
| 98 | + std::swap(status_message_, other.status_message_); |
| 99 | + std::swap(status_, other.status_); |
| 100 | + std::swap(version_, other.version_); |
| 101 | + std::swap(source_, other.source_); |
| 102 | + std::swap(destination_, other.destination_); |
| 103 | + std::swap(headers_, other.headers_); |
| 104 | + std::swap(body_, other.body_); |
| 105 | + } |
| 106 | + |
| 107 | + async_message & operator=(async_message other) { |
| 108 | + other.swap(*this); |
| 109 | + return *this; |
| 110 | + } |
| 111 | + |
| 112 | + private: |
| 113 | + |
| 114 | + mutable boost::shared_future<string_type> status_message_, |
| 115 | + version_, source_, destination_, body_; |
| 116 | + mutable boost::shared_future<boost::uint16_t> status_; |
| 117 | + mutable boost::shared_future<headers_container_type> headers_; |
| 118 | + |
| 119 | + }; |
| 120 | + |
| 121 | + template <class Tag> |
| 122 | + inline void swap(async_message<Tag> & lhs, async_message<Tag> & rhs) { |
| 123 | + lhs.swap(rhs); |
| 124 | + } |
| 125 | + |
| 126 | +} // namespace http |
| 127 | + |
| 128 | +} // namespace network |
| 129 | + |
| 130 | +} // namespace boost |
| 131 | + |
| 132 | +#include <boost/network/protocol/http/message/wrappers/source.hpp> |
| 133 | +#include <boost/network/protocol/http/message/wrappers/body.hpp> |
| 134 | + |
| 135 | +#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_ASYNC_MESSAGE_HPP_20100622 |
0 commit comments