qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [4/7] qpid-proton git commit: PROTON-865: C++ reactor binding for proton.
Date Fri, 04 Sep 2015 19:14:31 GMT
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/config.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/config.hpp b/proton-c/bindings/cpp/include/proton/config.hpp
new file mode 100644
index 0000000..178b6db
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/config.hpp
@@ -0,0 +1,57 @@
+#ifndef CONFIG_HPP
+#define CONFIG_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
+ *
+ * Configuration macros, can be set via -D compiler options or in code. 
+ *
+ * - PN_HAS_BOOST - include support for boost::shared_ptr and boost::intrusive_ptr
+ * - PN_HAS_STD_PTR - include support for c++11 std::shared_ptr and std::unique_ptr
+ * - PN_HAS_LONG_LONG - include support for the 'long long' type.
+ */
+
+#if ((defined(__cplusplus) && __cplusplus >= 201100))
+
+#define PN_HAS_CPP11 1
+
+#ifndef PN_HAS_STD_PTR
+#define PN_HAS_STD_PTR 1
+#endif
+
+#ifndef PN_HAS_LONG_LONG
+#define PN_HAS_LONG_LONG 1
+#endif
+
+#ifndef PN_HAS_STATIC_ASSERT
+#define PN_HAS_STATIC_ASSERT 1
+#endif
+
+#endif
+
+#if defined(BOOST_VERSION)
+
+#ifndef PN_HAS_BOOST
+#define PN_HAS_BOOST 1
+#endif
+
+#endif
+
+#endif // CONFIG_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..08b6ad9
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -0,0 +1,81 @@
+#ifndef PROTON_CPP_CONNECTION_H
+#define PROTON_CPP_CONNECTION_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/container.hpp"
+#include "proton/types.h"
+#include <string>
+
+struct pn_connection_t;
+
+namespace proton {
+
+class handler;
+class transport;
+
+/** connection to a remote AMQP peer. */
+class connection : public counted_facade<pn_connection_t, connection, endpoint>
+{
+  public:
+    ///@name getters @{
+    PN_CPP_EXTERN class transport& transport();
+    PN_CPP_EXTERN class container& container();
+    PN_CPP_EXTERN std::string hostname();
+    ///@}
+
+    /** Initiate local open, not complete till messaging_handler::on_connection_opened()
+     * or proton_handler::on_connection_remote_open()
+     */
+    PN_CPP_EXTERN void open();
+
+    /** Initiate local close, not complete till messaging_handler::on_connection_closed()
+     * or proton_handler::on_connection_remote_close()
+     */
+    PN_CPP_EXTERN void close();
+
+    /** Create a new session */
+    PN_CPP_EXTERN class session& create_session();
+
+    /** 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
+     */
+    PN_CPP_EXTERN link* link_head(endpoint::state mask);
+
+    /** Get the endpoint state */
+    PN_CPP_EXTERN endpoint::state state();
+};
+
+}
+
+#endif  /*!PROTON_CPP_CONNECTION_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/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
new file mode 100644
index 0000000..dc87082
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -0,0 +1,90 @@
+#ifndef PROTON_CPP_CONTAINER_H
+#define PROTON_CPP_CONTAINER_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/duration.hpp"
+#include "proton/export.hpp"
+#include "proton/reactor.hpp"
+#include "proton/url.hpp"
+#include "proton/memory.hpp"
+
+#include <string>
+
+namespace proton {
+
+class connection;
+class acceptor;
+class messaging_handler;
+class sender;
+class receiver;
+class link;
+class handler;
+class container_impl;
+
+/**
+ * Top level container for connections and other objects, runs the event loop.
+ */
+class container
+{
+  public:
+    /// 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  */
+    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();
+
+    /** 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 source=url.path() */
+    PN_CPP_EXTERN receiver& create_receiver(const url &);
+
+    /// Identifier for the container
+    PN_CPP_EXTERN std::string container_id();
+
+    /// 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();
+
+    /// The reactor associated with this container.
+    PN_CPP_EXTERN class reactor& reactor();
+
+  private:
+    PN_UNIQUE_PTR<container_impl> impl_;
+};
+
+}
+
+#endif  /*!PROTON_CPP_CONTAINER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/counted.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/counted.hpp b/proton-c/bindings/cpp/include/proton/counted.hpp
new file mode 100644
index 0000000..2195d93
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/counted.hpp
@@ -0,0 +1,48 @@
+#ifndef COUNTED_HPP
+#define COUNTED_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.
+ */
+
+namespace proton {
+
+/// Base class for reference counted objects other than proton struct facade types.
+class counted {
+  protected:
+    counted() : refcount_(0) {}
+    virtual ~counted() {}
+
+  private:
+    counted(const counted&);
+    counted& operator=(const counted&);
+    mutable int refcount_;
+
+    // TODO aconway 2015-08-27: atomic operations.
+    void incref() const { ++refcount_; }
+    void decref() const { if (--refcount_ == 0) delete this; }
+
+  friend void incref(const counted*);
+  friend void decref(const counted*);
+  template <class T> friend class counted_ptr;
+};
+
+inline void incref(const counted* p) { if (p) p->incref(); }
+inline void decref(const counted* p) { if (p) p->decref(); }
+
+}
+#endif // COUNTED_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/counted_ptr.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/counted_ptr.hpp b/proton-c/bindings/cpp/include/proton/counted_ptr.hpp
new file mode 100644
index 0000000..7023bd7
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/counted_ptr.hpp
@@ -0,0 +1,117 @@
+#ifndef COUNTED_PTR_HPP
+#define COUNTED_PTR_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/config.hpp"
+#include "proton/comparable.hpp"
+
+#if PN_HAS_BOOST
+#include <boost/shared_ptr.hpp>
+#include <boost/intrusive_ptr.hpp>
+#endif
+
+#include <memory>
+
+namespace proton {
+
+///@cond INTERNAL
+
+// Default refcounting uses pn_incref, pn_decref. Other types must define
+// their own incref/decref overloads.
+PN_CPP_EXTERN void incref(const void*);
+PN_CPP_EXTERN void decref(const void*);
+
+///@endcond
+
+/**
+ * Smart pointer for reference counted objects derived from `proton::counted`
+ * or `proton::pn_counted`
+ */
+template <class T> class counted_ptr : public proton::comparable<counted_ptr<T> > {
+  public:
+    typedef T element_type;
+
+    explicit counted_ptr(T *p = 0, bool add_ref = true) : ptr_(p) {
+        if (add_ref) incref(ptr_);
+    }
+
+    counted_ptr(const counted_ptr<T>& p) : ptr_(p.ptr_) { incref(ptr_); }
+
+    // TODO aconway 2015-08-20: C++11 move constructor
+
+    ~counted_ptr() { decref(ptr_); }
+
+    void swap(counted_ptr& x) { std::swap(ptr_, x.ptr_); }
+
+    counted_ptr<T>& operator=(const counted_ptr<T>& p) {
+        counted_ptr<T>(p.get()).swap(*this);
+        return *this;
+    }
+
+    void reset(T* p=0, bool add_ref = true) {
+        counted_ptr<T>(p, add_ref).swap(*this);
+    }
+
+    T* release() {
+        T* ret = ptr_;
+        ptr_ = 0;
+        return ret;
+    }
+
+    T* get() const { return ptr_; }
+    T* operator->() const { return ptr_; }
+    T& operator*() const { return *ptr_; }
+    operator bool() const { return ptr_; }
+    bool operator!() const { return !ptr_; }
+
+    template <class U> operator counted_ptr<U>() const { return counted_ptr<U>(get()); }
+    template <class U> bool operator==(const counted_ptr<U>& x) { return get() == x.get(); }
+    template <class U> bool operator<(const counted_ptr<U>& x) { return get() < x.get(); }
+
+#if PN_HAS_STD_PTR
+    // TODO aconway 2015-08-21: need weak pointer context for efficient shared_ptr
+    operator std::shared_ptr<T>() { return std::shared_ptr<T>(dup()); }
+    operator std::shared_ptr<const T>() const { return std::shared_ptr<const T>(dup()); }
+    operator std::unique_ptr<T>() { return std::unique_ptr<T>(dup()); }
+    operator std::unique_ptr<const T>() const { return std::unique_ptr<const T>(dup()); }
+#endif
+#if PN_HAS_BOOST
+    // TODO aconway 2015-08-21: need weak pointer context for efficient shared_ptr
+    operator boost::shared_ptr<T>() { return boost::shared_ptr<T>(dup()); }
+    operator boost::shared_ptr<const T>() const { return boost::shared_ptr<const T>(dup()); }
+    operator boost::intrusive_ptr<T>() { return boost::intrusive_ptr<T>(ptr_); }
+    operator boost::intrusive_ptr<const T>() const { return boost::intrusive_ptr<const T>(ptr_); }
+#endif
+
+  private:
+    T* dup() { incref(ptr_); return ptr_; }
+    const T* dup() const { incref(ptr_); return ptr_; }
+
+    T* ptr_;
+};
+
+#if PN_HAS_BOOST
+template <class T> inline void intrusive_ptr_add_ref(const T* p) { if (p) incref(p); }
+template <class T> inline void intrusive_ptr_release(const T* p) { if (p) decref(p); }
+#endif
+
+}
+
+#endif // COUNTED_PTR_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/data.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/data.hpp b/proton-c/bindings/cpp/include/proton/data.hpp
new file mode 100644
index 0000000..98d3973
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/data.hpp
@@ -0,0 +1,130 @@
+#ifndef DATA_H
+#define DATA_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/facade.hpp"
+#include "proton/decoder.hpp"
+#include "proton/encoder.hpp"
+#include "proton/memory.hpp"
+#include <iosfwd>
+
+struct pn_data_t;
+
+namespace proton {
+
+class data;
+
+/**
+ * Holds a sequence of AMQP values, allows inserting and extracting via encoder() and decoder().
+ * Cannot be directly instantiated, use `data_value`
+ */
+class data : public facade<pn_data_t, data, comparable<data> > {
+  public:
+    PN_CPP_EXTERN static PN_UNIQUE_PTR<data> create();
+
+    PN_CPP_EXTERN data& operator=(const data&);
+    template<class T> data& operator=(const T &t) {
+        clear(); encoder() << t; decoder().rewind(); return *this;
+    }
+
+    /** Clear the data. */
+    PN_CPP_EXTERN void clear();
+
+    /** True if there are no values. */
+    PN_CPP_EXTERN bool empty() const;
+
+    /** Encoder to encode into this value */
+    PN_CPP_EXTERN class encoder& encoder();
+
+    /** Decoder to decode from this value */
+    PN_CPP_EXTERN class decoder& decoder();
+
+    /** Type of the current value*/
+    PN_CPP_EXTERN type_id type() { return decoder().type(); }
+
+    /** Get the current value, don't move the decoder pointer. */
+    template<class T> void get(T &t) { decoder() >> t; decoder().backup(); }
+
+    /** Get the current value */
+    template<class T> T get() { T t; get(t); return t; }
+
+    PN_CPP_EXTERN bool operator==(const data& x) const;
+    PN_CPP_EXTERN bool operator<(const data& x) const;
+
+    PN_CPP_EXTERN void operator delete(void *);
+
+    /** Human readable representation of data. */
+  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&);
+};
+
+/** data with normal value semantics: copy, assign etc. */
+class data_value {
+  public:
+    data_value() : data_(data::create()) {}
+    data_value(const data_value& x) : data_(data::create()) { *data_ = *x.data_; }
+    data_value(const data& x) : data_(data::create()) { *data_ = x; }
+    template <class T> data_value(const T& x) : data_(data::create()) { *data_ = x; }
+
+    operator data&() { return *data_; }
+    operator const data&() const { return *data_; }
+
+    data_value& operator=(const data_value& x) { *data_ = *x.data_; return *this; }
+    data_value& operator=(const data& x) { *data_ = x; return *this; }
+    template <class T> data_value& operator=(const T& x) { *data_ = x; return *this; }
+
+    void clear() { data_->clear(); }
+    bool empty() const { return data_->empty(); }
+
+    /** Encoder to encode into this value */
+    class encoder& encoder() { return data_->encoder(); }
+
+    /** Decoder to decode from this value */
+    class decoder& decoder() { return data_->decoder(); }
+
+    /** Type of the current value*/
+    type_id type() { return decoder().type(); }
+
+    /** Get the current value, don't move the decoder pointer. */
+    template<class T> void get(T &t) { decoder() >> t; decoder().backup(); }
+
+    /** Get the current value */
+    template<class T> T get() { T t; get(t); return t; }
+    template<class T> operator T() { return get<T>(); }
+
+    bool operator==(const data_value& x) const { return *data_ == *x.data_; }
+    bool operator<(const data_value& x) const { return *data_ < *x.data_; }
+
+  friend inline class encoder& operator<<(class encoder& e, const data_value& dv) {
+      return e << *dv.data_;
+  }
+  friend inline class decoder& operator>>(class decoder& d, data_value& dv) {
+      return d >> *dv.data_;
+  }
+  friend inline std::ostream& operator<<(std::ostream& o, const data_value& dv) {
+      return o << *dv.data_;
+  }
+  private:
+    PN_UNIQUE_PTR<data> data_;
+};
+
+
+}
+#endif // DATA_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/decoder.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/decoder.hpp b/proton-c/bindings/cpp/include/proton/decoder.hpp
new file mode 100644
index 0000000..28feaf9
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/decoder.hpp
@@ -0,0 +1,234 @@
+#ifndef DECODER_H
+#define DECODER_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/error.hpp"
+#include "proton/type_traits.hpp"
+#include "proton/types.hpp"
+#include "proton/facade.hpp"
+#include <iosfwd>
+
+struct pn_data_t;
+
+namespace proton {
+
+class data;
+
+/** Raised by decoder operations on error.*/
+struct decode_error : public error { PN_CPP_EXTERN explicit decode_error(const std::string&) throw(); };
+
+/** Skips a value with `decoder >> skip()`. */
+struct skip{};
+
+/** Rewind the decoder with `decoder >> rewind()`. */
+struct rewind{};
+
+/**
+ * Stream-like decoder from AMQP bytes to a stream of C++ values.
+ *
+ * types.h defines C++ types corresponding to AMQP types.
+ *
+ * decoder operator>> will extract AMQP types into corresponding C++ types, and
+ * do simple conversions, e.g. from AMQP integer types to corresponding or
+ * larger C++ integer types.
+ *
+ * You can require an exact AMQP type using the `as<type>(value)` helper. E.g.
+ *
+ *     amqp_int i;
+ *     decoder >> as<INT>(i):       // Will throw if decoder does not contain an INT
+ *
+ * You can also use the `as` helper to extract an AMQP list, array or map into C++ containers.
+ *
+ *
+ *     std::vector<amqp_int> v;
+ *     decoder >> as<LIST>(v);     // Extract a list of INT.
+ *
+ * AMQP maps can be inserted/extracted to any container with pair<X,Y> as
+ * value_type, which includes std::map and std::unordered_map but also for
+ * example std::vector<std::pair<X,Y> >. This allows you to perserve order when
+ * extracting AMQP maps.
+ *
+ * You can also extract container values element-by-element, see decoder::operator>>(decoder&, start&)
+ *
+*/
+class decoder : public facade<pn_data_t, decoder> {
+  public:
+    /** Copy AMQP data from a byte buffer into the decoder. */
+    PN_CPP_EXTERN decoder(const char* buffer, size_t size);
+
+    /** Copy AMQP data from a std::string into the decoder. */
+    PN_CPP_EXTERN decoder(const std::string&);
+
+    /** Decode AMQP data from a byte buffer onto the end of the value stream. */
+    PN_CPP_EXTERN void decode(const char* buffer, size_t size);
+
+    /** Decode AMQP data from bytes in std::string onto the end of the value stream. */
+    PN_CPP_EXTERN void decode(const std::string&);
+
+    /** Return true if there are more values to read at the current level. */
+    PN_CPP_EXTERN bool more() const;
+
+    /** Type of the next value that will be read by operator>>
+     *@throw error if empty().
+     */
+    PN_CPP_EXTERN type_id type() const;
+
+    /** Rewind to the start of the data. */
+    PN_CPP_EXTERN void rewind();
+
+    /** Back up by one value */
+    PN_CPP_EXTERN void backup();
+
+    PN_CPP_EXTERN class data& data();
+
+    /** @name Extract simple types
+     * Overloads to extract simple types.
+     * @throw error if the decoder is empty or the current value has an incompatible type.
+     * @{
+     */
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_null);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_bool&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_ubyte&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_byte&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_ushort&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_short&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_uint&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_int&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_char&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_ulong&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_long&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_timestamp&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_float&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_double&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_decimal32&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_decimal64&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_decimal128&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, amqp_uuid&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, std::string&);
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, class data&);
+    ///@}
+
+    /** Extract and return a value of type T. */
+    template <class T> T get() { T value; *this >> value; return value; }
+
+    /** Extract and return a value of type T, as AMQP type. */
+    template <class T, type_id A> T get_as() { T value; *this >> as<A>(value); return value; }
+
+    /** Call decoder::start() in constructor, decoder::finish in destructor().
+     *
+     */
+    struct scope : public start {
+        decoder& decoder_;
+        scope(decoder& d) : decoder_(d) { d >> *this; }
+        ~scope() { decoder_ >> finish(); }
+    };
+
+    template <type_id A, class T> friend decoder& operator>>(decoder& d, ref<T, A> ref) {
+        d.check_type(A);
+        d >> ref.value;
+        return d;
+    }
+
+    /** start extracting a container value, one of array, list, map, described.
+     * The basic pattern is:
+     *
+     *     start s;
+     *     decoder >> s;
+     *     // check s.type() to see if this is an ARRAY, LIST, MAP or DESCRIBED type.
+     *     if (s.described) extract the descriptor...
+     *     for (size_t i = 0; i < s.size(); ++i) Extract each element...
+     *     decoder >> finish();
+     *
+     * The first value of an ARRAY is a descriptor if start::descriptor is true,
+     * followed by start.size elemets of type start::element.
+     *
+     * A LIST has start.size elements which may be of mixed type.
+     *
+     * A MAP has start.size elements which alternate key, value, key, value...
+     * and may be of mixed type.
+     *
+     * A DESCRIBED contains a descriptor and a single element, so it always has
+     * start.described=true and start.size=1.
+     *
+     * You must always end a complex type by extracting to an instance of `finish`,
+     * the decoder::scope automates this.
+     *
+     *@throw decoder::error if the curent value is not a container type.
+     */
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, start&);
+
+    /** Finish extracting a container value. */
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, finish);
+
+    /** Skip a value */
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, skip);
+
+    /** Rewind to the beginning */
+    PN_CPP_EXTERN friend decoder& operator>>(decoder&, struct rewind);
+
+  private:
+    PN_CPP_EXTERN void check_type(type_id);
+
+  friend class encoder;
+};
+
+// operator >> for integer types that are not covered by the standard overrides.
+template <class T>
+typename enable_if<is_unknown_integer<T>::value, decoder&>::type operator>>(decoder& d, T& i)  {
+    typename integer_type<sizeof(T), is_signed<T>::value>::type v;
+    d >> v;                     // Extract as a known integer type
+    i = v;
+    return d;
+}
+
+template <class T> decoder& operator>>(decoder& d, ref<T, ARRAY> ref)  {
+    decoder::scope s(d);
+    if (s.is_described) d >> skip();
+    ref.value.clear();
+    ref.value.resize(s.size);
+    for (typename T::iterator i = ref.value.begin(); i != ref.value.end(); ++i) {
+        d >> *i;
+    }
+    return d;
+}
+
+template <class T> decoder& operator>>(decoder& d, ref<T, LIST> ref)  {
+    decoder::scope s(d);
+    ref.value.clear();
+    ref.value.resize(s.size);
+    for (typename T::iterator i = ref.value.begin(); i != ref.value.end(); ++i)
+        d >> *i;
+    return d;
+}
+
+template <class T> decoder& operator>>(decoder& d, ref<T, MAP> ref)  {
+    decoder::scope m(d);
+    ref.value.clear();
+    for (size_t i = 0; i < m.size/2; ++i) {
+        typename T::key_type k;
+        typename T::mapped_type v;
+        d >> k >> v;
+        ref.value[k] = v;
+    }
+    return d;
+}
+
+}
+#endif // DECODER_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/delivery.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/delivery.hpp b/proton-c/bindings/cpp/include/proton/delivery.hpp
new file mode 100644
index 0000000..ca90831
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/delivery.hpp
@@ -0,0 +1,72 @@
+#ifndef PROTON_CPP_DELIVERY_H
+#define PROTON_CPP_DELIVERY_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/facade.hpp"
+
+#include "proton/delivery.h"
+#include "proton/disposition.h"
+
+namespace proton {
+
+/** delivery status of a message */
+class delivery : public counted_facade<pn_delivery_t, delivery> {
+  public:
+    /** Delivery state of a message */
+    enum state {
+        NONE = 0, ///< Unknown state
+        RECEIVED = PN_RECEIVED, ///< Received but not yet settled
+        ACCEPTED = PN_ACCEPTED, ///< Settled as accepted
+        REJECTED = PN_REJECTED, ///< Settled as rejected
+        RELEASED = PN_RELEASED, ///< Settled as released
+        MODIFIED = PN_MODIFIED  ///< Settled as modified
+    };  // AMQP spec 3.4 delivery State
+
+    /** Return true if the delivery has been settled. */
+    PN_CPP_EXTERN bool settled();
+
+    /** Settle the delivery, informs the remote end. */
+    PN_CPP_EXTERN void settle();
+
+    /** Set the local state of the delivery. */
+    PN_CPP_EXTERN void update(delivery::state state);
+
+    /** update and settle a delivery with the given delivery::state */
+    PN_CPP_EXTERN void settle(delivery::state s);
+
+    /** settle with ACCEPTED state */
+    PN_CPP_EXTERN void accept() { settle(ACCEPTED); }
+
+    /** settle with REJECTED state */
+    PN_CPP_EXTERN void reject() { settle(REJECTED); }
+
+    /** settle with REJECTED state */
+    PN_CPP_EXTERN void release() { settle(RELEASED); }
+
+    /** settle with MODIFIED state */
+    PN_CPP_EXTERN void modifiy() { settle(MODIFIED); }
+};
+
+}
+
+#endif  /*!PROTON_CPP_DELIVERY_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/duration.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/duration.hpp b/proton-c/bindings/cpp/include/proton/duration.hpp
new file mode 100644
index 0000000..e562c47
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/duration.hpp
@@ -0,0 +1,53 @@
+#ifndef PROTON_CPP_DURATION_H
+#define PROTON_CPP_DURATION_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/types.hpp"
+
+namespace proton {
+
+/** Duration in milliseconds. */
+class duration : public comparable<duration>
+{
+  public:
+    amqp_ulong milliseconds;
+    explicit duration(amqp_ulong ms = 0) : milliseconds(ms) {}
+
+    bool operator<(duration d) { return milliseconds < d.milliseconds; }
+    bool operator==(duration d) { return milliseconds == d.milliseconds; }
+
+    PN_CPP_EXTERN static const duration FOREVER; ///< Wait for ever
+    PN_CPP_EXTERN static const duration IMMEDIATE; ///< Don't wait at all
+    PN_CPP_EXTERN static const duration SECOND; ///< One second
+    PN_CPP_EXTERN static const duration MINUTE; ///< One minute
+};
+
+inline duration operator*(duration d, amqp_ulong n) { return duration(d.milliseconds*n); }
+inline duration operator*(amqp_ulong n, duration d) { return d * n; }
+
+inline amqp_timestamp operator+(amqp_timestamp ts, duration d) { return amqp_timestamp(ts.milliseconds+d.milliseconds); }
+inline amqp_timestamp operator+(duration d, amqp_timestamp ts) { return ts + d; }
+}
+
+#endif  /*!PROTON_CPP_DURATION_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/encoder.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/encoder.hpp b/proton-c/bindings/cpp/include/proton/encoder.hpp
new file mode 100644
index 0000000..b931682
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/encoder.hpp
@@ -0,0 +1,187 @@
+#ifndef ENCODER_H
+#define ENCODER_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/error.hpp"
+#include "proton/types.hpp"
+#include "proton/type_traits.hpp"
+#include "proton/facade.hpp"
+#include <iosfwd>
+
+struct pn_data_t;
+
+namespace proton {
+
+class data;
+
+/** Raised by encoder operations on error */
+struct encode_error : public error { PN_CPP_EXTERN explicit encode_error(const std::string&) throw(); };
+
+/**
+ * Stream C++ data values into an AMQP encoder using operator<<.
+ *
+ * types.h defines C++ typedefs and types for AMQP each type. These types insert
+ * as the corresponding AMQP type. Conversion rules apply to other types:
+ *
+ * - Integer types insert as the AMQP integer of matching size and signedness.
+ * - std::string or char* insert as AMQP strings.
+ *
+ * C++ containers can be inserted as AMQP containers with the as() helper
+ * functions. For example:
+ *
+ *     std::vector<amqp_symbol> v;
+ *     encoder << as<amqp_list>(v);
+ *
+ * AMQP maps can be inserted from any container with std::pair<X,Y> as the
+ * value_type. That includes std::map and std::unordered_map but also for
+ * example std::vector<std::pair<X,Y> >. This allows you to control the order
+ * of elements when inserting AMQP maps.
+ *
+ * You can also insert containers element-by-element, see operator<<(encoder&, const start&)
+ *
+ *@throw decoder::error if the curent value is not a container type.
+ */
+class encoder : public facade<pn_data_t, encoder> {
+  public:
+    /**
+     * Encode the current values into buffer and update size to reflect the number of bytes encoded.
+     *
+     * Clears the encoder.
+     *
+     *@return if buffer==0 or size is too small then return false and  size to the required size.
+     *Otherwise return true and set size to the number of bytes encoded.
+     */
+    PN_CPP_EXTERN bool encode(char* buffer, size_t& size);
+
+    /** Encode the current values into a std::string, resize the string if necessary.
+     *
+     * Clears the encoder.
+     */
+    PN_CPP_EXTERN void encode(std::string&);
+
+    /** Encode the current values into a std::string. Clears the encoder. */
+    PN_CPP_EXTERN std::string encode();
+
+    PN_CPP_EXTERN class data& data();
+
+    /** @name Insert simple types.
+     *@{
+     */
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_null);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_bool);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_ubyte);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_byte);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_ushort);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_short);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_uint);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_int);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_char);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_ulong);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_long);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_timestamp);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_float);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_double);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_decimal32);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_decimal64);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_decimal128);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_uuid);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_string);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_symbol);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, amqp_binary);
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, const class data&);
+    ///@}
+
+    /**
+     * Start a container type.
+     *
+     * Use one of the static functions start::array(), start::list(),
+     * start::map() or start::described() to create an appropriate start value
+     * and inser it into the encoder, followed by the contained elements.  For
+     * example:
+     *
+     *      encoder << start::list() << amqp_int(1) << amqp_symbol("two") << 3.0 << finish();
+     */
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, const start&);
+
+    /** Finish a container type. See operator<<(encoder&, const start&) */
+  friend PN_CPP_EXTERN encoder& operator<<(encoder& e, finish);
+
+
+    /**@name Insert values returned by the as<type_id> helper.
+     *@{
+     */
+  template <class T, type_id A> friend PN_CPP_EXTERN encoder& operator<<(encoder&, cref<T, A>);
+  template <class T> friend encoder& operator<<(encoder&, cref<T, ARRAY>);
+  template <class T> friend encoder& operator<<(encoder&, cref<T, LIST>);
+  template <class T> friend encoder& operator<<(encoder&, cref<T, MAP>);
+    // TODO aconway 2015-06-16: described values.
+    ///@}
+
+    /** Copy data from a raw pn_data_t */
+  friend PN_CPP_EXTERN encoder& operator<<(encoder&, pn_data_t*);
+};
+
+// Need to disambiguate char* conversion to bool and std::string as amqp_string.
+inline encoder& operator<<(encoder& e, char* s) { return e << amqp_string(s); }
+inline encoder& operator<<(encoder& e, const char* s) { return e << amqp_string(s); }
+inline encoder& operator<<(encoder& e, const std::string& s) { return e << amqp_string(s); }
+
+// operator << for integer types that are not covered by the standard overrides.
+template <class T>
+typename enable_if<is_unknown_integer<T>::value, encoder&>::type operator<<(encoder& e, T i)  {
+    typename integer_type<sizeof(T), is_signed<T>::value>::type v = i;
+    return e << v;              // Insert as a known integer type
+}
+
+// TODO aconway 2015-06-16: described array insertion.
+
+template <class T> encoder& operator<<(encoder& e, cref<T, ARRAY> a) {
+    e << start::array(type_id_of<typename T::value_type>::value);
+    for (typename T::const_iterator i = a.value.begin(); i != a.value.end(); ++i)
+        e << *i;
+    e << finish();
+    return e;
+}
+
+template <class T> encoder& operator<<(encoder& e, cref<T, LIST> l) {
+    e << start::list();
+    for (typename T::const_iterator i = l.value.begin(); i != l.value.end(); ++i)
+        e << *i;
+    e << finish();
+    return e;
+}
+
+template <class T> encoder& operator<<(encoder& e, cref<T, MAP> m){
+    e << start::map();
+    for (typename T::const_iterator i = m.value.begin(); i != m.value.end(); ++i) {
+        e << i->first;
+        e << i->second;
+    }
+    e << finish();
+    return e;
+}
+///@cond INTERNAL Convert a ref to a cref.
+template <class T, type_id A> encoder& operator<<(encoder& e, ref<T, A> ref) {
+    return e << cref<T,A>(ref);
+}
+///@endcond
+
+}
+#endif // ENCODER_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/endpoint.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/endpoint.hpp b/proton-c/bindings/cpp/include/proton/endpoint.hpp
new file mode 100644
index 0000000..51560e0
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/endpoint.hpp
@@ -0,0 +1,66 @@
+#ifndef PROTON_CPP_ENDPOINT_H
+#define PROTON_CPP_ENDPOINT_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/connection.h"
+
+namespace proton {
+
+class handler;
+class connection;
+class transport;
+
+/** endpoint is a base class for session, connection and link */
+class endpoint
+{
+  public:
+    /** state is a bit mask of state_bit values.
+     *
+     * A state mask is matched against an endpoint as follows: If the state mask
+     * contains both local and remote flags, then an exact match against those
+     * flags is performed. If state contains only local or only remote flags,
+     * then a match occurs if any of the local or remote flags are set
+     * respectively.
+     *
+     * @see connection::link_head, connection::session_head, link::next, session::next
+     */
+    typedef int state;
+
+    /// endpoint state bit values @{
+    PN_CPP_EXTERN static const int LOCAL_UNINIT;    ///< Local endpoint is un-initialized
+    PN_CPP_EXTERN static const int REMOTE_UNINIT;   ///< Remote endpoint is un-initialized
+    PN_CPP_EXTERN static const int LOCAL_ACTIVE;    ///< Local endpoint is active
+    PN_CPP_EXTERN static const int REMOTE_ACTIVE;   ///< Remote endpoint is active
+    PN_CPP_EXTERN static const int LOCAL_CLOSED;    ///< Local endpoint has been closed
+    PN_CPP_EXTERN static const int REMOTE_CLOSED;   ///< Remote endpoint has been closed
+    PN_CPP_EXTERN static const int LOCAL_MASK;      ///< Mask including all LOCAL_ bits (UNINIT, ACTIVE, CLOSED)
+    PN_CPP_EXTERN static const int REMOTE_MASK;     ///< Mask including all REMOTE_ bits (UNINIT, ACTIVE, CLOSED)
+     ///@}
+
+    // TODO: condition, remote_condition, update_condition, get/handler
+};
+
+
+}
+
+#endif  /*!PROTON_CPP_ENDPOINT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/error.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/error.hpp b/proton-c/bindings/cpp/include/proton/error.hpp
new file mode 100644
index 0000000..6432b71
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/error.hpp
@@ -0,0 +1,45 @@
+#ifndef PROTON_CPP_EXCEPTIONS_H
+#define PROTON_CPP_EXCEPTIONS_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 <stdexcept>
+#include <string>
+#include "proton/export.hpp"
+
+namespace proton {
+
+/** Functions in the proton namespace throw a subclass of proton::error on error. */
+struct error : public std::runtime_error { PN_CPP_EXTERN explicit error(const std::string&) throw(); };
+
+/** Raised if timeout expires */
+struct timeout_error : public error { PN_CPP_EXTERN explicit timeout_error(const std::string&) throw(); };
+
+/** Raised if a message is rejected */
+struct message_reject : public error { PN_CPP_EXTERN explicit message_reject(const std::string&) throw(); };
+
+/** Raised if a message is released */
+struct message_release : public error { PN_CPP_EXTERN explicit message_release(const std::string&) throw(); };
+
+
+}
+
+#endif  /*!PROTON_CPP_EXCEPTIONS_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/event.hpp b/proton-c/bindings/cpp/include/proton/event.hpp
new file mode 100644
index 0000000..486a5c9
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/event.hpp
@@ -0,0 +1,69 @@
+#ifndef PROTON_CPP_EVENT_H
+#define PROTON_CPP_EVENT_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.hpp"
+#include "proton/connection.hpp"
+#include "proton/message.hpp"
+#include <vector>
+
+namespace proton {
+
+class handler;
+class container;
+class connection;
+
+/** Context information about a proton event */
+class event {
+  public:
+    virtual PN_CPP_EXTERN ~event();
+
+    /// Dispatch this event to a handler.
+    virtual PN_CPP_EXTERN void dispatch(handler &h) = 0;
+
+    /// Get container.
+    virtual PN_CPP_EXTERN class container &container();
+    /// Get connection.
+    virtual PN_CPP_EXTERN class connection &connection();
+    /// Get sender @throws error if no sender.
+    virtual PN_CPP_EXTERN class sender& sender();
+    /// Get receiver @throws error if no receiver.
+    virtual PN_CPP_EXTERN class receiver& receiver();
+    /// Get link @throws error if no link.
+    virtual PN_CPP_EXTERN class link& link();
+    /// Get delivey @throws error if no delivery.
+    virtual PN_CPP_EXTERN class delivery& delivery();
+    /** Get message @throws error if no message. */
+    virtual PN_CPP_EXTERN class message &message();
+
+  protected:
+    PN_CPP_EXTERN event();
+
+  private:
+    event(const event&);
+    event& operator=(const event&);
+};
+
+}
+
+#endif  /*!PROTON_CPP_EVENT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/export.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/export.hpp b/proton-c/bindings/cpp/include/proton/export.hpp
new file mode 100644
index 0000000..fdebc6f
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/export.hpp
@@ -0,0 +1,49 @@
+#ifndef PN_CPP_IMPORTEXPORT_H
+#define PN_CPP_IMPORTEXPORT_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.
+ *
+ */
+
+/// @cond INTERNAL
+/// import/export macros
+#if defined(WIN32) && !defined(PN_CPP_DECLARE_STATIC)
+  //
+  // Import and Export definitions for Windows:
+  //
+#  define PN_CPP_EXPORT __declspec(dllexport)
+#  define PN_CPP_IMPORT __declspec(dllimport)
+#else
+  //
+  // Non-Windows (Linux, etc.) definitions:
+  //
+#  define PN_CPP_EXPORT
+#  define PN_CPP_IMPORT
+#endif
+
+// For qpid-proton-cpp library symbols
+#ifdef qpid_proton_cpp_EXPORTS
+#  define PN_CPP_EXTERN PN_CPP_EXPORT
+#else
+#  define PN_CPP_EXTERN PN_CPP_IMPORT
+#endif
+///@endcond
+
+#endif  /*!PN_CPP_IMPORTEXPORT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/facade.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/facade.hpp b/proton-c/bindings/cpp/include/proton/facade.hpp
new file mode 100644
index 0000000..7900ada
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/facade.hpp
@@ -0,0 +1,145 @@
+#ifndef PROTON_CPP_FACADE_H
+#define PROTON_CPP_FACADE_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.
+ *
+ */
+
+/*! \page c-and-cpp C and memory management.
+ *\brief
+ *
+ * The C++ API is a very thin wrapper over the C API.  The C API consists of a
+ * set of `struct` types and associated C functions.  For each there is a a C++
+ * `facade` that provides C++ member functions to call the corresponding C
+ * functions on the underlying C struct. Facade classes derive from the
+ * `proton::facade` template.
+ *
+ * The facade class occupies no additional memory. The C+ facade pointer points
+ * directly to the underlying C++ struct, calling C++ member functions corresponds
+ * directly to calling the C function.
+ *
+ * If you want to mix C and C++ code (which should be done carefully!) you can
+ * cast between a facade pointer and a C struct pointer with `proton::pn_cast`
+ * and `foo::cast()` where `foo` is some C++ facade class.
+ *
+ * Deleting a facade object calls the appropriate `pn_foo_free` function or
+ * `pn_decref` as appropriate.
+ *
+ * Some proton structs are reference counted, the facade classes for these
+ * derive from the `proton::counted_facade` template. Most proton functions that
+ * return facade objects return a reference to an object that is owned by the
+ * called object. Such references are only valid in a limited scope (for example
+ * in an event handler function.) To keep a reference outside that scope, call
+ * the `ptr()` member function. This returns a `proton::counted_ptr`, which you
+ * can convert safely to `std::shared_ptr`, `std::unique_ptr`,
+ * `boost::shared_ptr`, or `boost::intrusive_ptr`.
+ */
+
+/**@file
+ * Classes and templates used by object facades.
+ */
+
+#include "proton/export.hpp"
+#include "counted_ptr.hpp"
+
+namespace proton {
+
+///@cond INTERNAL
+struct empty_base {};
+///@endcond
+
+/**
+ * Base class for C++ facades of proton C struct types.
+ *
+ * @see \ref c-and-cpp
+ */
+template <class P, class T, class Base=empty_base> class facade : public Base {
+  public:
+    /// The underlying C struct type.
+    typedef P pn_type;
+
+    /// Cast the C struct pointer to a C++ facade pointer.
+    static T* cast(P* p) { return reinterpret_cast<T*>(p); }
+
+  private:
+    facade();
+    facade(const facade&);
+    facade& operator=(const facade&);
+    void operator delete(void* p);
+};
+
+/** Cast a facade type to the C struct type.
+ * Allow casting away const, the underlying pn structs have not constness.
+ */
+template <class T> typename T::pn_type* pn_cast(const T* p) {
+    return reinterpret_cast<typename T::pn_type*>(const_cast<T*>(p));
+}
+
+/** Cast a counted pointer to a facade type to the C struct type.
+ * Allow casting away const, the underlying pn structs have not constness.
+ */
+template <class T> typename T::pn_type* pn_cast(const counted_ptr<T>& p) {
+    return reinterpret_cast<typename T::pn_type*>(const_cast<T*>(p.get()));
+}
+
+/**
+ * Some proton C structs are reference counted. The C++ facade for such structs can be
+ * converted to any of the following smart pointers: std::shared_ptr, std::unique_ptr,
+ * boost::shared_ptr, boost::intrusive_ptr.
+ *
+ * unique_ptr takes ownership of a single *reference* not the underlying struct,
+ * so it is safe to have multiple unique_ptr to the same facade object or to mix
+ * unique_ptr with shared_ptr etc.
+ *
+ * Deleting a counted_facade subclass actually calls `pn_decref` to remove a reference.
+ */
+template <class P, class T, class Base=empty_base>
+class counted_facade : public facade<P, T, Base>
+{
+  public:
+
+    /// Deleting a counted_facade actually calls `pn_decref` to remove a reference.
+    void operator delete(void* p) { decref(p); }
+
+    /** Get a reference-counted pointer to the underlying object.  It can be
+     * converted safely to `std::shared_ptr`, `std::unique_ptr`,
+     * `boost::shared_ptr`, or `boost::intrusive_ptr`.
+     */
+    counted_ptr<T> ptr() {
+        return counted_ptr<T>(static_cast<T*>(this));
+    }
+
+    /** Get a reference-counted pointer to the underlying object.  It can be
+     * converted safely to `std::shared_ptr`, `std::unique_ptr`,
+     * `boost::shared_ptr`, or `boost::intrusive_ptr`.
+     */
+    counted_ptr<const T> ptr() const {
+        return counted_ptr<const T>(static_cast<const T*>(this));
+    }
+
+  private:
+    counted_facade(const counted_facade&);
+    counted_facade& operator=(const counted_facade&);
+
+  template <class U> friend class counted_ptr;
+};
+
+}
+#endif  /*!PROTON_CPP_FACADE_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/handler.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/handler.hpp b/proton-c/bindings/cpp/include/proton/handler.hpp
new file mode 100644
index 0000000..cfd2689
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/handler.hpp
@@ -0,0 +1,61 @@
+#ifndef PROTON_CPP_HANDLER_H
+#define PROTON_CPP_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/export.hpp"
+#include "proton/event.hpp"
+#include "proton/event.h"
+#include <vector>
+
+namespace proton {
+
+/** Base class for event handlers.
+ *
+ * A handler can have child handlers which are called in order, after the parent handler.
+ *
+ * Note: handlers are not deleted automatically. They must not be deleted while
+ * they are still in use.
+ *
+ * There are two simple strategies you can use:
+ *
+ * 1. Destroy handlers only after the container that uses them is closed.
+ *
+ * 2. Allocate handlers with `new` and call `delete this` in the appropriate
+ * `on_*_closed` or `on_*_final` event that indicates the handler is no longer needed.
+ *
+ */
+class handler : public std::vector<handler*> {
+  public:
+    PN_CPP_EXTERN handler();
+    PN_CPP_EXTERN virtual ~handler();
+
+    /// Called if a handler function is not over-ridden to handle an event.
+    PN_CPP_EXTERN virtual void on_unhandled(event &e);
+
+    /// Add a child handler, equivalent to this->push_back(&h)
+    /// h must not be deleted before this handler.
+    PN_CPP_EXTERN virtual void add_child_handler(handler &h);
+};
+
+}
+
+#endif  /*!PROTON_CPP_HANDLER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/link.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/link.hpp b/proton-c/bindings/cpp/include/proton/link.hpp
new file mode 100644
index 0000000..88b5368
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/link.hpp
@@ -0,0 +1,107 @@
+#ifndef PROTON_CPP_LINK_H
+#define PROTON_CPP_LINK_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/endpoint.hpp"
+#include "proton/export.hpp"
+#include "proton/message.hpp"
+#include "proton/terminus.hpp"
+#include "proton/types.h"
+#include "proton/facade.hpp"
+
+#include <string>
+
+namespace proton {
+
+class sender;
+class receiver;
+
+/** Messages are transferred across a link. Base class for sender, receiver. */
+class link : public counted_facade<pn_link_t, link, endpoint>
+{
+  public:
+    /** Locally open the link, not complete till messaging_handler::on_link_opened or
+     * proton_handler::link_remote_open
+     */
+    PN_CPP_EXTERN void open();
+
+    /** Locally close the link, not complete till messaging_handler::on_link_closed or
+     * proton_handler::link_remote_close
+     */
+    PN_CPP_EXTERN void close();
+
+    /** True if link is a sender */
+    PN_CPP_EXTERN bool is_sender();
+    /** True if link is a receiver */
+    PN_CPP_EXTERN bool is_receiver();
+    /** Return sender pointer. @throw if link is not a sender. */
+    PN_CPP_EXTERN class sender& sender();
+    /** Return receiver pointer. @throw if link is not a receiver. */
+    PN_CPP_EXTERN class receiver& receiver();
+    /** Credit available on the link */
+    PN_CPP_EXTERN int credit();
+
+    /** True if link has source */
+    PN_CPP_EXTERN bool has_source();
+    /** True if link has target */
+    PN_CPP_EXTERN bool has_target();
+    /** True if link has remote source */
+    PN_CPP_EXTERN bool has_remote_source();
+    /** True if link has remote target */
+    PN_CPP_EXTERN bool has_remote_target();
+
+    /** Local source of the link. @throw error if !has_source() */
+    PN_CPP_EXTERN terminus& source();
+    /** Local target of the link. @throw error if !has_target() */
+    PN_CPP_EXTERN terminus& target();
+    /** Remote source of the link. @throw error if !has_remote_source() */
+    PN_CPP_EXTERN terminus& remote_source();
+    /** Remote target of the link. @throw error if !has_remote_target() */
+    PN_CPP_EXTERN terminus& remote_target();
+
+    /** Link name */
+    PN_CPP_EXTERN std::string name();
+
+    /** Next link that matches state mask. @see endpoint::state.
+     * @return 0 if none, do not delete returned pointer
+     */
+    PN_CPP_EXTERN link* next(endpoint::state mask);
+
+    /** Connection that owns this link */
+    PN_CPP_EXTERN class connection &connection();
+
+    /** Set a custom handler for this link. */
+    PN_CPP_EXTERN void handler(class handler &);
+
+    /** Unset any custom handler */
+    PN_CPP_EXTERN void detach_handler();
+
+    /** Get the endpoint state */
+    PN_CPP_EXTERN endpoint::state state();
+};
+
+}
+
+#include "proton/sender.hpp"
+#include "proton/receiver.hpp"
+
+#endif  /*!PROTON_CPP_LINK_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/memory.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/memory.hpp b/proton-c/bindings/cpp/include/proton/memory.hpp
new file mode 100644
index 0000000..6102831
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/memory.hpp
@@ -0,0 +1,33 @@
+#ifndef UNIQUE_PTR_HPP
+#define UNIQUE_PTR_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/config.hpp"
+#include <memory>
+
+#if PN_HAS_STD_PTR
+// Simple ownership pointer, use std::unique_ptr in C++11 std::auto_ptr otherwise.
+#define PN_UNIQUE_PTR std::unique_ptr
+#else
+// Simple ownership pointer, use std::unique_ptr in C++11 std::auto_ptr otherwise.
+#define PN_UNIQUE_PTR std::auto_ptr
+#endif
+
+#endif // UNIQUE_PTR_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/message.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/message.hpp b/proton-c/bindings/cpp/include/proton/message.hpp
new file mode 100644
index 0000000..d04ee1a
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/message.hpp
@@ -0,0 +1,225 @@
+#ifndef PROTON_CPP_MESSAGE_H
+#define PROTON_CPP_MESSAGE_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/data.hpp"
+#include "proton/facade.hpp"
+#include "proton/memory.hpp"
+
+#include <string>
+
+struct pn_message_t;
+
+namespace proton {
+
+class link;
+class delivery;
+
+/** An AMQP message. Not directly construct-able, use create() or message_value.*/
+class message : public facade<pn_message_t, message>
+{
+  public:
+    PN_CPP_EXTERN static PN_UNIQUE_PTR<message> create();
+
+    /// Copy data from m to this.
+    PN_CPP_EXTERN message& operator=(const message& m);
+
+    /** Clear the message content and properties. */
+    PN_CPP_EXTERN void clear();
+
+    ///@name Message properties
+    ///@{
+
+    /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    PN_CPP_EXTERN void id(const data& id);
+    /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    PN_CPP_EXTERN const data& id() const;
+    PN_CPP_EXTERN data& id();
+
+    PN_CPP_EXTERN void user(const std::string &user);
+    PN_CPP_EXTERN std::string user() const;
+
+    PN_CPP_EXTERN void address(const std::string &addr);
+    PN_CPP_EXTERN std::string address() const;
+
+    PN_CPP_EXTERN void subject(const std::string &s);
+    PN_CPP_EXTERN std::string subject() const;
+
+    PN_CPP_EXTERN void reply_to(const std::string &s);
+    PN_CPP_EXTERN std::string reply_to() const;
+
+    /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    PN_CPP_EXTERN void correlation_id(const data&);
+    /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    PN_CPP_EXTERN const data& correlation_id() const;
+    PN_CPP_EXTERN data& correlation_id();
+
+    PN_CPP_EXTERN void content_type(const std::string &s);
+    PN_CPP_EXTERN std::string content_type() const;
+
+    PN_CPP_EXTERN void content_encoding(const std::string &s);
+    PN_CPP_EXTERN std::string content_encoding() const;
+
+    PN_CPP_EXTERN void expiry(amqp_timestamp t);
+    PN_CPP_EXTERN amqp_timestamp expiry() const;
+
+    PN_CPP_EXTERN void creation_time(amqp_timestamp t);
+    PN_CPP_EXTERN amqp_timestamp creation_time() const;
+
+    PN_CPP_EXTERN void group_id(const std::string &s);
+    PN_CPP_EXTERN std::string group_id() const;
+
+    PN_CPP_EXTERN void reply_to_group_id(const std::string &s);
+    PN_CPP_EXTERN std::string reply_to_group_id() const;
+    ///@}
+
+    /** Set the body. If data has more than one value, each is encoded as an AMQP section. */
+    PN_CPP_EXTERN void body(const data&);
+
+    /** Set the body to any type T that can be converted to proton::data */
+    template <class T> void body(const T& v) { body().clear(); body().encoder() << v; }
+
+    /** Get the body values. */
+    PN_CPP_EXTERN const data& body() const;
+
+    /** Get a reference to the body data, can be modified in-place. */
+    PN_CPP_EXTERN data& body();
+
+    // TODO aconway 2015-06-17: consistent and flexible treatment of buffers.
+    // Allow convenient std::string encoding/decoding (with re-use of existing
+    // string capacity) but also need to allow encoding/decoding of non-string
+    // buffers. Introduce a buffer type with begin/end pointers?
+
+    /** Encode the message into string data */
+    PN_CPP_EXTERN void encode(std::string &data) const;
+    /** Retrun encoded message as a string */
+    PN_CPP_EXTERN std::string encode() const;
+    /** Decode from string data into the message. */
+    PN_CPP_EXTERN void decode(const std::string &data);
+
+    /// Decode the message from link corresponding to delivery.
+    PN_CPP_EXTERN void decode(proton::link&, proton::delivery&);
+
+    PN_CPP_EXTERN void operator delete(void*);
+};
+
+
+/** A message with value semantics */
+class message_value {
+  public:
+    message_value() : message_(message::create()) {}
+    message_value(const message_value& x) : message_(message::create()) { *message_ = *x.message_; }
+    message_value(const message& x) : message_(message::create()) { *message_ = x; }
+    message_value& operator=(const message_value& x) { *message_ = *x.message_; return *this; }
+    message_value& operator=(const message& x) { *message_ = x; return *this; }
+
+    // TODO aconway 2015-09-02: C++11 move semantics.
+
+    operator message&() { return *message_; }
+    operator const message&() const { return *message_; }
+
+    /** Clear the message content */
+    void clear() { message_->clear(); }
+
+    ///@name Message properties
+    ///@{
+
+    /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    void id(const data& id) { message_->id(id); }
+    /// Globally unique identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    const data& id() const { return message_->id(); }
+    data& id() { return message_->id(); }
+
+    void user(const std::string &user) { message_->user(user); }
+    std::string user() const { return message_->user(); }
+
+    void address(const std::string &addr) { message_->address(addr); }
+    std::string address() const { return message_->address(); }
+
+    void subject(const std::string &s) { message_->subject(s); }
+    std::string subject() const { return message_->subject(); }
+
+    void reply_to(const std::string &s) { message_->reply_to(s); }
+    std::string reply_to() const { return message_->reply_to(); }
+
+    /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    void correlation_id(const data& d) { message_->correlation_id(d); }
+    /// Correlation identifier, can be an a string, an unsigned long, a uuid or a binary value.
+    const data& correlation_id() const { return message_->correlation_id(); }
+    data& correlation_id() { return message_->correlation_id(); }
+
+    void content_type(const std::string &s) { message_->content_type(s); }
+    std::string content_type() const { return message_->content_type(); }
+
+    void content_encoding(const std::string &s) { message_->content_encoding(s); }
+    std::string content_encoding() const { return message_->content_encoding(); }
+
+    void expiry(amqp_timestamp t) { message_->expiry(t); }
+    amqp_timestamp expiry() const { return message_->expiry(); }
+
+    void creation_time(amqp_timestamp t) { message_->creation_time(t); }
+    amqp_timestamp creation_time() const { return message_->creation_time(); }
+
+    void group_id(const std::string &s) { message_->group_id(s); }
+    std::string group_id() const { return message_->group_id(); }
+
+    void reply_to_group_id(const std::string &s) { message_->reply_to_group_id(s); }
+    std::string reply_to_group_id() const { return message_->reply_to_group_id(); }
+    ///@}
+
+    /** Set the body. If data has more than one value, each is encoded as an AMQP section. */
+    void body(const data& d) { message_->body(d); }
+
+    /** Set the body to any type T that can be converted to proton::data */
+    template <class T> void body(const T& v) { message_->body(v); }
+
+    /** Get the body values. */
+    const data& body() const { return message_->body(); }
+
+    /** Get a reference to the body data, can be modified in-place. */
+    data& body() { return message_->body(); }
+
+    // TODO aconway 2015-06-17: consistent and flexible treatment of buffers.
+    // Allow convenient std::string encoding/decoding (with re-use of existing
+    // string capacity) but also need to allow encoding/decoding of non-string
+    // buffers. Introduce a buffer type with begin/end pointers?
+
+    /** Encode the message into string data */
+    void encode(std::string &data) const { message_->encode(data); }
+    /** Retrun encoded message as a string */
+    std::string encode() const { return message_->encode(); }
+    /** Decode from string data into the message. */
+    void decode(const std::string &data) { message_->decode(data); }
+
+    /// Decode the message from link corresponding to delivery.
+    void decode(proton::link& l, proton::delivery& d) { message_->decode(l, d); }
+
+    void swap(message_value& x);
+
+  private:
+    PN_UNIQUE_PTR<class message> message_;
+};
+
+}
+
+#endif  /*!PROTON_CPP_MESSAGE_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/messaging_adapter.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/messaging_adapter.hpp b/proton-c/bindings/cpp/include/proton/messaging_adapter.hpp
new file mode 100644
index 0000000..ded1309
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/messaging_adapter.hpp
@@ -0,0 +1,78 @@
+#ifndef PROTON_CPP_MESSAGING_ADAPTER_H
+#define PROTON_CPP_MESSAGING_ADAPTER_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/messaging_handler.hpp"
+
+#include "proton/messaging_event.hpp"
+#include "proton/event.h"
+#include "proton/reactor.h"
+
+///@cond INTERNAL
+
+namespace proton {
+
+// Combine's Python's: endpoint_state_handler, incoming_message_handler, outgoing_message_handler
+
+class messaging_adapter : public messaging_handler
+{
+  public:
+    PN_CPP_EXTERN messaging_adapter(messaging_handler &delegate);
+    PN_CPP_EXTERN virtual ~messaging_adapter();
+    PN_CPP_EXTERN virtual void on_reactor_init(event &e);
+    PN_CPP_EXTERN virtual void on_link_flow(event &e);
+    PN_CPP_EXTERN virtual void on_delivery(event &e);
+    PN_CPP_EXTERN virtual void on_unhandled(event &e);
+    PN_CPP_EXTERN virtual void on_connection_closed(event &e);
+    PN_CPP_EXTERN virtual void on_connection_closing(event &e);
+    PN_CPP_EXTERN virtual void on_connection_error(event &e);
+    PN_CPP_EXTERN virtual void on_connection_local_open(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_opened(event &e);
+    PN_CPP_EXTERN virtual void on_connection_opening(event &e);
+    PN_CPP_EXTERN virtual void on_session_closed(event &e);
+    PN_CPP_EXTERN virtual void on_session_closing(event &e);
+    PN_CPP_EXTERN virtual void on_session_error(event &e);
+    PN_CPP_EXTERN virtual void on_session_local_open(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_opened(event &e);
+    PN_CPP_EXTERN virtual void on_session_opening(event &e);
+    PN_CPP_EXTERN virtual void on_link_closed(event &e);
+    PN_CPP_EXTERN virtual void on_link_closing(event &e);
+    PN_CPP_EXTERN virtual void on_link_error(event &e);
+    PN_CPP_EXTERN virtual void on_link_local_open(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_opened(event &e);
+    PN_CPP_EXTERN virtual void on_link_opening(event &e);
+    PN_CPP_EXTERN virtual void on_transport_tail_closed(event &e);
+  private:
+    messaging_handler &delegate_;  // The handler for generated messaging_event's
+};
+
+}
+///@endcond INTERNAL
+#endif  /*!PROTON_CPP_MESSAGING_ADAPTER_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/messaging_event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/messaging_event.hpp b/proton-c/bindings/cpp/include/proton/messaging_event.hpp
new file mode 100644
index 0000000..af22b41
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/messaging_event.hpp
@@ -0,0 +1,108 @@
+#ifndef PROTON_CPP_MESSAGINGEVENT_H
+#define PROTON_CPP_MESSAGINGEVENT_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_event.hpp"
+#include "proton/link.hpp"
+
+namespace proton {
+
+class handler;
+class container;
+class connection;
+class message;
+
+/** An event for the proton::messaging_handler */
+class messaging_event : public proton_event
+{
+  public:
+
+    // TODO aconway 2015-07-16: document meaning of each event type.
+
+    /** Event types for a messaging_handler */
+    enum event_type {
+        PROTON = 0,  // Wrapped pn_event_t
+        ABORT,
+        ACCEPTED,
+        COMMIT,
+        CONNECTION_CLOSED,
+        CONNECTION_CLOSING,
+        CONNECTION_ERROR,
+        CONNECTION_OPENED,
+        CONNECTION_OPENING,
+        DISCONNECTED,
+        FETCH,
+        ID_LOADED,
+        LINK_CLOSED,
+        LINK_CLOSING,
+        LINK_OPENED,
+        LINK_OPENING,
+        LINK_ERROR,
+        MESSAGE,
+        QUIT,
+        RECORD_INSERTED,
+        RECORDS_LOADED,
+        REJECTED,
+        RELEASED,
+        REQUEST,
+        RESPONSE,
+        SENDABLE,
+        SESSION_CLOSED,
+        SESSION_CLOSING,
+        SESSION_OPENED,
+        SESSION_OPENING,
+        SESSION_ERROR,
+        SETTLED,
+        START,
+        TIMER,
+        TRANSACTION_ABORTED,
+        TRANSACTION_COMMITTED,
+        TRANSACTION_DECLARED,
+        TRANSPORT_CLOSED
+    };
+
+    messaging_event(pn_event_t *ce, proton_event::event_type t, class container &c);
+    messaging_event(event_type t, proton_event &parent);
+    ~messaging_event();
+
+    virtual PN_CPP_EXTERN void dispatch(handler &h);
+    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();
+    virtual PN_CPP_EXTERN class message& message();
+
+    PN_CPP_EXTERN event_type type() const;
+
+  private:
+  friend class messaging_adapter;
+    event_type type_;
+    proton_event *parent_event_;
+    message_value message_;
+    messaging_event operator=(const messaging_event&);
+    messaging_event(const messaging_event&);
+};
+
+}
+
+#endif  /*!PROTON_CPP_MESSAGINGEVENT_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/445f8873/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/messaging_handler.hpp b/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
new file mode 100644
index 0000000..389b73f
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
@@ -0,0 +1,110 @@
+#ifndef PROTON_CPP_MESSAGING_HANDLER_H
+#define PROTON_CPP_MESSAGING_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"
+
+namespace proton {
+
+class event;
+class messaging_adapter;
+
+/** messaging_handler base class. Provides a simpler set of events than
+ * proton::proton_handler and automates some common tasks.  Subclass and
+ * over-ride event handling member functions.
+ * @see proton::messaging_event for meaning of events.
+ */
+class messaging_handler : public proton_handler
+{
+  public:
+    /** Create a messaging_handler
+     *@param prefetch set flow control to automatically pre-fetch this many messages
+     *@param auto_accept automatically accept received messages after on_message()
+     *@param auto_settle automatically settle on receipt of delivery for sent messages.
+     *@param peer_close_is_error treat orderly remote connection close as error.
+     */
+    PN_CPP_EXTERN messaging_handler(int prefetch=10, bool auto_accept=true, bool auto_settle=true,
+                                    bool peer_close_is_error=false);
+
+    PN_CPP_EXTERN virtual ~messaging_handler();
+
+    ///@name Over-ride these member functions to handle events
+    ///@{
+    PN_CPP_EXTERN virtual void on_abort(event &e);
+    PN_CPP_EXTERN virtual void on_accepted(event &e);
+    PN_CPP_EXTERN virtual void on_commit(event &e);
+    PN_CPP_EXTERN virtual void on_connection_closed(event &e);
+    PN_CPP_EXTERN virtual void on_connection_closing(event &e);
+    PN_CPP_EXTERN virtual void on_connection_error(event &e);
+    PN_CPP_EXTERN virtual void on_connection_opening(event &e);
+    PN_CPP_EXTERN virtual void on_connection_opened(event &e);
+    PN_CPP_EXTERN virtual void on_disconnected(event &e);
+    PN_CPP_EXTERN virtual void on_fetch(event &e);
+    PN_CPP_EXTERN virtual void on_id_loaded(event &e);
+    PN_CPP_EXTERN virtual void on_link_closed(event &e);
+    PN_CPP_EXTERN virtual void on_link_closing(event &e);
+    PN_CPP_EXTERN virtual void on_link_error(event &e);
+    PN_CPP_EXTERN virtual void on_link_opened(event &e);
+    PN_CPP_EXTERN virtual void on_link_opening(event &e);
+    PN_CPP_EXTERN virtual void on_message(event &e);
+    PN_CPP_EXTERN virtual void on_quit(event &e);
+    PN_CPP_EXTERN virtual void on_record_inserted(event &e);
+    PN_CPP_EXTERN virtual void on_records_loaded(event &e);
+    PN_CPP_EXTERN virtual void on_rejected(event &e);
+    PN_CPP_EXTERN virtual void on_released(event &e);
+    PN_CPP_EXTERN virtual void on_request(event &e);
+    PN_CPP_EXTERN virtual void on_response(event &e);
+    PN_CPP_EXTERN virtual void on_sendable(event &e);
+    PN_CPP_EXTERN virtual void on_session_closed(event &e);
+    PN_CPP_EXTERN virtual void on_session_closing(event &e);
+    PN_CPP_EXTERN virtual void on_session_error(event &e);
+    PN_CPP_EXTERN virtual void on_session_opened(event &e);
+    PN_CPP_EXTERN virtual void on_session_opening(event &e);
+    PN_CPP_EXTERN virtual void on_settled(event &e);
+    PN_CPP_EXTERN virtual void on_start(event &e);
+    PN_CPP_EXTERN virtual void on_timer(event &e);
+    PN_CPP_EXTERN virtual void on_transaction_aborted(event &e);
+    PN_CPP_EXTERN virtual void on_transaction_committed(event &e);
+    PN_CPP_EXTERN virtual void on_transaction_declared(event &e);
+    PN_CPP_EXTERN virtual void on_transport_closed(event &e);
+    ///@}
+
+  private:
+    int prefetch_;
+    bool auto_accept_;
+    bool auto_settle_;
+    bool peer_close_iserror_;
+    PN_UNIQUE_PTR<messaging_adapter> messaging_adapter_;
+    PN_UNIQUE_PTR<handler> flow_controller_;
+    PN_CPP_EXTERN messaging_handler(
+        bool raw_handler, int prefetch=10, bool auto_accept=true,
+        bool auto_settle=true, bool peer_close_is_error=false);
+    friend class container_impl;
+    friend class messaging_adapter;
+    PN_CPP_EXTERN void create_helpers();
+};
+
+}
+
+#endif  /*!PROTON_CPP_MESSAGING_HANDLER_H*/


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


Mime
View raw message