qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject qpid-proton git commit: PROTON-1180, PROTON-1179: Finish endpoint work, most of the condition work - Renamed condition -> error_condition - renamed all accessors for error_condition to error() - Made error_condition a value class holding the same informa
Date Thu, 21 Apr 2016 00:07:57 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master f1e2428ba -> 13364ad50


PROTON-1180, PROTON-1179: Finish endpoint work, most of the condition work
- Renamed condition -> error_condition
- renamed all accessors for error_condition to error()
- Made error_condition a value class holding the same information
  as the pn_condition_t it is made from.
- Added close(const error_condition&) to endpoint
- Enabled tests for endpoint::close(const error_condition&)
x Can't yet set the properties on an error_condition in a close()


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/13364ad5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/13364ad5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/13364ad5

Branch: refs/heads/master
Commit: 13364ad50e1f276def4487d8f54d6486619ec785
Parents: f1e2428
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Tue Apr 19 16:03:37 2016 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Wed Apr 20 20:02:39 2016 -0400

----------------------------------------------------------------------
 examples/cpp/broker.hpp                         |  4 +-
 proton-c/bindings/cpp/CMakeLists.txt            |  2 +-
 .../bindings/cpp/include/proton/condition.hpp   | 92 --------------------
 .../bindings/cpp/include/proton/connection.hpp  |  6 +-
 .../bindings/cpp/include/proton/endpoint.hpp    |  5 +-
 .../cpp/include/proton/error_condition.hpp      | 91 +++++++++++++++++++
 .../bindings/cpp/include/proton/handler.hpp     |  4 +-
 .../cpp/include/proton/io/connection_engine.hpp |  2 +-
 proton-c/bindings/cpp/include/proton/link.hpp   |  8 +-
 .../bindings/cpp/include/proton/session.hpp     |  7 +-
 .../bindings/cpp/include/proton/transport.hpp   |  4 +-
 proton-c/bindings/cpp/src/condition.cpp         | 65 --------------
 proton-c/bindings/cpp/src/connection.cpp        |  4 +-
 proton-c/bindings/cpp/src/endpoint.cpp          | 22 +++++
 proton-c/bindings/cpp/src/engine_test.cpp       | 62 +++++++------
 proton-c/bindings/cpp/src/error_condition.cpp   | 87 ++++++++++++++++++
 proton-c/bindings/cpp/src/handler.cpp           | 12 +--
 proton-c/bindings/cpp/src/link.cpp              |  2 +-
 proton-c/bindings/cpp/src/session.cpp           |  2 +-
 proton-c/bindings/cpp/src/transport.cpp         | 10 +--
 20 files changed, 273 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/examples/cpp/broker.hpp
----------------------------------------------------------------------
diff --git a/examples/cpp/broker.hpp b/examples/cpp/broker.hpp
index 8f16e61..8d08f2a 100644
--- a/examples/cpp/broker.hpp
+++ b/examples/cpp/broker.hpp
@@ -195,10 +195,10 @@ class broker_handler : public proton::handler {
     }
 
     void on_transport_error(proton::transport &t) override {
-        std::cout << "broker client disconnect: " << t.condition().what() <<
std::endl;
+        std::cout << "broker client disconnect: " << t.error().what() <<
std::endl;
     }
 
-    void on_unhandled_error(const proton::condition &c) override {
+    void on_unhandled_error(const proton::error_condition &c) override {
         std::cerr << "broker error: " << c.what() << std::endl;
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index 2549547..070728f 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -28,7 +28,6 @@ set(qpid-proton-cpp-source
   src/acceptor.cpp
   src/binary.cpp
   src/byte_array.cpp
-  src/condition.cpp
   src/connection.cpp
   src/connection_options.cpp
   src/connector.cpp
@@ -43,6 +42,7 @@ set(qpid-proton-cpp-source
   src/encoder.cpp
   src/endpoint.cpp
   src/error.cpp
+  src/error_condition.cpp
   src/handler.cpp
   src/id_generator.cpp
   src/io/connection_engine.cpp

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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
deleted file mode 100644
index 9a350f8..0000000
--- a/proton-c/bindings/cpp/include/proton/condition.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-#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 "proton/config.hpp"
-
-#include <string>
-
-struct pn_condition_t;
-
-namespace proton {
-
-/// Describes an endpoint error state.
-///
-/// This class has only one purpose: it can be used to get access to information about why
-/// an endpoint (a link, session, connection) or a transport has closed.
-///
-/// The information that is requuired (for instance the condition name and/or description)
-/// should be extracted immediately from the condition in order to enforce this conditions
-/// cannot be copied or assigned.
-class condition {
-    /// @cond INTERNAL
-    condition(pn_condition_t* c) : condition_(c) {}
-    /// @endcond
-
-  public:
-#if PN_CPP_HAS_CPP11
-    condition() = delete;
-    condition(const condition&) = delete;
-    condition(condition&&) = default;
-    condition& operator=(const condition&) = delete;
-    condition& operator=(condition&&) = delete;
-#endif
-
-    /// No condition set.
-    PN_CPP_EXTERN bool operator!() const;
-
-    /// XXX add C++11 explicit bool conversion with a note about
-    /// C++11-only usage
-
-    /// No condition has been set.
-    PN_CPP_EXTERN bool empty() const;
-
-    /// Condition name.
-    PN_CPP_EXTERN std::string name() const;
-
-    /// Descriptive string for condition.
-    PN_CPP_EXTERN std::string description() const;
-
-    /// Extra information for condition.
-    PN_CPP_EXTERN value properties() const;
-
-    /// Simple printable string for condition.
-    PN_CPP_EXTERN std::string what() const;
-
-    /// @cond INTERNAL
-  private:
-    pn_condition_t* const condition_;
-
-    friend class transport;
-    friend class connection;
-    friend class session;
-    friend class link;
-    /// @endcond
-};
-
-}
-
-#endif // PROTON_CPP_CONDITION_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 586b327..9a1feab 100644
--- a/proton-c/bindings/cpp/include/proton/connection.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -56,7 +56,7 @@ PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>,
publi
     PN_CPP_EXTERN bool active() const;
     PN_CPP_EXTERN bool closed() const;
 
-    PN_CPP_EXTERN class condition condition() const;
+    PN_CPP_EXTERN class error_condition error() const;
 
     /// Get the container.
     ///
@@ -84,6 +84,10 @@ PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>,
publi
     /// handler::on_connection_close().
     PN_CPP_EXTERN void close();
 
+    /// Initiate close with an error condition.
+    /// The operation is not complete till handler::on_connection_close().
+    PN_CPP_EXTERN void close(const error_condition&);
+
     /// @cond INTERNAL
     /// XXX undiscussed
     /// Release link and session resources of this connection.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 b0f1d55..b4d7034 100644
--- a/proton-c/bindings/cpp/include/proton/endpoint.hpp
+++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp
@@ -23,7 +23,7 @@
  */
 #include "proton/config.hpp"
 #include "proton/export.hpp"
-#include "proton/condition.hpp"
+#include "proton/error_condition.hpp"
 #include "proton/comparable.hpp"
 
 namespace proton {
@@ -43,10 +43,11 @@ PN_CPP_CLASS_EXTERN endpoint {
     virtual bool closed() const = 0;
 
     /// Get the error condition of the remote endpoint.
-    virtual class condition condition() const = 0;
+    virtual class error_condition error() const = 0;
 
     /// Close endpoint
     virtual void close() = 0;
+    virtual void close(const error_condition&) = 0;
 
 #if PN_CPP_HAS_CPP11
     // Make everything explicit for C++11 compilers

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/proton-c/bindings/cpp/include/proton/error_condition.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/error_condition.hpp b/proton-c/bindings/cpp/include/proton/error_condition.hpp
new file mode 100644
index 0000000..0d109dc
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/error_condition.hpp
@@ -0,0 +1,91 @@
+#ifndef PROTON_CPP_ERROR_CONDITION_H
+#define PROTON_CPP_ERROR_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 "proton/config.hpp"
+
+#include <string>
+
+struct pn_condition_t;
+
+namespace proton {
+
+/// Describes an endpoint error state.
+class error_condition {
+    /// @cond INTERNAL
+    error_condition(pn_condition_t* c);
+    /// @endcond
+
+  public:
+    error_condition() {}
+    PN_CPP_EXTERN error_condition(std::string description);
+    PN_CPP_EXTERN error_condition(std::string name, std::string description);
+    PN_CPP_EXTERN error_condition(std::string name, std::string description, proton::value
properties);
+
+#if PN_CPP_HAS_CPP11
+    error_condition(const error_condition&) = default;
+    error_condition(error_condition&&) = default;
+    error_condition& operator=(const error_condition&) = default;
+    error_condition& operator=(error_condition&&) = default;
+#endif
+
+    /// No condition set.
+    PN_CPP_EXTERN bool operator!() const;
+
+    /// XXX add C++11 explicit bool conversion with a note about
+    /// C++11-only usage
+
+    /// No condition has been set.
+    PN_CPP_EXTERN bool empty() const;
+
+    /// Condition name.
+    PN_CPP_EXTERN std::string name() const;
+
+    /// Descriptive string for condition.
+    PN_CPP_EXTERN std::string description() const;
+
+    /// Extra information for condition.
+    PN_CPP_EXTERN value properties() const;
+
+    /// Simple printable string for condition.
+    PN_CPP_EXTERN std::string what() const;
+
+    /// @cond INTERNAL
+  private:
+    std::string name_;
+    std::string description_;
+    proton::value properties_;
+
+    friend class transport;
+    friend class connection;
+    friend class session;
+    friend class link;
+    /// @endcond
+};
+
+}
+
+#endif // PROTON_CPP_ERROR_CONDITION_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 fa81454..ff50b37 100644
--- a/proton-c/bindings/cpp/include/proton/handler.hpp
+++ b/proton-c/bindings/cpp/include/proton/handler.hpp
@@ -28,7 +28,7 @@
 
 namespace proton {
 
-class condition;
+class error_condition;
 class container;
 class event;
 class transport;
@@ -138,7 +138,7 @@ PN_CPP_CLASS_EXTERN handler
     /// @endcond
 
     /// Fallback error handling.
-    PN_CPP_EXTERN virtual void on_unhandled_error(const condition &c);
+    PN_CPP_EXTERN virtual void on_unhandled_error(const error_condition &c);
 
     /// @}
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp b/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
index 3192d44..42ab06e 100644
--- a/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
+++ b/proton-c/bindings/cpp/include/proton/io/connection_engine.hpp
@@ -20,10 +20,10 @@
  * under the License.
  */
 
-#include "proton/condition.hpp"
 #include "proton/connection.hpp"
 #include "proton/connection_options.hpp"
 #include "proton/error.hpp"
+#include "proton/error_condition.hpp"
 #include "proton/export.hpp"
 #include "proton/pn_unique_ptr.hpp"
 #include "proton/transport.hpp"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 0d9a92c..a9c5edc 100644
--- a/proton-c/bindings/cpp/include/proton/link.hpp
+++ b/proton-c/bindings/cpp/include/proton/link.hpp
@@ -38,7 +38,7 @@ namespace proton {
 
 class sender;
 class receiver;
-class condition;
+class error_condition;
 class link_context;
 
 /// A named channel for sending or receiving messages.  It is the base
@@ -57,7 +57,7 @@ PN_CPP_CLASS_EXTERN link : public internal::object<pn_link_t> , public
endpoint
     PN_CPP_EXTERN bool active() const;
     PN_CPP_EXTERN bool closed() const;
 
-    PN_CPP_EXTERN class condition condition() const;
+    PN_CPP_EXTERN class error_condition error() const;
 
     /// Locally open the link.  The operation is not complete till
     /// handler::on_link_open.
@@ -67,6 +67,10 @@ PN_CPP_CLASS_EXTERN link : public internal::object<pn_link_t> , public
endpoint
     /// handler::on_link_close.
     PN_CPP_EXTERN void close();
 
+    /// Initiate close with an error condition.
+    /// The operation is not complete till handler::on_connection_close().
+    PN_CPP_EXTERN void close(const error_condition&);
+
     /// Suspend the link without closing it.  A suspended link may be
     /// reopened with the same or different link options if supported by
     /// the peer. A suspended durable subscriptions becomes inactive

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 73e75d6..5321221 100644
--- a/proton-c/bindings/cpp/include/proton/session.hpp
+++ b/proton-c/bindings/cpp/include/proton/session.hpp
@@ -54,7 +54,7 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>,
public endp
     PN_CPP_EXTERN bool active() const;
     PN_CPP_EXTERN bool closed() const;
 
-    PN_CPP_EXTERN class condition condition() const;
+    PN_CPP_EXTERN class error_condition error() const;
 
     /// @cond INTERNAL
     /// XXX needs to take connection options
@@ -67,6 +67,11 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>,
public endp
     /// handler::on_session_close().
     PN_CPP_EXTERN void close();
 
+    /// Initiate close with an error condition.
+    /// The operation is not complete till handler::on_connection_close().
+    PN_CPP_EXTERN void close(const error_condition&);
+
+
     /// Return the container for this session
     PN_CPP_EXTERN class container &container() const;
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 a6d7570..b29f480 100644
--- a/proton-c/bindings/cpp/include/proton/transport.hpp
+++ b/proton-c/bindings/cpp/include/proton/transport.hpp
@@ -31,7 +31,7 @@ struct pn_transport_t;
 namespace proton {
 
 class connection;
-class condition;
+class error_condition;
 class sasl;
 
 namespace io {
@@ -56,7 +56,7 @@ class transport : public internal::object<pn_transport_t> {
     PN_CPP_EXTERN class sasl sasl() const;
 
     /// Get the error condition.
-    PN_CPP_EXTERN class condition condition() const;
+    PN_CPP_EXTERN class error_condition error() const;
 
     /// @cond INTERNAL
     /// XXX need to discuss, local versus remote

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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
deleted file mode 100644
index 391c12e..0000000
--- a/proton-c/bindings/cpp/src/condition.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *
- * 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_);
-}
-
-bool condition::empty() 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::properties() const {
-    pn_data_t* t = pn_condition_info(condition_);
-    return t ? value(t) : value();
-}
-
-std::string condition::what() 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/13364ad5/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 9b5bf34..b1d296f 100644
--- a/proton-c/bindings/cpp/src/connection.cpp
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -71,7 +71,7 @@ std::string connection::container_id() const {
 container& connection::container() const {
     pn_reactor_t *r = pn_object_reactor(pn_object());
     if (!r)
-        throw error("connection does not have a container");
+        throw proton::error("connection does not have a container");
     return container_context::get(r);
 }
 
@@ -106,7 +106,7 @@ receiver connection::open_receiver(const std::string &addr, const
link_options &
     return default_session().open_receiver(addr, opts);
 }
 
-condition connection::condition() const {
+error_condition connection::error() const {
     return pn_connection_remote_condition(pn_object());
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 2cd55c3..c70edbf 100644
--- a/proton-c/bindings/cpp/src/endpoint.cpp
+++ b/proton-c/bindings/cpp/src/endpoint.cpp
@@ -22,6 +22,7 @@
 #include "proton/endpoint.hpp"
 
 #include "proton/connection.hpp"
+#include "proton/error_condition.hpp"
 #include "proton/session.hpp"
 #include "proton/link.hpp"
 
@@ -35,6 +36,21 @@ inline bool uninitialized(int state) { return state & PN_LOCAL_UNINIT;
}
 inline bool active(int state) { return state & PN_LOCAL_ACTIVE; }
 inline bool closed(int state) { return (state & PN_LOCAL_CLOSED) && (state &
PN_REMOTE_CLOSED); }
 
+inline void set_condition(pn_condition_t *c, const proton::error_condition &e) {
+    pn_condition_clear(c);
+
+    if (!e.name().empty()) {
+        pn_condition_set_name(c, e.name().c_str());
+    }
+    if (!e.description().empty()) {
+        pn_condition_set_description(c, e.description().c_str());
+    }
+    // TODO: This is wrong as it copies the value so doesn't change
+    // The internals of c
+    //proton::value v(pn_condition_info(c));
+    //v = e.properties();
+}
+
 }
 
 namespace proton {
@@ -43,14 +59,20 @@ bool connection::uninitialized() const { return ::uninitialized(pn_connection_st
 bool connection::active() const { return ::active(pn_connection_state(pn_object())); }
 bool connection::closed() const { return ::closed(pn_connection_state(pn_object())); }
 
+void connection::close(const error_condition& condition) { ::set_condition(pn_connection_condition(pn_object()),
condition); close(); }
+
 bool session::uninitialized() const { return ::uninitialized(pn_session_state(pn_object()));
}
 bool session::active() const { return ::active(pn_session_state(pn_object())); }
 bool session::closed() const { return ::closed(pn_session_state(pn_object())); }
 
+void session::close(const error_condition& condition) { ::set_condition(pn_session_condition(pn_object()),
condition); close(); }
+
 bool link::uninitialized() const { return ::uninitialized(pn_link_state(pn_object())); }
 bool link::active() const { return ::active(pn_link_state(pn_object())); }
 bool link::closed() const { return ::closed(pn_link_state(pn_object())); }
 
+void link::close(const error_condition& condition) { ::set_condition(pn_link_condition(pn_object()),
condition); close(); }
+
 endpoint::~endpoint() {}
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/proton-c/bindings/cpp/src/engine_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/engine_test.cpp b/proton-c/bindings/cpp/src/engine_test.cpp
index 8ff1380..319f25e 100644
--- a/proton-c/bindings/cpp/src/engine_test.cpp
+++ b/proton-c/bindings/cpp/src/engine_test.cpp
@@ -111,7 +111,7 @@ struct record_handler : public handler {
         sessions.push_back(s);
     }
 
-    void on_unhandled_error(const condition& c) override {
+    void on_unhandled_error(const proton::error_condition& c) override {
         errors.push_back(c.what());
     }
 };
@@ -186,35 +186,33 @@ void test_container_prefix() {
 void test_endpoint_close() {
     // Make sure conditions are sent to the remote end.
 
-    // FIXME aconway 2016-03-22: re-enable these tests when we can set error conditions.
-
-    // record_handler ha, hb;
-    // engine_pair e(ha, hb);
-    // e.a.connection().open();
-    // e.a.connection().open_sender("x");
-    // e.a.connection().open_receiver("y");
-    // while (ha.links.size() < 2 || hb.links.size() < 2) e.process();
-    // link ax = quick_pop(ha.links), ay = quick_pop(ha.links);
-    // link bx = quick_pop(hb.links), by = quick_pop(hb.links);
-
-    // // Close a link
-    // ax.close(condition("err", "foo bar"));
-    // while (!(bx.state() & endpoint::REMOTE_CLOSED)) e.process();
-    // condition c = bx.remote_condition();
-    // ASSERT_EQUAL("err", c.name());
-    // ASSERT_EQUAL("foo bar", c.description());
-    // ASSERT_EQUAL("err: foo bar", ax.local_condition().what());
-
-    // // Close a link with an empty condition
-    // ay.close(condition());
-    // while (!(by.state() & endpoint::REMOTE_CLOSED)) e.process();
-    // ASSERT(by.remote_condition().empty());
-
-    // // Close a connection
-    // connection ca = e.a.connection(), cb = e.b.connection();
-    // ca.close(condition("conn", "bad connection"));
-    // while (!cb.closed()) e.process();
-    // ASSERT_EQUAL("conn: bad connection", cb.remote_condition().what());
+    record_handler ha, hb;
+    engine_pair e(ha, hb);
+    e.a.connection().open();
+    e.a.connection().open_sender("x");
+    e.a.connection().open_receiver("y");
+    while (ha.links.size() < 2 || hb.links.size() < 2) e.process();
+    link ax = quick_pop(ha.links), ay = quick_pop(ha.links);
+    link bx = quick_pop(hb.links), by = quick_pop(hb.links);
+
+    // Close a link
+    ax.close(proton::error_condition("err", "foo bar"));
+    while (!bx.closed()) e.process();
+    proton::error_condition c = bx.error();
+    ASSERT_EQUAL("err", c.name());
+    ASSERT_EQUAL("foo bar", c.description());
+    ASSERT_EQUAL("err: foo bar", c.what());
+
+    // Close a link with an empty condition
+    ay.close(proton::error_condition());
+    while (!by.closed()) e.process();
+    ASSERT(by.error().empty());
+
+    // Close a connection
+    connection ca = e.a.connection(), cb = e.b.connection();
+    ca.close(proton::error_condition("conn", "bad connection"));
+    while (!cb.closed()) e.process();
+    ASSERT_EQUAL("conn: bad connection", cb.error().what());
 }
 
 void test_transport_close() {
@@ -230,8 +228,8 @@ void test_transport_close() {
     while (!e.b.connection().closed()) e.process();
     ASSERT_EQUAL(1, hb.errors.size());
     ASSERT_EQUAL("oops: engine failure", hb.errors.front());
-    ASSERT_EQUAL("oops", e.b.connection().condition().name());
-    ASSERT_EQUAL("engine failure", e.b.connection().condition().description());
+    ASSERT_EQUAL("oops", e.b.connection().error().name());
+    ASSERT_EQUAL("engine failure", e.b.connection().error().description());
 }
 
 int main(int, char**) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/proton-c/bindings/cpp/src/error_condition.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/error_condition.cpp b/proton-c/bindings/cpp/src/error_condition.cpp
new file mode 100644
index 0000000..247941f
--- /dev/null
+++ b/proton-c/bindings/cpp/src/error_condition.cpp
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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/error_condition.hpp"
+#include "proton/condition.h"
+namespace {
+inline std::string safe_convert(const char* s) {
+    return s ? s : std::string();
+}
+}
+
+namespace proton {
+
+error_condition::error_condition(pn_condition_t* c) :
+    name_(safe_convert(pn_condition_get_name(c))),
+    description_(safe_convert(pn_condition_get_description(c))),
+    properties_(pn_condition_info(c))
+{}
+
+
+error_condition::error_condition(std::string description) :
+    name_("proton:io:error"),
+    description_(description)
+{}
+
+error_condition::error_condition(std::string name, std::string description) :
+    name_(name),
+    description_(description)
+{}
+
+error_condition::error_condition(std::string name, std::string description, value properties)
:
+    name_(name),
+    description_(description),
+    properties_(properties)
+{}
+
+bool error_condition::operator!() const {
+    return name_.empty();
+}
+
+bool error_condition::empty() const {
+    return name_.empty();
+}
+
+std::string error_condition::name() const {
+    return name_;
+}
+
+std::string error_condition::description() const {
+    return description_;
+}
+
+value error_condition::properties() const {
+    return properties_;
+}
+
+std::string error_condition::what() const {
+    if (!*this) {
+        return "No error condition";
+    } else {
+      std::string s(name_);
+      if (!description_.empty()) {
+          s += ": ";
+          s += description_;
+      }
+      return s;
+    }
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 d7d43d2..d46b880 100644
--- a/proton-c/bindings/cpp/src/handler.cpp
+++ b/proton-c/bindings/cpp/src/handler.cpp
@@ -41,18 +41,18 @@ void handler::on_message(delivery &, message &) {}
 void handler::on_sendable(sender &) {}
 void handler::on_timer(container &) {}
 void handler::on_transport_close(transport &) {}
-void handler::on_transport_error(transport &t) { on_unhandled_error(t.condition()); }
+void handler::on_transport_error(transport &t) { on_unhandled_error(t.error()); }
 void handler::on_connection_close(connection &) {}
-void handler::on_connection_error(connection &c) { on_unhandled_error(c.condition());
}
+void handler::on_connection_error(connection &c) { on_unhandled_error(c.error()); }
 void handler::on_connection_open(connection &) {}
 void handler::on_session_close(session &) {}
-void handler::on_session_error(session &s) { on_unhandled_error(s.condition()); }
+void handler::on_session_error(session &s) { on_unhandled_error(s.error()); }
 void handler::on_session_open(session &) {}
 void handler::on_receiver_close(receiver &) {}
-void handler::on_receiver_error(receiver &l) { on_unhandled_error(l.condition()); }
+void handler::on_receiver_error(receiver &l) { on_unhandled_error(l.error()); }
 void handler::on_receiver_open(receiver &) {}
 void handler::on_sender_close(sender &) {}
-void handler::on_sender_error(sender &l) { on_unhandled_error(l.condition()); }
+void handler::on_sender_error(sender &l) { on_unhandled_error(l.error()); }
 void handler::on_sender_open(sender &) {}
 void handler::on_tracker_accept(tracker &) {}
 void handler::on_tracker_reject(tracker &) {}
@@ -60,6 +60,6 @@ void handler::on_tracker_release(tracker &) {}
 void handler::on_tracker_settle(tracker &) {}
 void handler::on_delivery_settle(delivery &) {}
 
-void handler::on_unhandled_error(const condition& c) { throw proton::error(c.what());
}
+void handler::on_unhandled_error(const error_condition& c) { throw proton::error(c.what());
}
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 b6e268b..8798694 100644
--- a/proton-c/bindings/cpp/src/link.cpp
+++ b/proton-c/bindings/cpp/src/link.cpp
@@ -99,7 +99,7 @@ void link::detach_handler() {
     pn_record_set_handler(record, 0);
 }
 
-condition link::condition() const {
+error_condition link::error() const {
     return pn_link_remote_condition(pn_object());
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 a6fed21..24bbb72 100644
--- a/proton-c/bindings/cpp/src/session.cpp
+++ b/proton-c/bindings/cpp/src/session.cpp
@@ -70,7 +70,7 @@ receiver session::open_receiver(const std::string &addr, const link_options
&lo)
     return rcv;
 }
 
-condition session::condition() const {
+error_condition session::error() const {
     return pn_session_remote_condition(pn_object());
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13364ad5/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 cbaab6e..a788816 100644
--- a/proton-c/bindings/cpp/src/transport.cpp
+++ b/proton-c/bindings/cpp/src/transport.cpp
@@ -21,7 +21,7 @@
 
 #include "proton/error.hpp"
 #include "proton/transport.hpp"
-#include "proton/condition.hpp"
+#include "proton/error_condition.hpp"
 #include "proton/connection.hpp"
 #include "proton/ssl.hpp"
 #include "proton/sasl.hpp"
@@ -45,18 +45,18 @@ class sasl transport::sasl() const {
     return pn_sasl(pn_object());
 }
 
-condition transport::condition() const {
-    return proton::condition(pn_transport_condition(pn_object()));
+error_condition transport::error() const {
+    return proton::error_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()))));
+        throw proton::error(MSG("transport::unbind failed " << pn_error_text(pn_transport_error(pn_object()))));
 }
 
 void transport::bind(class connection &conn) {
     if (pn_transport_bind(pn_object(), conn.pn_object()))
-        throw error(MSG("transport::bind failed " << pn_error_text(pn_transport_error(pn_object()))));
+        throw proton::error(MSG("transport::bind failed " << pn_error_text(pn_transport_error(pn_object()))));
 }
 
 uint32_t transport::max_frame_size() const {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message