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: [C++ binding] endpoint changes: - Implement boolean state predicates: - uninitialized(), - local_active(), remote_active() - closed() - These are the only ones used in the current code, but may still need a bi
Date Mon, 18 Apr 2016 22:06:01 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 288b1a6f7 -> a5db6a1ed


PROTON-1180: [C++ binding] endpoint changes:
- Implement boolean state predicates:
  - uninitialized(),
  - local_active(), remote_active()
  - closed()
- These are the only ones used in the current code,
  but may still need a bit of consideration
- Raised close() to endpoint class
  - Needed to implement session::close() as it was never used
    so we didn't notice it wasn't implemented!


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

Branch: refs/heads/master
Commit: a5db6a1edc3c804de1bc59b512b3879e1329bb40
Parents: 288b1a6
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Mon Apr 18 18:01:08 2016 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Mon Apr 18 18:01:08 2016 -0400

----------------------------------------------------------------------
 examples/cpp/broker.hpp                         |  2 +-
 .../bindings/cpp/include/proton/connection.hpp  |  8 ++---
 .../bindings/cpp/include/proton/endpoint.hpp    | 35 +++++++-------------
 proton-c/bindings/cpp/include/proton/link.hpp   |  7 ++--
 .../bindings/cpp/include/proton/session.hpp     |  5 ++-
 proton-c/bindings/cpp/src/connection.cpp        |  2 --
 .../bindings/cpp/src/connection_options.cpp     |  2 +-
 proton-c/bindings/cpp/src/connector.cpp         |  2 +-
 proton-c/bindings/cpp/src/endpoint.cpp          | 32 +++++++++++++-----
 proton-c/bindings/cpp/src/engine_test.cpp       |  2 +-
 proton-c/bindings/cpp/src/link.cpp              |  4 ---
 proton-c/bindings/cpp/src/link_options.cpp      |  2 +-
 proton-c/bindings/cpp/src/session.cpp           |  7 ++--
 13 files changed, 57 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/examples/cpp/broker.hpp
----------------------------------------------------------------------
diff --git a/examples/cpp/broker.hpp b/examples/cpp/broker.hpp
index 92b7bb5..2797e55 100644
--- a/examples/cpp/broker.hpp
+++ b/examples/cpp/broker.hpp
@@ -205,7 +205,7 @@ class broker_handler : public proton::handler {
     void remove_stale_consumers(proton::connection connection) {
         proton::link_range r = connection.links();
         for (proton::link_iterator l = r.begin(); l != r.end(); ++l) {
-            if ((l->state() & proton::endpoint::REMOTE_ACTIVE) && !!l->sender())
+            if (!!l->sender() && l->remote_active())
                 unsubscribe(l->sender());
         }
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 a451a9f..9167d83 100644
--- a/proton-c/bindings/cpp/include/proton/connection.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -52,7 +52,10 @@ PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>,
publi
     connection() : internal::object<pn_connection_t>(0) {}
 
     /// Get the state of this connection.
-    PN_CPP_EXTERN endpoint::state state() const;
+    PN_CPP_EXTERN bool uninitialized() const;
+    PN_CPP_EXTERN bool local_active() const;
+    PN_CPP_EXTERN bool remote_active() const;
+    PN_CPP_EXTERN bool closed() const;
 
     PN_CPP_EXTERN class condition condition() const;
 
@@ -114,9 +117,6 @@ PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>,
publi
     /// XXX not yet discussed, why this convenience but not others?
     /// opened?  should this not be on endpoint?
     ///
-    /// 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);
}
     /// @endcond
 
     /// @cond INTERNAL

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 809c2a3..3f06ebd 100644
--- a/proton-c/bindings/cpp/include/proton/endpoint.hpp
+++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp
@@ -34,33 +34,22 @@ PN_CPP_CLASS_EXTERN endpoint {
   public:
     PN_CPP_EXTERN virtual ~endpoint();
 
-    /// A bit mask of state bit values.
-    ///
-    /// A state mask is matched against an endpoint as follows: If the
-    /// state mask contains both local and remote flags, then an exact
-    /// match against those flags is performed. If state contains only
-    /// local or only remote flags, then a match occurs if any of the
-    /// local or remote flags are set respectively.
-    ///
-    /// @see connection::links, connection::sessions
-    typedef int state;
-
-    // XXX use an enum instead to handle name collision
-
-    PN_CPP_EXTERN static const state LOCAL_UNINIT;  ///< Local endpoint is uninitialized
-    PN_CPP_EXTERN static const state REMOTE_UNINIT; ///< Remote endpoint is uninitialized
-    PN_CPP_EXTERN static const state LOCAL_ACTIVE;  ///< Local endpoint is active
-    PN_CPP_EXTERN static const state REMOTE_ACTIVE; ///< Remote endpoint is active
-    PN_CPP_EXTERN static const state LOCAL_CLOSED;  ///< Local endpoint has been closed
-    PN_CPP_EXTERN static const state REMOTE_CLOSED; ///< Remote endpoint has been closed
-    PN_CPP_EXTERN static const state LOCAL_MASK;    ///< Mask including all LOCAL_ bits
(UNINIT, ACTIVE, CLOSED)
-    PN_CPP_EXTERN static const state REMOTE_MASK;   ///< Mask including all REMOTE_ bits
(UNINIT, ACTIVE, CLOSED)
-
-    /// XXX add endpoint state boolean operations
+    /// True if the connection is uninitialized
+    virtual bool uninitialized() const = 0;
+    /// True if the local end is active
+    virtual bool local_active() const = 0;
+    /// True if the remote end is active
+    virtual bool remote_active() const = 0;
+    /// True if the connection is fully closed, i.e. local and remote
+    /// ends are closed.
+    virtual bool closed() const = 0;
 
     /// Get the error condition of the remote endpoint.
     virtual class condition condition() const = 0;
 
+    /// Close endpoint
+    virtual void close() = 0;
+
 #if PN_CPP_HAS_CPP11
     // Make everything explicit for C++11 compilers
     endpoint() = default;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 8e07704..9c7c32b 100644
--- a/proton-c/bindings/cpp/include/proton/link.hpp
+++ b/proton-c/bindings/cpp/include/proton/link.hpp
@@ -53,9 +53,10 @@ PN_CPP_CLASS_EXTERN link : public internal::object<pn_link_t> , public
endpoint
     link() : internal::object<pn_link_t>(0) {}
 
     // Endpoint behaviours
-
-    /// Get the state of this link.
-    PN_CPP_EXTERN endpoint::state state() const;
+    PN_CPP_EXTERN bool uninitialized() const;
+    PN_CPP_EXTERN bool local_active() const;
+    PN_CPP_EXTERN bool remote_active() const;
+    PN_CPP_EXTERN bool closed() const;
 
     PN_CPP_EXTERN class condition condition() const;
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 74ffc21..01daf32 100644
--- a/proton-c/bindings/cpp/include/proton/session.hpp
+++ b/proton-c/bindings/cpp/include/proton/session.hpp
@@ -50,7 +50,10 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>,
public endp
     // Endpoint behaviours
 
     /// Get the state of this session.
-    PN_CPP_EXTERN endpoint::state state() const;
+    PN_CPP_EXTERN bool uninitialized() const;
+    PN_CPP_EXTERN bool local_active() const;
+    PN_CPP_EXTERN bool remote_active() const;
+    PN_CPP_EXTERN bool closed() const;
 
     PN_CPP_EXTERN class condition condition() const;
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 089f750..9b5bf34 100644
--- a/proton-c/bindings/cpp/src/connection.cpp
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -106,8 +106,6 @@ receiver connection::open_receiver(const std::string &addr, const
link_options &
     return default_session().open_receiver(addr, opts);
 }
 
-endpoint::state connection::state() const { return pn_connection_state(pn_object()); }
-
 condition connection::condition() const {
     return pn_connection_remote_condition(pn_object());
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 c218d64..4a0956b 100644
--- a/proton-c/bindings/cpp/src/connection_options.cpp
+++ b/proton-c/bindings/cpp/src/connection_options.cpp
@@ -67,7 +67,7 @@ class connection_options::impl {
         pn_transport_t *pnt = pn_connection_transport(pnc);
         connector *outbound = dynamic_cast<connector*>(
             connection_context::get(c).handler.get());
-        bool uninit = (c.state() & endpoint::LOCAL_UNINIT);
+        bool uninit = c.uninitialized();
 
         // pnt is NULL between reconnect attempts.
         // Only apply transport options if uninit or outbound with

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/proton-c/bindings/cpp/src/connector.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connector.cpp b/proton-c/bindings/cpp/src/connector.cpp
index 66b51a6..3967ca4 100644
--- a/proton-c/bindings/cpp/src/connector.cpp
+++ b/proton-c/bindings/cpp/src/connector.cpp
@@ -93,7 +93,7 @@ void connector::on_transport_tail_closed(proton_event &e) {
 
 void connector::on_transport_closed(proton_event &e) {
     if (!connection_) return;
-    if (connection_.state() & endpoint::LOCAL_ACTIVE) {
+    if (connection_.local_active()) {
         if (reconnect_timer_) {
             e.connection().transport().unbind();
             transport_configured_ = false;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 9b9a3ab..86adc13 100644
--- a/proton-c/bindings/cpp/src/endpoint.cpp
+++ b/proton-c/bindings/cpp/src/endpoint.cpp
@@ -24,22 +24,36 @@
 #include "proton/connection.hpp"
 #include "proton/session.hpp"
 #include "proton/link.hpp"
-#include "proton/transport.hpp"
 
 #include "proton/connection.h"
 #include "proton/session.h"
 #include "proton/link.h"
 
+namespace {
+
+inline bool uninitialized(int state) { return state & PN_LOCAL_UNINIT; }
+inline bool local_active(int state) { return state & PN_LOCAL_ACTIVE; }
+inline bool remote_active(int state) { return state & PN_REMOTE_ACTIVE; }
+inline bool closed(int state) { return (state & PN_LOCAL_CLOSED) && (state &
PN_REMOTE_CLOSED); }
+
+}
+
 namespace proton {
 
-const int endpoint::LOCAL_UNINIT = PN_LOCAL_UNINIT;
-const int endpoint::REMOTE_UNINIT = PN_REMOTE_UNINIT;
-const int endpoint::LOCAL_ACTIVE = PN_LOCAL_ACTIVE;
-const int endpoint::REMOTE_ACTIVE = PN_REMOTE_ACTIVE;
-const int endpoint::LOCAL_CLOSED = PN_LOCAL_CLOSED;
-const int endpoint::REMOTE_CLOSED = PN_REMOTE_CLOSED;
-const int endpoint::LOCAL_MASK = PN_LOCAL_MASK;
-const int endpoint::REMOTE_MASK = PN_REMOTE_MASK;
+bool connection::uninitialized() const { return ::uninitialized(pn_connection_state(pn_object()));
}
+bool connection::local_active() const { return ::local_active(pn_connection_state(pn_object()));
}
+bool connection::remote_active() const { return ::remote_active(pn_connection_state(pn_object()));
}
+bool connection::closed() const { return ::closed(pn_connection_state(pn_object())); }
+
+bool session::uninitialized() const { return ::uninitialized(pn_session_state(pn_object()));
}
+bool session::local_active() const { return ::local_active(pn_session_state(pn_object()));
}
+bool session::remote_active() const { return ::remote_active(pn_session_state(pn_object()));
}
+bool session::closed() const { return ::closed(pn_session_state(pn_object())); }
+
+bool link::uninitialized() const { return ::uninitialized(pn_link_state(pn_object())); }
+bool link::local_active() const { return ::local_active(pn_link_state(pn_object())); }
+bool link::remote_active() const { return ::remote_active(pn_link_state(pn_object())); }
+bool link::closed() const { return ::closed(pn_link_state(pn_object())); }
 
 endpoint::~endpoint() {}
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 99a003e..cca4e60 100644
--- a/proton-c/bindings/cpp/src/engine_test.cpp
+++ b/proton-c/bindings/cpp/src/engine_test.cpp
@@ -222,7 +222,7 @@ void test_transport_close() {
     record_handler ha, hb;
     engine_pair e(ha, hb);
     e.a.connection().open();
-    while (!e.a.connection().state() & endpoint::REMOTE_ACTIVE) e.process();
+    while (!e.a.connection().remote_active()) e.process();
 
     e.a.close("oops", "engine failure");
     // Closed but we still have output data to flush so a.dispatch() is true.

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

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/proton-c/bindings/cpp/src/link_options.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/link_options.cpp b/proton-c/bindings/cpp/src/link_options.cpp
index 2fecf3a..136d6a8 100644
--- a/proton-c/bindings/cpp/src/link_options.cpp
+++ b/proton-c/bindings/cpp/src/link_options.cpp
@@ -77,7 +77,7 @@ class link_options::impl {
     option<int> credit_window;
 
     void apply(link& l) {
-        if (l.state() & endpoint::LOCAL_UNINIT) {
+        if (l.uninitialized()) {
             bool sender = !l.receiver();
             if (local_address.set) {
                 if (sender)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5db6a1e/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 6deca10..a6fed21 100644
--- a/proton-c/bindings/cpp/src/session.cpp
+++ b/proton-c/bindings/cpp/src/session.cpp
@@ -36,6 +36,11 @@ void session::open() {
     pn_session_open(pn_object());
 }
 
+void session::close()
+{
+    pn_session_close(pn_object());
+}
+
 container& session::container() const {
     return connection().container();
 }
@@ -65,8 +70,6 @@ receiver session::open_receiver(const std::string &addr, const link_options
&lo)
     return rcv;
 }
 
-endpoint::state session::state() const { return pn_session_state(pn_object()); }
-
 condition session::condition() const {
     return pn_session_remote_condition(pn_object());
 }


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


Mime
View raw message