PROTON-1400: [C++ binding] Change semantic for incoming xx_open
- If not overridden then you get automatic outgoing matching xx_open
- If overridden then it is assumed you will handle the outgoing open
  yourself.


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

Branch: refs/heads/master
Commit: ec2364f0bb99937ff37165b7c7c4c74531f27633
Parents: 4eba80e
Author: Andrew Stitcher <[email protected]>
Authored: Fri Apr 14 02:13:12 2017 -0400
Committer: Andrew Stitcher <[email protected]>
Committed: Fri Jul 21 12:50:06 2017 -0400

----------------------------------------------------------------------
 examples/cpp/broker.cpp                         |  3 ++
 examples/cpp/ssl.cpp                            |  3 ++
 examples/cpp/ssl_client_cert.cpp                |  3 ++
 .../bindings/cpp/src/connection_driver_test.cpp |  3 ++
 proton-c/bindings/cpp/src/handler.cpp           | 34 +++++++++++++++-----
 proton-c/bindings/cpp/src/messaging_adapter.cpp | 20 ------------
 6 files changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/examples/cpp/broker.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/broker.cpp b/examples/cpp/broker.cpp
index e47a2a6..5b0982b 100644
--- a/examples/cpp/broker.cpp
+++ b/examples/cpp/broker.cpp
@@ -29,9 +29,11 @@
 #include <proton/listener.hpp>
 #include <proton/message.hpp>
 #include <proton/messaging_handler.hpp>
+#include <proton/receiver_options.hpp>
 #include <proton/sender_options.hpp>
 #include <proton/source_options.hpp>
 #include <proton/target.hpp>
+#include <proton/target_options.hpp>
 #include <proton/thread_safe.hpp>
 #include <proton/tracker.hpp>
 
@@ -180,6 +182,7 @@ class broker_connection_handler : public 
proton::messaging_handler {
             r.connection().container().stop(
                 proton::error_condition("shutdown", "stop broker"));
         } else {
+            
r.open(proton::receiver_options().target(proton::target_options().address(qname)));
             std::cout << "receiving to " << qname << std::endl;
         }
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/examples/cpp/ssl.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/ssl.cpp b/examples/cpp/ssl.cpp
index 00bbccd..85dfa48 100644
--- a/examples/cpp/ssl.cpp
+++ b/examples/cpp/ssl.cpp
@@ -72,6 +72,9 @@ struct server_handler : public proton::messaging_handler {
         std::cout << "Inbound server connection connected via SSL.  Protocol: 
" <<
             c.transport().ssl().protocol() << std::endl;
         listener.stop();  // Just expecting the one connection.
+
+        // Go and do default inbound open stuff too
+        messaging_handler::on_connection_open(c);
     }
 
     void on_transport_error(proton::transport &t) OVERRIDE {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/examples/cpp/ssl_client_cert.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/ssl_client_cert.cpp b/examples/cpp/ssl_client_cert.cpp
index 630e74b..8ca2dc2 100644
--- a/examples/cpp/ssl_client_cert.cpp
+++ b/examples/cpp/ssl_client_cert.cpp
@@ -65,6 +65,9 @@ struct server_handler : public proton::messaging_handler {
             c.close();
         }
         listener.stop();
+
+        // Go and do default inbound open stuff too
+        messaging_handler::on_connection_open(c);
     }
 
     void on_message(proton::delivery &, proton::message &m) OVERRIDE {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/proton-c/bindings/cpp/src/connection_driver_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connection_driver_test.cpp 
b/proton-c/bindings/cpp/src/connection_driver_test.cpp
index ae18ebe..db5bc90 100644
--- a/proton-c/bindings/cpp/src/connection_driver_test.cpp
+++ b/proton-c/bindings/cpp/src/connection_driver_test.cpp
@@ -131,14 +131,17 @@ struct record_handler : public messaging_handler {
     std::deque<proton::message> messages;
 
     void on_receiver_open(receiver &l) PN_CPP_OVERRIDE {
+        messaging_handler::on_receiver_open(l);
         receivers.push_back(l);
     }
 
     void on_sender_open(sender &l) PN_CPP_OVERRIDE {
+        messaging_handler::on_sender_open(l);
         senders.push_back(l);
     }
 
     void on_session_open(session &s) PN_CPP_OVERRIDE {
+        messaging_handler::on_session_open(s);
         sessions.push_back(s);
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/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 3137718..84d9e8a 100644
--- a/proton-c/bindings/cpp/src/handler.cpp
+++ b/proton-c/bindings/cpp/src/handler.cpp
@@ -21,17 +21,19 @@
 #include "proton/messaging_handler.hpp"
 
 #include "proton/connection.hpp"
+#include "proton/container.hpp"
 #include "proton/error_condition.hpp"
 #include "proton/receiver.hpp"
+#include "proton/receiver_options.hpp"
 #include "proton/sender.hpp"
+#include "proton/sender_options.hpp"
 #include "proton/session.hpp"
 #include "proton/transport.hpp"
 
-#include "messaging_adapter.hpp"
+#include "proton_bits.hpp"
 
-#include <proton/handlers.h>
-
-#include <algorithm>
+#include "proton/connection.h"
+#include "proton/session.h"
 
 namespace proton {
 
@@ -48,17 +50,33 @@ void messaging_handler::on_transport_error(transport &t) { 
on_error(t.error());
 void messaging_handler::on_transport_open(transport &) {}
 void messaging_handler::on_connection_close(connection &) {}
 void messaging_handler::on_connection_error(connection &c) { 
on_error(c.error()); }
-void messaging_handler::on_connection_open(connection &) {}
+void messaging_handler::on_connection_open(connection &c) {
+    if (c.uninitialized()) {
+        pn_connection_open(unwrap(c));
+    }
+}
 void messaging_handler::on_session_close(session &) {}
 void messaging_handler::on_session_error(session &s) { on_error(s.error()); }
-void messaging_handler::on_session_open(session &) {}
+void messaging_handler::on_session_open(session &s) {
+    if (s.uninitialized()) {
+        pn_session_open(unwrap(s));
+    }
+}
 void messaging_handler::on_receiver_close(receiver &) {}
 void messaging_handler::on_receiver_error(receiver &l) { on_error(l.error()); }
-void messaging_handler::on_receiver_open(receiver &) {}
+void messaging_handler::on_receiver_open(receiver &l) {
+    if (l.uninitialized()) {
+        l.open(l.connection().receiver_options());
+    }
+}
 void messaging_handler::on_receiver_detach(receiver &) {}
 void messaging_handler::on_sender_close(sender &) {}
 void messaging_handler::on_sender_error(sender &l) { on_error(l.error()); }
-void messaging_handler::on_sender_open(sender &) {}
+void messaging_handler::on_sender_open(sender &l) {
+    if (l.uninitialized()) {
+        l.open(l.connection().sender_options());
+    }
+}
 void messaging_handler::on_sender_detach(sender &) {}
 void messaging_handler::on_tracker_accept(tracker &) {}
 void messaging_handler::on_tracker_reject(tracker &) {}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ec2364f0/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 521566c..cb1b776 100644
--- a/proton-c/bindings/cpp/src/messaging_adapter.cpp
+++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp
@@ -176,14 +176,6 @@ void on_delivery(messaging_handler& handler, pn_event_t* 
event) {
     }
 }
 
-bool is_local_open(pn_state_t state) {
-    return state & PN_LOCAL_ACTIVE;
-}
-
-bool is_local_unititialised(pn_state_t state) {
-    return state & PN_LOCAL_UNINIT;
-}
-
 bool is_remote_unititialised(pn_state_t state) {
     return state & PN_REMOTE_UNINIT;
 }
@@ -256,18 +248,12 @@ void on_connection_remote_open(messaging_handler& 
handler, pn_event_t* event) {
     pn_connection_t *conn = pn_event_connection(event);
     connection c(make_wrapper(conn));
     handler.on_connection_open(c);
-    if (!is_local_open(pn_connection_state(conn)) && 
is_local_unititialised(pn_connection_state(conn))) {
-        pn_connection_open(conn);
-    }
 }
 
 void on_session_remote_open(messaging_handler& handler, pn_event_t* event) {
     pn_session_t *session = pn_event_session(event);
     class session s(make_wrapper(session));
     handler.on_session_open(s);
-    if (!is_local_open(pn_session_state(session)) && 
is_local_unititialised(pn_session_state(session))) {
-        pn_session_open(session);
-    }
 }
 
 void on_link_local_open(messaging_handler& handler, pn_event_t* event) {
@@ -286,16 +272,10 @@ void on_link_remote_open(messaging_handler& handler, 
pn_event_t* event) {
     if (pn_link_is_receiver(lnk)) {
       receiver r(make_wrapper<receiver>(lnk));
       handler.on_receiver_open(r);
-      if (is_local_unititialised(pn_link_state(lnk))) {
-          r.open(r.connection().receiver_options());
-      }
       credit_topup(lnk);
     } else {
       sender s(make_wrapper<sender>(lnk));
       handler.on_sender_open(s);
-      if (is_local_unititialised(pn_link_state(lnk))) {
-          s.open(s.connection().sender_options());
-      }
     }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to