PROTON-1095: [C++ binding] Improve error handling with events - Introduce on_unhandled_error that is called if the application does not handle the specific error conditions itself. -- Default action of on_unhandled_erro is to raise an exception with a useful message. - Added condition to represent error state (wrapper for pn_condition_t) x Examples now don't seem robust enough and fail because of errors
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/68369ac4 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/68369ac4 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/68369ac4 Branch: refs/heads/master Commit: 68369ac4448a88c07cfca767aebb28ab86c1360a Parents: 9355e97 Author: Andrew Stitcher <[email protected]> Authored: Mon Jan 11 22:02:50 2016 -0500 Committer: Andrew Stitcher <[email protected]> Committed: Mon Jan 25 16:51:29 2016 -0500 ---------------------------------------------------------------------- proton-c/bindings/cpp/CMakeLists.txt | 1 + .../bindings/cpp/include/proton/condition.hpp | 57 ++++++++++++++++++ .../bindings/cpp/include/proton/connection.hpp | 12 ++-- .../bindings/cpp/include/proton/endpoint.hpp | 12 ++-- proton-c/bindings/cpp/include/proton/event.hpp | 4 ++ .../bindings/cpp/include/proton/handler.hpp | 7 +-- proton-c/bindings/cpp/include/proton/link.hpp | 11 +++- .../bindings/cpp/include/proton/session.hpp | 9 ++- .../bindings/cpp/include/proton/transport.hpp | 2 + proton-c/bindings/cpp/src/blocking_fetcher.cpp | 2 +- proton-c/bindings/cpp/src/blocking_link.cpp | 8 +-- proton-c/bindings/cpp/src/condition.cpp | 62 ++++++++++++++++++++ proton-c/bindings/cpp/src/connection.cpp | 11 +++- .../bindings/cpp/src/connection_options.cpp | 1 + proton-c/bindings/cpp/src/contexts.cpp | 1 + proton-c/bindings/cpp/src/endpoint.cpp | 3 +- proton-c/bindings/cpp/src/event.cpp | 9 +++ proton-c/bindings/cpp/src/handler.cpp | 13 ++-- proton-c/bindings/cpp/src/link.cpp | 11 +++- proton-c/bindings/cpp/src/messaging_adapter.cpp | 8 +-- proton-c/bindings/cpp/src/messaging_event.cpp | 13 ++++ proton-c/bindings/cpp/src/messaging_event.hpp | 18 +++--- proton-c/bindings/cpp/src/proton_event.cpp | 15 +++++ proton-c/bindings/cpp/src/proton_event.hpp | 2 + proton-c/bindings/cpp/src/session.cpp | 9 +++ proton-c/bindings/cpp/src/transport.cpp | 5 ++ 26 files changed, 260 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt index 59f4d5b..05b6361 100644 --- a/proton-c/bindings/cpp/CMakeLists.txt +++ b/proton-c/bindings/cpp/CMakeLists.txt @@ -33,6 +33,7 @@ set(qpid-proton-cpp-source src/blocking_link.cpp src/blocking_receiver.cpp src/blocking_sender.cpp + src/condition.cpp src/connection.cpp src/connection_options.cpp src/connector.cpp http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/condition.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/condition.hpp b/proton-c/bindings/cpp/include/proton/condition.hpp new file mode 100644 index 0000000..46d6e75 --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/condition.hpp @@ -0,0 +1,57 @@ +#ifndef PROTON_CPP_CONDITION_H +#define PROTON_CPP_CONDITION_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "proton/export.hpp" +#include "proton/value.hpp" + +#include <string> + +struct pn_condition_t; + +namespace proton { + +/** condition allows access to error or other special circumstance information */ +class condition +{ + public: + condition(pn_condition_t* c) : condition_(c) {} + + /** Assert no condition set */ + bool operator!() const; + /** Condition name */ + std::string name() const; + /** Descriptive string for condition */ + std::string description() const; + /** Extra information for condition n*/ + value info() const; + + /** Simple printable string for condition */ + std::string str() const; + + private: + pn_condition_t* condition_; +}; + +} + +#endif /*!PROTON_CPP_CONDITION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/connection.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/connection.hpp b/proton-c/bindings/cpp/include/proton/connection.hpp index 6cbd8c3..ec86bd7 100644 --- a/proton-c/bindings/cpp/include/proton/connection.hpp +++ b/proton-c/bindings/cpp/include/proton/connection.hpp @@ -35,13 +35,20 @@ struct pn_connection_t; namespace proton { class handler; +class engine; /** connection to a remote AMQP peer. */ -class connection : public object<pn_connection_t>, endpoint +class connection : public object<pn_connection_t>, public endpoint { public: connection(pn_connection_t* c=0) : object<pn_connection_t>(c) {} + /* Endpoint behaviours */ + + PN_CPP_EXTERN endpoint::state state() const; + PN_CPP_EXTERN condition local_condition() const; + PN_CPP_EXTERN condition remote_condition() const; + /// Get the container, throw an exception if this connection is not managed /// by a container. PN_CPP_EXTERN class container &container() const; @@ -90,9 +97,6 @@ class connection : public object<pn_connection_t>, endpoint /** Return sessions on this connection matching the state mask. */ PN_CPP_EXTERN session_range find_sessions(endpoint::state mask) const; - /** Get the endpoint state */ - PN_CPP_EXTERN endpoint::state state() const; - /// True if the connection is fully closed, i.e. local and remote ends are closed. bool closed() const { return (state()&LOCAL_CLOSED) && (state()&REMOTE_CLOSED); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/endpoint.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/endpoint.hpp b/proton-c/bindings/cpp/include/proton/endpoint.hpp index b440512..832548a 100644 --- a/proton-c/bindings/cpp/include/proton/endpoint.hpp +++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp @@ -22,16 +22,11 @@ * */ #include "proton/export.hpp" -#include "proton/connection.h" +#include "proton/condition.hpp" #include "proton/comparable.hpp" namespace proton { -class handler; -class connection; -class session; -class link; - /** endpoint is a base class for session, connection and link */ class endpoint { @@ -59,8 +54,11 @@ class endpoint PN_CPP_EXTERN static const state REMOTE_MASK; ///< Mask including all REMOTE_ bits (UNINIT, ACTIVE, CLOSED) ///@} - // TODO: condition, remote_condition, update_condition, get/handler + virtual condition local_condition() const = 0; + virtual condition remote_condition() const = 0; + + virtual ~endpoint() {} }; ///@cond INTERNAL http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/event.hpp b/proton-c/bindings/cpp/include/proton/event.hpp index 62dd9b0..641d553 100644 --- a/proton-c/bindings/cpp/include/proton/event.hpp +++ b/proton-c/bindings/cpp/include/proton/event.hpp @@ -45,8 +45,12 @@ class event { /// Get the container, throw an exception this event was not generated by a container. virtual PN_CPP_EXTERN class container& container() const; + /// Get transport + virtual PN_CPP_EXTERN class transport transport() const; /// Get connection. virtual PN_CPP_EXTERN class connection connection() const; + /// Get session. + virtual PN_CPP_EXTERN class session session() const; /// Get sender @throws error if no sender. virtual PN_CPP_EXTERN class sender sender() const; /// Get receiver @throws error if no receiver. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/handler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/handler.hpp b/proton-c/bindings/cpp/include/proton/handler.hpp index 207df7f..a681cff 100644 --- a/proton-c/bindings/cpp/include/proton/handler.hpp +++ b/proton-c/bindings/cpp/include/proton/handler.hpp @@ -22,13 +22,12 @@ * */ #include "proton/export.hpp" -#include "proton/event.h" -#include "proton/pn_unique_ptr.hpp" -#include <stdexcept> +#include "proton/pn_unique_ptr.hpp" namespace proton { +class condition; class event; class messaging_adapter; @@ -84,7 +83,7 @@ class handler PN_CPP_EXTERN virtual void on_timer(event &e); PN_CPP_EXTERN virtual void on_unhandled(event &e); - PN_CPP_EXTERN virtual void on_unhandled_error(event &e); + PN_CPP_EXTERN virtual void on_unhandled_error(event &e, const condition &c); ///@} private: http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/link.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/link.hpp b/proton-c/bindings/cpp/include/proton/link.hpp index f33d19c..f3c62ef 100644 --- a/proton-c/bindings/cpp/include/proton/link.hpp +++ b/proton-c/bindings/cpp/include/proton/link.hpp @@ -35,6 +35,7 @@ namespace proton { class sender; class receiver; +class condition; /** Messages are transferred across a link. Base class for sender, receiver. */ class link : public object<pn_link_t> , public endpoint @@ -42,6 +43,12 @@ class link : public object<pn_link_t> , public endpoint public: link(pn_link_t* l=0) : object<pn_link_t>(l) {} + /* Endpoint behaviours */ + + PN_CPP_EXTERN endpoint::state state() const; + PN_CPP_EXTERN condition local_condition() const; + PN_CPP_EXTERN condition remote_condition() const; + /** Locally open the link, not complete till messaging_handler::on_link_opened or * proton_handler::link_remote_open */ @@ -96,9 +103,6 @@ class link : public object<pn_link_t> , public endpoint /** Unset any custom handler */ PN_CPP_EXTERN void detach_handler(); - /** Get the endpoint state */ - PN_CPP_EXTERN endpoint::state state() const; - /** Get message data from current delivery on link */ PN_CPP_EXTERN ssize_t recv(char* buffer, size_t size); @@ -114,6 +118,7 @@ class link : public object<pn_link_t> , public endpoint PN_CPP_EXTERN void receiver_settle_mode(link_options::receiver_settle_mode); PN_CPP_EXTERN link_options::sender_settle_mode remote_sender_settle_mode(); PN_CPP_EXTERN link_options::receiver_settle_mode remote_receiver_settle_mode(); + }; /// An iterator for links. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/session.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/session.hpp b/proton-c/bindings/cpp/include/proton/session.hpp index 49ed5d2..e88273e 100644 --- a/proton-c/bindings/cpp/include/proton/session.hpp +++ b/proton-c/bindings/cpp/include/proton/session.hpp @@ -43,6 +43,12 @@ class session : public object<pn_session_t>, public endpoint public: session(pn_session_t* s=0) : object<pn_session_t>(s) {} + /* Endpoint behaviours */ + + PN_CPP_EXTERN endpoint::state state() const; + PN_CPP_EXTERN condition local_condition() const; + PN_CPP_EXTERN condition remote_condition() const; + /** Initiate local open, not complete till messaging_handler::on_session_opened() * or proton_handler::on_session_remote_open() */ @@ -76,9 +82,6 @@ class session : public object<pn_session_t>, public endpoint /** Create and open a receiver with target=addr and optional link options opts */ PN_CPP_EXTERN receiver open_receiver(const std::string &addr, const link_options &opts = link_options()); - /** Get the endpoint state */ - PN_CPP_EXTERN endpoint::state state() const; - /** Navigate the sessions in a connection - get next session with endpoint state*/ PN_CPP_EXTERN session next(endpoint::state) const; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/include/proton/transport.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/transport.hpp b/proton-c/bindings/cpp/include/proton/transport.hpp index 971913b..b3a9c6d 100644 --- a/proton-c/bindings/cpp/include/proton/transport.hpp +++ b/proton-c/bindings/cpp/include/proton/transport.hpp @@ -31,6 +31,7 @@ struct pn_transport_t; namespace proton { class connection; +class condition; class sasl; /** Represents a connection transport */ @@ -42,6 +43,7 @@ class transport : public object<pn_transport_t> PN_CPP_EXTERN class connection connection() const; PN_CPP_EXTERN class ssl ssl() const; PN_CPP_EXTERN class sasl sasl() const; + PN_CPP_EXTERN class condition condition() const; PN_CPP_EXTERN void unbind(); PN_CPP_EXTERN void bind(class connection &); PN_CPP_EXTERN uint32_t max_frame_size() const; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/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 fb95aaf..dacee75 100644 --- a/proton-c/bindings/cpp/src/blocking_fetcher.cpp +++ b/proton-c/bindings/cpp/src/blocking_fetcher.cpp @@ -37,7 +37,7 @@ void blocking_fetcher::on_message(event &e) { void blocking_fetcher::on_link_error(event &e) { link lnk = e.link(); - if (lnk.state() & PN_LOCAL_ACTIVE) { + if (lnk.state() & endpoint::LOCAL_ACTIVE) { lnk.close(); throw error(MSG("Link detached: " << lnk.name())); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/blocking_link.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/blocking_link.cpp b/proton-c/bindings/cpp/src/blocking_link.cpp index 262f6d0..2ec39b3 100644 --- a/proton-c/bindings/cpp/src/blocking_link.cpp +++ b/proton-c/bindings/cpp/src/blocking_link.cpp @@ -34,19 +34,19 @@ namespace proton { namespace { struct link_opened : public blocking_connection_impl::condition { link_opened(link l) : pn_link(l) {} - bool operator()() const { return !(pn_link.state() & PN_REMOTE_UNINIT); } + bool operator()() const { return !(pn_link.state() & endpoint::REMOTE_UNINIT); } link pn_link; }; struct link_closed : public blocking_connection_impl::condition { link_closed(link l) : pn_link(l) {} - bool operator()() const { return (pn_link.state() & PN_REMOTE_CLOSED); } + bool operator()() const { return (pn_link.state() & endpoint::REMOTE_CLOSED); } link pn_link; }; struct link_not_open : public blocking_connection_impl::condition { link_not_open(link l) : pn_link(l) {} - bool operator()() const { return !(pn_link.state() & PN_REMOTE_ACTIVE); } + bool operator()() const { return !(pn_link.state() & endpoint::REMOTE_ACTIVE); } link pn_link; }; @@ -69,7 +69,7 @@ void blocking_link::wait_for_closed() { } void blocking_link::check_closed() { - if (link_.state() & PN_REMOTE_CLOSED) { + if (link_.state() & endpoint::REMOTE_CLOSED) { link_.close(); throw error(MSG("Link detached: " << link_.name())); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/condition.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/condition.cpp b/proton-c/bindings/cpp/src/condition.cpp new file mode 100644 index 0000000..221afcd --- /dev/null +++ b/proton-c/bindings/cpp/src/condition.cpp @@ -0,0 +1,62 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "proton/condition.hpp" + +#include "proton/condition.h" + +namespace proton { + +bool condition::operator!() const { + return !pn_condition_is_set(condition_); +} + +std::string condition::name() const { + const char* n = pn_condition_get_name(condition_); + return n ? n : ""; +} + +std::string condition::description() const { + const char* d = pn_condition_get_description(condition_); + return d ? d : ""; +} + +value condition::info() const { + pn_data_t* t = pn_condition_info(condition_); + return t ? t : value(); +} + +std::string condition::str() const { + if (!*this) { + return "No error condition"; + } else { + const char* n = pn_condition_get_name(condition_); + const char* d = pn_condition_get_description(condition_); + std::string s; + if (n) s += n; + if (d) { + if (n) s += ": "; + s += d; + } + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/connection.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/connection.cpp b/proton-c/bindings/cpp/src/connection.cpp index 603fa91..36824de 100644 --- a/proton-c/bindings/cpp/src/connection.cpp +++ b/proton-c/bindings/cpp/src/connection.cpp @@ -18,8 +18,9 @@ * under the License. * */ -#include "proton/container.hpp" #include "proton/connection.hpp" + +#include "proton/container.hpp" #include "proton/transport.hpp" #include "proton/session.hpp" #include "proton/error.hpp" @@ -107,6 +108,14 @@ receiver connection::open_receiver(const std::string &addr, const link_options & endpoint::state connection::state() const { return pn_connection_state(pn_object()); } +condition connection::local_condition() const { + return condition(pn_connection_condition(pn_object())); +} + +condition connection::remote_condition() const { + return condition(pn_connection_remote_condition(pn_object())); +} + void connection::user(const std::string &name) { pn_connection_set_user(pn_object(), name.c_str()); } void connection::password(const std::string &pass) { pn_connection_set_password(pn_object(), pass.c_str()); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/connection_options.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/connection_options.cpp b/proton-c/bindings/cpp/src/connection_options.cpp index fe795b0..2751aaa 100644 --- a/proton-c/bindings/cpp/src/connection_options.cpp +++ b/proton-c/bindings/cpp/src/connection_options.cpp @@ -30,6 +30,7 @@ #include "messaging_adapter.hpp" #include "msg.hpp" +#include "proton/connection.h" #include "proton/transport.h" namespace proton { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/contexts.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/contexts.cpp b/proton-c/bindings/cpp/src/contexts.cpp index 4a7c569..ae4e9c1 100644 --- a/proton-c/bindings/cpp/src/contexts.cpp +++ b/proton-c/bindings/cpp/src/contexts.cpp @@ -24,6 +24,7 @@ #include "proton/error.hpp" +#include "proton/connection.h" #include "proton/object.h" #include "proton/link.h" #include "proton/message.h" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/endpoint.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/endpoint.cpp b/proton-c/bindings/cpp/src/endpoint.cpp index dcca7bc..5647c33 100644 --- a/proton-c/bindings/cpp/src/endpoint.cpp +++ b/proton-c/bindings/cpp/src/endpoint.cpp @@ -19,8 +19,9 @@ * */ -#include "proton/connection.hpp" #include "proton/endpoint.hpp" + +#include "proton/connection.hpp" #include "proton/session.hpp" #include "proton/link.hpp" #include "proton/transport.hpp" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/event.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/event.cpp b/proton-c/bindings/cpp/src/event.cpp index 6490584..ebd3434 100644 --- a/proton-c/bindings/cpp/src/event.cpp +++ b/proton-c/bindings/cpp/src/event.cpp @@ -27,6 +27,7 @@ #include "proton/event.hpp" #include "proton/receiver.hpp" #include "proton/sender.hpp" +#include "proton/transport.hpp" #include "msg.hpp" #include "contexts.hpp" @@ -42,10 +43,18 @@ container& event::container() const { throw error(MSG("No container context for event")); } +transport event::transport() const { + throw error(MSG("No transport context for event")); +} + connection event::connection() const { throw error(MSG("No connection context for event")); } +session event::session() const { + throw error(MSG("No session context for event")); +} + sender event::sender() const { throw error(MSG("No sender context for event")); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/handler.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/handler.cpp b/proton-c/bindings/cpp/src/handler.cpp index b08628d..90198b0 100644 --- a/proton-c/bindings/cpp/src/handler.cpp +++ b/proton-c/bindings/cpp/src/handler.cpp @@ -20,6 +20,8 @@ */ #include "proton/handler.hpp" +#include "proton/transport.hpp" + #include "proton_event.hpp" #include "messaging_adapter.hpp" @@ -40,15 +42,15 @@ void handler::on_message(event &e) { on_unhandled(e); } void handler::on_sendable(event &e) { on_unhandled(e); } void handler::on_timer(event &e) { on_unhandled(e); } void handler::on_transport_close(event &e) { on_unhandled(e); } -void handler::on_transport_error(event &e) { on_unhandled(e); } +void handler::on_transport_error(event &e) { on_unhandled_error(e, e.transport().condition()); } void handler::on_connection_close(event &e) { on_unhandled(e); } -void handler::on_connection_error(event &e) { on_unhandled(e); } +void handler::on_connection_error(event &e) { on_unhandled_error(e, e.connection().remote_condition()); } void handler::on_connection_open(event &e) { on_unhandled(e); } void handler::on_session_close(event &e) { on_unhandled(e); } -void handler::on_session_error(event &e) { on_unhandled(e); } +void handler::on_session_error(event &e) { on_unhandled_error(e, e.session().remote_condition()); } void handler::on_session_open(event &e) { on_unhandled(e); } void handler::on_link_close(event &e) { on_unhandled(e); } -void handler::on_link_error(event &e) { on_unhandled(e); } +void handler::on_link_error(event &e) { on_unhandled_error(e, e.link().remote_condition()); } void handler::on_link_open(event &e) { on_unhandled(e); } void handler::on_delivery_accept(event &e) { on_unhandled(e); } void handler::on_delivery_reject(event &e) { on_unhandled(e); } @@ -59,5 +61,6 @@ void handler::on_transaction_commit(event &e) { on_unhandled(e); } void handler::on_transaction_declare(event &e) { on_unhandled(e); } void handler::on_unhandled(event &) {} -void handler::on_unhandled_error(event &) {} +void handler::on_unhandled_error(event &, const condition& c) { throw std::runtime_error(c.str()); } + } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/link.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/link.cpp b/proton-c/bindings/cpp/src/link.cpp index 95eed21..e79b932 100644 --- a/proton-c/bindings/cpp/src/link.cpp +++ b/proton-c/bindings/cpp/src/link.cpp @@ -21,8 +21,9 @@ #include "proton/link.hpp" #include "proton/error.hpp" #include "proton/connection.hpp" -#include "container_impl.hpp" + #include "msg.hpp" +#include "container_impl.hpp" #include "contexts.hpp" #include "proton/connection.h" @@ -94,6 +95,14 @@ endpoint::state link::state() const { return pn_link_state(pn_object()); } +condition link::local_condition() const { + return condition(pn_link_condition(pn_object())); +} + +condition link::remote_condition() const { + return condition(pn_link_remote_condition(pn_object())); +} + ssize_t link::recv(char* buffer, size_t size) { return pn_link_recv(pn_object(), buffer, size); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/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 fcaf478..c2fe210 100644 --- a/proton-c/bindings/cpp/src/messaging_adapter.cpp +++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp @@ -28,12 +28,12 @@ #include "messaging_event.hpp" #include "msg.hpp" -#include "proton/link.h" -#include "proton/handlers.h" -#include "proton/delivery.h" #include "proton/connection.h" -#include "proton/session.h" +#include "proton/delivery.h" +#include "proton/handlers.h" +#include "proton/link.h" #include "proton/message.h" +#include "proton/session.h" #include "proton/transport.h" namespace proton { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/messaging_event.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_event.cpp b/proton-c/bindings/cpp/src/messaging_event.cpp index 9ee8d9a..96fcf78 100644 --- a/proton-c/bindings/cpp/src/messaging_event.cpp +++ b/proton-c/bindings/cpp/src/messaging_event.cpp @@ -24,6 +24,7 @@ #include "proton/handler.hpp" #include "proton/sender.hpp" #include "proton/receiver.hpp" +#include "proton/transport.hpp" #include "proton/error.hpp" #include "contexts.hpp" @@ -55,12 +56,24 @@ container& messaging_event::container() const { throw error(MSG("No container context for event")); } +transport messaging_event::transport() const { + if (parent_event_) + return parent_event_->transport(); + throw error(MSG("No transport context for event")); +} + connection messaging_event::connection() const { if (parent_event_) return parent_event_->connection(); throw error(MSG("No connection context for event")); } +session messaging_event::session() const { + if (parent_event_) + return parent_event_->session(); + throw error(MSG("No session context for event")); +} + sender messaging_event::sender() const { if (parent_event_) return parent_event_->sender(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/messaging_event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_event.hpp b/proton-c/bindings/cpp/src/messaging_event.hpp index b2f3c36..45f1594 100644 --- a/proton-c/bindings/cpp/src/messaging_event.hpp +++ b/proton-c/bindings/cpp/src/messaging_event.hpp @@ -71,15 +71,17 @@ class messaging_event : public event messaging_event(event_type t, pn_event_t*); ~messaging_event(); - PN_CPP_EXTERN class container& container() const; - PN_CPP_EXTERN class connection connection() const; - PN_CPP_EXTERN class sender sender() const; - PN_CPP_EXTERN class receiver receiver() const; - PN_CPP_EXTERN class link link() const; - PN_CPP_EXTERN class delivery delivery() const; - PN_CPP_EXTERN class message& message() const; + class container& container() const; + class transport transport() const; + class connection connection() const; + class session session() const; + class sender sender() const; + class receiver receiver() const; + class link link() const; + class delivery delivery() const; + class message& message() const; - PN_CPP_EXTERN event_type type() const; + event_type type() const; private: friend class messaging_adapter; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/proton_event.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/proton_event.cpp b/proton-c/bindings/cpp/src/proton_event.cpp index d7230da..c11d9fd 100644 --- a/proton-c/bindings/cpp/src/proton_event.cpp +++ b/proton-c/bindings/cpp/src/proton_event.cpp @@ -26,6 +26,7 @@ #include "proton/error.hpp" #include "proton/receiver.hpp" #include "proton/sender.hpp" +#include "proton/transport.hpp" #include "msg.hpp" #include "contexts.hpp" @@ -54,6 +55,13 @@ container& proton_event::container() const { return *container_; } +transport proton_event::transport() const { + pn_transport_t *t = pn_event_transport(pn_event()); + if (!t) + throw error(MSG("No transport context for this event")); + return t; +} + connection proton_event::connection() const { pn_connection_t *conn = pn_event_connection(pn_event()); if (!conn) @@ -61,6 +69,13 @@ connection proton_event::connection() const { return conn; } +session proton_event::session() const { + pn_session_t *sess = pn_event_session(pn_event()); + if (!sess) + throw error(MSG("No session context for this event")); + return sess; +} + link proton_event::link() const { class link lnk = pn_event_link(pn_event()); if (!lnk) throw error(MSG("No link context for this event")); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/proton_event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/proton_event.hpp b/proton-c/bindings/cpp/src/proton_event.hpp index 5bee7db..8dd2f8f 100644 --- a/proton-c/bindings/cpp/src/proton_event.hpp +++ b/proton-c/bindings/cpp/src/proton_event.hpp @@ -275,7 +275,9 @@ class proton_event void dispatch(proton_handler& h); class container& container() const; + class transport transport() const; class connection connection() const; + class session session() const; class sender sender() const; class receiver receiver() const; class link link() const; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/session.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/session.cpp b/proton-c/bindings/cpp/src/session.cpp index 6b3628d..3d27119 100644 --- a/proton-c/bindings/cpp/src/session.cpp +++ b/proton-c/bindings/cpp/src/session.cpp @@ -19,6 +19,7 @@ * */ #include "proton/session.hpp" + #include "proton/connection.h" #include "proton/session.h" #include "proton/session.hpp" @@ -77,6 +78,14 @@ session session::next(endpoint::state s) const endpoint::state session::state() const { return pn_session_state(pn_object()); } +condition session::local_condition() const { + return condition(pn_session_condition(pn_object())); +} + +condition session::remote_condition() const { + return condition(pn_session_remote_condition(pn_object())); +} + link_range session::find_links(endpoint::state mask) const { link_range r(connection().find_links(mask)); link_iterator i(r.begin(), *this); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/68369ac4/proton-c/bindings/cpp/src/transport.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/transport.cpp b/proton-c/bindings/cpp/src/transport.cpp index 4db78d0..dc608bf 100644 --- a/proton-c/bindings/cpp/src/transport.cpp +++ b/proton-c/bindings/cpp/src/transport.cpp @@ -19,6 +19,7 @@ * */ #include "proton/transport.hpp" +#include "proton/condition.hpp" #include "proton/connection.hpp" #include "proton/ssl.hpp" #include "proton/sasl.hpp" @@ -39,6 +40,10 @@ class sasl transport::sasl() const { return proton::sasl(pn_sasl(pn_object())); } +condition transport::condition() const { + return proton::condition(pn_transport_condition(pn_object())); +} + void transport::unbind() { if (pn_transport_unbind(pn_object())) throw error(MSG("transport::unbind failed " << pn_error_text(pn_transport_error(pn_object())))); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
