You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2017/09/29 13:40:59 UTC

qpid-proton git commit: PROTON-1528: [C++ binding] Ensure that containers have a default id

Repository: qpid-proton
Updated Branches:
  refs/heads/master b03f8aad1 -> 689ffe1ed


PROTON-1528: [C++ binding] Ensure that containers have a default id


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

Branch: refs/heads/master
Commit: 689ffe1edfff824b1b6e7ef7e80e31666875a0f8
Parents: b03f8aa
Author: Andrew Stitcher <as...@apache.org>
Authored: Fri Sep 29 09:39:01 2017 -0400
Committer: Andrew Stitcher <as...@apache.org>
Committed: Fri Sep 29 09:39:01 2017 -0400

----------------------------------------------------------------------
 .../bindings/cpp/include/proton/container.hpp    | 19 +++++++++++++++++--
 proton-c/bindings/cpp/src/container.cpp          |  5 +++++
 proton-c/bindings/cpp/src/container_test.cpp     | 12 ++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/689ffe1e/proton-c/bindings/cpp/include/proton/container.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp
index 6b02282..8e12dc3 100644
--- a/proton-c/bindings/cpp/include/proton/container.hpp
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -64,11 +64,26 @@ class PN_CPP_CLASS_EXTERN container {
     /// managed by the container.
     ///
     /// @param id sets the container's unique identity.
-    PN_CPP_EXTERN container(messaging_handler& handler, const std::string& id="");
+    PN_CPP_EXTERN container(messaging_handler& handler, const std::string& id);
+
+    /// Create a container with a global handler for messaging events.
+    ///
+    /// **Thread safety** - in a multi-threaded container this handler will be
+    /// called concurrently. You can use locks to make that safe, or use a
+    /// separate handler for each connection.  See @ref mt_page.
+    ///
+    /// @param handler global handler, called for events on all connections
+    /// managed by the container.
+    PN_CPP_EXTERN container(messaging_handler& handler);
 
     /// Create a container.
     /// @param id sets the container's unique identity.
-    PN_CPP_EXTERN container(const std::string& id="");
+    PN_CPP_EXTERN container(const std::string& id);
+
+    /// Create a container.
+    ///
+    /// This will create a default random identity
+    PN_CPP_EXTERN container();
 
     /// Destroy a container.
     ///

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/689ffe1e/proton-c/bindings/cpp/src/container.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/container.cpp b/proton-c/bindings/cpp/src/container.cpp
index 11218db..0da852c 100644
--- a/proton-c/bindings/cpp/src/container.cpp
+++ b/proton-c/bindings/cpp/src/container.cpp
@@ -25,6 +25,7 @@
 #include "proton/error_condition.hpp"
 #include "proton/listen_handler.hpp"
 #include "proton/listener.hpp"
+#include "proton/uuid.hpp"
 
 #include "proactor_container_impl.hpp"
 
@@ -32,8 +33,12 @@ namespace proton {
 
 container::container(messaging_handler& h, const std::string& id) :
     impl_(new impl(*this, id, &h)) {}
+container::container(messaging_handler& h) :
+    impl_(new impl(*this, uuid::random().str(), &h)) {}
 container::container(const std::string& id) :
     impl_(new impl(*this, id)) {}
+container::container() :
+    impl_(new impl(*this, uuid::random().str())) {}
 container::~container() {}
 
 returned<connection> container::connect(const std::string &url) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/689ffe1e/proton-c/bindings/cpp/src/container_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/container_test.cpp b/proton-c/bindings/cpp/src/container_test.cpp
index ab7bfc7..62bb60f 100644
--- a/proton-c/bindings/cpp/src/container_test.cpp
+++ b/proton-c/bindings/cpp/src/container_test.cpp
@@ -64,6 +64,7 @@ class test_handler : public proton::messaging_handler {
     bool done;
 
     std::string peer_vhost;
+    std::string peer_container_id;
     proton::listener listener;
 
     test_handler(const std::string h, const proton::connection_options& c_opts)
@@ -78,6 +79,8 @@ class test_handler : public proton::messaging_handler {
     void on_connection_open(proton::connection &c) PN_CPP_OVERRIDE {
         if (peer_vhost.empty() && !c.virtual_host().empty())
             peer_vhost = c.virtual_host();
+        if (peer_container_id.empty() && !c.container_id().empty())
+            peer_container_id = c.container_id();
         if (!closing) c.close();
         closing = true;
     }
@@ -88,6 +91,14 @@ class test_handler : public proton::messaging_handler {
     }
 };
 
+int test_container_default_container_id() {
+    proton::connection_options opts;
+    test_handler th(std::string("127.0.0.1"), opts);
+    proton::container(th).run();
+    ASSERT(!th.peer_container_id.empty());
+    return 0;
+}
+
 int test_container_vhost() {
     proton::connection_options opts;
     opts.virtual_host(std::string("a.b.c"));
@@ -199,6 +210,7 @@ int test_container_stop() {
 
 int main(int, char**) {
     int failed = 0;
+    RUN_TEST(failed, test_container_default_container_id());
     RUN_TEST(failed, test_container_vhost());
     RUN_TEST(failed, test_container_default_vhost());
     RUN_TEST(failed, test_container_no_vhost());


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