Skip to content

Commit 78363fc

Browse files
committed
Big blob of changes, to support asynchronous messages that use Boost.Thread futures internally.
1 parent 7814723 commit 78363fc

35 files changed

+952
-394
lines changed

boost/network/message.hpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
// include wrappers base
2525
#include <boost/network/detail/wrapper_base.hpp>
2626

27+
#include <boost/network/message/modifiers/add_header.hpp>
28+
#include <boost/network/message/modifiers/remove_header.hpp>
29+
#include <boost/network/message/modifiers/clear_headers.hpp>
30+
#include <boost/network/message/modifiers/source.hpp>
31+
#include <boost/network/message/modifiers/destination.hpp>
32+
#include <boost/network/message/modifiers/body.hpp>
33+
2734
#include <boost/network/message/message_concept.hpp>
2835

2936
/** message.hpp
@@ -71,14 +78,30 @@ namespace boost { namespace network {
7178
return _headers;
7279
}
7380

74-
headers_container_type headers() const {
81+
void headers(headers_container_type const & headers_) const {
82+
_headers = headers_;
83+
}
84+
85+
void add_header(typename headers_container_type::value_type const & pair_) const {
86+
_headers.insert(pair_);
87+
}
88+
89+
void remove_header(typename headers_container_type::key_type const & key) const {
90+
_headers.erase(key);
91+
}
92+
93+
headers_container_type & headers() const {
7594
return _headers;
7695
}
7796

7897
string_type & body() {
7998
return _body;
8099
}
81100

101+
void body(string_type const & body_) const {
102+
_body = body_;
103+
}
104+
82105
string_type body() const {
83106
return _body;
84107
}
@@ -87,6 +110,10 @@ namespace boost { namespace network {
87110
return _source;
88111
}
89112

113+
void source(string_type const & source_) const {
114+
_source = source_;
115+
}
116+
90117
string_type source() const {
91118
return _source;
92119
}
@@ -95,6 +122,10 @@ namespace boost { namespace network {
95122
return _destination;
96123
}
97124

125+
void destination(string_type const & destination_) const {
126+
_destination = destination_;
127+
}
128+
98129
string_type destination() const {
99130
return _destination;
100131
}
@@ -104,10 +135,10 @@ namespace boost { namespace network {
104135
friend struct detail::directive_base<Tag> ;
105136
friend struct detail::wrapper_base<Tag> ;
106137

107-
headers_container_type _headers;
108-
string_type _body;
109-
string_type _source;
110-
string_type _destination;
138+
mutable headers_container_type _headers;
139+
mutable string_type _body;
140+
mutable string_type _source;
141+
mutable string_type _destination;
111142
};
112143

113144
template <class Tag>

boost/network/message/directives/body.hpp

Lines changed: 96 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,106 @@
88
#define __NETWORK_MESSAGE_DIRECTIVES_BODY_HPP__
99

1010
#include <boost/network/traits/string.hpp>
11+
#include <boost/network/support/is_async.hpp>
12+
#include <boost/network/support/is_sync.hpp>
13+
#include <boost/type_traits/is_same.hpp>
14+
#include <boost/variant/variant.hpp>
15+
#include <boost/variant/apply_visitor.hpp>
16+
#include <boost/variant/static_visitor.hpp>
17+
#include <boost/mpl/if.hpp>
18+
#include <boost/mpl/or.hpp>
1119

12-
13-
/** body.hpp
14-
*
15-
* Defines the types involved and the semantics of adding
16-
* body contents into message objects.
17-
*
18-
* WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
19-
* TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
20-
* HEADER.
21-
*/
2220
namespace boost { namespace network {
23-
namespace impl {
24-
template <
25-
class T
26-
>
27-
struct body_directive {
28-
29-
explicit body_directive(T body) :
30-
_body(body)
31-
{ };
32-
33-
template <class MessageTag>
34-
void operator() (basic_message<MessageTag> & msg) const {
35-
msg.body() = _body;
36-
}
37-
38-
private:
39-
40-
T _body;
41-
};
42-
} // namespace impl
43-
44-
45-
// template <
46-
// class T
47-
// >
48-
// inline
49-
// impl::body_directive<T>
50-
// body(T body_, boost::disable_if<T::message>::type) {
51-
// return impl::body_directive<T>(body_);
52-
// }
53-
54-
55-
inline
56-
impl::body_directive<std::string>
57-
body(std::string body_) {
58-
return impl::body_directive<std::string>(body_);
59-
}
6021

22+
namespace traits {
23+
template <class Tag>
24+
struct unsupported_tag;
25+
26+
template <class Message>
27+
struct body :
28+
mpl::if_<
29+
is_async<typename Message::tag>,
30+
boost::shared_future<typename string<typename Message::tag>::type>,
31+
typename mpl::if_<
32+
mpl::or_<
33+
is_sync<typename Message::tag>,
34+
is_same<typename Message::tag, tags::default_string>,
35+
is_same<typename Message::tag, tags::default_wstring>
36+
>,
37+
typename string<typename Message::tag>::type,
38+
unsupported_tag<typename Message::tag>
39+
>::type
40+
>
41+
{};
42+
} // namespace traits
43+
44+
namespace impl {
45+
46+
struct body_directive {
47+
boost::variant<
48+
string<tags::default_string>::type,
49+
string<tags::default_wstring>::type,
50+
boost::shared_future<string<tags::default_string>::type>,
51+
boost::shared_future<string<tags::default_wstring>::type>
52+
> body_;
53+
54+
body_directive(string<tags::default_string>::type const & body)
55+
: body_(body) {}
56+
body_directive(string<tags::default_wstring>::type const & body)
57+
: body_(body) {}
58+
body_directive(boost::shared_future<string<tags::default_string>::type> const & body)
59+
: body_(body) {}
60+
body_directive(boost::shared_future<string<tags::default_wstring>::type> const & body)
61+
: body_(body) {}
62+
63+
body_directive(body_directive const & other)
64+
: body_(other.body_) {}
65+
66+
template <class Tag>
67+
struct value :
68+
mpl::if_<
69+
is_async<Tag>,
70+
boost::shared_future<typename string<Tag>::type>,
71+
typename mpl::if_<
72+
mpl::or_<
73+
is_sync<Tag>,
74+
is_same<Tag, tags::default_string>,
75+
is_same<Tag, tags::default_wstring>
76+
>,
77+
typename string<Tag>::type,
78+
unsupported_tag<Tag>
79+
>::type
80+
>
81+
{};
82+
83+
template <class Message>
84+
struct body_visitor : boost::static_visitor<> {
85+
Message const & message_;
86+
body_visitor(Message const & message)
87+
: message_(message) {}
88+
void operator()(typename value<typename Message::tag>::type const & body) const {
89+
message_.body(body);
90+
}
91+
template <class T> void operator()(T const &) const {
92+
// FIXME -- fail here
93+
}
94+
};
95+
96+
template <class Tag, template <class> class Message>
97+
void operator()(Message<Tag> const & message) const {
98+
apply_visitor(body_visitor<Message<Tag> >(message), body_);
99+
}
100+
101+
};
102+
103+
} // namespace impl
104+
105+
106+
template <class Input>
107+
inline impl::body_directive const body(Input const & input) {
108+
return impl::body_directive(input);
109+
}
61110

62-
inline
63-
impl::body_directive<std::wstring>
64-
body(std::wstring body_) {
65-
return impl::body_directive<std::wstring>(body_);
66-
}
67111
} // namespace network
68112
} // namespace boost
69113

boost/network/message/directives/destination.hpp

Lines changed: 101 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,110 @@
88
#define __NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__
99

1010
#include <boost/network/traits/string.hpp>
11+
#include <boost/network/support/is_async.hpp>
12+
#include <boost/network/support/is_sync.hpp>
13+
#include <boost/type_traits/is_same.hpp>
14+
#include <boost/variant/variant.hpp>
15+
#include <boost/variant/apply_visitor.hpp>
16+
#include <boost/variant/static_visitor.hpp>
17+
#include <boost/mpl/if.hpp>
18+
#include <boost/mpl/or.hpp>
1119

12-
13-
/** destination.hpp
14-
*
15-
* Defines the types involved and the semantics of adding
16-
* destination information into message objects.
17-
*
18-
* WARNING: DO NOT INCLUDE THIS HEADER DIRECTLY. THIS REQUIRES
19-
* TYPES TO BE DEFINED FROM EARLIER FILES THAT INCLUDE THIS
20-
* HEADER.
21-
*/
2220
namespace boost { namespace network {
23-
24-
namespace impl {
25-
template <class T>
26-
struct destination_directive {
27-
28-
explicit destination_directive (T destination)
29-
: _destination(destination)
30-
{ };
31-
32-
template <
33-
class MessageTag
34-
>
35-
void operator() (basic_message<MessageTag> & msg) const {
36-
msg.destination() = _destination;
37-
};
38-
39-
private:
40-
41-
T _destination;
42-
};
43-
} // namespace impl
44-
45-
46-
inline
47-
impl::destination_directive<std::string>
48-
destination(std::string destination_) {
49-
return impl::destination_directive<std::string>(destination_);
50-
}
51-
52-
inline
53-
impl::destination_directive<std::wstring>
54-
destination(std::wstring destination_) {
55-
return impl::destination_directive<std::wstring>(destination_);
56-
}
21+
22+
namespace traits {
23+
24+
template <class Tag>
25+
struct unsupported_tag;
26+
27+
template <class Message>
28+
struct destination
29+
: mpl::if_<
30+
is_async<typename Message::tag>,
31+
boost::shared_future<typename string<typename Message::tag>::type>,
32+
typename mpl::if_<
33+
mpl::or_<
34+
is_sync<typename Message::tag>,
35+
is_same<typename Message::tag, tags::default_string>,
36+
is_same<typename Message::tag, tags::default_wstring>
37+
>,
38+
typename string<typename Message::tag>::type,
39+
unsupported_tag<typename Message::tag>
40+
>::type
41+
>
42+
{};
43+
44+
} // namespace traits
45+
46+
namespace impl {
47+
48+
struct destination_directive {
49+
boost::variant<
50+
string<tags::default_string>::type,
51+
string<tags::default_wstring>::type,
52+
boost::shared_future<string<tags::default_string>::type>,
53+
boost::shared_future<string<tags::default_wstring>::type>
54+
> destination_;
55+
56+
destination_directive(string<tags::default_string>::type const & destination)
57+
: destination_(destination) {}
58+
destination_directive(string<tags::default_wstring>::type const & destination)
59+
: destination_(destination) {}
60+
destination_directive(boost::shared_future<string<tags::default_string>::type> const & destination)
61+
: destination_(destination) {}
62+
destination_directive(boost::shared_future<string<tags::default_wstring>::type> const & destination)
63+
: destination_(destination) {}
64+
65+
destination_directive(destination_directive const & other)
66+
: destination_(other.destination_) {}
67+
68+
template <class Tag>
69+
struct value :
70+
mpl::if_<
71+
is_async<Tag>,
72+
boost::shared_future<typename string<Tag>::type>,
73+
typename mpl::if_<
74+
mpl::or_<
75+
is_sync<Tag>,
76+
is_same<Tag, tags::default_string>,
77+
is_same<Tag, tags::default_wstring>
78+
>,
79+
typename string<Tag>::type,
80+
unsupported_tag<Tag>
81+
>::type
82+
>
83+
{};
84+
85+
template <class Message>
86+
struct destination_visitor : boost::static_visitor<> {
87+
Message const & message_;
88+
destination_visitor(Message const & message)
89+
: message_(message) {}
90+
void operator()(typename value<typename Message::tag>::type const & destination) const {
91+
message_.destination(destination);
92+
}
93+
template <class T> void operator() (T const &) const {
94+
// FIXME -- fail here!
95+
}
96+
};
97+
98+
template <class Tag, template <class> class Message>
99+
void operator()(Message<Tag> const & message) const {
100+
apply_visitor(destination_visitor<Message<Tag> >(message), destination_);
101+
}
102+
};
103+
104+
} // namespace impl
105+
106+
template <class T>
107+
inline impl::destination_directive const
108+
destination(T const & destination_) {
109+
return impl::destination_directive(destination_);
110+
}
111+
57112
} // namespace network
58-
} // namespace boost
59113

114+
} // namespace boost
115+
60116

61117
#endif // __NETWORK_MESSAGE_DIRECTIVES_DESTINATION_HPP__

0 commit comments

Comments
 (0)