You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/11/03 21:43:41 UTC

qpid-proton git commit: PROTON-1678: [cpp] add option to set link name

Repository: qpid-proton
Updated Branches:
  refs/heads/master d82a958d0 -> a9d940f51


PROTON-1678: [cpp] add option to set link name

Added "name" option to sender_options and receiver_options


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

Branch: refs/heads/master
Commit: a9d940f51c52b2fa83d9efea33e674d63ec0c0bd
Parents: d82a958
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Nov 3 17:34:56 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Nov 3 17:40:13 2017 -0400

----------------------------------------------------------------------
 .../cpp/include/proton/receiver_options.hpp     |  7 ++++
 .../cpp/include/proton/sender_options.hpp       |  6 +++
 .../bindings/cpp/src/connection_driver_test.cpp | 39 +++++++++++++-------
 proton-c/bindings/cpp/src/receiver_options.cpp  |  5 +++
 proton-c/bindings/cpp/src/sender_options.cpp    |  5 +++
 proton-c/bindings/cpp/src/session.cpp           |  6 ++-
 6 files changed, 53 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/proton-c/bindings/cpp/include/proton/receiver_options.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/receiver_options.hpp b/proton-c/bindings/cpp/include/proton/receiver_options.hpp
index ae7a9fb..bcefb28 100644
--- a/proton-c/bindings/cpp/include/proton/receiver_options.hpp
+++ b/proton-c/bindings/cpp/include/proton/receiver_options.hpp
@@ -26,6 +26,7 @@
 #include "./internal/export.hpp"
 #include "./internal/pn_unique_ptr.hpp"
 #include "./delivery_mode.hpp"
+#include <string>
 
 /// @file
 /// @copybrief proton::receiver_options
@@ -97,14 +98,20 @@ class receiver_options {
     /// automatic replenishment.
     PN_CPP_EXTERN receiver_options& credit_window(int count);
 
+    /// Set the link name. If not set a unique name is generated.
+    PN_CPP_EXTERN receiver_options& name(const std::string& name);
+
+
   private:
     void apply(receiver &) const;
+    const std::string* get_name() const; // Pointer to name if set, else 0
 
     class impl;
     internal::pn_unique_ptr<impl> impl_;
 
     /// @cond INTERNAL
   friend class receiver;
+  friend class session;
     /// @endcond
 };
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/proton-c/bindings/cpp/include/proton/sender_options.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/sender_options.hpp b/proton-c/bindings/cpp/include/proton/sender_options.hpp
index 235513b..970da7e 100644
--- a/proton-c/bindings/cpp/include/proton/sender_options.hpp
+++ b/proton-c/bindings/cpp/include/proton/sender_options.hpp
@@ -26,6 +26,7 @@
 #include "./internal/export.hpp"
 #include "./internal/pn_unique_ptr.hpp"
 #include "./delivery_mode.hpp"
+#include <string>
 
 /// @file
 /// @copybrief proton::sender_options
@@ -87,14 +88,19 @@ class sender_options {
     /// Options for the receiver node of the receiver.
     PN_CPP_EXTERN sender_options& target(const target_options&);
 
+    /// Set the link name. If not set a unique name is generated.
+    PN_CPP_EXTERN sender_options& name(const std::string& name);
+
   private:
     void apply(sender&) const;
+    const std::string* get_name() const; // Pointer to name if set, else 0
 
     class impl;
     internal::pn_unique_ptr<impl> impl_;
 
     /// @cond INTERNAL
   friend class sender;
+  friend class session;
     /// @endcond
 };
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/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 18d4f6e..ed0e830 100644
--- a/proton-c/bindings/cpp/src/connection_driver_test.cpp
+++ b/proton-c/bindings/cpp/src/connection_driver_test.cpp
@@ -22,8 +22,8 @@
 #include "proton_bits.hpp"
 #include "link_namer.hpp"
 
-#include "proton/container.hpp"
 #include "proton/connection.hpp"
+#include "proton/container.hpp"
 #include "proton/io/connection_driver.hpp"
 #include "proton/link.hpp"
 #include "proton/message.hpp"
@@ -31,7 +31,9 @@
 #include "proton/receiver_options.hpp"
 #include "proton/sender.hpp"
 #include "proton/sender_options.hpp"
+#include "proton/source.hpp"
 #include "proton/source_options.hpp"
+#include "proton/target.hpp"
 #include "proton/transport.hpp"
 #include "proton/types_fwd.hpp"
 #include "proton/uuid.hpp"
@@ -327,39 +329,50 @@ void test_spin_interrupt() {
     } catch (test::error) {}
 }
 
-void test_link_filters() {
-    // Propagation of link properties
+void test_link_options() {
+    // Propagation of link properties, including filters
     record_handler ha, hb;
     driver_pair d(ha, hb);
 
-    source_options opts;
     source::filter_map f;
     f.put("xx", "xxx");
     ASSERT_EQUAL(1U, f.size());
-    d.a.connection().open_sender("x", sender_options().source(source_options().filters(f)));
+    d.a.connection().open_sender(
+        "x", sender_options().name("_x").source(source_options().filters(f)));
 
     f.clear();
     f.put("yy", "yyy");
     ASSERT_EQUAL(1U, f.size());
-    d.a.connection().open_receiver("y", receiver_options().source(source_options().filters(f)));
+    d.a.connection().open_receiver(
+        "y", receiver_options().name("_y").source(source_options().filters(f)));
 
     while (ha.senders.size()+ha.receivers.size() < 2 ||
            hb.senders.size()+hb.receivers.size() < 2)
         d.process();
 
     proton::sender ax = quick_pop(ha.senders);
+    ASSERT_EQUAL("_x", ax.name());
+    // FIXME aconway 2017-11-03:
+    // ASSERT_EQUAL("x", ax.target().address());
+
     proton::receiver ay = quick_pop(ha.receivers);
+    ASSERT_EQUAL("_y", ay.name());
+    // FIXME aconway 2017-11-03:
+    // ASSERT_EQUAL("y", ay.source().address());
+
     proton::receiver bx = quick_pop(hb.receivers);
-    proton::sender by = quick_pop(hb.senders);
+    ASSERT_EQUAL("x", bx.target().address());
+    ASSERT_EQUAL("_x", bx.name());
+    f = bx.source().filters();
+    ASSERT_EQUAL(1U, f.size());
+    ASSERT_EQUAL(value("xxx"), bx.source().filters().get("xx"));
 
-    // C++ binding only gives remote_source so only look at remote ends of links
+    proton::sender by = quick_pop(hb.senders);
+    ASSERT_EQUAL("y", by.source().address());
+    ASSERT_EQUAL("_y", by.name());
     f = by.source().filters();
     ASSERT_EQUAL(1U, f.size());
     ASSERT_EQUAL(value("yyy"), f.get("yy"));
-
-    f = bx.source().filters();
-    ASSERT_EQUAL(1U, f.size());
-    ASSERT_EQUAL(value("xxx"), bx.source().filters().get("xx"));
 }
 
 void test_message() {
@@ -437,7 +450,7 @@ int main(int argc, char** argv) {
     RUN_ARGV_TEST(failed, test_driver_disconnected());
     RUN_ARGV_TEST(failed, test_no_container());
     RUN_ARGV_TEST(failed, test_spin_interrupt());
-    RUN_ARGV_TEST(failed, test_link_filters());
+    RUN_ARGV_TEST(failed, test_link_options());
     RUN_ARGV_TEST(failed, test_message());
     RUN_ARGV_TEST(failed, test_message_timeout_succeed());
     RUN_ARGV_TEST(failed, test_message_timeout_fail());

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/proton-c/bindings/cpp/src/receiver_options.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/receiver_options.cpp b/proton-c/bindings/cpp/src/receiver_options.cpp
index 2b134bc..1deb2ed 100644
--- a/proton-c/bindings/cpp/src/receiver_options.cpp
+++ b/proton-c/bindings/cpp/src/receiver_options.cpp
@@ -70,6 +70,7 @@ class receiver_options::impl {
     option<bool> dynamic_address;
     option<source_options> source;
     option<target_options> target;
+    option<std::string> name;
 
 
     void apply(receiver& r) {
@@ -124,7 +125,11 @@ receiver_options& receiver_options::auto_settle(bool b) {impl_->auto_settle = b;
 receiver_options& receiver_options::credit_window(int w) {impl_->credit_window = w; return *this; }
 receiver_options& receiver_options::source(source_options &s) {impl_->source = s; return *this; }
 receiver_options& receiver_options::target(target_options &s) {impl_->target = s; return *this; }
+receiver_options& receiver_options::name(const std::string &s) {impl_->name = s; return *this; }
 
 void receiver_options::apply(receiver& r) const { impl_->apply(r); }
 
+const std::string* receiver_options::get_name() const {
+    return impl_->name.set ? &impl_->name.value : 0;
+}
 } // namespace proton

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/proton-c/bindings/cpp/src/sender_options.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/sender_options.cpp b/proton-c/bindings/cpp/src/sender_options.cpp
index 9305666..16595fc 100644
--- a/proton-c/bindings/cpp/src/sender_options.cpp
+++ b/proton-c/bindings/cpp/src/sender_options.cpp
@@ -65,6 +65,7 @@ class sender_options::impl {
     option<bool> auto_settle;
     option<source_options> source;
     option<target_options> target;
+    option<std::string> name;
 
     void apply(sender& s) {
         if (s.uninitialized()) {
@@ -110,7 +111,11 @@ sender_options& sender_options::delivery_mode(proton::delivery_mode m) {impl_->d
 sender_options& sender_options::auto_settle(bool b) {impl_->auto_settle = b; return *this; }
 sender_options& sender_options::source(const source_options &s) {impl_->source = s; return *this; }
 sender_options& sender_options::target(const target_options &s) {impl_->target = s; return *this; }
+sender_options& sender_options::name(const std::string &s) {impl_->name = s; return *this; }
 
 void sender_options::apply(sender& s) const { impl_->apply(s); }
 
+const std::string* sender_options::get_name() const {
+    return impl_->name.set ? &impl_->name.value : 0;
+}
 } // namespace proton

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a9d940f5/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 d2fb401..a64e0ad 100644
--- a/proton-c/bindings/cpp/src/session.cpp
+++ b/proton-c/bindings/cpp/src/session.cpp
@@ -75,7 +75,8 @@ sender session::open_sender(const std::string &addr) {
 }
 
 sender session::open_sender(const std::string &addr, const sender_options &so) {
-    pn_link_t *lnk = pn_sender(pn_object(), next_link_name(connection()).c_str());
+    std::string name = so.get_name() ? *so.get_name() : next_link_name(connection());
+    pn_link_t *lnk = pn_sender(pn_object(), name.c_str());
     pn_terminus_set_address(pn_link_target(lnk), addr.c_str());
     sender snd(make_wrapper<sender>(lnk));
     snd.open(so);
@@ -88,7 +89,8 @@ receiver session::open_receiver(const std::string &addr) {
 
 receiver session::open_receiver(const std::string &addr, const receiver_options &ro)
 {
-    pn_link_t *lnk = pn_receiver(pn_object(), next_link_name(connection()).c_str());
+    std::string name = ro.get_name() ? *ro.get_name() : next_link_name(connection());
+    pn_link_t *lnk = pn_receiver(pn_object(), name.c_str());
     pn_terminus_set_address(pn_link_source(lnk), addr.c_str());
     receiver rcv(make_wrapper<receiver>(lnk));
     rcv.open(ro);


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