NO-JIRA: C++ binding: Minor cleanup - rename/remove exceptions Rename bad_url as url_error for consistency.
Remove un-necessary message_reject, message_release exceptions. User can settle by calling methods on the delivery object, throwing an exception is not good C++. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7f1c8355 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7f1c8355 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7f1c8355 Branch: refs/heads/proton-go Commit: 7f1c8355873191a1b269fd5a97cf22e417fdfca7 Parents: ef1d3c8 Author: Alan Conway <[email protected]> Authored: Fri Sep 18 16:39:30 2015 -0400 Committer: Alan Conway <[email protected]> Committed: Fri Sep 18 16:39:30 2015 -0400 ---------------------------------------------------------------------- examples/cpp/helloworld.cpp | 3 +- .../bindings/cpp/include/proton/delivery.hpp | 43 +++++++++++++++++++ proton-c/bindings/cpp/include/proton/error.hpp | 7 ---- proton-c/bindings/cpp/include/proton/url.hpp | 14 +++---- proton-c/bindings/cpp/src/delivery.cpp | 6 +++ proton-c/bindings/cpp/src/error.cpp | 4 -- proton-c/bindings/cpp/src/messaging_adapter.cpp | 44 +++++++------------- proton-c/bindings/cpp/src/url.cpp | 4 +- 8 files changed, 73 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/examples/cpp/helloworld.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld.cpp b/examples/cpp/helloworld.cpp index 0bed09a..358162d 100644 --- a/examples/cpp/helloworld.cpp +++ b/examples/cpp/helloworld.cpp @@ -47,8 +47,7 @@ class hello_world : public proton::messaging_handler { } void on_message(proton::event &e) { - proton::data& body(e.message().body()); - std::cout << body << std::endl; + std::cout << e.message().body() << std::endl; e.connection().close(); } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/include/proton/delivery.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/delivery.hpp b/proton-c/bindings/cpp/include/proton/delivery.hpp index ca90831..1bd1dea 100644 --- a/proton-c/bindings/cpp/include/proton/delivery.hpp +++ b/proton-c/bindings/cpp/include/proton/delivery.hpp @@ -65,6 +65,49 @@ class delivery : public counted_facade<pn_delivery_t, delivery> { /** settle with MODIFIED state */ PN_CPP_EXTERN void modifiy() { settle(MODIFIED); } + + /** + * Check if a delivery is readable. + * + * A delivery is considered readable if it is the current delivery on + * an incoming link. + */ + PN_CPP_EXTERN bool partial(); + + /** + * Check if a delivery is writable. + * + * A delivery is considered writable if it is the current delivery on + * an outgoing link, and the link has positive credit. + */ + PN_CPP_EXTERN bool writable(); + + /** + * Check if a delivery is readable. + * + * A delivery is considered readable if it is the current delivery on + * an incoming link. + */ + PN_CPP_EXTERN bool readable(); + + /** + * Check if a delivery is updated. + * + * A delivery is considered updated whenever the peer communicates a + * new disposition for the delivery. Once a delivery becomes updated, + * it will remain so until clear() is called. + */ + PN_CPP_EXTERN bool updated(); + + /** + * Clear the updated flag for a delivery. + */ + PN_CPP_EXTERN void clear(); + + /** + * Get the remote disposition state for a delivery. + */ + PN_CPP_EXTERN state remote_state(); }; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/include/proton/error.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/error.hpp b/proton-c/bindings/cpp/include/proton/error.hpp index 6432b71..001cbc6 100644 --- a/proton-c/bindings/cpp/include/proton/error.hpp +++ b/proton-c/bindings/cpp/include/proton/error.hpp @@ -33,13 +33,6 @@ struct error : public std::runtime_error { PN_CPP_EXTERN explicit error(const st /** Raised if timeout expires */ struct timeout_error : public error { PN_CPP_EXTERN explicit timeout_error(const std::string&) throw(); }; -/** Raised if a message is rejected */ -struct message_reject : public error { PN_CPP_EXTERN explicit message_reject(const std::string&) throw(); }; - -/** Raised if a message is released */ -struct message_release : public error { PN_CPP_EXTERN explicit message_release(const std::string&) throw(); }; - - } #endif /*!PROTON_CPP_EXCEPTIONS_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/include/proton/url.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/url.hpp b/proton-c/bindings/cpp/include/proton/url.hpp index 8c8fbb0..42abadd 100644 --- a/proton-c/bindings/cpp/include/proton/url.hpp +++ b/proton-c/bindings/cpp/include/proton/url.hpp @@ -28,8 +28,8 @@ struct pn_url_t; namespace proton { /// Thrown if URL parsing fails. -struct bad_url : public error { - PN_CPP_EXTERN explicit bad_url(const std::string&) throw(); +struct url_error : public error { + PN_CPP_EXTERN explicit url_error(const std::string&) throw(); }; @@ -50,14 +50,14 @@ class url { /** Parse url_str as an AMQP URL. If defaults is true, fill in defaults for missing values * otherwise return an empty string for missing values. * Note: converts automatically from string. - *@throw bad_url if URL is invalid. + *@throw url_error if URL is invalid. */ PN_CPP_EXTERN url(const std::string& url_str, bool defaults=true); /** Parse url_str as an AMQP URL. If defaults is true, fill in defaults for missing values * otherwise return an empty string for missing values. * Note: converts automatically from string. - *@throw bad_url if URL is invalid. + *@throw url_error if URL is invalid. */ PN_CPP_EXTERN url(const char* url_str, bool defaults=true); @@ -66,12 +66,12 @@ class url { PN_CPP_EXTERN url& operator=(const url&); /** Parse a string as a URL - *@throws bad_url if URL is invalid. + *@throws url_error if URL is invalid. */ PN_CPP_EXTERN void parse(const std::string&); /** Parse a string as a URL - *@throws bad_url if URL is invalid. + *@throws url_error if URL is invalid. */ PN_CPP_EXTERN void parse(const char*); @@ -114,7 +114,7 @@ class url { /** parse url from istream, automatically fills in defaults for missing values. * - * Note: an invalid url is indicated by setting std::stream::fail() NOT by throwing bad_url. + * Note: an invalid url is indicated by setting std::stream::fail() NOT by throwing url_error. */ friend PN_CPP_EXTERN std::istream& operator>>(std::istream&, url&); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/src/delivery.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/delivery.cpp b/proton-c/bindings/cpp/src/delivery.cpp index 1962fa2..b292c70 100644 --- a/proton-c/bindings/cpp/src/delivery.cpp +++ b/proton-c/bindings/cpp/src/delivery.cpp @@ -35,4 +35,10 @@ void delivery::settle(delivery::state state) { settle(); } +bool delivery::partial() { return pn_delivery_partial(pn_cast(this)); } +bool delivery::readable() { return pn_delivery_readable(pn_cast(this)); } +bool delivery::writable() { return pn_delivery_writable(pn_cast(this)); } +bool delivery::updated() { return pn_delivery_updated(pn_cast(this)); } +void delivery::clear() { pn_delivery_clear(pn_cast(this)); } +delivery::state delivery::remote_state() { return state(pn_delivery_remote_state(pn_cast(this))); } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/src/error.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/error.cpp b/proton-c/bindings/cpp/src/error.cpp index fb409ef..615c22c 100644 --- a/proton-c/bindings/cpp/src/error.cpp +++ b/proton-c/bindings/cpp/src/error.cpp @@ -27,8 +27,4 @@ error::error(const std::string& msg) throw() : std::runtime_error(prefix+msg) {} timeout_error::timeout_error(const std::string& msg) throw() : error(msg) {} -message_reject::message_reject(const std::string& msg) throw() : error(msg) {} - -message_release::message_release(const std::string& msg) throw() : error(msg) {} - } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/src/messaging_adapter.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_adapter.cpp b/proton-c/bindings/cpp/src/messaging_adapter.cpp index 27dcc34..6c86581 100644 --- a/proton-c/bindings/cpp/src/messaging_adapter.cpp +++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp @@ -68,10 +68,10 @@ void messaging_adapter::on_delivery(event &e) { if (pe) { pn_event_t *cevent = pe->pn_event(); pn_link_t *lnk = pn_event_link(cevent); - pn_delivery_t *dlv = pn_event_delivery(cevent); + delivery &dlv = pe->delivery(); if (pn_link_is_receiver(lnk)) { - if (!pn_delivery_partial(dlv) && pn_delivery_readable(dlv)) { + if (!dlv.partial() && dlv.readable()) { // generate on_message messaging_event mevent(messaging_event::MESSAGE, *pe); pn_connection_t *pnc = pn_session_connection(pn_link_session(lnk)); @@ -80,40 +80,24 @@ void messaging_adapter::on_delivery(event &e) { // See PROTON-998 class message &msg(ctx.event_message); mevent.message_ = &msg; - - mevent.message_->decode(*reinterpret_cast<link*>(lnk), *reinterpret_cast<delivery*>(dlv)); + mevent.message_->decode(*link::cast(lnk), dlv); if (pn_link_state(lnk) & PN_LOCAL_CLOSED) { - if (auto_accept_) { - pn_delivery_update(dlv, PN_RELEASED); - pn_delivery_settle(dlv); - } - } - else { - try { - delegate_.on_message(mevent); - if (auto_accept_) { - pn_delivery_update(dlv, PN_ACCEPTED); - pn_delivery_settle(dlv); - } - } - catch (message_reject &) { - pn_delivery_update(dlv, PN_REJECTED); - pn_delivery_settle(dlv); - } - catch (message_release &) { - pn_delivery_update(dlv, PN_REJECTED); - pn_delivery_settle(dlv); - } + if (auto_accept_) + dlv.release(); + } else { + delegate_.on_message(mevent); + if (auto_accept_ && !dlv.settled()) + dlv.accept(); } } - else if (pn_delivery_updated(dlv) && pn_delivery_settled(dlv)) { + else if (dlv.updated() && dlv.settled()) { messaging_event mevent(messaging_event::SETTLED, *pe); delegate_.on_settled(mevent); } } else { // sender - if (pn_delivery_updated(dlv)) { - amqp_ulong rstate = pn_delivery_remote_state(dlv); + if (dlv.updated()) { + amqp_ulong rstate = dlv.remote_state(); if (rstate == PN_ACCEPTED) { messaging_event mevent(messaging_event::ACCEPTED, *pe); delegate_.on_accepted(mevent); @@ -127,12 +111,12 @@ void messaging_adapter::on_delivery(event &e) { delegate_.on_released(mevent); } - if (pn_delivery_settled(dlv)) { + if (dlv.settled()) { messaging_event mevent(messaging_event::SETTLED, *pe); delegate_.on_settled(mevent); } if (auto_settle_) - pn_delivery_settle(dlv); + dlv.settle(); } } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7f1c8355/proton-c/bindings/cpp/src/url.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/url.cpp b/proton-c/bindings/cpp/src/url.cpp index 4b8d956..b9407de 100644 --- a/proton-c/bindings/cpp/src/url.cpp +++ b/proton-c/bindings/cpp/src/url.cpp @@ -27,13 +27,13 @@ namespace proton { -bad_url::bad_url(const std::string& s) throw() : error(s) {} +url_error::url_error(const std::string& s) throw() : error(s) {} namespace { pn_url_t* parse_throw(const std::string& s) { pn_url_t* u = pn_url_parse(s.c_str()); - if (!u) throw bad_url("invalid URL: " + s); + if (!u) throw url_error("invalid URL: " + s); return u; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
