qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/2] qpid-proton git commit: PROTON-865: Generate container and link IDs, move link creation to session
Date Wed, 02 Sep 2015 15:19:24 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/cjansen-cpp-client 182fc5918 -> 9c25d4c21


PROTON-865: Generate container and link IDs, move link creation to session

Allow user to set container id, generate a random UUID-style ID by default.

Default link names to per-container prefix+counter so user can ignore link names entirely,
set them all by hand, or mix user and generated names without risk of clash (by setting
a safe prefix)

Moved create_sender and create_receiver methods from container to connection and session.

All other primary methods to create senders/receivers are now on session, with shortcuts
on connection to create on the default_session()

Dropped unused private_impl_ref.

The container still provides a shortcut to connect & create sender/receiver from URL.


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

Branch: refs/heads/cjansen-cpp-client
Commit: 2b6240b113b68b213cb9d5b0711ed0da11c511e8
Parents: 182fc59
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Sep 1 17:00:16 2015 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Sep 1 17:47:29 2015 -0400

----------------------------------------------------------------------
 examples/cpp/client.cpp                         |  2 +-
 examples/cpp/helloworld.cpp                     |  4 +-
 examples/cpp/server.cpp                         |  4 +-
 proton-c/bindings/cpp/CMakeLists.txt            |  1 +
 .../bindings/cpp/include/proton/connection.hpp  |  6 ++
 .../bindings/cpp/include/proton/container.hpp   | 22 +++--
 .../bindings/cpp/include/proton/session.hpp     | 26 +++++-
 .../bindings/cpp/src/blocking_connection.cpp    |  1 -
 proton-c/bindings/cpp/src/connection.cpp        |  9 ++
 proton-c/bindings/cpp/src/container.cpp         | 18 ++--
 proton-c/bindings/cpp/src/container_impl.cpp    | 33 +++----
 proton-c/bindings/cpp/src/container_impl.hpp    |  6 +-
 proton-c/bindings/cpp/src/conversion_test.cpp   |  8 +-
 proton-c/bindings/cpp/src/private_impl_ref.hpp  | 96 --------------------
 proton-c/bindings/cpp/src/session.cpp           | 43 +++++++--
 proton-c/bindings/cpp/src/uuid.cpp              | 59 ++++++++++++
 proton-c/bindings/cpp/src/uuid.hpp              | 37 ++++++++
 17 files changed, 215 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/examples/cpp/client.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/client.cpp b/examples/cpp/client.cpp
index 13e3b87..f670f6c 100644
--- a/examples/cpp/client.cpp
+++ b/examples/cpp/client.cpp
@@ -40,7 +40,7 @@ class client : public proton::messaging_handler {
     void on_start(proton::event &e) {
         sender = e.container().create_sender(url);
         // Create a receiver with a dynamically chosen unique address.
-        receiver = e.container().create_receiver(sender->connection(), "", true/*dynamic*/);
+        receiver = sender->connection().create_receiver("", true/*dynamic*/);
     }
 
     void send_request() {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/examples/cpp/helloworld.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/helloworld.cpp b/examples/cpp/helloworld.cpp
index 4f73432..bbb5330 100644
--- a/examples/cpp/helloworld.cpp
+++ b/examples/cpp/helloworld.cpp
@@ -35,8 +35,8 @@ class hello_world : public proton::messaging_handler {
 
     void on_start(proton::event &e) {
         proton::connection& conn = e.container().connect(url);
-        e.container().create_receiver(conn, url.path());
-        e.container().create_sender(conn, url.path());
+        conn.create_receiver(url.path());
+        conn.create_sender(url.path());
     }
 
     void on_sendable(proton::event &e) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/examples/cpp/server.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/server.cpp b/examples/cpp/server.cpp
index 08c4376..2aa097c 100644
--- a/examples/cpp/server.cpp
+++ b/examples/cpp/server.cpp
@@ -42,7 +42,7 @@ class server : public proton::messaging_handler {
 
     void on_start(proton::event &e) {
         connection = e.container().connect(url);
-        e.container().create_receiver(*connection, url.path());
+        connection->create_receiver(url.path());
         std::cout << "server connected to " << url << std::endl;
     }
 
@@ -61,7 +61,7 @@ class server : public proton::messaging_handler {
         reply.body(to_upper(e.message().body().get<std::string>()));
         reply.correlation_id(e.message().correlation_id());
         if (!senders[reply_to])
-            senders[reply_to] = e.container().create_sender(*connection, reply_to);
+            senders[reply_to] = connection->create_sender(reply_to);
         senders[reply_to]->send(reply);
     }
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index 25b8e5d..5df220e 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -79,6 +79,7 @@ set(qpid-proton-cpp-source
   src/transport.cpp
   src/types.cpp
   src/url.cpp
+  src/uuid.cpp
   src/facade.cpp
   )
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 d9369b6..03e58d5 100644
--- a/proton-c/bindings/cpp/include/proton/connection.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -60,6 +60,12 @@ class connection : public counted_facade<pn_connection_t, connection>,
public en
     /** Default session is created on first call and re-used for the lifeime of the connection
*/
     PN_CPP_EXTERN class session& default_session();
 
+    /** Create a sender on default_session() with target=addr and optional handler h */
+    PN_CPP_EXTERN sender& create_sender(const std::string &addr, handler *h=0);
+
+    /** Create a receiver on default_session() with target=addr and optional handler h */
+    PN_CPP_EXTERN receiver& create_receiver(const std::string &addr, bool dynamic=false,
handler *h=0);
+
     /** Get the first link on this connection matching the state mask.
      * Return 0 if none. Don't delete returned pointer.
      * @see link::next, endpoint::state

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 3749a3e..b6b7f18 100644
--- a/proton-c/bindings/cpp/include/proton/container.hpp
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -26,6 +26,8 @@
 #include "proton/reactor.hpp"
 #include "proton/url.hpp"
 
+#include <string>
+
 namespace proton {
 
 class connection;
@@ -43,8 +45,12 @@ class container_impl;
 class container
 {
   public:
-    PN_CPP_EXTERN container();
-    PN_CPP_EXTERN container(messaging_handler& mhandler);
+    /// Container ID should be unique within your system. By default a random ID is generated.
+    PN_CPP_EXTERN container(const std::string& id=std::string());
+
+    /// Container ID should be unique within your system. By default a random ID is generated.
+    PN_CPP_EXTERN container(messaging_handler& mhandler, const std::string& id=std::string());
+
     PN_CPP_EXTERN ~container();
 
     /** Locally open a connection @see connection::open  */
@@ -56,15 +62,9 @@ class container
     /** Run the event loop, return when all connections and acceptors are closed. */
     PN_CPP_EXTERN void run();
 
-    /** Create a sender on connection with target=addr and optional handler h */
-    PN_CPP_EXTERN sender& create_sender(connection &connection, const std::string
&addr, handler *h=0);
-
     /** Open a connection to url and create a sender with target=url.path() */
     PN_CPP_EXTERN sender& create_sender(const proton::url &);
 
-    /** Create a receiver on connection with target=addr and optional handler h */
-    PN_CPP_EXTERN receiver& create_receiver(connection &connection, const std::string
&addr, bool dynamic=false, handler *h=0);
-
     /** Create a receiver on connection with source=url.path() */
     PN_CPP_EXTERN receiver& create_receiver(const url &);
 
@@ -79,6 +79,12 @@ class container
 
     PN_CPP_EXTERN class reactor& reactor();
 
+    /// Set the prefix to be used when generating link names. @see proton::session
+    PN_CPP_EXTERN void link_prefix(const std::string&);
+
+    /// Get the prefix to be used when generating link names. @see proton::session
+    PN_CPP_EXTERN std::string link_prefix();
+
   private:
     PN_UNIQUE_PTR<container_impl> impl_;
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 e94a75b..4e3131f 100644
--- a/proton-c/bindings/cpp/include/proton/session.hpp
+++ b/proton-c/bindings/cpp/include/proton/session.hpp
@@ -54,13 +54,29 @@ class session : public counted_facade<pn_session_t, session>, public
endpoint
     /// Get connection
     PN_CPP_EXTERN class connection &connection();
 
-    // TODO aconway 2015-08-31: default generate unique name. Container args?
-    /// Create a receiver link
-    PN_CPP_EXTERN receiver& create_receiver(const std::string& name);
-    /// Create a sender link
-    PN_CPP_EXTERN sender& create_sender(const std::string& name);
+    /** An un-opened receiver link, you can set link properties before calling open().
+     *
+     *@param name must be unique within a container, if empty a unique name is
+     * generated beginning with connection().container().link_prefix()
+     */
+    PN_CPP_EXTERN receiver& create_receiver_link(const std::string& name=std::string());
+
+    /** An un-opened sender link, you can set link properties before calling open().
+     *
+     *@param name must be unique within a container, if empty a unique name is
+     * generated beginning with connection().container().link_prefix()
+     */
+    PN_CPP_EXTERN sender& create_sender_link(const std::string& name=std::string());
+
+    /** Create and open a sender with target=addr and optional handler h */
+    PN_CPP_EXTERN sender& create_sender(const std::string &addr, handler *h=0);
+
+    /** Create and open a receiver with target=addr and optional handler h */
+    PN_CPP_EXTERN receiver& create_receiver(const std::string &addr, bool dynamic=false,
handler *h=0);
+
 };
 
 }
 
 #endif  /*!PROTON_CPP_SESSION_H*/
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/blocking_connection.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_connection.cpp b/proton-c/bindings/cpp/src/blocking_connection.cpp
index 3ac8dbc..6d1c051 100644
--- a/proton-c/bindings/cpp/src/blocking_connection.cpp
+++ b/proton-c/bindings/cpp/src/blocking_connection.cpp
@@ -30,7 +30,6 @@
 #include "fetcher.hpp"
 #include "msg.hpp"
 #include "blocking_connection_impl.hpp"
-#include "private_impl_ref.hpp"
 
 namespace proton {
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 d5d8d06..fc48b68 100644
--- a/proton-c/bindings/cpp/src/connection.cpp
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -68,4 +68,13 @@ session& connection::default_session() {
     return *ctx.default_session;
 }
 
+sender& connection::create_sender(const std::string &addr, handler *h) {
+    return default_session().create_sender(addr, h);
+}
+
+receiver& connection::create_receiver(const std::string &addr, bool dynamic, handler
*h)
+{
+    return default_session().create_receiver(addr, dynamic, h);
+}
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 30ae88b..9d9bc85 100644
--- a/proton-c/bindings/cpp/src/container.cpp
+++ b/proton-c/bindings/cpp/src/container.cpp
@@ -30,7 +30,6 @@
 #include "proton/receiver.hpp"
 
 #include "container_impl.hpp"
-#include "private_impl_ref.hpp"
 #include "connector.hpp"
 #include "contexts.hpp"
 #include "proton/connection.h"
@@ -40,9 +39,11 @@ namespace proton {
 
 //// Public container class.
 
-container::container() : impl_(new container_impl(*this, 0)) {}
+container::container(const std::string& id) :
+    impl_(new container_impl(*this, 0, id)) {}
 
-container::container(messaging_handler &mhandler) : impl_(new container_impl(*this, &mhandler))
{}
+container::container(messaging_handler &mhandler, const std::string& id) :
+    impl_(new container_impl(*this, &mhandler, id)) {}
 
 container::~container() {}
 
@@ -58,18 +59,10 @@ void container::timeout(duration timeout) { impl_->reactor_->timeout(timeout);
}
 void container::run() { impl_->reactor_->run(); }
 
 
-sender& container::create_sender(connection &connection, const std::string &addr,
handler *h) {
-    return impl_->create_sender(connection, addr, h);
-}
-
 sender& container::create_sender(const proton::url &url) {
     return impl_->create_sender(url);
 }
 
-receiver& container::create_receiver(connection &connection, const std::string &addr,
bool dynamic, handler *h) {
-    return impl_->create_receiver(connection, addr, dynamic, h);
-}
-
 receiver& container::create_receiver(const proton::url &url) {
     return impl_->create_receiver(url);
 }
@@ -78,4 +71,7 @@ acceptor& container::listen(const proton::url &url) {
     return impl_->listen(url);
 }
 
+void container::link_prefix(const std::string& s) { impl_->prefix_ = s; }
+std::string  container::link_prefix() { return impl_->prefix_; }
+
 } // namespace proton

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/container_impl.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/container_impl.cpp b/proton-c/bindings/cpp/src/container_impl.cpp
index ab4379c..b565210 100644
--- a/proton-c/bindings/cpp/src/container_impl.cpp
+++ b/proton-c/bindings/cpp/src/container_impl.cpp
@@ -34,7 +34,7 @@
 #include "container_impl.hpp"
 #include "connector.hpp"
 #include "contexts.hpp"
-#include "private_impl_ref.hpp"
+#include "uuid.hpp"
 
 #include "proton/connection.h"
 #include "proton/session.h"
@@ -103,9 +103,11 @@ counted_ptr<pn_handler_t> container_impl::cpp_handler(handler *h)
     return handler;
 }
 
-container_impl::container_impl(container& c, handler *h) :
-    container_(c), reactor_(reactor::create()), handler_(h)
+container_impl::container_impl(container& c, handler *h, const std::string& id) :
+    container_(c), reactor_(reactor::create()), handler_(h), container_id_(id),
+    link_id_(0)
 {
+    if (container_id_.empty()) container_id_ = uuid().str();
     container_context(pn_cast(reactor_.get()), container_);
 
     // Set our own global handler that "subclasses" the existing one
@@ -140,14 +142,6 @@ connection& container_impl::connect(const proton::url &url, handler
*h) {
     return *conn;
 }
 
-sender& container_impl::create_sender(connection &connection, const std::string &addr,
handler *h) {
-    sender& snd = connection.default_session().create_sender(container_id_  + '-' + addr);
-    snd.target().address(addr);
-    if (h) snd.handler(*h);
-    snd.open();
-    return snd;
-}
-
 sender& container_impl::create_sender(const proton::url &url) {
     connection& conn = connect(url, 0);
     std::string path = url.path();
@@ -157,16 +151,6 @@ sender& container_impl::create_sender(const proton::url &url)
{
     return snd;
 }
 
-receiver& container_impl::create_receiver(connection &conn, const std::string &addr,
bool dynamic, handler *h)
-{
-    receiver& rcv = conn.default_session().create_receiver(container_id_ + '-' + addr);
-    rcv.source().address(addr);
-    if (dynamic) rcv.source().dynamic(true);
-    if (h) rcv.handler(*h);
-    rcv.open();
-    return rcv;
-}
-
 receiver& container_impl::create_receiver(const proton::url &url) {
     connection& conn = connect(url, 0);
     std::string path = url.path();
@@ -187,4 +171,11 @@ acceptor& container_impl::listen(const proton::url& url) {
                         << "(" << url << ")"));
 }
 
+std::string container_impl::next_link_name() {
+    std::ostringstream s;
+    // TODO aconway 2015-09-01: atomic operation
+    s << prefix_ << std::hex << ++link_id_;
+    return s.str();
+}
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/container_impl.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/container_impl.hpp b/proton-c/bindings/cpp/src/container_impl.hpp
index bfd87a0..6caf439 100644
--- a/proton-c/bindings/cpp/src/container_impl.hpp
+++ b/proton-c/bindings/cpp/src/container_impl.hpp
@@ -42,7 +42,7 @@ class container;
 class container_impl
 {
   public:
-    PN_CPP_EXTERN container_impl(container&, handler *);
+    PN_CPP_EXTERN container_impl(container&, handler *, const std::string& id);
     PN_CPP_EXTERN ~container_impl();
     PN_CPP_EXTERN connection& connect(const url&, handler *h);
     PN_CPP_EXTERN sender& create_sender(connection &connection, const std::string
&addr, handler *h);
@@ -55,6 +55,8 @@ class container_impl
 
     counted_ptr<pn_handler_t> cpp_handler(handler *h);
 
+    std::string next_link_name();
+
   private:
 
     container& container_;
@@ -64,6 +66,8 @@ class container_impl
     PN_UNIQUE_PTR<handler> override_handler_;
     PN_UNIQUE_PTR<handler> flow_controller_;
     std::string container_id_;
+    uint64_t link_id_;
+    std::string prefix_;
 
   friend class container;
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/conversion_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/conversion_test.cpp b/proton-c/bindings/cpp/src/conversion_test.cpp
index c393faa..a13d016 100644
--- a/proton-c/bindings/cpp/src/conversion_test.cpp
+++ b/proton-c/bindings/cpp/src/conversion_test.cpp
@@ -23,6 +23,7 @@
 
 #include "test_bits.hpp"
 #include "proton/connection.hpp"
+#include "proton/connection.hpp"
 #include "proton/session.hpp"
 #include "proton/session.hpp"
 
@@ -31,12 +32,11 @@ using namespace proton;
 
 template <class connection_ptr, class session_ptr>
 void test_shared() {
+
     connection_ptr conn(connection::cast(pn_connection()));
     session& s = conn->default_session();
     session_ptr p = s;
     session_ptr p2 = s;
-    conn.reset();               // Make sure we still have session
-    p->create_sender("");
 }
 
 template <class connection_ptr, class session_ptr>
@@ -45,8 +45,6 @@ void test_counted() {
     session& s = conn->default_session();
     session_ptr p = s;
     session_ptr p2 = s;
-    conn.reset();                               // Make sure we still have session
-    p->create_sender("");
 }
 
 template <class connection_ptr, class session_ptr>
@@ -55,8 +53,6 @@ void test_unique() {
     session& s = conn->default_session();
     session_ptr p(s);
     session_ptr p2(s);
-    conn.reset();                               // Make sure we still have session
-    p->create_sender("");
 }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/private_impl_ref.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/private_impl_ref.hpp b/proton-c/bindings/cpp/src/private_impl_ref.hpp
deleted file mode 100644
index 2935d79..0000000
--- a/proton-c/bindings/cpp/src/private_impl_ref.hpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#ifndef PROTON_CPP_PRIVATEIMPL_H
-#define PROTON_CPP_PRIVATEIMPL_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"
-
-namespace proton {
-
-// Modified from qpid::messaging version to work without
-// boost::intrusive_ptr but integrate with Proton's pn_class_t
-// reference counting.  Thread safety currently absent but fluid in
-// intention...
-
-
-/**
- * Helper class to implement a class with a private, reference counted
- * implementation and reference semantics.
- *
- * Such classes are used in the public API to hide implementation, they
- * should. Example of use:
- *
- * === Foo.h
- *
- * template <class T> private_impl_ref;
- * class foo_impl;
- *
- * Foo : public handle<foo_impl> {
- *  public:
- *   Foo(foo_impl* = 0);
- *   Foo(const Foo&);
- *   ~Foo();
- *   Foo& operator=(const Foo&);
- *
- *   int foo_do();              //  and other Foo functions...
- *
- *  private:
- *   typedef foo_impl Impl;
- *   Impl* impl_;
- *   friend class private_impl_ref<Foo>;
- *
- * === Foo.cpp
- *
- * typedef private_impl_ref<Foo> PI;
- * Foo::Foo(foo_impl* p) { PI::ctor(*this, p); }
- * Foo::Foo(const Foo& c) : handle<foo_impl>() { PI::copy(*this, c); }
- * Foo::~Foo() { PI::dtor(*this); }
- * Foo& Foo::operator=(const Foo& c) { return PI::assign(*this, c); }
- *
- * int foo::foo_do() { return impl_->foo_do(); }
- *
- */
-template <class T> class private_impl_ref {
-  public:
-    typedef typename T::Impl Impl;
-
-    /** Get the implementation pointer from a handle */
-    static Impl* get(const T& t) { return t.impl_; }
-
-    /** Set the implementation pointer in a handle */
-    static void set(T& t, const Impl* p) {
-        if (t.impl_ == p) return;
-        if (t.impl_) Impl::decref(t.impl_);
-        t.impl_ = const_cast<Impl *>(p);
-        if (t.impl_) Impl::incref(t.impl_);
-    }
-
-    // Helper functions to implement the ctor, dtor, copy, assign
-    static void ctor(T& t, Impl* p) { t.impl_ = p; if (p) Impl::incref(p); }
-    static void copy(T& t, const T& x) { if (&t == &x) return; t.impl_ =
0; assign(t, x); }
-    static void dtor(T& t) { if(t.impl_) Impl::decref(t.impl_); }
-    static T& assign(T& t, const T& x) { set(t, get(x)); return t;}
-};
-
-}
-
-#endif  /*!PROTON_CPP_PRIVATEIMPL_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/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 43c0cd0..11d5f30 100644
--- a/proton-c/bindings/cpp/src/session.cpp
+++ b/proton-c/bindings/cpp/src/session.cpp
@@ -19,13 +19,14 @@
  *
  */
 #include "proton/session.hpp"
-#include "contexts.hpp"
-
 #include "proton/connection.h"
 #include "proton/session.h"
 #include "proton/session.hpp"
 #include "proton/connection.hpp"
 
+#include "contexts.hpp"
+#include "container_impl.hpp"
+
 namespace proton {
 
 void session::open() {
@@ -36,12 +37,42 @@ connection &session::connection() {
     return *proton::connection::cast(pn_session_connection(pn_cast(this)));
 }
 
-receiver& session::create_receiver(const std::string& name) {
-    return *reinterpret_cast<receiver*>(pn_receiver(pn_cast(this), name.c_str()));
+namespace {
+std::string set_name(const std::string& name, session* s) {
+    if (name.empty()) 
+        return connection_context::get(
+            pn_cast(&s->connection())).container_impl->next_link_name();
+    return name;
+}
+}
+
+receiver& session::create_receiver_link(const std::string& name) {
+    return *reinterpret_cast<receiver*>(
+        pn_receiver(pn_cast(this), set_name(name, this).c_str()));
+}
+
+sender& session::create_sender_link(const std::string& name) {
+    return *reinterpret_cast<sender*>(
+        pn_sender(pn_cast(this), set_name(name, this).c_str()));
 }
 
-sender& session::create_sender(const std::string& name) {
-    return *reinterpret_cast<sender*>(pn_sender(pn_cast(this), name.c_str()));
+sender& session::create_sender(const std::string &addr, handler *h) {
+    sender& snd = create_sender_link();
+    snd.target().address(addr);
+    if (h) snd.handler(*h);
+    snd.open();
+    return snd;
 }
 
+receiver& session::create_receiver(const std::string &addr, bool dynamic, handler
*h)
+{
+    receiver& rcv = create_receiver_link();
+    rcv.source().address(addr);
+    if (dynamic) rcv.source().dynamic(true);
+    if (h) rcv.handler(*h);
+    rcv.open();
+    return rcv;
+}
+
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/uuid.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/uuid.cpp b/proton-c/bindings/cpp/src/uuid.cpp
new file mode 100644
index 0000000..d1bb10e
--- /dev/null
+++ b/proton-c/bindings/cpp/src/uuid.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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 "uuid.hpp"
+
+#include <cstdlib>
+#include <ctime>
+#include <sstream>
+#include <iomanip>
+
+namespace proton {
+
+uuid::uuid() {
+    static bool seeded = false;
+    if (!seeded) {
+        std::srand(std::time(0)); // use current time as seed for random generator
+        seeded = true;
+    }
+    int r = std::rand();
+    for (int i = 0; i < sizeof(bytes); ++i ) {
+        bytes[i] = r & 0xFF;
+        r >>= 8;
+        if (!r) r = std::rand();
+    }
+
+    // From RFC4122, the version bits are set to 0100
+    bytes[6] = (bytes[6] & 0x0F) | 0x40;
+
+    // From RFC4122, the top two bits of byte 8 get set to 01
+    bytes[8] = (bytes[8] & 0x3F) | 0x80;
+}
+
+std::string uuid::str() {
+    // UUID standard format: 8-4-4-4-12 (36 chars, 32 alphanumeric and 4 hypens)
+    std::ostringstream s;
+    s << std::hex << std::setw(2) << std::setfill('0');
+    s << b(0) << b(1) << b(2) << b(3);
+    s << '-' << b(4) << b(5) << '-' << b(6) << b(7) <<
'-' << b(8) << b(9);
+    s << '-' << b(10) << b(11) << b(12) << b(13) << b(14)
<< b(15);
+    return s.str();
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2b6240b1/proton-c/bindings/cpp/src/uuid.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/uuid.hpp b/proton-c/bindings/cpp/src/uuid.hpp
new file mode 100644
index 0000000..67ed581
--- /dev/null
+++ b/proton-c/bindings/cpp/src/uuid.hpp
@@ -0,0 +1,37 @@
+#ifndef UUID_HPP
+#define UUID_HPP
+/*
+ * 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 <string>
+
+namespace proton {
+
+/// A simple random UUID-like value. Fallback if user does not provide a container id. 
+struct uuid {
+    uuid();
+    uint8_t bytes[16];
+    std::string str();
+  private:
+    int b(int i) { return bytes[i]; }
+};
+
+}
+
+#endif // UUID_HPP


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


Mime
View raw message