NO-JIRA: C++ binding: Merge message/message_value into a single value-semantic message class.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ef1d3c86 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ef1d3c86 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ef1d3c86 Branch: refs/heads/proton-go Commit: ef1d3c86907142d0bccb9cd21461d26da8a4f3ca Parents: 7d028ae Author: Alan Conway <[email protected]> Authored: Fri Sep 18 16:00:04 2015 -0400 Committer: Alan Conway <[email protected]> Committed: Fri Sep 18 16:00:04 2015 -0400 ---------------------------------------------------------------------- examples/cpp/broker.cpp | 7 +- examples/cpp/client.cpp | 2 +- examples/cpp/direct_send.cpp | 2 +- examples/cpp/helloworld.cpp | 2 +- examples/cpp/helloworld_blocking.cpp | 4 +- examples/cpp/helloworld_direct.cpp | 2 +- examples/cpp/server.cpp | 2 +- examples/cpp/server_direct.cpp | 2 +- examples/cpp/simple_send.cpp | 2 +- examples/cpp/sync_client.cpp | 4 +- .../cpp/include/proton/blocking_receiver.hpp | 4 +- .../cpp/include/proton/blocking_sender.hpp | 4 +- .../bindings/cpp/include/proton/message.hpp | 127 +++---------------- .../include/proton/sync_request_response.hpp | 2 +- proton-c/bindings/cpp/src/blocking_fetcher.cpp | 4 +- proton-c/bindings/cpp/src/blocking_fetcher.hpp | 4 +- proton-c/bindings/cpp/src/blocking_receiver.cpp | 4 +- proton-c/bindings/cpp/src/blocking_sender.cpp | 4 +- proton-c/bindings/cpp/src/contexts.hpp | 4 +- proton-c/bindings/cpp/src/conversion_test.cpp | 10 -- proton-c/bindings/cpp/src/facade.cpp | 1 - proton-c/bindings/cpp/src/message.cpp | 86 +++++++------ .../bindings/cpp/src/sync_request_response.cpp | 4 +- tests/tools/apps/cpp/reactor_send.cpp | 2 +- 24 files changed, 97 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/broker.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/broker.cpp b/examples/cpp/broker.cpp index 7f32650..f8ea87b 100644 --- a/examples/cpp/broker.cpp +++ b/examples/cpp/broker.cpp @@ -36,7 +36,7 @@ class queue { public: bool dynamic; - typedef std::deque<proton::message_value> message_queue; + typedef std::deque<proton::message> message_queue; typedef std::list<proton::counted_ptr<proton::sender> > sender_list; message_queue messages; sender_list consumers; @@ -52,7 +52,7 @@ class queue { return (consumers.size() == 0 && (dynamic || messages.size() == 0)); } - void publish(const proton::message_value &m) { + void publish(const proton::message &m) { messages.push_back(m); dispatch(0); } @@ -191,8 +191,7 @@ class broker : public proton::messaging_handler { void on_message(proton::event &e) { std::string addr = e.link().target().address(); - proton::message_value msg = e.message(); - get_queue(addr).publish(msg); + get_queue(addr).publish(e.message()); } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/client.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/client.cpp b/examples/cpp/client.cpp index 21c83f8..502e490 100644 --- a/examples/cpp/client.cpp +++ b/examples/cpp/client.cpp @@ -44,7 +44,7 @@ class client : public proton::messaging_handler { } void send_request() { - proton::message_value req; + proton::message req; req.body(requests.front()); req.reply_to(receiver->remote_source().address()); sender->send(req); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/direct_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/direct_send.cpp b/examples/cpp/direct_send.cpp index 02bc372..910c9a0 100644 --- a/examples/cpp/direct_send.cpp +++ b/examples/cpp/direct_send.cpp @@ -48,7 +48,7 @@ class simple_send : public proton::messaging_handler { void on_sendable(proton::event &e) { proton::sender& sender = e.sender(); while (sender.credit() && sent < total) { - proton::message_value msg; + proton::message msg; msg.id(proton::data_value(sent + 1)); std::map<std::string, int> m; m["sequence"] = sent+1; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/helloworld.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld.cpp b/examples/cpp/helloworld.cpp index bbb5330..0bed09a 100644 --- a/examples/cpp/helloworld.cpp +++ b/examples/cpp/helloworld.cpp @@ -40,7 +40,7 @@ class hello_world : public proton::messaging_handler { } void on_sendable(proton::event &e) { - proton::message_value m; + proton::message m; m.body("Hello World!"); e.sender().send(m); e.sender().close(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/helloworld_blocking.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_blocking.cpp b/examples/cpp/helloworld_blocking.cpp index 49094a3..f054df2 100644 --- a/examples/cpp/helloworld_blocking.cpp +++ b/examples/cpp/helloworld_blocking.cpp @@ -34,12 +34,12 @@ int main(int argc, char **argv) { proton::blocking_receiver receiver(conn, url.path()); proton::blocking_sender sender(conn, url.path()); - proton::message_value m; + proton::message m; m.body("Hello World!"); sender.send(m); proton::duration timeout(30000); - proton::message_value m2 = receiver.receive(timeout); + proton::message m2 = receiver.receive(timeout); std::cout << m2.body() << std::endl; receiver.accept(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/helloworld_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_direct.cpp b/examples/cpp/helloworld_direct.cpp index 119d134..4d96924 100644 --- a/examples/cpp/helloworld_direct.cpp +++ b/examples/cpp/helloworld_direct.cpp @@ -40,7 +40,7 @@ class hello_world_direct : public proton::messaging_handler { } void on_sendable(proton::event &e) { - proton::message_value m; + proton::message m; m.body("Hello World!"); e.sender().send(m); e.sender().close(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/server.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/server.cpp b/examples/cpp/server.cpp index 60cc972..7c94228 100644 --- a/examples/cpp/server.cpp +++ b/examples/cpp/server.cpp @@ -57,7 +57,7 @@ class server : public proton::messaging_handler { void on_message(proton::event &e) { std::cout << "Received " << e.message().body() << std::endl; std::string reply_to = e.message().reply_to(); - proton::message_value reply; + proton::message reply; reply.address(reply_to); reply.body(to_upper(e.message().body().get<std::string>())); reply.correlation_id(e.message().correlation_id()); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/server_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/server_direct.cpp b/examples/cpp/server_direct.cpp index 1e1839c..80e672a 100644 --- a/examples/cpp/server_direct.cpp +++ b/examples/cpp/server_direct.cpp @@ -77,7 +77,7 @@ class server : public proton::messaging_handler { std::cout << "No link for reply_to: " << reply_to << std::endl; } else { proton::counted_ptr<proton::sender> sender = it->second; - proton::message_value reply; + proton::message reply; reply.address(reply_to); reply.body(to_upper(e.message().body().get<std::string>())); reply.correlation_id(e.message().correlation_id()); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/simple_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/simple_send.cpp b/examples/cpp/simple_send.cpp index 11af17c..2898f80 100644 --- a/examples/cpp/simple_send.cpp +++ b/examples/cpp/simple_send.cpp @@ -46,7 +46,7 @@ class simple_send : public proton::messaging_handler { void on_sendable(proton::event &e) { proton::sender& sender = e.sender(); while (sender.credit() && sent < total) { - proton::message_value msg; + proton::message msg; msg.id(proton::data_value(sent + 1)); std::map<std::string, int> m; m["sequence"] = sent+1; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/examples/cpp/sync_client.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/sync_client.cpp b/examples/cpp/sync_client.cpp index 7bf08d9..39bdabf 100644 --- a/examples/cpp/sync_client.cpp +++ b/examples/cpp/sync_client.cpp @@ -52,9 +52,9 @@ int main(int argc, char **argv) { proton::blocking_connection conn(url, proton::duration(timeout)); proton::sync_request_response client(conn, url.path()); for (std::vector<std::string>::const_iterator i=requests.begin(); i != requests.end(); i++) { - proton::message_value request; + proton::message request; request.body(*i); - proton::message_value response(client.call(request)); + proton::message response(client.call(request)); std::cout << request.body() << " => " << response.body() << std::endl; } return 0; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/include/proton/blocking_receiver.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/blocking_receiver.hpp b/proton-c/bindings/cpp/include/proton/blocking_receiver.hpp index ac4a0b4..3bd657d 100644 --- a/proton-c/bindings/cpp/include/proton/blocking_receiver.hpp +++ b/proton-c/bindings/cpp/include/proton/blocking_receiver.hpp @@ -42,8 +42,8 @@ class blocking_receiver : public blocking_link blocking_connection&, const std::string &address, int credit = 0, bool dynamic = false); PN_CPP_EXTERN ~blocking_receiver(); - PN_CPP_EXTERN message_value receive(); - PN_CPP_EXTERN message_value receive(duration timeout); + PN_CPP_EXTERN message receive(); + PN_CPP_EXTERN message receive(duration timeout); PN_CPP_EXTERN void accept(); PN_CPP_EXTERN void reject(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/include/proton/blocking_sender.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/blocking_sender.hpp b/proton-c/bindings/cpp/include/proton/blocking_sender.hpp index 334faad..713ae6d 100644 --- a/proton-c/bindings/cpp/include/proton/blocking_sender.hpp +++ b/proton-c/bindings/cpp/include/proton/blocking_sender.hpp @@ -39,8 +39,8 @@ class blocking_sender : public blocking_link PN_CPP_EXTERN blocking_sender(class blocking_connection &c, const std::string &address); PN_CPP_EXTERN ~blocking_sender(); - PN_CPP_EXTERN delivery& send(const message_value &msg); - PN_CPP_EXTERN delivery& send(const message_value &msg, duration timeout); + PN_CPP_EXTERN delivery& send(const message &msg); + PN_CPP_EXTERN delivery& send(const message &msg, duration timeout); PN_CPP_EXTERN class sender& sender(); }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/include/proton/message.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/message.hpp b/proton-c/bindings/cpp/include/proton/message.hpp index be2485f..44d75c0 100644 --- a/proton-c/bindings/cpp/include/proton/message.hpp +++ b/proton-c/bindings/cpp/include/proton/message.hpp @@ -27,6 +27,7 @@ #include "proton/pn_unique_ptr.hpp" #include <string> +#include <utility> struct pn_message_t; @@ -35,14 +36,19 @@ namespace proton { class link; class delivery; -/** An AMQP message. Not directly construct-able, use create() or message_value.*/ -class message : public facade<pn_message_t, message> +/** An AMQP message. Value semantics, can be copied or assigned to make a new message. */ +class message { public: - PN_CPP_EXTERN static pn_unique_ptr<message> create(); + PN_CPP_EXTERN message(); + PN_CPP_EXTERN message(const message&); +#if PN_HAS_CPP11 + PN_CPP_EXTERN message(message&&); +#endif + PN_CPP_EXTERN ~message(); + PN_CPP_EXTERN message& operator=(const message&); - /// Copy data from m to this. - PN_CPP_EXTERN message& operator=(const message& m); + void swap(message& x); /** Clear the message content and properties. */ PN_CPP_EXTERN void clear(); @@ -105,15 +111,18 @@ class message : public facade<pn_message_t, message> /** Get a reference to the body data, can be modified in-place. */ PN_CPP_EXTERN data& body(); - // TODO aconway 2015-06-17: consistent and flexible treatment of buffers. - // Allow convenient std::string encoding/decoding (with re-use of existing - // string capacity) but also need to allow encoding/decoding of non-string - // buffers. Introduce a buffer type with begin/end pointers? + /** Encode into memory starting at buffer.first and ending before buffer.second */ + PN_CPP_EXTERN void encode(std::pair<char*, char*> buffer); - /** Encode the message into string data */ + /** Encode into a string, growing the string if necessary. */ PN_CPP_EXTERN void encode(std::string &data) const; - /** Retrun encoded message as a string */ + + /** Return encoded message as a string */ PN_CPP_EXTERN std::string encode() const; + + /** Decode from memory starting at buffer.first and ending before buffer.second */ + PN_CPP_EXTERN void decode(std::pair<const char*, const char*> buffer); + /** Decode from string data into the message. */ PN_CPP_EXTERN void decode(const std::string &data); @@ -121,103 +130,9 @@ class message : public facade<pn_message_t, message> PN_CPP_EXTERN void decode(proton::link&, proton::delivery&); PN_CPP_EXTERN void operator delete(void*); -}; - - -/** A message with value semantics */ -class message_value { - public: - message_value() : message_(message::create()) {} - message_value(const message_value& x) : message_(message::create()) { *message_ = *x.message_; } - message_value(const message& x) : message_(message::create()) { *message_ = x; } - message_value& operator=(const message_value& x) { *message_ = *x.message_; return *this; } - message_value& operator=(const message& x) { *message_ = x; return *this; } - - // TODO aconway 2015-09-02: C++11 move semantics. - - operator message&() { return *message_; } - operator const message&() const { return *message_; } - - /** Clear the message content */ - void clear() { message_->clear(); } - - ///@name Message properties - ///@{ - - /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value. - void id(const data& id) { message_->id(id); } - /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value. - const data& id() const { return message_->id(); } - data& id() { return message_->id(); } - - void user(const std::string &user) { message_->user(user); } - std::string user() const { return message_->user(); } - - void address(const std::string &addr) { message_->address(addr); } - std::string address() const { return message_->address(); } - - void subject(const std::string &s) { message_->subject(s); } - std::string subject() const { return message_->subject(); } - - void reply_to(const std::string &s) { message_->reply_to(s); } - std::string reply_to() const { return message_->reply_to(); } - - /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value. - void correlation_id(const data& d) { message_->correlation_id(d); } - /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value. - const data& correlation_id() const { return message_->correlation_id(); } - data& correlation_id() { return message_->correlation_id(); } - - void content_type(const std::string &s) { message_->content_type(s); } - std::string content_type() const { return message_->content_type(); } - - void content_encoding(const std::string &s) { message_->content_encoding(s); } - std::string content_encoding() const { return message_->content_encoding(); } - - void expiry(amqp_timestamp t) { message_->expiry(t); } - amqp_timestamp expiry() const { return message_->expiry(); } - - void creation_time(amqp_timestamp t) { message_->creation_time(t); } - amqp_timestamp creation_time() const { return message_->creation_time(); } - - void group_id(const std::string &s) { message_->group_id(s); } - std::string group_id() const { return message_->group_id(); } - - void reply_to_group_id(const std::string &s) { message_->reply_to_group_id(s); } - std::string reply_to_group_id() const { return message_->reply_to_group_id(); } - ///@} - - /** Set the body. If data has more than one value, each is encoded as an AMQP section. */ - void body(const data& d) { message_->body(d); } - - /** Set the body to any type T that can be converted to proton::data */ - template <class T> void body(const T& v) { message_->body(v); } - - /** Get the body values. */ - const data& body() const { return message_->body(); } - - /** Get a reference to the body data, can be modified in-place. */ - data& body() { return message_->body(); } - - // TODO aconway 2015-06-17: consistent and flexible treatment of buffers. - // Allow convenient std::string encoding/decoding (with re-use of existing - // string capacity) but also need to allow encoding/decoding of non-string - // buffers. Introduce a buffer type with begin/end pointers? - - /** Encode the message into string data */ - void encode(std::string &data) const { message_->encode(data); } - /** Retrun encoded message as a string */ - std::string encode() const { return message_->encode(); } - /** Decode from string data into the message. */ - void decode(const std::string &data) { message_->decode(data); } - - /// Decode the message from link corresponding to delivery. - void decode(proton::link& l, proton::delivery& d) { message_->decode(l, d); } - - void swap(message_value& x); private: - pn_unique_ptr<class message> message_; + pn_message_t *message_; }; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/include/proton/sync_request_response.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/sync_request_response.hpp b/proton-c/bindings/cpp/include/proton/sync_request_response.hpp index c1f47df..d5bfb59 100644 --- a/proton-c/bindings/cpp/include/proton/sync_request_response.hpp +++ b/proton-c/bindings/cpp/include/proton/sync_request_response.hpp @@ -46,7 +46,7 @@ class sync_request_response * Send a request message, wait for and return the response message. * Modifies the message to set `address` (if not already set), `reply_to` and `correlation_id`. */ - PN_CPP_EXTERN message_value call(message &); + PN_CPP_EXTERN message call(message &request); /** Return the dynamic address of our receiver. */ PN_CPP_EXTERN std::string reply_to(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/blocking_fetcher.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/blocking_fetcher.cpp b/proton-c/bindings/cpp/src/blocking_fetcher.cpp index 7a53487..55877af 100644 --- a/proton-c/bindings/cpp/src/blocking_fetcher.cpp +++ b/proton-c/bindings/cpp/src/blocking_fetcher.cpp @@ -44,13 +44,13 @@ void blocking_fetcher::on_link_error(event &e) { bool blocking_fetcher::has_message() { return !messages_.empty(); } -message_value blocking_fetcher::pop() { +message blocking_fetcher::pop() { if (messages_.empty()) throw error(MSG("receiver has no messages")); counted_ptr<delivery> dlv(deliveries_.front()); if (!dlv->settled()) unsettled_.push_back(dlv); - message_value m = messages_.front(); + message m = messages_.front(); messages_.pop_front(); deliveries_.pop_front(); return m; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/blocking_fetcher.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/blocking_fetcher.hpp b/proton-c/bindings/cpp/src/blocking_fetcher.hpp index f0a8d17..a0db252 100644 --- a/proton-c/bindings/cpp/src/blocking_fetcher.hpp +++ b/proton-c/bindings/cpp/src/blocking_fetcher.hpp @@ -34,11 +34,11 @@ class blocking_fetcher : public messaging_handler { void on_message(event &e); void on_link_error(event &e); bool has_message(); - message_value pop(); + message pop(); void settle(delivery::state state = delivery::NONE); private: - std::deque<message_value> messages_; + std::deque<message> messages_; std::deque<counted_ptr<delivery> > deliveries_; std::deque<counted_ptr<delivery> > unsettled_; }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/blocking_receiver.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/blocking_receiver.cpp b/proton-c/bindings/cpp/src/blocking_receiver.cpp index 10a3585..9628620 100644 --- a/proton-c/bindings/cpp/src/blocking_receiver.cpp +++ b/proton-c/bindings/cpp/src/blocking_receiver.cpp @@ -61,7 +61,7 @@ blocking_receiver::blocking_receiver( blocking_receiver::~blocking_receiver() { link_->detach_handler(); } -message_value blocking_receiver::receive(duration timeout) { +message blocking_receiver::receive(duration timeout) { if (!receiver().credit()) receiver().flow(1); fetcher_has_message cond(*fetcher_); @@ -69,7 +69,7 @@ message_value blocking_receiver::receive(duration timeout) { return fetcher_->pop(); } -message_value blocking_receiver::receive() { +message blocking_receiver::receive() { // Use default timeout return receive(connection_.timeout()); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/blocking_sender.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/blocking_sender.cpp b/proton-c/bindings/cpp/src/blocking_sender.cpp index 1d579c0..323dc5e 100644 --- a/proton-c/bindings/cpp/src/blocking_sender.cpp +++ b/proton-c/bindings/cpp/src/blocking_sender.cpp @@ -52,13 +52,13 @@ blocking_sender::blocking_sender(blocking_connection &c, const std::string &addr blocking_sender::~blocking_sender() {} -delivery& blocking_sender::send(const message_value &msg, duration timeout) { +delivery& blocking_sender::send(const message &msg, duration timeout) { delivery& dlv = sender().send(msg); connection_.impl_->wait(delivery_settled(pn_cast(&dlv)), "sending on sender " + link_->name(), timeout); return dlv; } -delivery& blocking_sender::send(const message_value &msg) { +delivery& blocking_sender::send(const message &msg) { // Use default timeout return send(msg, connection_.timeout()); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/contexts.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/contexts.hpp b/proton-c/bindings/cpp/src/contexts.hpp index 1a11259..028b123 100644 --- a/proton-c/bindings/cpp/src/contexts.hpp +++ b/proton-c/bindings/cpp/src/contexts.hpp @@ -46,8 +46,8 @@ struct connection_context : public counted { pn_unique_ptr<class handler> handler; session* default_session; // Owned by connection - class container_impl* container_impl; - class message_value event_message; // re-used by messaging_adapter for performance + container_impl* container_impl; + message event_message; // re-used by messaging_adapter for performance }; class container; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/conversion_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/conversion_test.cpp b/proton-c/bindings/cpp/src/conversion_test.cpp index 904c6e8..d056247 100644 --- a/proton-c/bindings/cpp/src/conversion_test.cpp +++ b/proton-c/bindings/cpp/src/conversion_test.cpp @@ -51,15 +51,6 @@ void test_auto() { std::auto_ptr<session> p(s.ptr().release()); } -void test_pn_unique() { - std::auto_ptr<message> a(message::create().release()); - a->clear(); -#if PN_HAS_STD_PTR - std::unique_ptr<message> u = message::create(); - u->clear(); -#endif -} - int main(int argc, char** argv) { int failed = 0; failed += run_test(&test_counted<counted_ptr<connection>, @@ -85,6 +76,5 @@ int main(int argc, char** argv) { boost::intrusive_ptr<session> >, "boost::intrusive"); #endif - failed += run_test(&test_pn_unique, "pn_unique_ptr"); return failed; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/facade.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/facade.cpp b/proton-c/bindings/cpp/src/facade.cpp index 6d0291a..6609f79 100644 --- a/proton-c/bindings/cpp/src/facade.cpp +++ b/proton-c/bindings/cpp/src/facade.cpp @@ -64,7 +64,6 @@ CHECK_EMPTY(decoder); CHECK_EMPTY(delivery); CHECK_EMPTY(encoder); CHECK_EMPTY(link); -CHECK_EMPTY(message); CHECK_EMPTY(session); CHECK_EMPTY(terminus); CHECK_EMPTY(transport); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/message.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/message.cpp b/proton-c/bindings/cpp/src/message.cpp index a68addf..b056cd7 100644 --- a/proton-c/bindings/cpp/src/message.cpp +++ b/proton-c/bindings/cpp/src/message.cpp @@ -35,136 +35,143 @@ namespace proton { -void message::operator delete(void *p) { ::pn_message_free(reinterpret_cast<pn_message_t*>(p)); } +message::message() : message_(::pn_message()) {} -pn_unique_ptr<message> message::create() { return pn_unique_ptr<message>(cast(::pn_message())); } +message::message(const message &m) : message_(::pn_message()) { *this = m; } + +#if PN_HAS_CPP11 +message::message(message &&m) : message_(::pn_message()) { swap(m); } +#endif + +message::~message() { ::pn_message_free(message_); } + +void message::swap(message& m) { std::swap(message_, m.message_); } message& message::operator=(const message& m) { - // TODO aconway 2015-08-10: need more efficient pn_message_copy function + // TODO aconway 2015-08-10: more efficient pn_message_copy function std::string data; m.encode(data); decode(data); return *this; } -void message::clear() { pn_message_clear(pn_cast(this)); } +void message::clear() { pn_message_clear(message_); } namespace { void check(int err) { if (err) throw error(error_str(err)); } - } // namespace -void message::id(const data& id) { *data::cast(pn_message_id(pn_cast(this))) = id; } -const data& message::id() const { return *data::cast(pn_message_id(pn_cast(this))); } -data& message::id() { return *data::cast(pn_message_id(pn_cast(this))); } +void message::id(const data& id) { *data::cast(pn_message_id(message_)) = id; } +const data& message::id() const { return *data::cast(pn_message_id(message_)); } +data& message::id() { return *data::cast(pn_message_id(message_)); } void message::user(const std::string &id) { - check(pn_message_set_user_id(pn_cast(this), pn_bytes(id))); + check(pn_message_set_user_id(message_, pn_bytes(id))); } std::string message::user() const { - return str(pn_message_get_user_id(pn_cast(this))); + return str(pn_message_get_user_id(message_)); } void message::address(const std::string &addr) { - check(pn_message_set_address(pn_cast(this), addr.c_str())); + check(pn_message_set_address(message_, addr.c_str())); } std::string message::address() const { - const char* addr = pn_message_get_address(pn_cast(this)); + const char* addr = pn_message_get_address(message_); return addr ? std::string(addr) : std::string(); } void message::subject(const std::string &s) { - check(pn_message_set_subject(pn_cast(this), s.c_str())); + check(pn_message_set_subject(message_, s.c_str())); } std::string message::subject() const { - const char* s = pn_message_get_subject(pn_cast(this)); + const char* s = pn_message_get_subject(message_); return s ? std::string(s) : std::string(); } void message::reply_to(const std::string &s) { - check(pn_message_set_reply_to(pn_cast(this), s.c_str())); + check(pn_message_set_reply_to(message_, s.c_str())); } std::string message::reply_to() const { - const char* s = pn_message_get_reply_to(pn_cast(this)); + const char* s = pn_message_get_reply_to(message_); return s ? std::string(s) : std::string(); } void message::correlation_id(const data& id) { - *data::cast(pn_message_correlation_id(pn_cast(this))) = id; + *data::cast(pn_message_correlation_id(message_)) = id; } const data& message::correlation_id() const { - return *data::cast(pn_message_correlation_id(pn_cast(this))); + return *data::cast(pn_message_correlation_id(message_)); } data& message::correlation_id() { - return *data::cast(pn_message_correlation_id(pn_cast(this))); + return *data::cast(pn_message_correlation_id(message_)); } void message::content_type(const std::string &s) { - check(pn_message_set_content_type(pn_cast(this), s.c_str())); + check(pn_message_set_content_type(message_, s.c_str())); } std::string message::content_type() const { - const char* s = pn_message_get_content_type(pn_cast(this)); + const char* s = pn_message_get_content_type(message_); return s ? std::string(s) : std::string(); } void message::content_encoding(const std::string &s) { - check(pn_message_set_content_encoding(pn_cast(this), s.c_str())); + check(pn_message_set_content_encoding(message_, s.c_str())); } std::string message::content_encoding() const { - const char* s = pn_message_get_content_encoding(pn_cast(this)); + const char* s = pn_message_get_content_encoding(message_); return s ? std::string(s) : std::string(); } void message::expiry(amqp_timestamp t) { - pn_message_set_expiry_time(pn_cast(this), t.milliseconds); + pn_message_set_expiry_time(message_, t.milliseconds); } amqp_timestamp message::expiry() const { - return amqp_timestamp(pn_message_get_expiry_time(pn_cast(this))); + return amqp_timestamp(pn_message_get_expiry_time(message_)); } void message::creation_time(amqp_timestamp t) { - pn_message_set_creation_time(pn_cast(this), t); + pn_message_set_creation_time(message_, t); } amqp_timestamp message::creation_time() const { - return pn_message_get_creation_time(pn_cast(this)); + return pn_message_get_creation_time(message_); } void message::group_id(const std::string &s) { - check(pn_message_set_group_id(pn_cast(this), s.c_str())); + check(pn_message_set_group_id(message_, s.c_str())); } std::string message::group_id() const { - const char* s = pn_message_get_group_id(pn_cast(this)); + const char* s = pn_message_get_group_id(message_); return s ? std::string(s) : std::string(); } void message::reply_to_group_id(const std::string &s) { - check(pn_message_set_reply_to_group_id(pn_cast(this), s.c_str())); + check(pn_message_set_reply_to_group_id(message_, s.c_str())); } std::string message::reply_to_group_id() const { - const char* s = pn_message_get_reply_to_group_id(pn_cast(this)); + const char* s = pn_message_get_reply_to_group_id(message_); return s ? std::string(s) : std::string(); } void message::body(const data& v) { body() = v; } const data& message::body() const { - return *data::cast(pn_message_body(pn_cast(this))); + return *data::cast(pn_message_body(message_)); } data& message::body() { - return *data::cast(pn_message_body(pn_cast(this))); + return *data::cast(pn_message_body(message_)); } void message::encode(std::string &s) const { @@ -172,7 +179,7 @@ void message::encode(std::string &s) const { if (sz < 512) sz = 512; while (true) { s.resize(sz); - int err = pn_message_encode(pn_cast(this), (char *) s.data(), &sz); + int err = pn_message_encode(message_, (char *) s.data(), &sz); if (err) { if (err != PN_OVERFLOW) check(err); @@ -191,7 +198,7 @@ std::string message::encode() const { } void message::decode(const std::string &s) { - check(pn_message_decode(pn_cast(this), s.data(), s.size())); + check(pn_message_decode(message_, s.data(), s.size())); } void message::decode(proton::link &link, proton::delivery &delivery) { @@ -204,12 +211,7 @@ void message::decode(proton::link &link, proton::delivery &delivery) { pn_link_advance(pn_cast(&link)); } -void message_value::swap(message_value& x) { - // This works with unique_ptr and auto_ptr (which has no swap) - message* a = message_.release(); - message* b = x.message_.release(); - message_.reset(b); - x.message_.reset(a); -} } + + http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/proton-c/bindings/cpp/src/sync_request_response.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/sync_request_response.cpp b/proton-c/bindings/cpp/src/sync_request_response.cpp index 1c9b220..8234010 100644 --- a/proton-c/bindings/cpp/src/sync_request_response.cpp +++ b/proton-c/bindings/cpp/src/sync_request_response.cpp @@ -35,7 +35,7 @@ sync_request_response::sync_request_response(blocking_connection &conn, const st correlation_id_(0) {} -message_value sync_request_response::call(message &request) { +message sync_request_response::call(message &request) { if (address_.empty() && request.address().empty()) throw error(MSG("Request message has no address")); // TODO: atomic increment. @@ -43,7 +43,7 @@ message_value sync_request_response::call(message &request) { request.correlation_id(cid); request.reply_to(this->reply_to()); sender_->send(request); - message_value response; + message response; while (response.correlation_id() != cid) { response = receiver_->receive(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ef1d3c86/tests/tools/apps/cpp/reactor_send.cpp ---------------------------------------------------------------------- diff --git a/tests/tools/apps/cpp/reactor_send.cpp b/tests/tools/apps/cpp/reactor_send.cpp index 852bd96..35c9552 100644 --- a/tests/tools/apps/cpp/reactor_send.cpp +++ b/tests/tools/apps/cpp/reactor_send.cpp @@ -38,7 +38,7 @@ class reactor_send : public proton::messaging_handler { private: proton::url url_; - proton::message_value message_; + proton::message message_; std::string reply_to_; int sent_; int confirmed_; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
