qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [3/7] qpid-proton git commit: PROTON-865: C++ reactor binding for proton.
Date Fri, 04 Sep 2015 19:14:30 GMT
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/proton_event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/proton_event.hpp b/proton-c/bindings/cpp/include/proton/proton_event.hpp
new file mode 100644
index 0000000..c809e55
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/proton_event.hpp
@@ -0,0 +1,296 @@
+#ifndef PROTON_CPP_PROTONEVENT_H
+#define PROTON_CPP_PROTONEVENT_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/event.hpp"
+#include "proton/link.hpp"
+
+struct pn_event_t;
+
+namespace proton {
+
+class handler;
+class container;
+class connection;
+class container;
+
+/** Event information for a proton::proton_handler */
+class proton_event : public event
+{
+  public:
+
+    ///@name Event types
+    ///@{
+
+    /// The type of an event
+    typedef int event_type;
+
+    /**
+     * Defined as a programming convenience. No event of this type will
+     * ever be generated.
+     */
+    PN_CPP_EXTERN static const event_type EVENT_NONE;
+
+    /**
+     * A reactor has been started. Events of this type point to the reactor.
+     */
+    PN_CPP_EXTERN static const event_type REACTOR_INIT;
+
+    /**
+     * A reactor has no more events to process. Events of this type
+     * point to the reactor.
+     */
+    PN_CPP_EXTERN static const event_type REACTOR_QUIESCED;
+
+    /**
+     * A reactor has been stopped. Events of this type point to the reactor.
+     */
+    PN_CPP_EXTERN static const event_type REACTOR_FINAL;
+
+    /**
+     * A timer event has occurred.
+     */
+    PN_CPP_EXTERN static const event_type TIMER_TASK;
+
+    /**
+     * The connection has been created. This is the first event that
+     * will ever be issued for a connection. Events of this type point
+     * to the relevant connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_INIT;
+
+    /**
+     * The connection has been bound to a transport. This event is
+     * issued when the transport::bind() is called.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_BOUND;
+
+    /**
+     * The connection has been unbound from its transport. This event is
+     * issued when transport::unbind() is called.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_UNBOUND;
+
+    /**
+     * The local connection endpoint has been closed. Events of this
+     * type point to the relevant connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_LOCAL_OPEN;
+
+    /**
+     * The remote endpoint has opened the connection. Events of this
+     * type point to the relevant connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_REMOTE_OPEN;
+
+    /**
+     * The local connection endpoint has been closed. Events of this
+     * type point to the relevant connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_LOCAL_CLOSE;
+
+    /**
+     *  The remote endpoint has closed the connection. Events of this
+     *  type point to the relevant connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_REMOTE_CLOSE;
+
+    /**
+     * The connection has been freed and any outstanding processing has
+     * been completed. This is the final event that will ever be issued
+     * for a connection.
+     */
+    PN_CPP_EXTERN static const event_type CONNECTION_FINAL;
+
+    /**
+     * The session has been created. This is the first event that will
+     * ever be issued for a session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_INIT;
+
+    /**
+     * The local session endpoint has been opened. Events of this type
+     * point ot the relevant session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_LOCAL_OPEN;
+
+    /**
+     * The remote endpoint has opened the session. Events of this type
+     * point to the relevant session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_REMOTE_OPEN;
+
+    /**
+     * The local session endpoint has been closed. Events of this type
+     * point ot the relevant session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_LOCAL_CLOSE;
+
+    /**
+     * The remote endpoint has closed the session. Events of this type
+     * point to the relevant session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_REMOTE_CLOSE;
+
+    /**
+     * The session has been freed and any outstanding processing has
+     * been completed. This is the final event that will ever be issued
+     * for a session.
+     */
+    PN_CPP_EXTERN static const event_type SESSION_FINAL;
+
+    /**
+     * The link has been created. This is the first event that will ever
+     * be issued for a link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_INIT;
+
+    /**
+     * The local link endpoint has been opened. Events of this type
+     * point ot the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_LOCAL_OPEN;
+
+    /**
+     * The remote endpoint has opened the link. Events of this type
+     * point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_REMOTE_OPEN;
+
+    /**
+     * The local link endpoint has been closed. Events of this type
+     * point ot the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_LOCAL_CLOSE;
+
+    /**
+     * The remote endpoint has closed the link. Events of this type
+     * point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_REMOTE_CLOSE;
+
+    /**
+     * The local link endpoint has been detached. Events of this type
+     * point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_LOCAL_DETACH;
+
+    /**
+     * The remote endpoint has detached the link. Events of this type
+     * point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_REMOTE_DETACH;
+
+    /**
+     * The flow control state for a link has changed. Events of this
+     * type point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_FLOW;
+
+    /**
+     * The link has been freed and any outstanding processing has been
+     * completed. This is the final event that will ever be issued for a
+     * link. Events of this type point to the relevant link.
+     */
+    PN_CPP_EXTERN static const event_type LINK_FINAL;
+
+    /**
+     * A delivery has been created or updated. Events of this type point
+     * to the relevant delivery.
+     */
+    PN_CPP_EXTERN static const event_type DELIVERY;
+
+    /**
+     * The transport has new data to read and/or write. Events of this
+     * type point to the relevant transport.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT;
+
+    /**
+     * The transport has authenticated, if this is received by a server
+     * the associated transport has authenticated an incoming connection
+     * and transport::user() can be used to obtain the authenticated
+     * user.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT_AUTHENTICATED;
+
+    /**
+     * Indicates that a transport error has occurred. Use
+     * transport::condition() to access the details of the error
+     * from the associated transport.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT_ERROR;
+
+    /**
+     * Indicates that the head of the transport has been closed. This
+     * means the transport will never produce more bytes for output to
+     * the network. Events of this type point to the relevant transport.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT_HEAD_CLOSED;
+
+    /**
+     * Indicates that the tail of the transport has been closed. This
+     * means the transport will never be able to process more bytes from
+     * the network. Events of this type point to the relevant transport.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT_TAIL_CLOSED;
+
+    /**
+     * Indicates that the both the head and tail of the transport are
+     * closed. Events of this type point to the relevant transport.
+     */
+    PN_CPP_EXTERN static const event_type TRANSPORT_CLOSED;
+
+    PN_CPP_EXTERN static const event_type SELECTABLE_INIT;
+    PN_CPP_EXTERN static const event_type SELECTABLE_UPDATED;
+    PN_CPP_EXTERN static const event_type SELECTABLE_READABLE;
+    PN_CPP_EXTERN static const event_type SELECTABLE_WRITABLE;
+    PN_CPP_EXTERN static const event_type SELECTABLE_ERROR;
+    PN_CPP_EXTERN static const event_type SELECTABLE_EXPIRED;
+    PN_CPP_EXTERN static const event_type SELECTABLE_FINAL;
+
+    ///@}
+
+    virtual PN_CPP_EXTERN void dispatch(handler &h);
+    virtual PN_CPP_EXTERN class container &container();
+    virtual PN_CPP_EXTERN class connection &connection();
+    virtual PN_CPP_EXTERN class sender& sender();
+    virtual PN_CPP_EXTERN class receiver& receiver();
+    virtual PN_CPP_EXTERN class link& link();
+    virtual PN_CPP_EXTERN class delivery& delivery();
+
+    /** Get type of event */
+    PN_CPP_EXTERN event_type type();
+
+    PN_CPP_EXTERN pn_event_t* pn_event();
+
+  protected:
+    PN_CPP_EXTERN proton_event(pn_event_t *ce, proton_event::event_type t, class container &c);
+  private:
+    pn_event_t *pn_event_;
+    event_type type_;
+    class container &container_;
+};
+
+}
+
+#endif  /*!PROTON_CPP_PROTONEVENT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/proton_handler.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/proton_handler.hpp b/proton-c/bindings/cpp/include/proton/proton_handler.hpp
new file mode 100644
index 0000000..2738f71
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/proton_handler.hpp
@@ -0,0 +1,86 @@
+#ifndef PROTON_CPP_PROTONHANDLER_H
+#define PROTON_CPP_PROTONHANDLER_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/handler.hpp"
+
+namespace proton {
+
+class event;
+class proton_event;
+
+/// Handler base class, subclass and over-ride event handling member functions.
+/// @see proton::proton_event for meaning of events.
+class proton_handler : public handler
+{
+  public:
+    PN_CPP_EXTERN proton_handler();
+
+    ///@name Over-ride these member functions to handle events
+    ///@{
+    PN_CPP_EXTERN virtual void on_reactor_init(event &e);
+    PN_CPP_EXTERN virtual void on_reactor_quiesced(event &e);
+    PN_CPP_EXTERN virtual void on_reactor_final(event &e);
+    PN_CPP_EXTERN virtual void on_timer_task(event &e);
+    PN_CPP_EXTERN virtual void on_connection_init(event &e);
+    PN_CPP_EXTERN virtual void on_connection_bound(event &e);
+    PN_CPP_EXTERN virtual void on_connection_unbound(event &e);
+    PN_CPP_EXTERN virtual void on_connection_local_open(event &e);
+    PN_CPP_EXTERN virtual void on_connection_local_close(event &e);
+    PN_CPP_EXTERN virtual void on_connection_remote_open(event &e);
+    PN_CPP_EXTERN virtual void on_connection_remote_close(event &e);
+    PN_CPP_EXTERN virtual void on_connection_final(event &e);
+    PN_CPP_EXTERN virtual void on_session_init(event &e);
+    PN_CPP_EXTERN virtual void on_session_local_open(event &e);
+    PN_CPP_EXTERN virtual void on_session_local_close(event &e);
+    PN_CPP_EXTERN virtual void on_session_remote_open(event &e);
+    PN_CPP_EXTERN virtual void on_session_remote_close(event &e);
+    PN_CPP_EXTERN virtual void on_session_final(event &e);
+    PN_CPP_EXTERN virtual void on_link_init(event &e);
+    PN_CPP_EXTERN virtual void on_link_local_open(event &e);
+    PN_CPP_EXTERN virtual void on_link_local_close(event &e);
+    PN_CPP_EXTERN virtual void on_link_local_detach(event &e);
+    PN_CPP_EXTERN virtual void on_link_remote_open(event &e);
+    PN_CPP_EXTERN virtual void on_link_remote_close(event &e);
+    PN_CPP_EXTERN virtual void on_link_remote_detach(event &e);
+    PN_CPP_EXTERN virtual void on_link_flow(event &e);
+    PN_CPP_EXTERN virtual void on_link_final(event &e);
+    PN_CPP_EXTERN virtual void on_delivery(event &e);
+    PN_CPP_EXTERN virtual void on_transport(event &e);
+    PN_CPP_EXTERN virtual void on_transport_error(event &e);
+    PN_CPP_EXTERN virtual void on_transport_head_closed(event &e);
+    PN_CPP_EXTERN virtual void on_transport_tail_closed(event &e);
+    PN_CPP_EXTERN virtual void on_transport_closed(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_init(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_updated(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_readable(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_writable(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_expired(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_error(event &e);
+    PN_CPP_EXTERN virtual void on_selectable_final(event &e);
+    PN_CPP_EXTERN virtual void on_unhandled(event &e);
+    ///@}
+};
+
+}
+
+#endif  /*!PROTON_CPP_PROTONHANDLER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/reactor.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/reactor.hpp b/proton-c/bindings/cpp/include/proton/reactor.hpp
new file mode 100644
index 0000000..37dec6e
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/reactor.hpp
@@ -0,0 +1,75 @@
+#ifndef REACTOR_HPP
+#define REACTOR_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 "proton/facade.hpp"
+#include "proton/duration.hpp"
+#include "proton/memory.hpp"
+
+struct pn_reactor_t;
+
+namespace proton {
+
+class connection;
+class acceptor;
+class url;
+class handler;
+
+class reactor : public facade<pn_reactor_t, reactor> {
+ public:
+    /** Create a new reactor. */
+    PN_CPP_EXTERN static PN_UNIQUE_PTR<reactor> create();
+
+    /** Open a connection @see connection::open  */
+    PN_CPP_EXTERN connection& connect(const proton::url&, handler *h=0);
+
+    /** Open a connection to url and create a receiver with source=url.path() */
+    PN_CPP_EXTERN acceptor& listen(const proton::url &);
+
+    /** Run the event loop, return when all connections and acceptors are closed. */
+    PN_CPP_EXTERN void run();
+
+    /** Start the reactor, you must call process() to process events */
+    PN_CPP_EXTERN void start();
+
+    /** Process events, return true if there are more events to process. */
+    PN_CPP_EXTERN bool process();
+
+    /** Stop the reactor, causes run() to return and process() to return false. */
+    PN_CPP_EXTERN void stop();
+
+    /// Identifier for the container
+    PN_CPP_EXTERN std::string container_id();
+
+    /// Get timeout, process() will return if there is no activity within the timeout.
+    PN_CPP_EXTERN duration timeout();
+
+    /// Set timeout, process() will return if there is no activity within the timeout.
+    PN_CPP_EXTERN void timeout(duration timeout);
+
+    PN_CPP_EXTERN void wakeup();
+    PN_CPP_EXTERN bool quiesced();
+    PN_CPP_EXTERN void yield();
+
+    void operator delete(void*);
+};
+
+}
+#endif // REACTOR_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/receiver.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/receiver.hpp b/proton-c/bindings/cpp/include/proton/receiver.hpp
new file mode 100644
index 0000000..16c9425
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/receiver.hpp
@@ -0,0 +1,46 @@
+#ifndef PROTON_CPP_RECEIVER_H
+#define PROTON_CPP_RECEIVER_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"
+#include "proton/endpoint.hpp"
+#include "proton/link.hpp"
+#include "proton/types.h"
+#include <string>
+
+struct pn_connection_t;
+
+namespace proton {
+
+/// A receiving link
+class receiver : public counted_facade<pn_link_t, receiver, link>
+{
+  public:
+    /// Add credit to the link
+    PN_CPP_EXTERN void flow(int count);
+
+    PN_CPP_EXTERN receiver* cast(pn_type*);
+};
+
+}
+
+#endif  /*!PROTON_CPP_RECEIVER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/sender.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/sender.hpp b/proton-c/bindings/cpp/include/proton/sender.hpp
new file mode 100644
index 0000000..3106a7b
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/sender.hpp
@@ -0,0 +1,49 @@
+#ifndef PROTON_CPP_SENDER_H
+#define PROTON_CPP_SENDER_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"
+#include "proton/delivery.hpp"
+#include "proton/link.hpp"
+#include "proton/message.hpp"
+
+#include "proton/types.h"
+#include <string>
+
+struct pn_connection_t;
+
+namespace proton {
+
+/// A sending link
+class sender : public counted_facade<pn_link_t, sender, link>
+{
+  public:
+    /// Send a message on the link.
+    PN_CPP_EXTERN delivery& send(const message &m);
+
+    PN_CPP_EXTERN sender* cast(pn_type*);
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_SENDER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..fdee859
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/session.hpp
@@ -0,0 +1,83 @@
+#ifndef PROTON_CPP_SESSION_H
+#define PROTON_CPP_SESSION_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"
+#include "proton/endpoint.hpp"
+#include "proton/link.hpp"
+
+#include "proton/types.h"
+#include "proton/link.h"
+#include <string>
+
+struct pn_connection_t;
+
+namespace proton {
+
+class container;
+class handler;
+class transport;
+
+/** A session is a collection of links */
+class session : public counted_facade<pn_session_t, session, endpoint>
+{
+  public:
+    /** Initiate local open, not complete till messaging_handler::on_session_opened()
+     * or proton_handler::on_session_remote_open()
+     */
+    PN_CPP_EXTERN void open();
+
+    /** Initiate local close, not complete till messaging_handler::on_session_closed()
+     * or proton_handler::on_session_remote_close()
+     */
+    PN_CPP_EXTERN void close();
+
+    /// Get connection
+    PN_CPP_EXTERN class connection &connection();
+
+    /** 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);
+
+    /** Get the endpoint state */
+    PN_CPP_EXTERN endpoint::state state();
+};
+
+}
+
+#endif  /*!PROTON_CPP_SESSION_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/sync_request_response.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/sync_request_response.hpp b/proton-c/bindings/cpp/include/proton/sync_request_response.hpp
new file mode 100644
index 0000000..8c54d64
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/sync_request_response.hpp
@@ -0,0 +1,63 @@
+#ifndef PROTON_CPP_SYNC_REQUEST_RESPONSE_H
+#define PROTON_CPP_SYNC_REQUEST_RESPONSE_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"
+#include "proton/messaging_handler.hpp"
+#include "proton/blocking_receiver.hpp"
+#include "proton/blocking_sender.hpp"
+#include "proton/memory.hpp"
+
+#include <string>
+
+struct pn_message_t;
+struct pn_data_t;
+
+namespace proton {
+
+/**
+ * An implementation of the synchronous request-response pattern (aka RPC).
+ */
+class sync_request_response
+{
+  public:
+    PN_CPP_EXTERN sync_request_response(
+        blocking_connection &, const std::string address=std::string());
+    /**
+     * Send a request message, wait for and return the response message.
+     * Modifies the message to set `address` (if not already set), `reply_to` and `correlation_id`.
+     */
+    PN_CPP_EXTERN message_value call(message &);
+    /** Return the dynamic address of our receiver. */
+    PN_CPP_EXTERN std::string reply_to();
+
+  private:
+    blocking_connection &connection_;
+    std::string address_;
+    PN_UNIQUE_PTR<blocking_sender> sender_;
+    PN_UNIQUE_PTR<blocking_receiver> receiver_;
+    amqp_ulong correlation_id_;
+};
+
+}
+
+#endif  /*!PROTON_CPP_SYNC_REQUEST_RESPONSE_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/terminus.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/terminus.hpp b/proton-c/bindings/cpp/include/proton/terminus.hpp
new file mode 100644
index 0000000..4bb9651
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/terminus.hpp
@@ -0,0 +1,77 @@
+#ifndef PROTON_CPP_TERMINUS_H
+#define PROTON_CPP_TERMINUS_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"
+
+#include "proton/link.h"
+#include "proton/facade.hpp"
+#include <string>
+
+namespace proton {
+
+class link;
+
+/** A terminus represents one end of a link.
+ * The source terminus is where originate, the target terminus is where they go.
+ */
+class terminus : public counted_facade<pn_terminus_t, terminus>
+{
+  public:
+    /// Type of terminus
+    enum type_t {
+        TYPE_UNSPECIFIED = PN_UNSPECIFIED,
+        SOURCE = PN_SOURCE,
+        TARGET = PN_TARGET,
+        COORDINATOR = PN_COORDINATOR ///< Transaction co-ordinator
+    };
+
+    /// Expiry policy
+    enum expiry_policy_t {
+        NONDURABLE = PN_NONDURABLE,
+        CONFIGURATION = PN_CONFIGURATION,
+        DELIVERIES = PN_DELIVERIES
+    };
+
+    /// Distribution mode
+    enum distribution_mode_t {
+        MODE_UNSPECIFIED = PN_DIST_MODE_UNSPECIFIED,
+        COPY = PN_DIST_MODE_COPY,
+        MOVE = PN_DIST_MODE_MOVE
+    };
+
+    PN_CPP_EXTERN type_t type();
+    PN_CPP_EXTERN void type(type_t);
+    PN_CPP_EXTERN expiry_policy_t expiry_policy();
+    PN_CPP_EXTERN void expiry_policy(expiry_policy_t);
+    PN_CPP_EXTERN distribution_mode_t distribution_mode();
+    PN_CPP_EXTERN void distribution_mode(distribution_mode_t);
+    PN_CPP_EXTERN std::string address();
+    PN_CPP_EXTERN void address(const std::string &);
+    PN_CPP_EXTERN bool is_dynamic();
+    PN_CPP_EXTERN void dynamic(bool);
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_TERMINUS_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/transport.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/transport.hpp b/proton-c/bindings/cpp/include/proton/transport.hpp
new file mode 100644
index 0000000..c909166
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/transport.hpp
@@ -0,0 +1,45 @@
+#ifndef PROTON_CPP_TRANSPORT_H
+#define PROTON_CPP_TRANSPORT_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/facade.hpp"
+
+#include "proton/export.hpp"
+
+struct pn_transport_t;
+
+namespace proton {
+
+class connection;
+
+/** Represents a connection transport */
+class transport : public counted_facade<pn_transport_t, transport>
+{
+  public:
+    class connection* connection();
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_TRANSPORT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/type_traits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/type_traits.hpp b/proton-c/bindings/cpp/include/proton/type_traits.hpp
new file mode 100644
index 0000000..fb43cb9
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/type_traits.hpp
@@ -0,0 +1,118 @@
+#ifndef TYPE_TRAITS_HPP
+#define TYPE_TRAITS_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.
+ */
+
+/**@file
+ * Internal: Type traits for mapping between AMQP and C++ types.
+ *
+ * Also provides workarounds for missing type_traits classes on older C++ compilers.
+ * @cond INTERNAL
+ */
+
+#include "proton/config.hpp"
+#include "proton/types.hpp"
+
+namespace proton {
+template <bool, class T=void> struct enable_if;
+template <class T> struct enable_if<true, T> { typedef T type; };
+
+struct true_type { static const bool value = true; };
+struct false_type { static const bool value = false; };
+
+template <class T> struct is_integral : public false_type {};
+
+template <> struct is_integral<unsigned char> : public true_type {};
+template <> struct is_integral<unsigned short> : public true_type {};
+template <> struct is_integral<unsigned int> : public true_type {};
+template <> struct is_integral<unsigned long> : public true_type {};
+
+template <> struct is_integral<signed char> : public true_type {};
+template <> struct is_integral<signed short> : public true_type {};
+template <> struct is_integral<signed int> : public true_type {};
+template <> struct is_integral<signed long> : public true_type {};
+
+template <class T> struct is_signed : public false_type {};
+
+template <> struct is_signed<unsigned char> : public false_type {};
+template <> struct is_signed<unsigned short> : public false_type {};
+template <> struct is_signed<unsigned int> : public false_type {};
+template <> struct is_signed<unsigned long> : public false_type {};
+
+template <> struct is_signed<signed char> : public true_type {};
+template <> struct is_signed<signed short> : public true_type {};
+template <> struct is_signed<signed int> : public true_type {};
+template <> struct is_signed<signed long> : public true_type {};
+
+#if PN_HAS_LONG_LONG
+template <> struct is_integral<unsigned long long> : public true_type {};
+template <> struct is_integral<signed long long> : public true_type {};
+template <> struct is_signed<unsigned long long> : public false_type {};
+template <> struct is_signed<signed long long> : public true_type {};
+#endif
+
+// Metafunction returning exact AMQP type associated with a C++ type
+template <class T> struct type_id_of;
+template<> struct type_id_of<amqp_null> { static const type_id value=NULL_; };
+template<> struct type_id_of<amqp_bool> { static const type_id value=BOOL; };
+template<> struct type_id_of<amqp_ubyte> { static const type_id value=UBYTE; };
+template<> struct type_id_of<amqp_byte> { static const type_id value=BYTE; };
+template<> struct type_id_of<amqp_ushort> { static const type_id value=USHORT; };
+template<> struct type_id_of<amqp_short> { static const type_id value=SHORT; };
+template<> struct type_id_of<amqp_uint> { static const type_id value=UINT; };
+template<> struct type_id_of<amqp_int> { static const type_id value=INT; };
+template<> struct type_id_of<amqp_char> { static const type_id value=CHAR; };
+template<> struct type_id_of<amqp_ulong> { static const type_id value=ULONG; };
+template<> struct type_id_of<amqp_long> { static const type_id value=LONG; };
+template<> struct type_id_of<amqp_timestamp> { static const type_id value=TIMESTAMP; };
+template<> struct type_id_of<amqp_float> { static const type_id value=FLOAT; };
+template<> struct type_id_of<amqp_double> { static const type_id value=DOUBLE; };
+template<> struct type_id_of<amqp_decimal32> { static const type_id value=DECIMAL32; };
+template<> struct type_id_of<amqp_decimal64> { static const type_id value=DECIMAL64; };
+template<> struct type_id_of<amqp_decimal128> { static const type_id value=DECIMAL128; };
+template<> struct type_id_of<amqp_uuid> { static const type_id value=UUID; };
+template<> struct type_id_of<amqp_binary> { static const type_id value=BINARY; };
+template<> struct type_id_of<amqp_string> { static const type_id value=STRING; };
+template<> struct type_id_of<amqp_symbol> { static const type_id value=SYMBOL; };
+
+template <class T, class Enable=void> struct has_type_id { static const bool value = false; };
+template <class T> struct has_type_id<T, typename enable_if<type_id_of<T>::value>::type>  {
+    static const bool value = true;
+};
+
+// amqp_map to known integer types by sizeof and signedness.
+template<size_t N, bool S> struct integer_type;
+template<> struct integer_type<1, true> { typedef amqp_byte type; };
+template<> struct integer_type<2, true> { typedef amqp_short type; };
+template<> struct integer_type<4, true> { typedef amqp_int type; };
+template<> struct integer_type<8, true> { typedef amqp_long type; };
+template<> struct integer_type<1, false> { typedef amqp_ubyte type; };
+template<> struct integer_type<2, false> { typedef amqp_ushort type; };
+template<> struct integer_type<4, false> { typedef amqp_uint type; };
+template<> struct integer_type<8, false> { typedef amqp_ulong type; };
+
+// True if T is an integer type that does not have a type_id mapping.
+template <class T> struct is_unknown_integer {
+    static const bool value = bool((!has_type_id<T>::value) && is_integral<T>::value);
+};
+
+}
+///@endcond
+
+#endif // TYPE_TRAITS_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/types.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/types.hpp b/proton-c/bindings/cpp/include/proton/types.hpp
new file mode 100644
index 0000000..2de83d2
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/types.hpp
@@ -0,0 +1,248 @@
+#ifndef TYPES_H
+#define TYPES_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.
+ */
+
+/**@file
+ * Defines C++ types representing AMQP types.
+ */
+
+#include "proton/export.hpp"
+#include "proton/comparable.hpp"
+
+#include <proton/codec.h>
+#include <proton/type_compat.h>
+
+#include <algorithm>
+#include <bitset>
+#include <string>
+#include <memory.h>
+#include <algorithm>
+
+namespace proton {
+
+/** type_id identifies an AMQP type. */
+enum type_id {
+    NULL_=PN_NULL,              ///< The null type, contains no data.
+    BOOL=PN_BOOL,               ///< Boolean true or false.
+    UBYTE=PN_UBYTE,             ///< Unsigned 8 bit integer.
+    BYTE=PN_BYTE,               ///< Signed 8 bit integer.
+    USHORT=PN_USHORT,           ///< Unsigned 16 bit integer.
+    SHORT=PN_SHORT,             ///< Signed 16 bit integer.
+    UINT=PN_UINT,               ///< Unsigned 32 bit integer.
+    INT=PN_INT,                 ///< Signed 32 bit integer.
+    CHAR=PN_CHAR,               ///< 32 bit unicode character.
+    ULONG=PN_ULONG,             ///< Unsigned 64 bit integer.
+    LONG=PN_LONG,               ///< Signed 64 bit integer.
+    TIMESTAMP=PN_TIMESTAMP,     ///< Signed 64 bit milliseconds since the epoch.
+    FLOAT=PN_FLOAT,             ///< 32 bit binary floating point.
+    DOUBLE=PN_DOUBLE,           ///< 64 bit binary floating point.
+    DECIMAL32=PN_DECIMAL32,     ///< 32 bit decimal floating point.
+    DECIMAL64=PN_DECIMAL64,     ///< 64 bit decimal floating point.
+    DECIMAL128=PN_DECIMAL128,   ///< 128 bit decimal floating point.
+    UUID=PN_UUID,               ///< 16 byte UUID.
+    BINARY=PN_BINARY,           ///< Variable length sequence of bytes.
+    STRING=PN_STRING,           ///< Variable length utf8-encoded string.
+    SYMBOL=PN_SYMBOL,           ///< Variable length encoded string.
+    DESCRIBED=PN_DESCRIBED,     ///< A descriptor and a value.
+    ARRAY=PN_ARRAY,             ///< A sequence of values of the same type.
+    LIST=PN_LIST,               ///< A sequence of values, may be of mixed types.
+    MAP=PN_MAP                  ///< A sequence of key:value pairs, may be of mixed types.
+};
+
+PN_CPP_EXTERN pn_bytes_t pn_bytes(const std::string&);
+PN_CPP_EXTERN std::string str(const pn_bytes_t& b);
+///@endcond
+
+/// AMQP NULL type.
+struct amqp_null {};
+/// AMQP boolean type.
+typedef bool amqp_bool;
+/// AMQP unsigned 8-bit type.
+typedef ::uint8_t amqp_ubyte;
+/// AMQP signed 8-bit integer type.
+typedef ::int8_t amqp_byte;
+/// AMQP unsigned 16-bit integer type.
+typedef ::uint16_t amqp_ushort;
+/// AMQP signed 16-bit integer type.
+typedef ::int16_t amqp_short;
+/// AMQP unsigned 32-bit integer type.
+typedef ::uint32_t amqp_uint;
+/// AMQP signed 32-bit integer type.
+typedef ::int32_t amqp_int;
+/// AMQP 32-bit unicode character type.
+typedef wchar_t amqp_char;
+/// AMQP unsigned 64-bit integer type.
+typedef ::uint64_t amqp_ulong;
+/// AMQP signed 64-bit integer type.
+typedef ::int64_t amqp_long;
+/// AMQP 32-bit floating-point type.
+typedef float amqp_float;
+/// AMQP 64-bit floating-point type.
+typedef double amqp_double;
+
+/// AMQP UTF-8 encoded string.
+struct amqp_string : public std::string {
+    amqp_string(const std::string& s=std::string()) : std::string(s) {}
+    amqp_string(const char* s) : std::string(s) {}
+    amqp_string(const pn_bytes_t& b) : std::string(b.start, b.size) {}
+    operator pn_bytes_t() const { return pn_bytes(*this); }
+};
+
+/// AMQP ASCII encoded symbolic name.
+struct amqp_symbol : public std::string {
+    amqp_symbol(const std::string& s=std::string()) : std::string(s) {}
+    amqp_symbol(const char* s) : std::string(s) {}
+    amqp_symbol(const pn_bytes_t& b) : std::string(b.start, b.size) {}
+    operator pn_bytes_t() const { return pn_bytes(*this); }
+};
+
+/// AMQP variable-length binary data.
+struct amqp_binary : public std::string {
+    amqp_binary(const std::string& s=std::string()) : std::string(s) {}
+    amqp_binary(const char* s) : std::string(s) {}
+    amqp_binary(const pn_bytes_t& b) : std::string(b.start, b.size) {}
+    operator pn_bytes_t() const { return pn_bytes(*this); }
+};
+
+// TODO aconway 2015-06-11: alternative representation of variable-length data
+// as pointer to existing buffer.
+
+/// Template for opaque proton proton types that can be treated as byte arrays.
+template <class P> struct opaque: public comparable<opaque<P> > {
+    P value;
+    opaque(const P& p=P()) : value(p) {}
+    operator P() const { return value; }
+
+    static size_t size() { return sizeof(P); }
+    char* begin() { return reinterpret_cast<char*>(&value); }
+    char* end() { return reinterpret_cast<char*>(&value)+size(); }
+    const char* begin() const { return reinterpret_cast<const char*>(&value); }
+    const char* end() const { return reinterpret_cast<const char*>(&value)+size(); }
+    char& operator[](size_t i) { return *(begin()+i); }
+    const char& operator[](size_t i) const { return *(begin()+i); }
+
+    bool operator==(const opaque& x) const { return std::equal(begin(), end(), x.begin()); }
+    bool operator<(const opaque& x) const { return std::lexicographical_compare(begin(), end(), x.begin(), x.end()); }
+};
+
+/// AMQP 16-byte UUID.
+typedef opaque<pn_uuid_t> amqp_uuid;
+PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const amqp_uuid&);
+/// AMQP 32-bit decimal floating point (IEEE 854).
+typedef opaque<pn_decimal32_t> amqp_decimal32;
+/// AMQP 64-bit decimal floating point (IEEE 854).
+typedef opaque<pn_decimal64_t> amqp_decimal64;
+/// AMQP 128-bit decimal floating point (IEEE 854).
+typedef opaque<pn_decimal128_t> amqp_decimal128;
+
+/// AMQP timestamp, milliseconds since the epoch 00:00:00 (UTC), 1 January 1970.
+struct amqp_timestamp : public comparable<amqp_timestamp> {
+    pn_timestamp_t milliseconds;
+    amqp_timestamp(::int64_t ms=0) : milliseconds(ms) {}
+    operator pn_timestamp_t() const { return milliseconds; }
+    bool operator==(const amqp_timestamp& x) { return milliseconds == x.milliseconds; }
+    bool operator<(const amqp_timestamp& x) { return milliseconds < x.milliseconds; }
+};
+
+///@cond INTERNAL
+template<class T, type_id A> struct type_pair {
+    typedef T cpp_type;
+    type_id type;
+};
+
+template<class T, type_id A> struct ref : public type_pair<T, A> {
+    ref(T& v) : value(v) {}
+    T& value;
+};
+
+template<class T, type_id A> struct cref : public type_pair<T, A> {
+    cref(const T& v) : value(v) {}
+    cref(const ref<T,A>& ref) : value(ref.value) {}
+    const T& value;
+};
+///@endcond INTERNAL
+
+/** A holder for AMQP values. A holder is always encoded/decoded as its amqp_value, no need
+ * for the as<TYPE>() helper functions.
+ *
+ * For example to encode an array of arrays using std::vector:
+ *
+ *     typedef holder<std::vector<amqp_string>, ARRAY> Inner;
+ *     typedef holder<std::vector<Inner>, ARRAY> Outer;
+ *     Outer o ...
+ *     encoder << o;
+ *
+ */
+template<class T, type_id A> struct holder : public type_pair<T, A> {
+    T value;
+};
+
+/** Create a reference to value as AMQP type A for decoding.
+ * For example to decode an array of amqp_int:
+ *
+ *     std::vector<amqp_int> v;
+ *     decoder >> as<ARRAY>(v);
+ */
+template <type_id A, class T> ref<T, A> as(T& value) { return ref<T, A>(value); }
+
+/** Create a const reference to value as AMQP type A for encoding.
+ * For example to encode an array of amqp_int:
+ *
+ *     std::vector<amqp_int> v;
+ *     encoder << as<ARRAY>(v);
+ */
+template <type_id A, class T> cref<T, A> as(const T& value) { return cref<T, A>(value); }
+
+// TODO aconway 2015-06-16: described types.
+
+/** Return the name of a type. */
+PN_CPP_EXTERN std::string type_name(type_id);
+
+/** Print the name of a type. */
+PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
+
+/** Information needed to start extracting or inserting a container type.
+ *
+ * See encoder::operator<<(encoder&, const start&) and decoder::operator>>(decoder&, start&)
+ * for examples of use.
+ */
+struct start {
+    PN_CPP_EXTERN start(type_id type=NULL_, type_id element=NULL_, bool described=false, size_t size=0);
+    type_id type;            ///< The container type: ARRAY, LIST, MAP or DESCRIBED.
+    type_id element;         ///< the element type for array only.
+    bool is_described;       ///< true if first value is a descriptor.
+    size_t size;            ///< the element count excluding the descriptor (if any)
+
+    /** Return a start for an array */
+    PN_CPP_EXTERN static start array(type_id element, bool described=false);
+    /** Return a start for a list */
+    PN_CPP_EXTERN static start list();
+    /** Return a start for a map */
+    PN_CPP_EXTERN static start map();
+    /** Return a start for a described type */
+    PN_CPP_EXTERN static start described();
+};
+
+/** Finish insterting or extracting a container value. */
+struct finish {};
+
+}
+
+#endif // TYPES_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/url.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/url.hpp b/proton-c/bindings/cpp/include/proton/url.hpp
new file mode 100644
index 0000000..8c8fbb0
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/url.hpp
@@ -0,0 +1,128 @@
+#ifndef URL_HPP
+#define URL_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 "proton/facade.hpp"
+#include "proton/error.hpp"
+#include <iosfwd>
+
+struct pn_url_t;
+
+namespace proton {
+
+/// Thrown if URL parsing fails.
+struct bad_url : public error {
+    PN_CPP_EXTERN explicit bad_url(const std::string&) throw();
+};
+
+
+/**
+ * url is a proton URL of the form `<scheme>://<username>:<password>@<host>:<port>/<path>`.
+ * scheme can be `amqp` or `amqps`. host is a DNS name or IP address (v4 or v6)
+ * port can be a number or symbolic service name like `amqp`. path is normally used as
+ * a link source or target address, on a broker it typically it corresponds to a queue or topic name.
+ */
+class url {
+  public:
+    static const std::string AMQP;     ///< "amqp" prefix
+    static const std::string AMQPS;    ///< "amqps" prefix
+
+    /** Create an empty url */
+    PN_CPP_EXTERN url();
+
+    /** Parse url_str as an AMQP URL. If defaults is true, fill in defaults for missing values
+     *  otherwise return an empty string for missing values.
+     *  Note: converts automatically from string.
+     *@throw bad_url if URL is invalid.
+     */
+    PN_CPP_EXTERN url(const std::string& url_str, bool defaults=true);
+
+    /** Parse url_str as an AMQP URL. If defaults is true, fill in defaults for missing values
+     *  otherwise return an empty string for missing values.
+     *  Note: converts automatically from string.
+     *@throw bad_url if URL is invalid.
+     */
+    PN_CPP_EXTERN url(const char* url_str, bool defaults=true);
+
+    PN_CPP_EXTERN url(const url&);
+    PN_CPP_EXTERN ~url();
+    PN_CPP_EXTERN url& operator=(const url&);
+
+    /** Parse a string as a URL
+     *@throws bad_url if URL is invalid.
+     */
+    PN_CPP_EXTERN void parse(const std::string&);
+
+    /** Parse a string as a URL
+     *@throws bad_url if URL is invalid.
+     */
+    PN_CPP_EXTERN void parse(const char*);
+
+    PN_CPP_EXTERN bool empty() const;
+
+    /** str returns the URL as a string string */
+    PN_CPP_EXTERN std::string str() const;
+
+    /**@name Get parts of the URL
+     *@{
+     */
+    PN_CPP_EXTERN std::string scheme() const;
+    PN_CPP_EXTERN std::string username() const;
+    PN_CPP_EXTERN std::string password() const;
+    PN_CPP_EXTERN std::string host() const;
+    /** port is a string, it can be a number or a symbolic name like "amqp" */
+    PN_CPP_EXTERN std::string port() const;
+    PN_CPP_EXTERN std::string path() const;
+    //@}
+
+    /** host_port returns just the host:port part of the URL */
+    PN_CPP_EXTERN std::string host_port() const;
+
+    /**@name Set parts of the URL
+     *@{
+     */
+    PN_CPP_EXTERN void scheme(const std::string&);
+    PN_CPP_EXTERN void username(const std::string&);
+    PN_CPP_EXTERN void password(const std::string&);
+    PN_CPP_EXTERN void host(const std::string&);
+    /** port is a string, it can be a number or a symbolic name like "amqp" */
+    PN_CPP_EXTERN void port(const std::string&);
+    PN_CPP_EXTERN void path(const std::string&);
+    //@}
+
+    /** defaults fills in default values for missing parts of the URL */
+    PN_CPP_EXTERN void defaults();
+
+  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const url&);
+
+    /** parse url from istream, automatically fills in defaults for missing values.
+     *
+     * Note: an invalid url is indicated by setting std::stream::fail() NOT by throwing bad_url.
+     */
+  friend PN_CPP_EXTERN std::istream& operator>>(std::istream&, url&);
+
+  private:
+    pn_url_t* url_;
+};
+
+
+}
+
+#endif // URL_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/acceptor.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/acceptor.cpp b/proton-c/bindings/cpp/src/acceptor.cpp
new file mode 100644
index 0000000..4fc538c
--- /dev/null
+++ b/proton-c/bindings/cpp/src/acceptor.cpp
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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/acceptor.hpp"
+#include "proton/error.hpp"
+#include "msg.hpp"
+
+namespace proton {
+
+void acceptor::close() { pn_acceptor_close(pn_cast(this)); }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..6b0308c
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_connection.cpp
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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/container.hpp"
+#include "proton/blocking_connection.hpp"
+#include "blocking_connection_impl.hpp"
+
+namespace proton {
+
+blocking_connection::blocking_connection(const proton::url &url, duration timeout) :
+    impl_(new blocking_connection_impl(url, timeout))
+{}
+
+blocking_connection::~blocking_connection() {}
+
+void blocking_connection::close() { impl_->close(); }
+
+duration blocking_connection::timeout() { return impl_->container_->reactor().timeout(); }
+
+connection& blocking_connection::connection() { return *impl_->connection_; }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_connection_impl.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_connection_impl.cpp b/proton-c/bindings/cpp/src/blocking_connection_impl.cpp
new file mode 100644
index 0000000..8abd24b
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_connection_impl.cpp
@@ -0,0 +1,103 @@
+/*
+ *
+ * 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/container.hpp"
+#include "proton/messaging_handler.hpp"
+#include "proton/duration.hpp"
+#include "proton/connection.h"
+#include "proton/error.hpp"
+
+#include "blocking_connection_impl.hpp"
+#include "msg.hpp"
+#include "contexts.hpp"
+
+
+namespace proton {
+
+namespace {
+struct connection_opening : public blocking_connection_impl::condition {
+    connection_opening(pn_connection_t *c) : pn_connection(c) {}
+    bool operator()() const { return (pn_connection_state(pn_connection) & PN_REMOTE_UNINIT); }
+    pn_connection_t *pn_connection;
+};
+
+struct connection_closed : public blocking_connection_impl::condition {
+    connection_closed(pn_connection_t *c) : pn_connection(c) {}
+    bool operator()() const { return !(pn_connection_state(pn_connection) & PN_REMOTE_ACTIVE); }
+    pn_connection_t *pn_connection;
+};
+}
+
+blocking_connection_impl::blocking_connection_impl(const url& url, duration timeout) :
+    container_(new container())
+{
+    container_->reactor().start();
+    container_->reactor().timeout(timeout);
+    connection_ = container_->connect(url, this).ptr(); // Set this as handler.
+    wait(connection_opening(pn_cast(connection_.get())));
+}
+
+blocking_connection_impl::~blocking_connection_impl() {}
+
+void blocking_connection_impl::close() {
+    connection_->close();
+    wait(connection_closed(pn_cast(connection_.get())));
+}
+
+namespace {
+struct save_timeout {
+    reactor& reactor_;
+    duration timeout_;
+    save_timeout(reactor& r) : reactor_(r), timeout_(r.timeout()) {}
+    ~save_timeout() { reactor_.timeout(timeout_); }
+};
+}
+
+void blocking_connection_impl::wait(const condition &condition, const std::string &msg, duration wait_timeout)
+{
+    reactor& reactor = container_->reactor();
+
+    if (wait_timeout == duration(-1))
+        wait_timeout = container_->reactor().timeout();
+
+    if (wait_timeout == duration::FOREVER) {
+        while (!condition()) {
+            reactor.process();
+        }
+    } else {
+        save_timeout st(reactor);
+        reactor.timeout(wait_timeout);
+        pn_timestamp_t deadline = pn_reactor_mark(pn_cast(&reactor)) + wait_timeout.milliseconds;
+        while (!condition()) {
+            reactor.process();
+            if (!condition()) {
+                pn_timestamp_t now = pn_reactor_mark(pn_cast(&reactor));
+                if (now < deadline)
+                    reactor.timeout(duration(deadline - now));
+                else
+                    throw timeout_error("connection timed out " + msg);
+            }
+        }
+    }
+}
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_connection_impl.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_connection_impl.hpp b/proton-c/bindings/cpp/src/blocking_connection_impl.hpp
new file mode 100644
index 0000000..d3570b9
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_connection_impl.hpp
@@ -0,0 +1,60 @@
+#ifndef PROTON_CPP_BLOCKING_CONNECTION_IMPL_H
+#define PROTON_CPP_BLOCKING_CONNECTION_IMPL_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"
+#include "proton/container.hpp"
+#include "proton/messaging_handler.hpp"
+#include "proton/connection.hpp"
+#include "proton/types.h"
+#include <string>
+
+struct pn_connection_t;
+
+namespace proton {
+
+class handler;
+class container;
+
+class blocking_connection_impl : public messaging_handler
+{
+  public:
+    blocking_connection_impl(const url &url, duration d);
+    ~blocking_connection_impl();
+
+    void close();
+
+    struct condition {
+        virtual ~condition() {}
+        virtual bool operator()() const = 0;
+    };
+
+    void wait(const condition&, const std::string & ="", duration=duration(-1));
+
+    PN_UNIQUE_PTR<container> container_;
+    counted_ptr<connection> connection_;
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_BLOCKING_CONNECTION_IMPL_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_fetcher.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_fetcher.cpp b/proton-c/bindings/cpp/src/blocking_fetcher.cpp
new file mode 100644
index 0000000..7a53487
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_fetcher.cpp
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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 "blocking_fetcher.hpp"
+#include "msg.hpp"
+
+#include "proton/event.hpp"
+
+namespace proton {
+
+blocking_fetcher::blocking_fetcher(int prefetch) : messaging_handler(prefetch, false /*auto_accept*/) {}
+
+void blocking_fetcher::on_message(event &e) {
+    messages_.push_back(e.message());
+    deliveries_.push_back(e.delivery().ptr());
+    // Wake up enclosing connection.wait()
+    e.container().reactor().yield();
+}
+
+void blocking_fetcher::on_link_error(event &e) {
+    link& lnk = e.link();
+    if (pn_link_state(pn_cast(&lnk)) & PN_LOCAL_ACTIVE) {
+        lnk.close();
+        throw error(MSG("Link detached: " << lnk.name()));
+    }
+}
+
+bool blocking_fetcher::has_message() { return !messages_.empty(); }
+
+message_value blocking_fetcher::pop() {
+    if (messages_.empty())
+        throw error(MSG("receiver has no messages"));
+    counted_ptr<delivery> dlv(deliveries_.front());
+    if (!dlv->settled())
+        unsettled_.push_back(dlv);
+    message_value m = messages_.front();
+    messages_.pop_front();
+    deliveries_.pop_front();
+    return m;
+}
+
+void blocking_fetcher::settle(delivery::state state) {
+    counted_ptr<delivery> dlv = unsettled_.front();
+    if (state)
+        dlv->update(state);
+    dlv->settle();
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_fetcher.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_fetcher.hpp b/proton-c/bindings/cpp/src/blocking_fetcher.hpp
new file mode 100644
index 0000000..f0a8d17
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_fetcher.hpp
@@ -0,0 +1,48 @@
+#ifndef PROTON_CPP_FETCHER_H
+#define PROTON_CPP_FETCHER_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/messaging_handler.hpp"
+#include "proton/message.hpp"
+#include <string>
+#include <deque>
+
+namespace proton {
+
+class blocking_fetcher : public messaging_handler {
+  public:
+    blocking_fetcher(int prefetch);
+    void on_message(event &e);
+    void on_link_error(event &e);
+    bool has_message();
+    message_value pop();
+    void settle(delivery::state state = delivery::NONE);
+
+  private:
+    std::deque<message_value> messages_;
+    std::deque<counted_ptr<delivery> > deliveries_;
+    std::deque<counted_ptr<delivery> > unsettled_;
+};
+
+}
+
+#endif  /*!PROTON_CPP_FETCHER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_link.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_link.cpp b/proton-c/bindings/cpp/src/blocking_link.cpp
new file mode 100644
index 0000000..3fc2904
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_link.cpp
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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/blocking_link.hpp"
+#include "proton/blocking_connection.hpp"
+#include "proton/connection.hpp"
+#include "proton/error.hpp"
+#include "proton/link.hpp"
+
+#include "blocking_connection_impl.hpp"
+#include "msg.hpp"
+
+#include <proton/link.h>
+
+namespace proton {
+
+namespace {
+struct link_opened : public blocking_connection_impl::condition {
+    link_opened(pn_link_t *l) : pn_link(l) {}
+    bool operator()() const { return !(pn_link_state(pn_link) & PN_REMOTE_UNINIT); }
+    pn_link_t *pn_link;
+};
+
+struct link_closed : public blocking_connection_impl::condition {
+    link_closed(pn_link_t *l) : pn_link(l) {}
+    bool operator()() const { return (pn_link_state(pn_link) & PN_REMOTE_CLOSED); }
+    pn_link_t *pn_link;
+};
+
+struct link_not_open : public blocking_connection_impl::condition {
+    link_not_open(pn_link_t *l) : pn_link(l) {}
+    bool operator()() const { return !(pn_link_state(pn_link) & PN_REMOTE_ACTIVE); }
+    pn_link_t *pn_link;
+};
+
+} // namespace
+
+blocking_link::blocking_link(blocking_connection &c) : connection_(c) {}
+
+void blocking_link::open(proton::link& l) {
+    link_ = l.ptr();
+    connection_.impl_->wait(link_opened(pn_cast(link_.get())), "opening link " + link_->name());
+    check_closed();
+}
+
+blocking_link::~blocking_link() {}
+
+void blocking_link::wait_for_closed() {
+    link_closed link_closed(pn_cast(link_.get()));
+    connection_.impl_->wait(link_closed, "closing link " + link_->name());
+    check_closed();
+}
+
+void blocking_link::check_closed() {
+    pn_link_t * pn_link = pn_cast(link_.get());
+    if (pn_link_state(pn_link) & PN_REMOTE_CLOSED) {
+        link_->close();
+        throw error(MSG("Link detached: " << link_->name()));
+    }
+}
+
+void blocking_link::close() {
+    link_->close();
+    link_not_open link_not_open(pn_cast(link_.get()));
+    connection_.impl_->wait(link_not_open, "closing link " + link_->name());
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_receiver.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_receiver.cpp b/proton-c/bindings/cpp/src/blocking_receiver.cpp
new file mode 100644
index 0000000..10a3585
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_receiver.cpp
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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/blocking_connection.hpp"
+#include "proton/blocking_receiver.hpp"
+#include "proton/receiver.hpp"
+#include "proton/connection.hpp"
+#include "proton/receiver.hpp"
+#include "proton/error.hpp"
+
+#include "blocking_connection_impl.hpp"
+#include "blocking_fetcher.hpp"
+#include "msg.hpp"
+
+
+namespace proton {
+
+namespace {
+
+struct fetcher_has_message : public blocking_connection_impl::condition {
+    fetcher_has_message(blocking_fetcher &f) : fetcher_(f) {}
+    bool operator()() const { return fetcher_.has_message(); }
+    blocking_fetcher &fetcher_;
+};
+
+} // namespace
+
+blocking_receiver::blocking_receiver(
+    class blocking_connection &c, const std::string& addr, int credit, bool dynamic) :
+    blocking_link(c), fetcher_(new blocking_fetcher(credit))
+{
+    open(c.impl_->connection_->create_receiver(addr, dynamic, fetcher_.get()));
+    std::string sa = link_->source().address();
+    std::string rsa = link_->remote_source().address();
+    if (!sa.empty() && sa.compare(rsa) != 0) {
+        wait_for_closed();
+        link_->close();
+        std::string txt = "Failed to open receiver " + link_->name() + ", source does not match";
+        throw error(MSG(txt));
+    }
+    if (credit)
+        pn_link_flow(pn_cast(link_), credit);
+}
+
+blocking_receiver::~blocking_receiver() { link_->detach_handler(); }
+
+message_value blocking_receiver::receive(duration timeout) {
+    if (!receiver().credit())
+        receiver().flow(1);
+    fetcher_has_message cond(*fetcher_);
+    connection_.impl_->wait(cond, "receiving on receiver " + link_->name(), timeout);
+    return fetcher_->pop();
+}
+
+message_value blocking_receiver::receive() {
+    // Use default timeout
+    return receive(connection_.timeout());
+}
+
+void blocking_receiver::accept() {
+    settle(delivery::ACCEPTED);
+}
+
+void blocking_receiver::reject() {
+    settle(delivery::REJECTED);
+}
+
+void blocking_receiver::release(bool delivered) {
+    if (delivered)
+        settle(delivery::MODIFIED);
+    else
+        settle(delivery::RELEASED);
+}
+
+void blocking_receiver::settle(delivery::state state = delivery::NONE) {
+    fetcher_->settle(state);
+}
+
+void blocking_receiver::flow(int count) {
+    receiver().flow(count);
+}
+
+receiver& blocking_receiver::receiver() { return link_->receiver(); }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/blocking_sender.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/blocking_sender.cpp b/proton-c/bindings/cpp/src/blocking_sender.cpp
new file mode 100644
index 0000000..1d579c0
--- /dev/null
+++ b/proton-c/bindings/cpp/src/blocking_sender.cpp
@@ -0,0 +1,68 @@
+/*
+ *
+ * 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/blocking_sender.hpp"
+#include "proton/blocking_connection.hpp"
+#include "proton/sender.hpp"
+#include "proton/receiver.hpp"
+#include "proton/error.hpp"
+#include "blocking_connection_impl.hpp"
+#include "msg.hpp"
+
+namespace proton {
+
+namespace {
+struct delivery_settled : public blocking_connection_impl::condition {
+    delivery_settled(pn_delivery_t *d) : pn_delivery(d) {}
+    bool operator()() const { return pn_delivery_settled(pn_delivery); }
+    pn_delivery_t *pn_delivery;
+};
+} // namespace
+
+blocking_sender::blocking_sender(blocking_connection &c, const std::string &address) :
+    blocking_link(c)
+{
+    open(c.impl_->connection_->create_sender(address));
+    std::string ta = link_->target().address();
+    std::string rta = link_->remote_target().address();
+    if (ta.empty() || ta.compare(rta) != 0) {
+        wait_for_closed();
+        link_->close();
+        std::string txt = "Failed to open sender " + link_->name() + ", target does not match";
+        throw error(MSG(txt));
+    }
+}
+
+blocking_sender::~blocking_sender() {}
+
+delivery& blocking_sender::send(const message_value &msg, duration timeout) {
+    delivery& dlv = sender().send(msg);
+    connection_.impl_->wait(delivery_settled(pn_cast(&dlv)), "sending on sender " + link_->name(), timeout);
+    return dlv;
+}
+
+delivery& blocking_sender::send(const message_value &msg) {
+    // Use default timeout
+    return send(msg, connection_.timeout());
+}
+
+sender& blocking_sender::sender() { return link_->sender(); }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..84c79a6
--- /dev/null
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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/container.hpp"
+#include "proton/connection.hpp"
+#include "proton/transport.hpp"
+#include "proton/handler.hpp"
+#include "proton/session.hpp"
+#include "proton/error.hpp"
+
+#include "msg.hpp"
+#include "contexts.hpp"
+#include "container_impl.hpp"
+
+#include "proton/connection.h"
+#include "proton/session.h"
+#include "proton/transport.h"
+#include "proton/reactor.h"
+#include "proton/object.h"
+
+namespace proton {
+
+transport &connection::transport() {
+    return *transport::cast(pn_connection_transport(pn_cast(this)));
+}
+
+void connection::open() { pn_connection_open(pn_cast(this)); }
+
+void connection::close() { pn_connection_close(pn_cast(this)); }
+
+std::string connection::hostname() {
+    return std::string(pn_connection_get_hostname(pn_cast(this)));
+}
+
+container& connection::container() {
+    return container_context(pn_object_reactor(pn_cast(this)));
+}
+
+link* connection::link_head(endpoint::state mask) {
+    return link::cast(pn_link_head(pn_cast(this), mask));
+}
+
+session& connection::create_session() { return *session::cast(pn_session(pn_cast(this))); }
+
+session& connection::default_session() {
+    struct connection_context& ctx = connection_context::get(pn_cast(this));
+    if (!ctx.default_session) {
+        ctx.default_session = &create_session();
+        ctx.default_session->open();
+    }
+    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);
+}
+
+endpoint::state connection::state() { return pn_connection_state(pn_cast(this)); }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..3c7c970
--- /dev/null
+++ b/proton-c/bindings/cpp/src/connector.cpp
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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/connection.hpp"
+#include "proton/transport.hpp"
+#include "proton/container.hpp"
+#include "proton/event.hpp"
+#include "proton/connection.h"
+#include "proton/url.hpp"
+
+#include "connector.hpp"
+
+namespace proton {
+
+connector::connector(connection &c) : connection_(&c) {}
+
+connector::~connector() {}
+
+void connector::address(const url &a) {
+    address_ = a;
+}
+
+void connector::connect() {
+    pn_connection_t *conn = pn_cast(connection_);
+    pn_connection_set_container(conn, connection_->container().container_id().c_str());
+    pn_connection_set_hostname(conn, address_.host_port().c_str());
+}
+
+void connector::on_connection_local_open(event &e) {
+    connect();
+}
+
+void connector::on_connection_remote_open(event &e) {}
+
+void connector::on_connection_init(event &e) {
+}
+
+void connector::on_transport_closed(event &e) {
+    // TODO: prepend with reconnect logic
+    pn_connection_release(pn_cast(connection_));
+    connection_  = 0;
+}
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/src/connector.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connector.hpp b/proton-c/bindings/cpp/src/connector.hpp
new file mode 100644
index 0000000..b311cc9
--- /dev/null
+++ b/proton-c/bindings/cpp/src/connector.hpp
@@ -0,0 +1,58 @@
+#ifndef PROTON_CPP_CONNECTOR_HANDLER_H
+#define PROTON_CPP_CONNECTOR_HANDLER_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/proton_handler.hpp"
+#include "proton/event.h"
+#include "proton/reactor.h"
+#include "proton/url.h"
+#include <string>
+
+
+namespace proton {
+
+class event;
+class connection;
+class transport;
+
+class connector : public proton_handler
+{
+  public:
+    connector(connection &c);
+    ~connector();
+    void address(const url&);
+    void connect();
+    virtual void on_connection_local_open(event &e);
+    virtual void on_connection_remote_open(event &e);
+    virtual void on_connection_init(event &e);
+    virtual void on_transport_closed(event &e);
+
+  private:
+    connection* connection_;
+    url address_;
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_CONNECTOR_HANDLER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..574f5a7
--- /dev/null
+++ b/proton-c/bindings/cpp/src/container.cpp
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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/container.hpp"
+#include "proton/messaging_event.hpp"
+#include "proton/connection.hpp"
+#include "proton/session.hpp"
+#include "proton/messaging_adapter.hpp"
+#include "proton/acceptor.hpp"
+#include "proton/error.hpp"
+#include "proton/url.hpp"
+#include "proton/sender.hpp"
+#include "proton/receiver.hpp"
+
+#include "container_impl.hpp"
+#include "connector.hpp"
+#include "contexts.hpp"
+#include "proton/connection.h"
+#include "proton/session.h"
+
+namespace proton {
+
+//// Public container class.
+
+container::container(const std::string& id) :
+    impl_(new container_impl(*this, 0, id)) {}
+
+container::container(messaging_handler &mhandler, const std::string& id) :
+    impl_(new container_impl(*this, &mhandler, id)) {}
+
+container::~container() {}
+
+connection& container::connect(const url &host, handler *h) { return impl_->connect(host, h); }
+
+reactor &container::reactor() { return *impl_->reactor_; }
+
+std::string container::container_id() { return impl_->container_id_; }
+
+void container::run() { impl_->reactor_->run(); }
+
+sender& container::create_sender(const proton::url &url) {
+    return impl_->create_sender(url);
+}
+
+receiver& container::create_receiver(const proton::url &url) {
+    return impl_->create_receiver(url);
+}
+
+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


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


Mime
View raw message