http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/session.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/session.cpp b/proton-c/bindings/cpp/src/session.cpp deleted file mode 100644 index de152d6..0000000 --- a/proton-c/bindings/cpp/src/session.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * - * 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/session.hpp" - -#include "proton/connection.hpp" -#include "proton/receiver_options.hpp" -#include "proton/sender_options.hpp" -#include "proton/session_options.hpp" - -#include "contexts.hpp" -#include "proton_bits.hpp" - -#include <proton/connection.h> -#include <proton/session.h> - -#include <string> - -namespace proton { - -void session::open() { - pn_session_open(pn_object()); -} - -void session::open(const session_options &opts) { - opts.apply(*this); - pn_session_open(pn_object()); -} - -void session::close() -{ - pn_session_close(pn_object()); -} - -container& session::container() const { - return connection().container(); -} - -connection session::connection() const { - return make_wrapper(pn_session_connection(pn_object())); -} - -namespace { -std::string next_link_name(const connection& c) { - io::link_namer* ln = connection_context::get(c).link_gen; - - return ln ? ln->link_name() : uuid::random().str(); -} -} - -sender session::open_sender(const std::string &addr) { - return open_sender(addr, sender_options()); -} - -sender session::open_sender(const std::string &addr, const sender_options &so) { - pn_link_t *lnk = pn_sender(pn_object(), next_link_name(connection()).c_str()); - pn_terminus_set_address(pn_link_target(lnk), addr.c_str()); - sender snd(make_wrapper<sender>(lnk)); - snd.open(so); - return snd; -} - -receiver session::open_receiver(const std::string &addr) { - return open_receiver(addr, receiver_options()); -} - -receiver session::open_receiver(const std::string &addr, const receiver_options &ro) -{ - pn_link_t *lnk = pn_receiver(pn_object(), next_link_name(connection()).c_str()); - pn_terminus_set_address(pn_link_source(lnk), addr.c_str()); - receiver rcv(make_wrapper<receiver>(lnk)); - rcv.open(ro); - return rcv; -} - -error_condition session::error() const { - return make_wrapper(pn_session_remote_condition(pn_object())); -} - -size_t session::incoming_bytes() const { - return pn_session_incoming_bytes(pn_object()); -} - -size_t session::outgoing_bytes() const { - return pn_session_outgoing_bytes(pn_object()); -} - -sender_range session::senders() const { - pn_link_t *lnk = pn_link_head(pn_session_connection(pn_object()), 0); - while (lnk) { - if (pn_link_is_sender(lnk) && pn_link_session(lnk) == pn_object()) - break; - lnk = pn_link_next(lnk, 0); - } - return sender_range(sender_iterator(make_wrapper<sender>(lnk), pn_object())); -} - -receiver_range session::receivers() const { - pn_link_t *lnk = pn_link_head(pn_session_connection(pn_object()), 0); - while (lnk) { - if (pn_link_is_receiver(lnk) && pn_link_session(lnk) == pn_object()) - break; - lnk = pn_link_next(lnk, 0); - } - return receiver_range(receiver_iterator(make_wrapper<receiver>(lnk), pn_object())); -} - -session_iterator session_iterator::operator++() { - obj_ = pn_session_next(unwrap(obj_), 0); - return *this; -} - -} // namespace proton
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/session_options.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/session_options.cpp b/proton-c/bindings/cpp/src/session_options.cpp deleted file mode 100644 index 2147fd4..0000000 --- a/proton-c/bindings/cpp/src/session_options.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * 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/session_options.hpp" -#include "proton/session.hpp" -#include "proton/connection.hpp" -#include "proton/container.hpp" - -#include <proton/session.h> - -#include "messaging_adapter.hpp" -#include "container_impl.hpp" -#include "proton_bits.hpp" - -namespace proton { - -template <class T> struct option { - T value; - bool set; - - option() : value(), set(false) {} - option& operator=(const T& x) { value = x; set = true; return *this; } - void update(const option<T>& x) { if (x.set) *this = x.value; } -}; - -class session_options::impl { - public: - option<messaging_handler *> handler; - - void apply(session& s) { - if (s.uninitialized()) { - if (handler.set && handler.value) container::impl::set_handler(s, handler.value); - } - } - -}; - -session_options::session_options() : impl_(new impl()) {} -session_options::session_options(const session_options& x) : impl_(new impl()) { - *this = x; -} -session_options::~session_options() {} - -session_options& session_options::operator=(const session_options& x) { - *impl_ = *x.impl_; - return *this; -} - -session_options& session_options::handler(class messaging_handler &h) { impl_->handler = &h; return *this; } - -void session_options::apply(session& s) const { impl_->apply(s); } - - - - -} // namespace proton http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/source.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/source.cpp b/proton-c/bindings/cpp/src/source.cpp deleted file mode 100644 index a407d0b..0000000 --- a/proton-c/bindings/cpp/src/source.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * 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_bits.hpp" - -#include "proton/source.hpp" -#include "proton/sender.hpp" -#include "proton/receiver.hpp" - -#include "proton_bits.hpp" - -namespace proton { - -// Set parent_ non-null when the local terminus is authoritative and may need to be looked up. -source::source(pn_terminus_t *t) : terminus(make_wrapper(t)) {} - -source::source(const sender& snd) : terminus(make_wrapper(pn_link_remote_source(unwrap(snd)))) { parent_ = unwrap(snd); } - -source::source(const receiver& rcv) : terminus(make_wrapper(pn_link_remote_source(unwrap(rcv)))) {} - -std::string source::address() const { - pn_terminus_t *authoritative = object_; - if (parent_ && pn_terminus_is_dynamic(object_)) - authoritative = pn_link_source(parent_); - return str(pn_terminus_get_address(authoritative)); -} - -enum source::distribution_mode source::distribution_mode() const { - return (enum distribution_mode)pn_terminus_get_distribution_mode(object_); -} - -source::filter_map source::filters() const { - codec::decoder d(make_wrapper(pn_terminus_filter(object_))); - filter_map map; - if (!d.empty()) { - d.rewind(); - d >> map; - } - return map; -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/ssl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ssl.cpp b/proton-c/bindings/cpp/src/ssl.cpp deleted file mode 100644 index 9a76442..0000000 --- a/proton-c/bindings/cpp/src/ssl.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * 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/ssl.hpp" -#include "proton/error.hpp" -#include "msg.hpp" - -#include <proton/ssl.h> - -namespace proton { - -std::string ssl::cipher() const { - char buf[128]; - if (pn_ssl_get_cipher_name(object_, buf, sizeof(buf))) - return std::string(buf); - return std::string(); -} - -int ssl::ssf() const { - return pn_ssl_get_ssf(object_); -} - -std::string ssl::protocol() const { - char buf[128]; - if (pn_ssl_get_protocol_name(object_, buf, sizeof(buf))) - return std::string(buf); - return std::string(); -} - -enum ssl::resume_status ssl::resume_status() const { - return (enum ssl::resume_status)pn_ssl_resume_status(object_); -} - -std::string ssl::remote_subject() const { - const char *s = pn_ssl_get_remote_subject(object_); - return s ? std::string(s) : std::string(); -} - - -} // namespace http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/ssl_domain.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ssl_domain.cpp b/proton-c/bindings/cpp/src/ssl_domain.cpp deleted file mode 100644 index bb95bec..0000000 --- a/proton-c/bindings/cpp/src/ssl_domain.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * 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/ssl.hpp" -#include "proton/error.hpp" -#include "msg.hpp" - -#include <proton/ssl.h> - -namespace proton { - -/// TODO: This whole class isn't really needed as pn_ssl_domain_t is already refcounted, with shared ownership for all pn_ssl_t objects -/// that hold one -class ssl_domain_impl { - public: - ssl_domain_impl(bool is_server) : refcount_(1), pn_domain_(pn_ssl_domain(is_server ? PN_SSL_MODE_SERVER : PN_SSL_MODE_CLIENT)) { - if (!pn_domain_) throw error(MSG("SSL/TLS unavailable")); - } - ~ssl_domain_impl() { pn_ssl_domain_free(pn_domain_); } - void incref() { refcount_++; } - void decref() { - if (--refcount_ == 0) { - delete this; - } - } - pn_ssl_domain_t *pn_domain() { return pn_domain_; } - private: - int refcount_; - pn_ssl_domain_t *pn_domain_; - ssl_domain_impl(const ssl_domain_impl&); - ssl_domain_impl& operator=(const ssl_domain_impl&); -}; - -namespace internal { -ssl_domain::ssl_domain(bool is_server) : impl_(0), server_type_(is_server) {} - -ssl_domain::ssl_domain(const ssl_domain &x) : impl_(x.impl_), server_type_(x.server_type_) { - if (impl_) impl_->incref(); -} - -ssl_domain& internal::ssl_domain::operator=(const ssl_domain&x) { - if (impl_) impl_->decref(); - impl_ = x.impl_; - server_type_ = x.server_type_; - if (impl_) impl_->incref(); - return *this; -} - -ssl_domain::~ssl_domain() { if (impl_) impl_->decref(); } - -pn_ssl_domain_t *ssl_domain::pn_domain() { - if (!impl_) - // Lazily create in case never actually used or configured. - // The pn_ssl_domain_t is a heavy object. - impl_ = new ssl_domain_impl(server_type_); - return impl_->pn_domain(); -} - -} // namespace internal - -namespace { - -void set_cred(pn_ssl_domain_t *dom, const std::string &main, const std::string &extra, const std::string &pass, bool pwset) { - const char *cred2 = extra.empty() ? NULL : extra.c_str(); - const char *pw = pwset ? pass.c_str() : NULL; - if (pn_ssl_domain_set_credentials(dom, main.c_str(), cred2, pw)) - throw error(MSG("SSL certificate initialization failure for " << main << ":" << - (cred2 ? cred2 : "NULL") << ":" << (pw ? pw : "NULL"))); -} -} - -ssl_server_options::ssl_server_options(ssl_certificate &cert) : internal::ssl_domain(true) { - set_cred(pn_domain(), cert.certdb_main_, cert.certdb_extra_, cert.passwd_, cert.pw_set_); -} - -ssl_server_options::ssl_server_options( - ssl_certificate &cert, - const std::string &trust_db, - const std::string &advertise_db, - enum ssl::verify_mode mode) : internal::ssl_domain(true) -{ - pn_ssl_domain_t* dom = pn_domain(); - set_cred(dom, cert.certdb_main_, cert.certdb_extra_, cert.passwd_, cert.pw_set_); - if (pn_ssl_domain_set_trusted_ca_db(dom, trust_db.c_str())) - throw error(MSG("SSL trust store initialization failure for " << trust_db)); - const std::string &db = advertise_db.empty() ? trust_db : advertise_db; - if (pn_ssl_domain_set_peer_authentication(dom, pn_ssl_verify_mode_t(mode), db.c_str())) - throw error(MSG("SSL server configuration failure requiring client certificates using " << db)); -} - -ssl_server_options::ssl_server_options() : ssl_domain(true) {} - -namespace { -void client_setup(pn_ssl_domain_t *dom, const std::string &trust_db, enum ssl::verify_mode mode) { - if (pn_ssl_domain_set_trusted_ca_db(dom, trust_db.c_str())) - throw error(MSG("SSL trust store initialization failure for " << trust_db)); - if (pn_ssl_domain_set_peer_authentication(dom, pn_ssl_verify_mode_t(mode), NULL)) - throw error(MSG("SSL client verify mode failure")); -} -} - -ssl_client_options::ssl_client_options(const std::string &trust_db, enum ssl::verify_mode mode) : ssl_domain(false) { - client_setup(pn_domain(), trust_db, mode); -} - -ssl_client_options::ssl_client_options(ssl_certificate &cert, const std::string &trust_db, enum ssl::verify_mode mode) : ssl_domain(false) { - pn_ssl_domain_t *dom = pn_domain(); - set_cred(dom, cert.certdb_main_, cert.certdb_extra_, cert.passwd_, cert.pw_set_); - client_setup(dom, trust_db, mode); -} - -ssl_client_options::ssl_client_options() : ssl_domain(false) {} - -ssl_certificate::ssl_certificate(const std::string &main) - : certdb_main_(main), pw_set_(false) {} - -ssl_certificate::ssl_certificate(const std::string &main, const std::string &extra) - : certdb_main_(main), certdb_extra_(extra), pw_set_(false) {} - -ssl_certificate::ssl_certificate(const std::string &main, const std::string &extra, const std::string &pw) - : certdb_main_(main), certdb_extra_(extra), passwd_(pw), pw_set_(true) {} - -} // namespace http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/target.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/target.cpp b/proton-c/bindings/cpp/src/target.cpp deleted file mode 100644 index 2085601..0000000 --- a/proton-c/bindings/cpp/src/target.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * 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_bits.hpp" - -#include "proton/target.hpp" -#include "proton/sender.hpp" -#include "proton/receiver.hpp" - -#include "proton_bits.hpp" - -namespace proton { - -// Set parent_ non-null when the local terminus is authoritative and may need to be looked up. -target::target(pn_terminus_t *t) : terminus(make_wrapper(t)) {} -target::target(const sender& snd) : terminus(make_wrapper(pn_link_remote_target(unwrap(snd)))) {} -target::target(const receiver& rcv) : terminus(make_wrapper(pn_link_remote_target(unwrap(rcv)))) { parent_ = unwrap(rcv); } - -std::string target::address() const { - pn_terminus_t *authoritative = object_; - if (parent_ && pn_terminus_is_dynamic(object_)) - authoritative = pn_link_target(parent_); - return str(pn_terminus_get_address(authoritative)); -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/terminus.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/terminus.cpp b/proton-c/bindings/cpp/src/terminus.cpp deleted file mode 100644 index 8065fe4..0000000 --- a/proton-c/bindings/cpp/src/terminus.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * 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/terminus.hpp" - -#include "proton/duration.hpp" -#include "proton/value.hpp" - -#include "proton_bits.hpp" - -namespace proton { - -terminus::terminus(pn_terminus_t* t) : - object_(t), parent_(0) -{} - -enum terminus::expiry_policy terminus::expiry_policy() const { - return (enum expiry_policy)pn_terminus_get_expiry_policy(object_); -} - -duration terminus::timeout() const { - return duration::SECOND * pn_terminus_get_timeout(object_); -} - -enum terminus::durability_mode terminus::durability_mode() { - return (enum durability_mode) pn_terminus_get_durability(object_); -} - -bool terminus::dynamic() const { - return pn_terminus_is_dynamic(object_); -} - -value terminus::node_properties() const { - return internal::value_ref(pn_terminus_properties(object_)); -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/thread_safe_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/thread_safe_test.cpp b/proton-c/bindings/cpp/src/thread_safe_test.cpp deleted file mode 100644 index 3a72f7f..0000000 --- a/proton-c/bindings/cpp/src/thread_safe_test.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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. - */ - -/// Test reference counting for object wrappers, threads_safe<> wrappers and returned<> wrappers. -/// - -#include "test_bits.hpp" -#include "proton_bits.hpp" - -#include "proton/thread_safe.hpp" -#include "proton/io/connection_driver.hpp" - -#include <proton/connection.h> - -namespace { - -using namespace std; -using namespace proton; - -void test_new() { - pn_connection_t* c = 0; - thread_safe<connection>* p = 0; - { - io::connection_driver e; - c = unwrap(e.connection()); - int r = pn_refcount(c); - ASSERT(r >= 1); // engine may have internal refs (transport, collector). - p = make_thread_safe(e.connection()).release(); - ASSERT_EQUAL(r+1, pn_refcount(c)); - delete p; - ASSERT_EQUAL(r, pn_refcount(c)); - p = make_thread_safe(e.connection()).release(); - } - ASSERT_EQUAL(1, pn_refcount(c)); // Engine gone, thread_safe keeping c alive. - delete p; - -#if PN_CPP_HAS_SHARED_PTR - { - std::shared_ptr<thread_safe<connection> > sp; - { - io::connection_driver e; - c = unwrap(e.connection()); - sp = make_shared_thread_safe(e.connection()); - } - ASSERT_EQUAL(1, pn_refcount(c)); // Engine gone, sp keeping c alive. - } -#endif -#if PN_CPP_HAS_UNIQUE_PTR - { - std::unique_ptr<thread_safe<connection> > up; - { - io::connection_driver e; - c = unwrap(e.connection()); - up = make_unique_thread_safe(e.connection()); - } - ASSERT_EQUAL(1, pn_refcount(c)); // Engine gone, sp keeping c alive. - } -#endif -} - -void test_convert() { - // Verify refcounts as expected with conversion between proton::object - // and thread_safe. - connection c; - pn_connection_t* pc = 0; - { - io::connection_driver eng; - c = eng.connection(); - pc = unwrap(c); // Unwrap in separate scope to avoid confusion from temp values. - } - { - ASSERT_EQUAL(1, pn_refcount(pc)); - returned<connection> pptr = make_thread_safe(c); - ASSERT_EQUAL(2, pn_refcount(pc)); - returned<connection> pp2 = pptr; - ASSERT(!pptr.release()); // Transferred to pp2 - ASSERT_EQUAL(2, pn_refcount(pc)); - connection c2 = pp2; // Transfer and convert to target - ASSERT_EQUAL(3, pn_refcount(pc)); // c, c2, thread_safe. - ASSERT(c == c2); - } - ASSERT_EQUAL(1, pn_refcount(pc)); // only c is left -} - -} - -int main(int, char**) { - int failed = 0; - RUN_TEST(failed, test_new()); - RUN_TEST(failed, test_convert()); - return failed; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/timestamp.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/timestamp.cpp b/proton-c/bindings/cpp/src/timestamp.cpp deleted file mode 100644 index da7c49f..0000000 --- a/proton-c/bindings/cpp/src/timestamp.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/timestamp.hpp" - -#include "proton/internal/config.hpp" -#include <proton/types.h> - -#include <iostream> - -#if PN_CPP_HAS_CHRONO -#include <chrono> -#else -#include <time.h> -#endif - -namespace proton { - -#if PN_CPP_HAS_CHRONO -timestamp timestamp::now() { - using namespace std::chrono; - return timestamp( duration_cast<std::chrono::milliseconds>(system_clock::now().time_since_epoch()).count() ); -} -#else -// Fallback with low (seconds) precision -timestamp timestamp::now() { - return timestamp( time(0)*1000 ); -} -#endif - -std::ostream& operator<<(std::ostream& o, timestamp ts) { return o << ts.milliseconds(); } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/tracker.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/tracker.cpp b/proton-c/bindings/cpp/src/tracker.cpp deleted file mode 100644 index 3b15ed5..0000000 --- a/proton-c/bindings/cpp/src/tracker.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * 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/tracker.hpp" - -#include "proton/sender.hpp" - -#include "proton_bits.hpp" - -#include <proton/delivery.h> - -namespace proton { - -tracker::tracker(pn_delivery_t *d): transfer(make_wrapper(d)) {} -sender tracker::sender() const { return make_wrapper<class sender>(pn_delivery_link(pn_object())); } -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/transfer.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/transfer.cpp b/proton-c/bindings/cpp/src/transfer.cpp deleted file mode 100644 index 78b6c0e..0000000 --- a/proton-c/bindings/cpp/src/transfer.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * 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/delivery.hpp" - -#include "proton/connection.hpp" -#include "proton/link.hpp" -#include "proton/session.hpp" - -#include <proton/delivery.h> -#include <proton/link.h> -#include <proton/session.h> - -#include "proton_bits.hpp" - -namespace proton { - -session transfer::session() const { return make_wrapper(pn_link_session(pn_delivery_link(pn_object()))); } -connection transfer::connection() const { return make_wrapper(pn_session_connection(pn_link_session(pn_delivery_link(pn_object())))); } -container& transfer::container() const { return connection().container(); } - -bool transfer::settled() const { return pn_delivery_settled(pn_object()); } - -void transfer::settle() { pn_delivery_settle(pn_object()); } - -enum transfer::state transfer::state() const { return static_cast<enum state>(pn_delivery_remote_state(pn_object())); } -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/transport.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/transport.cpp b/proton-c/bindings/cpp/src/transport.cpp deleted file mode 100644 index da3119e..0000000 --- a/proton-c/bindings/cpp/src/transport.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * 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/transport.hpp" -#include "proton/error_condition.hpp" -#include "proton/connection.hpp" -#include "proton/ssl.hpp" -#include "proton/sasl.hpp" -#include <proton/transport.h> -#include <proton/error.h> - -#include "msg.hpp" -#include "proton_bits.hpp" - - -namespace proton { - -connection transport::connection() const { - return make_wrapper(pn_transport_connection(pn_object())); -} - -class ssl transport::ssl() const { - return make_wrapper(pn_ssl(pn_object())); -} - -class sasl transport::sasl() const { - return make_wrapper(pn_sasl(pn_object())); -} - -error_condition transport::error() const { - return make_wrapper(pn_transport_condition(pn_object())); -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/type_id.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/type_id.cpp b/proton-c/bindings/cpp/src/type_id.cpp deleted file mode 100644 index b28a6e8..0000000 --- a/proton-c/bindings/cpp/src/type_id.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 "types_internal.hpp" - -#include "proton/type_id.hpp" - -#include <ostream> - -namespace proton { - -std::string type_name(type_id t) { - switch (t) { - case NULL_TYPE: return "null"; - case BOOLEAN: return "boolean"; - case UBYTE: return "ubyte"; - case BYTE: return "byte"; - case USHORT: return "ushort"; - case SHORT: return "short"; - case UINT: return "uint"; - case INT: return "int"; - case CHAR: return "char"; - case ULONG: return "ulong"; - case LONG: return "long"; - case TIMESTAMP: return "timestamp"; - case FLOAT: return "float"; - case DOUBLE: return "double"; - case DECIMAL32: return "decimal32"; - case DECIMAL64: return "decimal64"; - case DECIMAL128: return "decimal128"; - case UUID: return "uuid"; - case BINARY: return "binary"; - case STRING: return "string"; - case SYMBOL: return "symbol"; - case DESCRIBED: return "described"; - case ARRAY: return "array"; - case LIST: return "list"; - case MAP: return "map"; - } -// Avoid unreached diagnostic from clang -#if defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif - return "unknown"; -#if defined(__clang__) -#pragma GCC diagnostic pop -#endif -} - -std::ostream& operator<<(std::ostream& o, type_id t) { return o << type_name(t); } - -void assert_type_equal(type_id want, type_id got) { - if (want != got) throw make_conversion_error(want, got); -} - -} // proton http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/url.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/url.cpp b/proton-c/bindings/cpp/src/url.cpp deleted file mode 100644 index 867f605..0000000 --- a/proton-c/bindings/cpp/src/url.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * - * 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/url.hpp" - -#include "proton/error.hpp" - -#include "proton_bits.hpp" - -#include <cstdlib> -#include <cstring> -#include <iomanip> -#include <sstream> -#include <vector> - -namespace { - -/** URL-encode src and append to dst. */ -static std::string pni_urlencode(const std::string &src) { - static const char *bad = "@:/"; - - std::ostringstream dst; - dst << std::hex << std::uppercase << std::setfill('0'); - - std::size_t i = 0; - std::size_t j = src.find_first_of(bad); - while (j!=std::string::npos) { - dst << src.substr(i, j-i); - dst << "%" << std::setw(2) << src[j]; - i = j + 1; - j = src.find_first_of(bad); - } - dst << src.substr(i); - return dst.str(); -} - -// Low level url parser -static void pni_urldecode(const char *src, char *dst) -{ - const char *in = src; - char *out = dst; - while (*in != '\0') - { - if ('%' == *in) - { - if ((in[1] != '\0') && (in[2] != '\0')) - { - char esc[3]; - esc[0] = in[1]; - esc[1] = in[2]; - esc[2] = '\0'; - unsigned long d = std::strtoul(esc, NULL, 16); - *out = (char)d; - in += 3; - out++; - } - else - { - *out = *in; - in++; - out++; - } - } - else - { - *out = *in; - in++; - out++; - } - } - *out = '\0'; -} - -void parse_url(char *url, const char **scheme, const char **user, const char **pass, const char **host, const char **port, const char **path) -{ - if (!url) return; - - char *slash = std::strchr(url, '/'); - - if (slash && slash>url) { - char *scheme_end = std::strstr(slash-1, "://"); - - if (scheme_end && scheme_end<slash) { - *scheme_end = '\0'; - *scheme = url; - url = scheme_end + 3; - slash = std::strchr(url, '/'); - } - } - - if (slash) { - *slash = '\0'; - *path = slash + 1; - } - - char *at = std::strchr(url, '@'); - if (at) { - *at = '\0'; - char *up = url; - url = at + 1; - char *colon = std::strchr(up, ':'); - if (colon) { - *colon = '\0'; - char *p = colon + 1; - pni_urldecode(p, p); - *pass = p; - } - pni_urldecode(up, up); - *user = up; - } - - *host = url; - char *open = (*url == '[') ? url : 0; - if (open) { - char *close = std::strchr(open, ']'); - if (close) { - *host = open + 1; - *close = '\0'; - url = close + 1; - } - } - - char *colon = std::strchr(url, ':'); - if (colon) { - *colon = '\0'; - *port = colon + 1; - } -} - -} // namespace - -namespace proton { - -struct url::impl { - static const char* const default_host; - const char* scheme; - const char* username; - const char* password; - const char* host; - const char* port; - const char* path; - std::vector<char> cstr; - mutable std::string str; - - impl(const std::string& s) : - scheme(0), username(0), password(0), host(0), port(0), path(0), - cstr(s.size()+1, '\0') - { - std::copy(s.begin(), s.end(), cstr.begin()); - parse_url(&cstr[0], &scheme, &username, &password, &host, &port, &path); - } - - void defaults() { - if (!scheme || *scheme=='\0' ) scheme = proton::url::AMQP.c_str(); - if (!host || *host=='\0' ) host = default_host; - if (!port || *port=='\0' ) port = scheme; - } - - operator std::string() const { - if ( str.empty() ) { - if (scheme) { - str += scheme; - str += "://"; - } - if (username) { - str += pni_urlencode(username); - } - if (password) { - str += ":"; - str += pni_urlencode(password); - } - if (username || password) { - str += "@"; - } - if (host) { - if (std::strchr(host, ':')) { - str += '['; - str += host; - str += ']'; - } else { - str += host; - } - } - if (port) { - str += ':'; - str += port; - } - if (path) { - str += '/'; - str += path; - } - } - return str; - } - -}; - -const char* const url::impl::default_host = "localhost"; - - -url_error::url_error(const std::string& s) : error(s) {} - -url::url(const std::string &s) : impl_(new impl(s)) { impl_->defaults(); } - -url::url(const std::string &s, bool d) : impl_(new impl(s)) { if (d) impl_->defaults(); } - -url::url(const url& u) : impl_(new impl(u)) {} - -url::~url() {} - -url& url::operator=(const url& u) { - if (this != &u) { - impl_.reset(new impl(*u.impl_)); - } - return *this; -} - -url::operator std::string() const { return *impl_; } - -std::string url::scheme() const { return str(impl_->scheme); } -std::string url::user() const { return str(impl_->username); } -std::string url::password() const { return str(impl_->password); } -std::string url::host() const { return str(impl_->host); } -std::string url::port() const { return str(impl_->port); } -std::string url::path() const { return str(impl_->path); } - -std::string url::host_port() const { return host() + ":" + port(); } - -bool url::empty() const { return impl_->str.empty(); } - -const std::string url::AMQP("amqp"); -const std::string url::AMQPS("amqps"); - -uint16_t url::port_int() const { - // TODO aconway 2015-10-27: full service name lookup - // astitcher 2016-11-17: It is hard to make the full service name lookup platform independent - if (port() == AMQP) return 5672; - if (port() == AMQPS) return 5671; - std::istringstream is(port()); - uint16_t result; - is >> result; - if (is.fail()) - throw url_error("invalid port '" + port() + "'"); - return result; -} - -std::ostream& operator<<(std::ostream& o, const url& u) { - return o << std::string(u); -} - -std::string to_string(const url& u) { - return u; -} - -std::istream& operator>>(std::istream& i, url& u) { - std::string s; - i >> s; - if (!i.fail() && !i.bad()) { - if (!s.empty()) { - url::impl* p = new url::impl(s); - p->defaults(); - u.impl_.reset(p); - } else { - i.clear(std::ios::failbit); - } - } - return i; -} - -} // namespace proton http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/url_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/url_test.cpp b/proton-c/bindings/cpp/src/url_test.cpp deleted file mode 100644 index 0727e2c..0000000 --- a/proton-c/bindings/cpp/src/url_test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 "test_bits.hpp" -#include <proton/url.hpp> - -namespace { - -void check_url(const std::string& s, - const std::string& scheme, - const std::string& user, - const std::string& pwd, - const std::string& host, - const std::string& port, - const std::string& path - ) -{ - proton::url u(s); - ASSERT_EQUAL(scheme, u.scheme()); - ASSERT_EQUAL(user, u.user()); - ASSERT_EQUAL(pwd, u.password()); - ASSERT_EQUAL(host, u.host()); - ASSERT_EQUAL(port, u.port()); - ASSERT_EQUAL(path, u.path()); -} - -void parse_to_string_test() { - check_url("amqp://foo:xyz/path", - "amqp", "", "", "foo", "xyz", "path"); - check_url("amqp://username:password@host:1234/path", - "amqp", "username", "password", "host", "1234", "path"); - check_url("host:1234", - "amqp", "", "", "host", "1234", ""); - check_url("host", - "amqp", "", "", "host", "amqp", ""); - check_url("host/path", - "amqp", "", "", "host", "amqp", "path"); - check_url("amqps://host", - "amqps", "", "", "host", "amqps", ""); - check_url("/path", - "amqp", "", "", "localhost", "amqp", "path"); - check_url("", - "amqp", "", "", "localhost", "amqp", ""); - check_url(":1234", - "amqp", "", "", "localhost", "1234", ""); -} - -} - -int main(int, char**) { - int failed = 0; - RUN_TEST(failed, parse_to_string_test()); - return failed; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/uuid.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/uuid.cpp b/proton-c/bindings/cpp/src/uuid.cpp deleted file mode 100644 index 7e0af2c..0000000 --- a/proton-c/bindings/cpp/src/uuid.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 "types_internal.hpp" - -#include "proton/uuid.hpp" -#include "proton/types_fwd.hpp" - -#include <cstdlib> -#include <ctime> -#include <sstream> -#include <iomanip> - -#ifdef WIN32 -#include <process.h> -#define GETPID _getpid -#else -#include <unistd.h> -#define GETPID getpid -#endif - -namespace proton { - -namespace { - - -// Seed the random number generated once at startup. -struct seed { - seed() { - // A hash of time and PID, time alone is a bad seed as programs started - // within the same second will get the same seed. - long secs = time(0); - long pid = GETPID(); - std::srand(((secs*181)*((pid-83)*359))%104729); - } -} seed_; - -} - -uuid uuid::copy() { - uuid u; - std::fill(u.begin(), u.end(), 0); - return u; -} - -uuid uuid::copy(const char* bytes) { - uuid u; - if (bytes) - std::copy(bytes, bytes + u.size(), u.begin()); - else - std::fill(u.begin(), u.end(), 0); - return u; -} - -uuid uuid::random() { - uuid bytes; - int r = std::rand(); - for (size_t i = 0; i < bytes.size(); ++i ) { - bytes[i] = r & 0xFF; - r >>= 8; - if (!r) r = std::rand(); - } - - // From RFC4122, the version bits are set to 0100 - bytes[6] = (bytes[6] & 0x0F) | 0x40; - - // From RFC4122, the top two bits of byte 8 get set to 01 - bytes[8] = (bytes[8] & 0x3F) | 0x80; - return bytes; -} - -/// UUID standard format: 8-4-4-4-12 (36 chars, 32 alphanumeric and 4 hypens) -std::ostream& operator<<(std::ostream& o, const uuid& u) { - ios_guard restore_flags(o); - o << std::hex << std::setfill('0'); - static const int segments[] = {4,2,2,2,6}; // 1 byte is 2 hex chars. - const uint8_t *p = reinterpret_cast<const uint8_t*>(u.begin()); - for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); ++i) { - if (i > 0) - o << '-'; - for (int j = 0; j < segments[i]; ++j) { - o << std::setw(2) << printable_byte(*(p++)); - } - } - return o; -} - -std::string uuid::str() const { - std::ostringstream s; - s << *this; - return s.str(); -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/value.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/value.cpp b/proton-c/bindings/cpp/src/value.cpp deleted file mode 100644 index ceb3463..0000000 --- a/proton-c/bindings/cpp/src/value.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * 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_bits.hpp" -#include "proton/internal/data.hpp" -#include "proton/value.hpp" -#include "proton/types.hpp" -#include "proton/scalar.hpp" -#include "proton/error.hpp" - -#include <ostream> -#include <sstream> - -namespace proton { - -using codec::decoder; -using codec::encoder; -using codec::start; - -value::value() {} -value::value(const value& x) { *this = x; } -#if PN_CPP_HAS_RVALUE_REFERENCES -value::value(value&& x) { swap(*this, x); } -value& value::operator=(value&& x) { swap(*this, x); return *this; } -#endif - -value& value::operator=(const value& x) { - if (this != &x) { - if (x.empty()) - clear(); - else - data().copy(x.data_); - } - return *this; -} - -void swap(value& x, value& y) { std::swap(x.data_, y.data_); } - -void value::clear() { if (!!data_) data_.clear(); } - -namespace internal { - -// On demand -internal::data& value_base::data() { - if (!data_) - data_ = internal::data::create(); - return data_; -} - -} - -type_id value::type() const { - return (!data_ || data_.empty()) ? NULL_TYPE : codec::decoder(*this).next_type(); -} - -bool value::empty() const { return type() == NULL_TYPE; } - -namespace { - -// Compare nodes, return -1 if a<b, 0 if a==b, +1 if a>b -// Forward-declare so we can use it recursively. -int compare_next(decoder& a, decoder& b); - -template <class T> int compare(const T& a, const T& b) { - if (a < b) return -1; - else if (a > b) return +1; - else return 0; -} - -int compare_container(decoder& a, decoder& b) { - start sa, sb; - a >> sa; - b >> sb; - // Compare described vs. not-described. - int cmp = compare(sa.is_described, sb.is_described); - if (cmp) return cmp; - // Lexical sort (including descriptor if there is one) - size_t min_size = std::min(sa.size, sb.size) + size_t(sa.is_described); - for (size_t i = 0; i < min_size; ++i) { - cmp = compare_next(a, b); - if (cmp) return cmp; - } - return compare(sa.size, sb.size); -} - -template <class T> int compare_simple(decoder& a, decoder& b) { - T va = T(); - T vb = T(); - a >> va; - b >> vb; - return compare(va, vb); -} - -int compare_next(decoder& a, decoder& b) { - // Sort by type_id first. - type_id ta = a.next_type(), tb = b.next_type(); - int cmp = compare(ta, tb); - if (cmp) return cmp; - - switch (ta) { - case NULL_TYPE: return 0; - case ARRAY: - case LIST: - case MAP: - case DESCRIBED: - return compare_container(a, b); - case BOOLEAN: return compare_simple<bool>(a, b); - case UBYTE: return compare_simple<uint8_t>(a, b); - case BYTE: return compare_simple<int8_t>(a, b); - case USHORT: return compare_simple<uint16_t>(a, b); - case SHORT: return compare_simple<int16_t>(a, b); - case UINT: return compare_simple<uint32_t>(a, b); - case INT: return compare_simple<int32_t>(a, b); - case ULONG: return compare_simple<uint64_t>(a, b); - case LONG: return compare_simple<int64_t>(a, b); - case CHAR: return compare_simple<wchar_t>(a, b); - case TIMESTAMP: return compare_simple<timestamp>(a, b); - case FLOAT: return compare_simple<float>(a, b); - case DOUBLE: return compare_simple<double>(a, b); - case DECIMAL32: return compare_simple<decimal32>(a, b); - case DECIMAL64: return compare_simple<decimal64>(a, b); - case DECIMAL128: return compare_simple<decimal128>(a, b); - case UUID: return compare_simple<uuid>(a, b); - case BINARY: return compare_simple<binary>(a, b); - case STRING: return compare_simple<std::string>(a, b); - case SYMBOL: return compare_simple<symbol>(a, b); - } -// Avoid unreached diagnostic from clang -#if defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif - // Invalid but equal type_id, treat as equal. - return 0; -#if defined(__clang__) -#pragma GCC diagnostic pop -#endif -} - -int compare(const value& x, const value& y) { - decoder a(x), b(y); - internal::state_guard s1(a), s2(b); - a.rewind(); - b.rewind(); - while (a.more() && b.more()) { - int cmp = compare_next(a, b); - if (cmp != 0) return cmp; - } - if (b.more()) return -1; - if (a.more()) return 1; - return 0; -} - -} // namespace - -bool operator==(const value& x, const value& y) { - if (x.empty() && y.empty()) return true; - if (x.empty() || y.empty()) return false; - return compare(x, y) == 0; -} - -bool operator<(const value& x, const value& y) { - if (x.empty() && y.empty()) return false; - if (x.empty()) return true; // empty is < !empty - return compare(x, y) < 0; -} - -std::ostream& operator<<(std::ostream& o, const value& x) { - if (type_id_is_scalar(x.type()) || x.empty()) - return o << proton::get<scalar>(x); // Print as a scalar - // Use pn_inspect for complex types. - proton::decoder d(x); - return o << d; -} - -namespace internal { -value_ref::value_ref(pn_data_t* p) { refer(p); } -value_ref::value_ref(const internal::data& d) { refer(d); } -value_ref::value_ref(const value_base& v) { refer(v); } - -void value_ref::refer(pn_data_t* p) { data_ = make_wrapper(p); } -void value_ref::refer(const internal::data& d) { data_ = d; } -void value_ref::refer(const value_base& v) { data_ = v.data_; } - -void value_ref::reset() { refer(0); } -} // namespace internal - -std::string to_string(const value& x) { - std::ostringstream os; - os << std::boolalpha << x; - return os.str(); -} - -} // namespace proton http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/value_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/value_test.cpp b/proton-c/bindings/cpp/src/value_test.cpp deleted file mode 100644 index d9f0f4a..0000000 --- a/proton-c/bindings/cpp/src/value_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 "scalar_test.hpp" - -namespace { - -using namespace std; -using namespace proton; - -using test::many; -using test::scalar_test_group; - -// Inserting and extracting arrays from a container T of type U -template <class T> void sequence_test( - type_id tid, const many<typename T::value_type>& values, const string& s) -{ - T x(values.begin(), values.end()); - - value vx(x); // construct - ASSERT_EQUAL(tid, vx.type()); - ASSERT_EQUAL(x, get<T>(vx)); - ASSERT_EQUAL(x, coerce<T>(vx)); - { - T y; - get(vx, y); // Two argument get. - ASSERT_EQUAL(x, y); - } - { - T y; - coerce(vx, y); // Two argument coerce. - ASSERT_EQUAL(x, y); - } - value v2; // assign - v2 = x; - ASSERT_EQUAL(tid, v2.type()); - ASSERT_EQUAL(x, get<T>(v2)); - ASSERT_EQUAL(x, coerce<T>(v2)); - ASSERT_EQUAL(vx, v2); - - T y(x); - typename T::iterator it = y.begin(); - *y.begin() = *(++it); // Second element is bigger so y is lexicographically bigger than x - value vy(y); - ASSERT(vx != vy); - ASSERT(vx < vy); - ASSERT(vy > vx); - - ASSERT_EQUAL(s, to_string(vx)); -} - -template <class T, class U> void map_test(const U& values, const string& s) { - T m(values.begin(), values.end()); - value v(m); - ASSERT_EQUAL(MAP, v.type()); - T m2(get<T>(v)); - ASSERT_EQUAL(m.size(), m2.size()); - ASSERT_EQUAL(m, m2); - if (!s.empty()) - ASSERT_EQUAL(s, to_string(v)); -} - -} - -int main(int, char**) { - int failed = 0; - scalar_test_group<value>(failed); - - // Sequence tests - RUN_TEST(failed, sequence_test<list<bool> >( - ARRAY, many<bool>() + false + true, "@PN_BOOL[false, true]")); - RUN_TEST(failed, sequence_test<vector<int> >( - ARRAY, many<int>() + -1 + 2, "@PN_INT[-1, 2]")); - RUN_TEST(failed, sequence_test<deque<string> >( - ARRAY, many<string>() + "a" + "b", "@PN_STRING[\"a\", \"b\"]")); - RUN_TEST(failed, sequence_test<deque<symbol> >( - ARRAY, many<symbol>() + "a" + "b", "@PN_SYMBOL[:a, :b]")); - RUN_TEST(failed, sequence_test<vector<value> >( - LIST, many<value>() + value(0) + value("a"), "[0, \"a\"]")); - RUN_TEST(failed, sequence_test<vector<scalar> >( - LIST, many<scalar>() + scalar(0) + scalar("a"), "[0, \"a\"]")); - - // // Map tests - typedef pair<string, uint64_t> si_pair; - many<si_pair> si_pairs; - si_pairs << si_pair("a", 0) << si_pair("b", 1) << si_pair("c", 2); - - RUN_TEST(failed, (map_test<map<string, uint64_t> >( - si_pairs, "{\"a\"=0, \"b\"=1, \"c\"=2}"))); - RUN_TEST(failed, (map_test<vector<si_pair> >( - si_pairs, "{\"a\"=0, \"b\"=1, \"c\"=2}"))); - - many<std::pair<value,value> > value_pairs(si_pairs); - RUN_TEST(failed, (map_test<map<value, value> >( - value_pairs, "{\"a\"=0, \"b\"=1, \"c\"=2}"))); - - many<pair<scalar,scalar> > scalar_pairs(si_pairs); - RUN_TEST(failed, (map_test<map<scalar, scalar> >( - scalar_pairs, "{\"a\"=0, \"b\"=1, \"c\"=2}"))); - - annotation_key ak(si_pairs[0].first); - pair<annotation_key, message_id> p(si_pairs[0]); - many<pair<annotation_key, message_id> > restricted_pairs(si_pairs); - RUN_TEST(failed, (map_test<map<annotation_key, message_id> >( - restricted_pairs, "{:a=0, :b=1, :c=2}"))); - -#if PN_CPP_HAS_CPP11 - RUN_TEST(failed, sequence_test<forward_list<binary> >( - ARRAY, many<binary>() + binary("xx") + binary("yy"), "@PN_BINARY[b\"xx\", b\"yy\"]")); - RUN_TEST(failed, (map_test<unordered_map<string, uint64_t> >(si_pairs, ""))); -#endif - return failed; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/go/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/CMakeLists.txt b/proton-c/bindings/go/CMakeLists.txt deleted file mode 100644 index 16c633b..0000000 --- a/proton-c/bindings/go/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# -# 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. -# - -# Go version -execute_process(COMMAND ${GO_EXE} version OUTPUT_VARIABLE go_ver OUTPUT_STRIP_TRAILING_WHITESPACE) -message(STATUS "Found Go: ${GO_EXE} (${go_ver})") - -set(GO_BUILD_FLAGS "" CACHE STRING "Flags for 'go build'") - -# Flags that differ for golang go and gcc go. -if (go_ver MATCHES "gccgo") - # TODO aconway 2015-10-08: import cycles with -race under gccgo, investigate. - set(GO_TEST_FLAGS "-v" CACHE STRING "Flags for 'go test'") - set(GO_RPATH_FLAGS -gccgoflags "-Wl,-rpath=${CMAKE_BINARY_DIR}/proton-c") -else() - set(GO_TEST_FLAGS "-v -race" CACHE STRING "Flags for 'go test'") - set(GO_RPATH_FLAGS -ldflags "-r ${CMAKE_BINARY_DIR}/proton-c") -endif() - -separate_arguments(GO_BUILD_FLAGS) -separate_arguments(GO_TEST_FLAGS) - -# Following are CACHE INTERNAL so examples/CMakeLists.txt can see them. -set(GO_ENV ${env_py} -- - "GOPATH=${CMAKE_CURRENT_SOURCE_DIR}" - "CGO_CFLAGS=-I${CMAKE_SOURCE_DIR}/proton-c/include -I${CMAKE_BINARY_DIR}/proton-c/include" - "CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/proton-c" - "PN_INTEROP_DIR=${CMAKE_SOURCE_DIR}/tests/interop" - CACHE INTERNAL "Run a command with Go environment variables") - -set(GO ${GO_ENV} ${GO_EXE} CACHE INTERNAL "Run go with environment set") - -set(GO_BUILD ${GO} build ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} CACHE INTERNAL "Run go build") -set(GO_INSTALL ${GO} install ${GO_BUILD_FLAGS} CACHE INTERNAL "Run go install" ) -set(GO_TEST ${GO} test ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} ${GO_TEST_FLAGS} CACHE INTERNAL "Run go test") - -# Go tools insist on standard Go layout which puts compiled code in the source tree :( -# Build output is all under git-ignored pkg or bin subdirectories, they are removed by make clean. - -# The go build tools handle dependency checks and incremental builds better than -# CMake so just run them every time, they do nothing if nothing needs to be -# done. -add_custom_target(go-build ALL - COMMAND ${GO_INSTALL} qpid.apache.org/... - DEPENDS qpid-proton-core - WORKING_DIRECTORY $ENV{PWD}) - -add_test( - NAME go-test COMMAND ${GO_TEST} qpid.apache.org/... - WORKING_DIRECTORY $ENV{PWD}) - -# Make available to examples/go/CMakeLists -set(GO_TARGETS go-build CACHE INTERNAL "Go package library targets") - -# Clean up go output directories. -list(APPEND ADDITIONAL_MAKE_CLEAN_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/pkg - ${CMAKE_CURRENT_SOURCE_DIR}/bin) - -# Install go sources. -set (GO_INSTALL_DIR ${SHARE_INSTALL_DIR}/gocode/src CACHE PATH "Installation directory for Go code") -mark_as_advanced (GO_INSTALL_DIR) -install(DIRECTORY src/qpid.apache.org DESTINATION ${GO_INSTALL_DIR} COMPONENT Go) http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/go/genwrap.go ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/genwrap.go b/proton-c/bindings/go/genwrap.go deleted file mode 100644 index 7782b0b..0000000 --- a/proton-c/bindings/go/genwrap.go +++ /dev/null @@ -1,434 +0,0 @@ -/* -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. -*/ - -// Code generator to generate a thin Go wrapper API around the C proton API. -// -// Not run automatically, generated sources are checked in. To update the -// generated sources run `go run genwrap.go` in this directory. -// -package main - -import ( - "flag" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "regexp" - "strings" - "text/template" -) - -var includeProton = "../../include/proton" -var outpath = "src/qpid.apache.org/proton/wrappers_gen.go" - -func main() { - flag.Parse() - out, err := os.Create(outpath) - panicIf(err) - defer out.Close() - - apis := []string{"session", "link", "delivery", "disposition", "condition", "terminus", "connection", "transport", "sasl"} - fmt.Fprintln(out, copyright) - fmt.Fprint(out, ` -package proton - -import ( - "time" - "unsafe" -) - -// #include <proton/types.h> -// #include <proton/error.h> -// #include <proton/condition.h> -// #include <proton/event.h> -// #include <stdlib.h> -`) - for _, api := range apis { - fmt.Fprintf(out, "// #include <proton/%s.h>\n", api) - } - fmt.Fprintln(out, `import "C"`) - - event(out) - - for _, api := range apis { - fmt.Fprintf(out, "// Wrappers for declarations in %s.h\n\n", api) - header := readHeader(api) - enums := findEnums(header) - for _, e := range enums { - genEnum(out, e.Name, e.Values) - } - apiWrapFns(api, header, out) - } - out.Close() - - // Run gofmt. - cmd := exec.Command("gofmt", "-w", outpath) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err = cmd.Run() - if err != nil { - fmt.Fprintf(os.Stderr, "gofmt: %s", err) - os.Exit(1) - } -} - -// Identify acronyms that should be uppercase not Mixedcase -var acronym = regexp.MustCompile("(?i)SASL|AMQP") - -func mixedCase(s string) string { - result := "" - for _, w := range strings.Split(s, "_") { - if acronym.MatchString(w) { - w = strings.ToUpper(w) - } else { - w = strings.ToUpper(w[0:1]) + strings.ToLower(w[1:]) - } - result = result + w - } - return result -} - -func mixedCaseTrim(s, prefix string) string { - return mixedCase(strings.TrimPrefix(s, prefix)) -} - -var templateFuncs = template.FuncMap{"mixedCase": mixedCase, "mixedCaseTrim": mixedCaseTrim} - -func doTemplate(out io.Writer, data interface{}, tmpl string) { - panicIf(template.Must(template.New("").Funcs(templateFuncs).Parse(tmpl)).Execute(out, data)) -} - -type enumType struct { - Name string - Values []string -} - -// Find enums in a header file return map of enum name to values. -func findEnums(header string) (enums []enumType) { - for _, enum := range enumDefRe.FindAllStringSubmatch(header, -1) { - enums = append(enums, enumType{enum[2], enumValRe.FindAllString(enum[1], -1)}) - } - return enums -} - -// Types that are integral, not wrappers. Enums are added automatically. -var simpleType = map[string]bool{ - "State": true, // integral typedef -} - -func genEnum(out io.Writer, name string, values []string) { - simpleType[mixedCase(name)] = true - doTemplate(out, []interface{}{name, values}, ` -{{$enumName := index . 0}}{{$values := index . 1}} -type {{mixedCase $enumName}} C.pn_{{$enumName}}_t -const ({{range $values}} - {{mixedCaseTrim . "PN_"}} {{mixedCase $enumName}} = C.{{.}} {{end}} -) - -func (e {{mixedCase $enumName}}) String() string { - switch e { -{{range $values}} - case C.{{.}}: return "{{mixedCaseTrim . "PN_"}}" {{end}} - } - return "unknown" -} -`) -} - -func panicIf(err error) { - if err != nil { - panic(err) - } -} - -func readHeader(name string) string { - file, err := os.Open(path.Join(includeProton, name+".h")) - panicIf(err) - defer file.Close() - s, err := ioutil.ReadAll(file) - panicIf(err) - return string(s) -} - -var copyright string = `/* -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. -*/ - -// -// NOTE: DO NOT EDIT. This file was generated by genwrap.go from the proton header files. -// Update the generator and re-run if you need to modify this code. -// -` - -type eventType struct { - // C, function and interface names for the event - Name, Cname, Fname, Iname string -} - -func newEventType(cName string) eventType { - var etype eventType - etype.Cname = cName - etype.Name = mixedCaseTrim(cName, "PN_") - etype.Fname = "On" + etype.Name - etype.Iname = etype.Fname + "Interface" - return etype -} - -var ( - enumDefRe = regexp.MustCompile("typedef enum {([^}]*)} pn_([a-z_]+)_t;") - enumValRe = regexp.MustCompile("PN_[A-Z_]+") - skipEventRe = regexp.MustCompile("EVENT_NONE|REACTOR|SELECTABLE|TIMER") - skipFnRe = regexp.MustCompile("attach|context|class|collect|link_recv|link_send|transport_.*logf$|transport_.*trace|transport_head|transport_tail|transport_push|connection_set_password|link_get_drain") -) - -// Generate event wrappers. -func event(out io.Writer) { - event_h := readHeader("event") - - // Event is implented by hand in wrappers.go - - // Get all the pn_event_type_t enum values - var etypes []eventType - enums := findEnums(event_h) - for _, e := range enums[0].Values { - if skipEventRe.FindStringSubmatch(e) == nil { - etypes = append(etypes, newEventType(e)) - } - } - - doTemplate(out, etypes, ` -type EventType int -const ({{range .}} - E{{.Name}} EventType = C.{{.Cname}}{{end}} -) -`) - - doTemplate(out, etypes, ` -func (e EventType) String() string { - switch e { -{{range .}} - case C.{{.Cname}}: return "{{.Name}}"{{end}} - } - return "Unknown" -} -`) -} - -type genType struct { - Ctype, Gotype string - ToGo func(value string) string - ToC func(value string) string - Assign func(value string) string -} - -func (g genType) printBody(out io.Writer, value string) { - if g.Gotype != "" { - fmt.Fprintf(out, "return %s", g.ToGo(value)) - } else { - fmt.Fprintf(out, "%s", value) - } -} - -func (g genType) goLiteral(value string) string { - return fmt.Sprintf("%s{%s}", g.Gotype, value) -} - -func (g genType) goConvert(value string) string { - switch g.Gotype { - case "string": - return fmt.Sprintf("C.GoString(%s)", value) - case "Event": - return fmt.Sprintf("makeEvent(%s)", value) - default: - return fmt.Sprintf("%s(%s)", g.Gotype, value) - } -} - -func mapType(ctype string) (g genType) { - g.Ctype = "C." + strings.Trim(ctype, " \n") - - // Special-case mappings for C types, default: is the general wrapper type case. - switch g.Ctype { - case "C.void": - g.Gotype = "" - case "C.size_t": - g.Gotype = "uint" - case "C.int": - g.Gotype = "int" - case "C.void *": - g.Gotype = "unsafe.Pointer" - g.Ctype = "unsafe.Pointer" - case "C.bool": - g.Gotype = "bool" - case "C.ssize_t": - g.Gotype = "int" - case "C.uint64_t": - g.Gotype = "uint64" - case "C.uint32_t": - g.Gotype = "uint16" - case "C.uint16_t": - g.Gotype = "uint32" - case "C.const char *": - fallthrough - case "C.char *": - g.Gotype = "string" - g.Ctype = "C.CString" - g.ToC = func(v string) string { return fmt.Sprintf("%sC", v) } - g.Assign = func(v string) string { - return fmt.Sprintf("%sC := C.CString(%s)\n defer C.free(unsafe.Pointer(%sC))\n", v, v, v) - } - case "C.pn_seconds_t": - g.Gotype = "time.Duration" - g.ToGo = func(v string) string { return fmt.Sprintf("(time.Duration(%s) * time.Second)", v) } - case "C.pn_millis_t": - g.Gotype = "time.Duration" - g.ToGo = func(v string) string { return fmt.Sprintf("(time.Duration(%s) * time.Millisecond)", v) } - g.ToC = func(v string) string { return fmt.Sprintf("C.pn_millis_t(%s/time.Millisecond)", v) } - case "C.pn_timestamp_t": - g.Gotype = "time.Time" - g.ToC = func(v string) string { return fmt.Sprintf("pnTime(%s)", v) } - g.ToGo = func(v string) string { return fmt.Sprintf("goTime(%s)", v) } - case "C.pn_error_t *": - g.Gotype = "error" - g.ToGo = func(v string) string { return fmt.Sprintf("PnError(%s)", v) } - default: - pnId := regexp.MustCompile(" *pn_([a-z_]+)_t *\\*? *") - match := pnId.FindStringSubmatch(g.Ctype) - if match == nil { - panic(fmt.Errorf("unknown C type %#v", g.Ctype)) - } - g.Gotype = mixedCase(match[1]) - if !simpleType[g.Gotype] { - g.ToGo = g.goLiteral - g.ToC = func(v string) string { return v + ".pn" } - } - } - if g.ToGo == nil { - g.ToGo = g.goConvert // Use conversion by default. - } - if g.ToC == nil { - g.ToC = func(v string) string { return fmt.Sprintf("%s(%s)", g.Ctype, v) } - } - return -} - -type genArg struct { - Name string - genType -} - -var typeNameRe = regexp.MustCompile("^(.*( |\\*))([^ *]+)$") - -func splitArgs(argstr string) []genArg { - argstr = strings.Trim(argstr, " \n") - if argstr == "" { - return []genArg{} - } - args := make([]genArg, 0) - for _, item := range strings.Split(argstr, ",") { - item = strings.Trim(item, " \n") - typeName := typeNameRe.FindStringSubmatch(item) - if typeName == nil { - panic(fmt.Errorf("Can't split argument type/name %#v", item)) - } - cType := strings.Trim(typeName[1], " \n") - name := strings.Trim(typeName[3], " \n") - if name == "type" { - name = "type_" - } - args = append(args, genArg{name, mapType(cType)}) - } - return args -} - -func goArgs(args []genArg) string { - l := "" - for i, arg := range args { - if i != 0 { - l += ", " - } - l += arg.Name + " " + arg.Gotype - } - return l -} - -func cArgs(args []genArg) string { - l := "" - for _, arg := range args { - l += fmt.Sprintf(", %s", arg.ToC(arg.Name)) - } - return l -} - -func cAssigns(args []genArg) string { - l := "\n" - for _, arg := range args { - if arg.Assign != nil { - l += fmt.Sprintf("%s\n", arg.Assign(arg.Name)) - } - } - return l -} - -// Return the go name of the function or "" to skip the function. -func goFnName(api, fname string) string { - // Skip class, context and attachment functions. - if skipFnRe.FindStringSubmatch(api+"_"+fname) != nil { - return "" - } - return mixedCaseTrim(fname, "get_") -} - -func apiWrapFns(api, header string, out io.Writer) { - fmt.Fprintf(out, "type %s struct{pn *C.pn_%s_t}\n", mixedCase(api), api) - fmt.Fprintf(out, "func (%c %s) IsNil() bool { return %c.pn == nil }\n", api[0], mixedCase(api), api[0]) - fmt.Fprintf(out, "func (%c %s) CPtr() unsafe.Pointer { return unsafe.Pointer(%c.pn) }\n", api[0], mixedCase(api), api[0]) - fn := regexp.MustCompile(fmt.Sprintf(`PN_EXTERN ([a-z0-9_ ]+ *\*?) *pn_%s_([a-z_]+)\(pn_%s_t *\*[a-z_]+ *,? *([^)]*)\)`, api, api)) - for _, m := range fn.FindAllStringSubmatch(header, -1) { - rtype, fname, argstr := mapType(m[1]), m[2], m[3] - gname := goFnName(api, fname) - if gname == "" { // Skip - continue - } - args := splitArgs(argstr) - fmt.Fprintf(out, "func (%c %s) %s", api[0], mixedCase(api), gname) - fmt.Fprintf(out, "(%s) %s { ", goArgs(args), rtype.Gotype) - fmt.Fprint(out, cAssigns(args)) - rtype.printBody(out, fmt.Sprintf("C.pn_%s_%s(%c.pn%s)", api, fname, api[0], cArgs(args))) - fmt.Fprintf(out, "}\n") - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/go/src/qpid.apache.org/README.md ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/src/qpid.apache.org/README.md b/proton-c/bindings/go/src/qpid.apache.org/README.md deleted file mode 100644 index ffd67f8..0000000 --- a/proton-c/bindings/go/src/qpid.apache.org/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# Qpid Go packages for AMQP - -These packages provide [Go](http://golang.org) support for sending and receiving -AMQP messages in client or server applications. Reference documentation is -available at: <http://godoc.org/?q=qpid.apache.org> - -There are 3 packages: - -[qpid.apache.org/amqp](http://godoc.org/qpid.apache.org/amqp) provides functions -to convert AMQP messages and data types to and from Go data types. Used by both -the proton and electron packages to manage AMQP data. - -[qpid.apache.org/electron](http://godoc.org/qpid.apache.org/electron) is a -simple, concurrent-safe API for sending and receiving messages. It can be used -with goroutines and channels to build concurrent AMQP clients and servers. - -[qpid.apache.org/proton](http://godoc.org/qpid.apache.org/proton) is an -event-driven, concurrent-unsafe package that closely follows the proton C -API. Most Go programmers will find the -[electron](http://godoc.org/qpid.apache.org/electron) package easier to use. - -See the [examples](https://github.com/apache/qpid-proton/blob/master/examples/go/README.md) -to help you get started. - -Feedback is encouraged at: - -- Email <pro...@qpid.apache.org> -- Create issues <https://issues.apache.org/jira/browse/PROTON>, attach patches to an issue. - -### Why two APIs? - -The `proton` API is a direct mapping of the proton C library into Go. It is -usable but not very natural for a Go programmer because it takes an -*event-driven* approach and has no built-in support for concurrent -use. `electron` uses `proton` internally but provides a more Go-like API that is -safe to use from multiple concurrent goroutines. - -Go encourages programs to be structured as concurrent *goroutines* that -communicate via *channels*. Go literature distinguishes between: - -- *concurrency*: "keeping track of things that could be done in parallel" -- *parallelism*: "actually doing things in parallel on multiple CPUs or cores" - -A Go program expresses concurrency by starting goroutines for potentially -concurrent tasks. The Go runtime schedules the activity of goroutines onto a -small number (possibly one) of actual parallel executions. - -Even with no hardware parallelism, goroutine concurrency lets the Go runtime -order unpredictable events like file descriptors being readable/writable, -channels having data, timers firing etc. Go automatically takes care of -switching out goroutines that block or sleep so it is normal to write code in -terms of blocking calls. - -By contrast, event-driven programming is based on polling mechanisms like -`select`, `poll` or `epoll`. These also dispatch unpredictably ordered events to -a single thread or a small thread pool. However this requires a different style -of programming: "event-driven" or "reactive" programming. Go developers call it -"inside-out" programming. In an event-driven program blocking is a big problem -as it consumes a scarce thread of execution, so actions that take time to -complete have to be re-structured in terms of multiple events. - -The promise of Go is that you can express your program in concurrent, sequential -terms and the Go runtime will turn it inside-out for you. You can start -goroutines for all concurrent activities. They can loop forever or block for as -long as they need waiting for timers, IO or any unpredictable event. Go will -interleave and schedule them efficiently onto the available parallel hardware. - -For example: in the `electron` API, you can send a message and wait for it to be -acknowledged in a single function. All the information about the message, why -you sent it, and what to do when it is acknowledged can be held in local -variables, all the code is in a simple sequence. Other goroutines in your -program can be sending and receiving messages concurrently, they are not -blocked. - -In the `proton` API, an event handler that sends a message must return -*immediately*, it cannot block the event loop to wait for -acknowledgement. Acknowledgement is a separate event, so the code for handling -it is in a different event handler. Context information about the message has to -be stored in some non-local variable that both functions can find. This makes -the code harder to follow. - -The `proton` API is important because it is the foundation for the `electron` -API, and may be useful for programs that need to be close to the original C -library for some reason. However the `electron` API hides the event-driven -details behind simple, sequential, concurrent-safe methods that can be called -from arbitrary goroutines. Under the covers, data is passed through channels to -dedicated `proton` goroutines so user goroutines can work concurrently with the -proton event-loop. - -## New to Go? - -If you are new to Go then these are a good place to start: - -- [A Tour of Go](http://tour.golang.org) -- [Effective Go](http://golang.org/doc/effective_go.html) - -Then look at the tools and docs at <http://golang.org> as you need them. http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/go/src/qpid.apache.org/amqp/doc.go ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/doc.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/doc.go deleted file mode 100644 index 97051a5..0000000 --- a/proton-c/bindings/go/src/qpid.apache.org/amqp/doc.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -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. -*/ - -/* -Package amqp encodes and decodes AMQP 1.0 messages and data types as Go types. - -It follows the standard 'encoding' libraries pattern. The mapping between AMQP -and Go types is described in the documentation of the Marshal and Unmarshal -functions. - -Package 'electron' is a full AMQP 1.0 client/server toolkit using this package. - -AMQP 1.0 is an open standard for inter-operable message exchange, see <http://www.amqp.org/> -*/ -package amqp - -// #cgo LDFLAGS: -lqpid-proton -import "C" - -// This file is just for the package comment. http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/go/src/qpid.apache.org/amqp/error.go ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/error.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/error.go deleted file mode 100644 index 3a178b2..0000000 --- a/proton-c/bindings/go/src/qpid.apache.org/amqp/error.go +++ /dev/null @@ -1,103 +0,0 @@ -/* -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. -*/ - -package amqp - -// #include <proton/error.h> -import "C" - -import ( - "fmt" - "reflect" -) - -// Error is an AMQP error condition. It has a name and a description. -// It implements the Go error interface so can be returned as an error value. -// -// You can pass amqp.Error to methods that send an error to a remote endpoint, -// this gives you full control over what the remote endpoint will see. -// -// You can also pass any Go error to such functions, the remote peer -// will see the equivalent of MakeError(error) -// -type Error struct{ Name, Description string } - -// Error implements the Go error interface for AMQP error errors. -func (c Error) Error() string { return fmt.Sprintf("%s: %s", c.Name, c.Description) } - -// Errorf makes a Error with name and formatted description as per fmt.Sprintf -func Errorf(name, format string, arg ...interface{}) Error { - return Error{name, fmt.Sprintf(format, arg...)} -} - -// MakeError makes an AMQP error from a go error using the Go error type as the name -// and the err.Error() string as the description. -func MakeError(err error) Error { - return Error{reflect.TypeOf(err).Name(), err.Error()} -} - -var ( - InternalError = "amqp:internal-error" - NotFound = "amqp:not-found" - UnauthorizedAccess = "amqp:unauthorized-access" - DecodeError = "amqp:decode-error" - ResourceLimitExceeded = "amqp:resource-limit-exceeded" - NotAllowed = "amqp:not-allowed" - InvalidField = "amqp:invalid-field" - NotImplemented = "amqp:not-implemented" - ResourceLocked = "amqp:resource-locked" - PreconditionFailed = "amqp:precondition-failed" - ResourceDeleted = "amqp:resource-deleted" - IllegalState = "amqp:illegal-state" - FrameSizeTooSmall = "amqp:frame-size-too-small" -) - -type PnErrorCode int - -func (e PnErrorCode) String() string { - switch e { - case C.PN_EOS: - return "end-of-data" - case C.PN_ERR: - return "error" - case C.PN_OVERFLOW: - return "overflow" - case C.PN_UNDERFLOW: - return "underflow" - case C.PN_STATE_ERR: - return "bad-state" - case C.PN_ARG_ERR: - return "invalid-argument" - case C.PN_TIMEOUT: - return "timeout" - case C.PN_INTR: - return "interrupted" - case C.PN_INPROGRESS: - return "in-progress" - default: - return fmt.Sprintf("unknown-error(%d)", e) - } -} - -func PnError(e *C.pn_error_t) error { - if e == nil || C.pn_error_code(e) == 0 { - return nil - } - return fmt.Errorf("%s: %s", PnErrorCode(C.pn_error_code(e)), C.GoString(C.pn_error_text(e))) -} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org