http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/error_condition.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/error_condition.cpp b/proton-c/bindings/cpp/src/error_condition.cpp deleted file mode 100644 index ead1cff..0000000 --- a/proton-c/bindings/cpp/src/error_condition.cpp +++ /dev/null @@ -1,102 +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_condition.hpp" - -#include <proton/condition.h> - -#include "proton_bits.hpp" - -#include <ostream> - -namespace proton { - -error_condition::error_condition(pn_condition_t* c) : - name_(str(pn_condition_get_name(c))), - description_(str(pn_condition_get_description(c))), - properties_(internal::value_ref(pn_condition_info(c))) -{} - - -error_condition::error_condition(std::string description) : - name_("proton:io:error"), - description_(description) -{} - -error_condition::error_condition(std::string name, std::string description) : - name_(name), - description_(description) -{} - -error_condition::error_condition(std::string name, std::string description, value properties) : - name_(name), - description_(description), - properties_(properties) -{} - -#if PN_CPP_HAS_EXPLICIT_CONVERSIONS -error_condition::operator bool() const { - return !name_.empty(); -} -#endif - -bool error_condition::operator!() const { - return name_.empty(); -} - -bool error_condition::empty() const { - return name_.empty(); -} - -std::string error_condition::name() const { - return name_; -} - -std::string error_condition::description() const { - return description_; -} - -value error_condition::properties() const { - return properties_; -} - -std::string error_condition::what() const { - if (!*this) { - return "No error condition"; - } else { - std::string s(name_); - if (!description_.empty()) { - s += ": "; - s += description_; - } - return s; - } -} - -bool operator==(const error_condition& x, const error_condition& y) { - return x.name() == y.name() && x.description() == y.description() - && x.properties() == y.properties(); -} - -std::ostream& operator<<(std::ostream& o, const error_condition& err) { - return o << err.what(); -} - -}
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/event_loop.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/event_loop.cpp b/proton-c/bindings/cpp/src/event_loop.cpp deleted file mode 100644 index ea4ee71..0000000 --- a/proton-c/bindings/cpp/src/event_loop.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/event_loop.hpp" - -#include "contexts.hpp" -#include "event_loop_impl.hpp" - -#include <proton/session.h> -#include <proton/link.h> - -namespace proton { - -event_loop::event_loop() {} -event_loop::~event_loop() {} - -event_loop& event_loop::operator=(impl* i) { impl_.reset(i); return *this; } - -bool event_loop::inject(void_function0& f) { - return impl_->inject(f); -} - -#if PN_CPP_HAS_STD_FUNCTION -bool event_loop::inject(std::function<void()> f) { - return impl_->inject(f); -} -#endif - -event_loop& event_loop::get(pn_connection_t* c) { - return connection_context::get(c).event_loop_; -} - -event_loop& event_loop::get(pn_session_t* s) { - return get(pn_session_connection(s)); -} - -event_loop& event_loop::get(pn_link_t* l) { - return get(pn_link_session(l)); -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/handler.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/handler.cpp b/proton-c/bindings/cpp/src/handler.cpp deleted file mode 100644 index 5cf6208..0000000 --- a/proton-c/bindings/cpp/src/handler.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/messaging_handler.hpp" - -#include "proton/connection.hpp" -#include "proton/error_condition.hpp" -#include "proton/receiver.hpp" -#include "proton/sender.hpp" -#include "proton/session.hpp" -#include "proton/transport.hpp" - -#include "proton_event.hpp" -#include "messaging_adapter.hpp" - -#include <proton/handlers.h> - -#include <algorithm> - -namespace proton { - -messaging_handler::messaging_handler(){} - -messaging_handler::~messaging_handler(){} - -void messaging_handler::on_container_start(container &) {} -void messaging_handler::on_container_stop(container &) {} -void messaging_handler::on_message(delivery &, message &) {} -void messaging_handler::on_sendable(sender &) {} -void messaging_handler::on_transport_close(transport &) {} -void messaging_handler::on_transport_error(transport &t) { on_error(t.error()); } -void messaging_handler::on_transport_open(transport &) {} -void messaging_handler::on_connection_close(connection &) {} -void messaging_handler::on_connection_error(connection &c) { on_error(c.error()); } -void messaging_handler::on_connection_open(connection &) {} -void messaging_handler::on_session_close(session &) {} -void messaging_handler::on_session_error(session &s) { on_error(s.error()); } -void messaging_handler::on_session_open(session &) {} -void messaging_handler::on_receiver_close(receiver &) {} -void messaging_handler::on_receiver_error(receiver &l) { on_error(l.error()); } -void messaging_handler::on_receiver_open(receiver &) {} -void messaging_handler::on_receiver_detach(receiver &) {} -void messaging_handler::on_sender_close(sender &) {} -void messaging_handler::on_sender_error(sender &l) { on_error(l.error()); } -void messaging_handler::on_sender_open(sender &) {} -void messaging_handler::on_sender_detach(sender &) {} -void messaging_handler::on_tracker_accept(tracker &) {} -void messaging_handler::on_tracker_reject(tracker &) {} -void messaging_handler::on_tracker_release(tracker &) {} -void messaging_handler::on_tracker_settle(tracker &) {} -void messaging_handler::on_delivery_settle(delivery &) {} -void messaging_handler::on_sender_drain_start(sender &) {} -void messaging_handler::on_receiver_drain_finish(receiver &) {} - -void messaging_handler::on_error(const error_condition& c) { throw proton::error(c.what()); } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/acceptor.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/acceptor.hpp b/proton-c/bindings/cpp/src/include/acceptor.hpp deleted file mode 100644 index 9a25592..0000000 --- a/proton-c/bindings/cpp/src/include/acceptor.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef PROTON_ACCEPTOR_HPP -#define PROTON_ACCEPTOR_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/internal/export.hpp" -#include "proton/internal/object.hpp" - -#include <proton/reactor.h> - -struct pn_acceptor_t; - -namespace proton { - -/// A context for accepting inbound connections. -/// -/// @see container::listen -class acceptor : public internal::object<pn_acceptor_t> { - /// @cond INTERNAL - acceptor(pn_acceptor_t* a) : internal::object<pn_acceptor_t>(a) {} - /// @endcond - - public: - acceptor() : internal::object<pn_acceptor_t>(0) {} - - /// Close the acceptor. - PN_CPP_EXTERN void close(); - - /// Return the current set of connection options applied to - /// inbound connectons by the acceptor. - /// - /// Note that changes made to the connection options only affect - /// connections accepted after this call returns. - PN_CPP_EXTERN class connection_options &connection_options(); - - /// @cond INTERNAL - friend class internal::factory<acceptor>; - /// @endcond -}; - -} // proton - -#endif // PROTON_ACCEPTOR_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/connector.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/connector.hpp b/proton-c/bindings/cpp/src/include/connector.hpp deleted file mode 100644 index 6bcd0db..0000000 --- a/proton-c/bindings/cpp/src/include/connector.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef PROTON_CPP_CONNECTOR_HANDLER_H -#define PROTON_CPP_CONNECTOR_HANDLER_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "proton/connection.hpp" -#include "proton/connection_options.hpp" -#include <proton/event.h> -#include <proton/reactor.h> -#include "proton/url.hpp" - -#include "container_impl.hpp" -#include "proton_handler.hpp" - -#include <string> - - -namespace proton { - -class reconnect_timer; - -class container::impl::connector : public proton_handler -{ - public: - connector(connection &c, const connection_options &options, const url&); - ~connector(); - const url &address() const { return address_; } - void connect(); - void reconnect_timer(const class reconnect_timer &); - virtual void on_connection_local_open(proton_event &e); - virtual void on_connection_remote_open(proton_event &e); - virtual void on_connection_init(proton_event &e); - virtual void on_transport_closed(proton_event &e); - virtual void on_transport_tail_closed(proton_event &e); - virtual void on_timer_task(proton_event &e); - - private: - connection connection_; - const connection_options options_; - const url address_; - class reconnect_timer *reconnect_timer_; -}; - - -} - -#endif /*!PROTON_CPP_CONNECTOR_HANDLER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/container_impl.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/container_impl.hpp b/proton-c/bindings/cpp/src/include/container_impl.hpp deleted file mode 100644 index 7443150..0000000 --- a/proton-c/bindings/cpp/src/include/container_impl.hpp +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef PROTON_CPP_CONTAINERIMPL_H -#define PROTON_CPP_CONTAINERIMPL_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/fwd.hpp" -#include "proton/container.hpp" -#include "proton/connection.hpp" -#include "proton/connection_options.hpp" -#include "proton/duration.hpp" -#include "proton/sender.hpp" -#include "proton/sender_options.hpp" -#include "proton/receiver.hpp" -#include "proton/receiver_options.hpp" - -#include "messaging_adapter.hpp" -#include "reactor.hpp" -#include "proton_bits.hpp" -#include "proton_handler.hpp" - -#include <list> -#include <map> -#include <string> - -namespace proton { - -class dispatch_helper; -class connector; -class acceptor; -class url; -class listen_handler; - -class container::impl { - public: - impl(container& c, const std::string& id, messaging_handler* = 0); - ~impl(); - std::string id() const { return id_; } - returned<connection> connect(const std::string&, const connection_options&); - returned<sender> open_sender( - const std::string&, const proton::sender_options &, const connection_options &); - returned<receiver> open_receiver( - const std::string&, const proton::receiver_options &, const connection_options &); - listener listen(const std::string&, listen_handler& lh); - void stop_listening(const std::string&); - void client_connection_options(const connection_options &); - connection_options client_connection_options() const { return client_connection_options_; } - void server_connection_options(const connection_options &); - connection_options server_connection_options() const { return server_connection_options_; } - void sender_options(const proton::sender_options&); - class sender_options sender_options() const { return sender_options_; } - void receiver_options(const proton::receiver_options&); - class receiver_options receiver_options() const { return receiver_options_; } - void run(); - void stop(const error_condition& err); - void auto_stop(bool set); - void schedule(duration, void_function0&); -#if PN_CPP_HAS_STD_FUNCTION - void schedule(duration, std::function<void()>); -#endif - - // non-interface functionality - class connector; - - void configure_server_connection(connection &c); - static void schedule(impl& ci, int delay, proton_handler *h); - static void schedule(container& c, int delay, proton_handler *h); - template <class T> static void set_handler(T s, messaging_handler* h); - - private: - class handler_context; - class override_handler; - - internal::pn_ptr<pn_handler_t> cpp_handler(proton_handler *h); - - container& container_; - reactor reactor_; - // Keep a list of all the handlers used by the container so they last as long as the container - std::list<internal::pn_unique_ptr<proton_handler> > handlers_; - std::string id_; - connection_options client_connection_options_; - connection_options server_connection_options_; - proton::sender_options sender_options_; - proton::receiver_options receiver_options_; - typedef std::map<std::string, acceptor> acceptors; - acceptors acceptors_; - bool auto_stop_; -}; - -template <class T> -void container::impl::set_handler(T s, messaging_handler* mh) { - pn_record_t *record = internal::get_attachments(unwrap(s)); - proton_handler* h = new messaging_adapter(*mh); - impl* ci = s.container().impl_.get(); - ci->handlers_.push_back(h); - pn_record_set_handler(record, ci->cpp_handler(h).get()); -} - -} - -#endif /*!PROTON_CPP_CONTAINERIMPL_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/contexts.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/contexts.hpp b/proton-c/bindings/cpp/src/include/contexts.hpp deleted file mode 100644 index e80c434..0000000 --- a/proton-c/bindings/cpp/src/include/contexts.hpp +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef PROTON_CPP_CONTEXTS_H -#define PROTON_CPP_CONTEXTS_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/connection.hpp" -#include "proton/container.hpp" -#include "proton/io/connection_driver.hpp" -#include "proton/event_loop.hpp" -#include "proton/listen_handler.hpp" -#include "proton/message.hpp" -#include "proton/internal/pn_unique_ptr.hpp" - -#include "proton/io/link_namer.hpp" - -#include "proton_handler.hpp" - -struct pn_session_t; -struct pn_event_t; -struct pn_reactor_t; -struct pn_record_t; -struct pn_acceptor_t; - -namespace proton { - -class proton_handler; -class reactor; - -// Base class for C++ classes that are used as proton contexts. -// Contexts are pn_objects managed by pn reference counts, the C++ value is allocated in-place. -class context { - public: - // identifies a context, contains a record pointer and a handle. - typedef std::pair<pn_record_t*, pn_handle_t> id; - - virtual ~context(); - - // Allocate a default-constructed T as a proton object. - // T must be a subclass of context. - template <class T> static T *create() { return new(alloc(sizeof(T))) T(); } - - // The pn_class for a context - static pn_class_t* pn_class(); - - // Get the context identified by id as a C++ T*, return null pointer if not present. - template <class T> static T* ptr(id id_) { - return reinterpret_cast<T*>(pn_record_get(id_.first, id_.second)); - } - - // If the context is not present, create it with value x. - template <class T> static T& ref(id id_) { - T* ctx = context::ptr<T>(id_); - if (!ctx) { - ctx = create<T>(); - pn_record_def(id_.first, id_.second, pn_class()); - pn_record_set(id_.first, id_.second, ctx); - pn_decref(ctx); - } - return *ctx; - } - - private: - static void *alloc(size_t n); -}; - -// Connection context used by all connections. -class connection_context : public context { - public: - connection_context() : container(0), default_session(0), link_gen(0) {} - - class container* container; - pn_session_t *default_session; // Owned by connection. - message event_message; // re-used by messaging_adapter for performance. - io::link_namer* link_gen; // Link name generator. - - internal::pn_unique_ptr<proton_handler> handler; - event_loop event_loop_; - - static connection_context& get(pn_connection_t *c) { return ref<connection_context>(id(c)); } - static connection_context& get(const connection& c) { return ref<connection_context>(id(c)); } - - protected: - static context::id id(pn_connection_t*); - static context::id id(const connection& c); -}; - -void container_context(const reactor&, container&); - -class container_context { - public: - static void set(const reactor& r, container& c); - static container& get(pn_reactor_t*); -}; - -class listener_context : public context { - public: - static listener_context& get(pn_acceptor_t* c); - listener_context() : listen_handler_(0), ssl(false) {} - connection_options get_options() { return listen_handler_->on_accept(); } - class listen_handler* listen_handler_; - bool ssl; -}; - -class link_context : public context { - public: - static link_context& get(pn_link_t* l); - link_context() : credit_window(10), auto_accept(true), auto_settle(true), draining(false), pending_credit(0) {} - int credit_window; - bool auto_accept; - bool auto_settle; - bool draining; - uint32_t pending_credit; -}; - -} - -#endif /*!PROTON_CPP_CONTEXTS_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/event_loop_impl.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/event_loop_impl.hpp b/proton-c/bindings/cpp/src/include/event_loop_impl.hpp deleted file mode 100644 index b34a981..0000000 --- a/proton-c/bindings/cpp/src/include/event_loop_impl.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef PROTON_CPP_EVENT_LOOP_IMPL_HPP -#define PROTON_CPP_EVENT_LOOP_IMPL_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/fwd.hpp" - -namespace proton { - -class event_loop::impl { - public: - bool inject(void_function0& f); -#if PN_CPP_HAS_CPP11 - bool inject(std::function<void()> f); -#endif -}; - -} - -#endif // PROTON_CPP_EVENT_LOOP_IMPL_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/messaging_adapter.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/messaging_adapter.hpp b/proton-c/bindings/cpp/src/include/messaging_adapter.hpp deleted file mode 100644 index 5371eec..0000000 --- a/proton-c/bindings/cpp/src/include/messaging_adapter.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#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/messaging_handler.hpp" - -#include "proton_handler.hpp" - -#include <proton/event.h> -#include <proton/reactor.h> - -///@cond INTERNAL - -namespace proton { - -/// Convert the low level proton-c events to the higher level proton::messaging_handler calls -class messaging_adapter : public proton_handler -{ - public: - messaging_adapter(messaging_handler &delegate) : delegate_(delegate) {} - - void on_reactor_init(proton_event &e); - void on_reactor_final(proton_event & e); - void on_link_flow(proton_event &e); - void on_delivery(proton_event &e); - void on_connection_remote_open(proton_event &e); - void on_connection_remote_close(proton_event &e); - void on_session_remote_open(proton_event &e); - void on_session_remote_close(proton_event &e); - void on_link_local_open(proton_event &e); - void on_link_remote_open(proton_event &e); - void on_link_remote_detach(proton_event & e); - void on_link_remote_close(proton_event &e); - void on_transport_closed(proton_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-j/blob/2f85988e/proton-c/bindings/cpp/src/include/msg.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/msg.hpp b/proton-c/bindings/cpp/src/include/msg.hpp deleted file mode 100644 index b24b25c..0000000 --- a/proton-c/bindings/cpp/src/include/msg.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef PROTON_MSG_H -#define PROTON_MSG_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 <sstream> -#include <iostream> - -namespace proton { - -/** A simple facade for std::ostringstream that allows - * in place construction of a message and automatic conversion - * to string. - * E.g. - *@code - * void foo(const std::string&); - * foo(msg() << "hello " << 32); - *@endcode - * Will construct the string "hello 32" and pass it to foo() - */ -struct msg { - std::ostringstream os; - msg() {} - msg(const msg& m) : os(m.str()) {} - std::string str() const { return os.str(); } - operator std::string() const { return str(); } - template <class T> msg& operator<<(const T& t) { os << t; return *this; } -}; - -inline std::ostream& operator<<(std::ostream& o, const msg& m) { return o << m.str(); } - -/** Construct a message using operator << and append (file:line) */ -#define QUOTe_(x) #x -#define QUOTE(x) QUOTe_(x) -#define MSG(message) (::proton::msg() << message) - -} - -#endif /*!PROTON_MSG_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/proton_bits.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/proton_bits.hpp b/proton-c/bindings/cpp/src/include/proton_bits.hpp deleted file mode 100644 index 97d4bee..0000000 --- a/proton-c/bindings/cpp/src/include/proton_bits.hpp +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef PROTON_BITS_HPP -#define PROTON_BITS_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/link.h> -#include <proton/session.h> - -#include <string> -#include <iosfwd> - -/**@file - * - * Assorted internal proton utilities. - */ - -struct pn_error_t; - -struct pn_data_t; -struct pn_transport_t; -struct pn_sasl_t; -struct pn_ssl_t; -struct pn_connection_t; -struct pn_session_t; -struct pn_link_t; -struct pn_delivery_t; -struct pn_condition_t; -struct pn_acceptor_t; -struct pn_terminus_t; -struct pn_reactor_t; -struct pn_record_t; - -namespace proton { - -namespace internal { class data; } -class transport; -class sasl; -class ssl; -class connection; -class session; -class link; -class sender; -class receiver; -class transfer; -class tracker; -class delivery; -class error_condition; -class acceptor; -class terminus; -class source; -class target; -class reactor; - -std::string error_str(long code); - -/** Print the error string from pn_error_t, or from code if pn_error_t has no error. */ -std::string error_str(pn_error_t*, long code=0); - -/** Make a void* inspectable via operator <<. */ -struct inspectable { void* value; inspectable(void* o) : value(o) {} }; - -/** Stream a proton object via pn_inspect. */ -std::ostream& operator<<(std::ostream& o, const inspectable& object); - -void set_error_condition(const error_condition&, pn_condition_t*); - -/// Convert a const char* to std::string, convert NULL to the empty string. -inline std::string str(const char* s) { return s ? s : std::string(); } - -namespace internal { - -// These traits relate the wrapped and wrapper classes for the templated factories below -template <class T> struct wrapped {}; -template <> struct wrapped<internal::data> { typedef pn_data_t type; }; -template <> struct wrapped<transport> { typedef pn_transport_t type; }; -template <> struct wrapped<sasl> { typedef pn_sasl_t type; }; -template <> struct wrapped<ssl> { typedef pn_ssl_t type; }; -template <> struct wrapped<connection> { typedef pn_connection_t type; }; -template <> struct wrapped<session> { typedef pn_session_t type; }; -template <> struct wrapped<link> { typedef pn_link_t type; }; -template <> struct wrapped<sender> { typedef pn_link_t type; }; -template <> struct wrapped<receiver> { typedef pn_link_t type; }; -template <> struct wrapped<transfer> { typedef pn_delivery_t type; }; -template <> struct wrapped<tracker> { typedef pn_delivery_t type; }; -template <> struct wrapped<delivery> { typedef pn_delivery_t type; }; -template <> struct wrapped<error_condition> { typedef pn_condition_t type; }; -template <> struct wrapped<acceptor> { typedef pn_acceptor_t type; }; // TODO aconway 2016-05-13: reactor only -template <> struct wrapped<terminus> { typedef pn_terminus_t type; }; -template <> struct wrapped<source> { typedef pn_terminus_t type; }; -template <> struct wrapped<target> { typedef pn_terminus_t type; }; -template <> struct wrapped<reactor> { typedef pn_reactor_t type; }; - -template <class T> struct wrapper {}; -template <> struct wrapper<pn_data_t> { typedef internal::data type; }; -template <> struct wrapper<pn_transport_t> { typedef transport type; }; -template <> struct wrapper<pn_sasl_t> { typedef sasl type; }; -template <> struct wrapper<pn_ssl_t> { typedef ssl type; }; -template <> struct wrapper<pn_connection_t> { typedef connection type; }; -template <> struct wrapper<pn_session_t> { typedef session type; }; -template <> struct wrapper<pn_link_t> { typedef link type; }; -template <> struct wrapper<pn_delivery_t> { typedef transfer type; }; -template <> struct wrapper<pn_condition_t> { typedef error_condition type; }; -template <> struct wrapper<pn_acceptor_t> { typedef acceptor type; }; -template <> struct wrapper<pn_terminus_t> { typedef terminus type; }; -template <> struct wrapper<pn_reactor_t> { typedef reactor type; }; - -// Factory for wrapper types -template <class T> -class factory { -public: - static T wrap(typename wrapped<T>::type* t) { return t; } - static typename wrapped<T>::type* unwrap(T t) { return t.pn_object(); } -}; - -// Get attachments for various proton-c types -template <class T> -inline pn_record_t* get_attachments(T*); - -template <> inline pn_record_t* get_attachments(pn_session_t* s) { return pn_session_attachments(s); } -template <> inline pn_record_t* get_attachments(pn_link_t* l) { return pn_link_attachments(l); } -} - -template <class T> -typename internal::wrapper<T>::type make_wrapper(T* t) { return internal::factory<typename internal::wrapper<T>::type>::wrap(t); } - -template <class U> -U make_wrapper(typename internal::wrapped<U>::type* t) { return internal::factory<U>::wrap(t); } - -template <class T> -typename internal::wrapped<T>::type* unwrap(T t) {return internal::factory<T>::unwrap(t); } - -} - -#endif // PROTON_BITS_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/proton_event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/proton_event.hpp b/proton-c/bindings/cpp/src/include/proton_event.hpp deleted file mode 100644 index 00fdadf..0000000 --- a/proton-c/bindings/cpp/src/include/proton_event.hpp +++ /dev/null @@ -1,293 +0,0 @@ -#ifndef PROTON_CPP_PROTONEVENT_H -#define PROTON_CPP_PROTONEVENT_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "proton/fwd.hpp" -#include "proton/error.hpp" - -#include <proton/event.h> - -namespace proton { - -class proton_handler; - -/** Event information for a proton::proton_handler */ -class proton_event -{ - public: - /// The type of an event - enum event_type { - ///@name Event types - ///@{ - - /** - * Defined as a programming convenience. No event of this type will - * ever be generated. - */ - EVENT_NONE=PN_EVENT_NONE, - - /** - * A reactor has been started. Events of this type point to the reactor. - */ - REACTOR_INIT=PN_REACTOR_INIT, - - /** - * A reactor has no more events to process. Events of this type - * point to the reactor. - */ - REACTOR_QUIESCED=PN_REACTOR_QUIESCED, - - /** - * A reactor has been stopped. Events of this type point to the reactor. - */ - REACTOR_FINAL=PN_REACTOR_FINAL, - - /** - * A timer event has occurred. - */ - TIMER_TASK=PN_TIMER_TASK, - - /** - * The connection has been created. This is the first event that - * will ever be issued for a connection. Events of this type point - * to the relevant connection. - */ - CONNECTION_INIT=PN_CONNECTION_INIT, - - /** - * The connection has been bound to a transport. This event is - * issued when the transport::bind() is called. - */ - CONNECTION_BOUND=PN_CONNECTION_BOUND, - - /** - * The connection has been unbound from its transport. This event is - * issued when transport::unbind() is called. - */ - CONNECTION_UNBOUND=PN_CONNECTION_UNBOUND, - - /** - * The local connection endpoint has been closed. Events of this - * type point to the relevant connection. - */ - CONNECTION_LOCAL_OPEN=PN_CONNECTION_LOCAL_OPEN, - - /** - * The remote endpoint has opened the connection. Events of this - * type point to the relevant connection. - */ - CONNECTION_REMOTE_OPEN=PN_CONNECTION_REMOTE_OPEN, - - /** - * The local connection endpoint has been closed. Events of this - * type point to the relevant connection. - */ - CONNECTION_LOCAL_CLOSE=PN_CONNECTION_LOCAL_CLOSE, - - /** - * The remote endpoint has closed the connection. Events of this - * type point to the relevant connection. - */ - CONNECTION_REMOTE_CLOSE=PN_CONNECTION_REMOTE_CLOSE, - - /** - * The connection has been freed and any outstanding processing has - * been completed. This is the final event that will ever be issued - * for a connection. - */ - CONNECTION_FINAL=PN_CONNECTION_FINAL, - - /** - * The session has been created. This is the first event that will - * ever be issued for a session. - */ - SESSION_INIT=PN_SESSION_INIT, - - /** - * The local session endpoint has been opened. Events of this type - * point to the relevant session. - */ - SESSION_LOCAL_OPEN=PN_SESSION_LOCAL_OPEN, - - /** - * The remote endpoint has opened the session. Events of this type - * point to the relevant session. - */ - SESSION_REMOTE_OPEN=PN_SESSION_REMOTE_OPEN, - - /** - * The local session endpoint has been closed. Events of this type - * point ot the relevant session. - */ - SESSION_LOCAL_CLOSE=PN_SESSION_LOCAL_CLOSE, - - /** - * The remote endpoint has closed the session. Events of this type - * point to the relevant session. - */ - SESSION_REMOTE_CLOSE=PN_SESSION_REMOTE_CLOSE, - - /** - * The session has been freed and any outstanding processing has - * been completed. This is the final event that will ever be issued - * for a session. - */ - SESSION_FINAL=PN_SESSION_FINAL, - - /** - * The link has been created. This is the first event that will ever - * be issued for a link. - */ - LINK_INIT=PN_LINK_INIT, - - /** - * The local link endpoint has been opened. Events of this type - * point ot the relevant link. - */ - LINK_LOCAL_OPEN=PN_LINK_LOCAL_OPEN, - - /** - * The remote endpoint has opened the link. Events of this type - * point to the relevant link. - */ - LINK_REMOTE_OPEN=PN_LINK_REMOTE_OPEN, - - /** - * The local link endpoint has been closed. Events of this type - * point ot the relevant link. - */ - LINK_LOCAL_CLOSE=PN_LINK_LOCAL_CLOSE, - - /** - * The remote endpoint has closed the link. Events of this type - * point to the relevant link. - */ - LINK_REMOTE_CLOSE=PN_LINK_REMOTE_CLOSE, - - /** - * The local link endpoint has been detached. Events of this type - * point to the relevant link. - */ - LINK_LOCAL_DETACH=PN_LINK_LOCAL_DETACH, - - /** - * The remote endpoint has detached the link. Events of this type - * point to the relevant link. - */ - LINK_REMOTE_DETACH=PN_LINK_REMOTE_DETACH, - - /** - * The flow control state for a link has changed. Events of this - * type point to the relevant link. - */ - LINK_FLOW=PN_LINK_FLOW, - - /** - * The link has been freed and any outstanding processing has been - * completed. This is the final event that will ever be issued for a - * link. Events of this type point to the relevant link. - */ - LINK_FINAL=PN_LINK_FINAL, - - /** - * A delivery has been created or updated. Events of this type point - * to the relevant delivery. - */ - DELIVERY=PN_DELIVERY, - - /** - * The transport has new data to read and/or write. Events of this - * type point to the relevant transport. - */ - TRANSPORT=PN_TRANSPORT, - - /** - * The transport has authenticated, if this is received by a server - * the associated transport has authenticated an incoming connection - * and transport::user() can be used to obtain the authenticated - * user. - */ - TRANSPORT_AUTHENTICATED=PN_TRANSPORT_AUTHENTICATED, - - /** - * Indicates that a transport error has occurred. Use - * transport::condition() to access the details of the error - * from the associated transport. - */ - TRANSPORT_ERROR=PN_TRANSPORT_ERROR, - - /** - * Indicates that the head of the transport has been closed. This - * means the transport will never produce more bytes for output to - * the network. Events of this type point to the relevant transport. - */ - TRANSPORT_HEAD_CLOSED=PN_TRANSPORT_HEAD_CLOSED, - - /** - * Indicates that the tail of the transport has been closed. This - * means the transport will never be able to process more bytes from - * the network. Events of this type point to the relevant transport. - */ - TRANSPORT_TAIL_CLOSED=PN_TRANSPORT_TAIL_CLOSED, - - /** - * Indicates that the both the head and tail of the transport are - * closed. Events of this type point to the relevant transport. - */ - TRANSPORT_CLOSED=PN_TRANSPORT_CLOSED, - - SELECTABLE_INIT=PN_SELECTABLE_INIT, - SELECTABLE_UPDATED=PN_SELECTABLE_UPDATED, - SELECTABLE_READABLE=PN_SELECTABLE_READABLE, - SELECTABLE_WRITABLE=PN_SELECTABLE_WRITABLE, - SELECTABLE_ERROR=PN_SELECTABLE_ERROR, - SELECTABLE_EXPIRED=PN_SELECTABLE_EXPIRED, - SELECTABLE_FINAL=PN_SELECTABLE_FINAL - }; - ///@} - - proton_event(pn_event_t *ce, class container* cont) : - pn_event_(ce), - container_(cont) - {} - - pn_event_t* pn_event() const { return pn_event_; } - class container& container() const { - if (!container_) - throw proton::error("event does not have a container"); - return *container_; - } - - /// Get type of event - event_type type() const { return event_type(pn_event_type(pn_event_)); } - - void dispatch(proton_handler& h); - - private: - pn_event_t *pn_event_; - class container* container_; -}; - -} - -#endif /*!PROTON_CPP_PROTONEVENT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/proton_handler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/proton_handler.hpp b/proton-c/bindings/cpp/src/include/proton_handler.hpp deleted file mode 100644 index 9941396..0000000 --- a/proton-c/bindings/cpp/src/include/proton_handler.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef PROTON_CPP_PROTONHANDLER_H -#define PROTON_CPP_PROTONHANDLER_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "proton/internal/object.hpp" - -#include <vector> - -struct pn_handler_t; - -namespace proton { - -class event; -class proton_event; - -/// Handler base class, subclass and over-ride event handling member functions. -/// @see proton::proton_event for meaning of events. -class proton_handler -{ - public: - proton_handler(); - virtual ~proton_handler(); - - ///@name Over-ride these member functions to handle events - ///@{ - virtual void on_reactor_init(proton_event &e); - virtual void on_reactor_quiesced(proton_event &e); - virtual void on_reactor_final(proton_event &e); - virtual void on_timer_task(proton_event &e); - virtual void on_connection_init(proton_event &e); - virtual void on_connection_bound(proton_event &e); - virtual void on_connection_unbound(proton_event &e); - virtual void on_connection_local_open(proton_event &e); - virtual void on_connection_local_close(proton_event &e); - virtual void on_connection_remote_open(proton_event &e); - virtual void on_connection_remote_close(proton_event &e); - virtual void on_connection_final(proton_event &e); - virtual void on_session_init(proton_event &e); - virtual void on_session_local_open(proton_event &e); - virtual void on_session_local_close(proton_event &e); - virtual void on_session_remote_open(proton_event &e); - virtual void on_session_remote_close(proton_event &e); - virtual void on_session_final(proton_event &e); - virtual void on_link_init(proton_event &e); - virtual void on_link_local_open(proton_event &e); - virtual void on_link_local_close(proton_event &e); - virtual void on_link_local_detach(proton_event &e); - virtual void on_link_remote_open(proton_event &e); - virtual void on_link_remote_close(proton_event &e); - virtual void on_link_remote_detach(proton_event &e); - virtual void on_link_flow(proton_event &e); - virtual void on_link_final(proton_event &e); - virtual void on_delivery(proton_event &e); - virtual void on_transport(proton_event &e); - virtual void on_transport_error(proton_event &e); - virtual void on_transport_head_closed(proton_event &e); - virtual void on_transport_tail_closed(proton_event &e); - virtual void on_transport_closed(proton_event &e); - virtual void on_selectable_init(proton_event &e); - virtual void on_selectable_updated(proton_event &e); - virtual void on_selectable_readable(proton_event &e); - virtual void on_selectable_writable(proton_event &e); - virtual void on_selectable_expired(proton_event &e); - virtual void on_selectable_error(proton_event &e); - virtual void on_selectable_final(proton_event &e); - virtual void on_unhandled(proton_event &e); - ///@} -}; - -} - -#endif /*!PROTON_CPP_PROTONHANDLER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/reactor.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/reactor.hpp b/proton-c/bindings/cpp/src/include/reactor.hpp deleted file mode 100644 index 07678e4..0000000 --- a/proton-c/bindings/cpp/src/include/reactor.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef REACTOR_HPP -#define REACTOR_HPP - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/// @cond INTERNAL -/// XXX remove - -#include "proton/fwd.hpp" -#include "proton/internal/object.hpp" -#include "proton/duration.hpp" -#include "proton/timestamp.hpp" - -struct pn_reactor_t; -struct pn_handler_t; -struct pn_io_t; - -namespace proton { - -class acceptor; - -class reactor : public internal::object<pn_reactor_t> { - public: - reactor(pn_reactor_t* r = 0) : internal::object<pn_reactor_t>(r) {} - - /** Create a new reactor. */ - static reactor create(); - - /** Open a connection to url and create a receiver with source=url.path() */ - acceptor listen(const proton::url &); - - /** Run the event loop, return when all connections and acceptors are closed. */ - void run(); - - /** Start the reactor, you must call process() to process events */ - void start(); - - /** Process events, return true if there are more events to process. */ - bool process(); - - /** Stop the reactor, causes run() to return and process() to return false. */ - void stop(); - - /// Identifier for the container - std::string id() const; - - /// Get timeout, process() will return if there is no activity within the timeout. - duration timeout(); - - /// Set timeout, process() will return if there is no activity within the timeout. - void timeout(duration timeout); - - timestamp mark(); - timestamp now(); - - void schedule(int, pn_handler_t*); - - class connection connection(pn_handler_t*) const; - - class connection connection_to_host(const std::string &host, const std::string &port, pn_handler_t*) const; - - pn_handler_t* pn_handler() const; - - void pn_handler(pn_handler_t* ); - - pn_handler_t* pn_global_handler() const; - - void pn_global_handler(pn_handler_t* ); - - pn_io_t* pn_io() const; - - void wakeup(); - bool quiesced(); - void yield(); - - friend class internal::factory<reactor>; -}; - -} - -/// @endcond - -#endif // REACTOR_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/scalar_test.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/scalar_test.hpp b/proton-c/bindings/cpp/src/include/scalar_test.hpp deleted file mode 100644 index b075c98..0000000 --- a/proton-c/bindings/cpp/src/include/scalar_test.hpp +++ /dev/null @@ -1,209 +0,0 @@ -#ifndef SCALAR_TEST_HPP -#define SCALAR_TEST_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. - */ - -// Template tests used by both scalar_test.cpp and value_test.hpp to test conversion -// of scalar values via a proton::scalar or a proton::value. - -#include "test_bits.hpp" - -#include "proton/types.hpp" -#include "proton/error.hpp" - -#include <sstream> - - -namespace test { - -using namespace proton; - -// Inserting and extracting simple C++ values using same-type get<T> and coerce<T> -template <class V, class T> void simple_type_test(T x, type_id tid, const std::string& s, T y) { - V vx(x); // Construct from C++ value - ASSERT_EQUAL(tid, vx.type()); - ASSERT(!vx.empty()); - ASSERT_EQUAL(x, get<T>(vx)); - ASSERT_EQUAL(x, coerce<T>(vx)); - - V vxa = x; // Assign from C++ value - ASSERT_EQUAL(tid, vxa.type()); - ASSERT(!vx.empty()); - ASSERT_EQUAL(vx, vxa); - ASSERT_EQUAL(x, get<T>(vxa)); - ASSERT_EQUAL(x, coerce<T>(vxa)); - - V v2; // Default construct - ASSERT(v2.type() == NULL_TYPE); - ASSERT(v2.empty()); - v2 = x; // Assign from C++ value - ASSERT_EQUAL(tid, v2.type()); - ASSERT_EQUAL(vx, v2); - ASSERT_EQUAL(x, get<T>(v2)); - ASSERT_EQUAL(x, coerce<T>(v2)); - - V v3(vx); // Copy construct - ASSERT_EQUAL(tid, v3.type()); - ASSERT_EQUAL(vx, v3); - ASSERT_EQUAL(x, get<T>(v3)); - ASSERT_EQUAL(x, coerce<T>(v3)); - - V v4 = vx; // Copy assign - ASSERT_EQUAL(tid, v4.type()); - ASSERT_EQUAL(x, get<T>(v4)); - ASSERT_EQUAL(x, coerce<T>(v4)); - - ASSERT_EQUAL(s, to_string(vx)); // Stringify - V vy(y); - ASSERT(vx != vy); // Compare - ASSERT(vx < vy); - ASSERT(vy > vx); -} - -// Test native C/C++ integer types via their mapped integer type ([u]int_x_t) -template <class V, class T> void simple_integral_test() { - typedef typename internal::integer_type<sizeof(T), internal::is_signed<T>::value>::type int_type; - simple_type_test<V>(T(3), internal::type_id_of<int_type>::value, "3", T(4)); -} - -// Test invalid gets, valid same-type get<T> is tested by simple_type_test -// Templated to test both scalar and value. -template<class V> void bad_get_test() { - try { get<bool>(V(int8_t(1))); FAIL("byte as bool"); } catch (conversion_error) {} - try { get<uint8_t>(V(true)); FAIL("bool as uint8_t"); } catch (conversion_error) {} - try { get<uint8_t>(V(int8_t(1))); FAIL("int8 as uint8"); } catch (conversion_error) {} - try { get<int16_t>(V(uint16_t(1))); FAIL("uint16 as int16"); } catch (conversion_error) {} - try { get<int16_t>(V(int32_t(1))); FAIL("int32 as int16"); } catch (conversion_error) {} - try { get<symbol>(V(std::string())); FAIL("string as symbol"); } catch (conversion_error) {} - try { get<std::string>(V(binary())); FAIL("binary as string"); } catch (conversion_error) {} - try { get<binary>(V(symbol())); FAIL("symbol as binary"); } catch (conversion_error) {} - try { get<binary>(V(timestamp())); FAIL("timestamp as binary"); } catch (conversion_error) {} - try { get<int>(V(timestamp())); FAIL("timestamp as int"); } catch (conversion_error) {} - try { get<timestamp>(V(0)); FAIL("int as timestamp"); } catch (conversion_error) {} - try { get<timestamp>(V(std::string())); FAIL("string as timestamp"); } catch (conversion_error) {} -} - -// Test some valid coercions and some bad ones with mixed types. -// Templated to test both scalar and value. -template<class V> void coerce_test() { - // Valid C++ conversions should work with coerce. - ASSERT_EQUAL(false, coerce<bool>(V(0))); - ASSERT_EQUAL(true, coerce<bool>(V(-1))); - ASSERT_EQUAL(true, coerce<bool>(V(int64_t(0xFFFF0000)))); - - ASSERT_EQUAL(1, coerce<uint8_t>(V(uint64_t(1)))); // In range. - ASSERT_EQUAL(1, coerce<uint8_t>(V(uint32_t(0xFF01)))); // int truncate. - ASSERT_EQUAL(0xFFFF, coerce<uint16_t>(V(int8_t(-1)))); // Sign extend. - ASSERT_EQUAL(-1, coerce<int32_t>(V(uint64_t(0xFFFFFFFFul)))); // 2s complement - - ASSERT_EQUALISH(1.2f, coerce<float>(V(double(1.2))), 0.001f); - ASSERT_EQUALISH(3.4, coerce<double>(V(float(3.4))), 0.001); - ASSERT_EQUALISH(23.0, coerce<double>(V(uint64_t(23))), 0.001); // int to double. - ASSERT_EQUAL(-1945, coerce<int>(V(float(-1945.123)))); // round to int. - - // String-like conversions. - ASSERT_EQUAL(std::string("foo"), coerce<std::string>(V(symbol("foo")))); - ASSERT_EQUAL(std::string("foo"), coerce<std::string>(V(binary("foo")))); - - // Bad coercions, types are not `is_convertible` - V s("foo"); - try { coerce<bool>(s); FAIL("string as bool"); } catch (conversion_error) {} - try { coerce<int>(s); FAIL("string as int"); } catch (conversion_error) {} - try { coerce<double>(s); FAIL("string as double"); } catch (conversion_error) {} - - try { coerce<std::string>(V(0)); FAIL("int as string"); } catch (conversion_error) {} - try { coerce<symbol>(V(true)); FAIL("bool as symbol"); } catch (conversion_error) {} - try { coerce<binary>(V(0.0)); FAIL("double as binary"); } catch (conversion_error) {} - try { coerce<symbol>(V(binary())); FAIL("binary as symbol"); } catch (conversion_error) {} - try { coerce<binary>(V(symbol())); FAIL("symbol as binary"); } catch (conversion_error) {} - try { coerce<binary>(s); } catch (conversion_error) {} - try { coerce<symbol>(s); } catch (conversion_error) {} -} - -template <class V> void null_test() { - V v; - ASSERT(v.empty()); - ASSERT_EQUAL(NULL_TYPE, v.type()); - get<null>(v); - null n; - get(v, n); - V v2(n); - ASSERT(v.empty()); - ASSERT_EQUAL(NULL_TYPE, v.type()); - v = "foo"; - ASSERT_EQUAL(STRING, v.type()); - try { get<null>(v); FAIL("Expected conversion_error"); } catch (conversion_error) {} - v = null(); - get<null>(v); -} - -// Nasty hack for uninterpreted decimal<> types. -template <class T> T make(const char c) { T x; std::fill(x.begin(), x.end(), c); return x; } - -template <class V> void scalar_test_group(int& failed) { - // Direct AMQP-mapped types. - RUN_TEST(failed, simple_type_test<V>(false, BOOLEAN, "false", true)); - RUN_TEST(failed, simple_type_test<V>(uint8_t(42), UBYTE, "42", uint8_t(50))); - RUN_TEST(failed, simple_type_test<V>(int8_t(-42), BYTE, "-42", int8_t(-40))); - RUN_TEST(failed, simple_type_test<V>(uint16_t(4242), USHORT, "4242", uint16_t(5252))); - RUN_TEST(failed, simple_type_test<V>(int16_t(-4242), SHORT, "-4242", int16_t(3))); - RUN_TEST(failed, simple_type_test<V>(uint32_t(4242), UINT, "4242", uint32_t(5252))); - RUN_TEST(failed, simple_type_test<V>(int32_t(-4242), INT, "-4242", int32_t(3))); - RUN_TEST(failed, simple_type_test<V>(uint64_t(4242), ULONG, "4242", uint64_t(5252))); - RUN_TEST(failed, simple_type_test<V>(int64_t(-4242), LONG, "-4242", int64_t(3))); - RUN_TEST(failed, simple_type_test<V>(wchar_t('X'), CHAR, "88", wchar_t('Y'))); - RUN_TEST(failed, simple_type_test<V>(float(1.234), FLOAT, "1.234", float(2.345))); - RUN_TEST(failed, simple_type_test<V>(double(11.2233), DOUBLE, "11.2233", double(12))); - RUN_TEST(failed, simple_type_test<V>(timestamp(1234), TIMESTAMP, "1234", timestamp(12345))); - RUN_TEST(failed, simple_type_test<V>(make<decimal32>(1), DECIMAL32, "decimal32(0x01010101)", make<decimal32>(2))); - RUN_TEST(failed, simple_type_test<V>(make<decimal64>(3), DECIMAL64, "decimal64(0x0303030303030303)", make<decimal64>(4))); - RUN_TEST(failed, simple_type_test<V>(make<decimal128>(5), DECIMAL128, "decimal128(0x05050505050505050505050505050505)", make<decimal128>(6))); - RUN_TEST(failed, simple_type_test<V>( - uuid::copy("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"), - UUID, "00112233-4455-6677-8899-aabbccddeeff", - uuid::copy("\xff\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"))); - RUN_TEST(failed, simple_type_test<V>(std::string("xxx"), STRING, "xxx", std::string("yyy"))); - RUN_TEST(failed, simple_type_test<V>(symbol("aaa"), SYMBOL, "aaa", symbol("aaaa"))); - RUN_TEST(failed, simple_type_test<V>(binary("\010aaa"), BINARY, "b\"\\x08aaa\"", binary("aaaa"))); - - // Test native C++ integral types. - RUN_TEST(failed, (simple_integral_test<V, char>())); - RUN_TEST(failed, (simple_integral_test<V, signed char>())); - RUN_TEST(failed, (simple_integral_test<V, unsigned char>())); - RUN_TEST(failed, (simple_integral_test<V, short>())); - RUN_TEST(failed, (simple_integral_test<V, int>())); - RUN_TEST(failed, (simple_integral_test<V, long>())); - RUN_TEST(failed, (simple_integral_test<V, unsigned short>())); - RUN_TEST(failed, (simple_integral_test<V, unsigned int>())); - RUN_TEST(failed, (simple_integral_test<V, unsigned long>())); -#if PN_CPP_HAS_LONG_LONG - RUN_TEST(failed, (simple_integral_test<V, long long>())); - RUN_TEST(failed, (simple_integral_test<V, unsigned long long>())); -#endif - - - RUN_TEST(failed, (coerce_test<V>())); - RUN_TEST(failed, (null_test<V>())); - RUN_TEST(failed, (bad_get_test<V>())); -} - -} - -#endif // SCALAR_TEST_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/test_bits.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/test_bits.hpp b/proton-c/bindings/cpp/src/include/test_bits.hpp deleted file mode 100644 index 0cfbe1f..0000000 --- a/proton-c/bindings/cpp/src/include/test_bits.hpp +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef TEST_BITS_HPP -#define TEST_BITS_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 "msg.hpp" -#include "proton/types.hpp" - -#include <stdexcept> -#include <iostream> -#include <iterator> -#include <sstream> -#include <math.h> - -namespace test { - -struct fail : public std::logic_error { - fail(const std::string& what) : logic_error(what) {} -}; - -template <class T, class U> -void assert_equal(const T& want, const U& got, const std::string& what) { - if (!(want == got)) - throw fail(MSG(what << " " << want << " != " << got)); -} - -template <class T> -inline void assert_equalish(T want, T got, T delta, const std::string& what) -{ - if (!(fabs(want-got) <= delta)) - throw fail(MSG(what << " " << want << " !=~ " << got)); -} - -#define FAIL_MSG(WHAT) (MSG(__FILE__ << ":" << __LINE__ << ": " << WHAT).str()) -#define FAIL(WHAT) throw test::fail(FAIL_MSG(WHAT)) -#define ASSERT(TEST) do { if (!(TEST)) FAIL("failed ASSERT(" #TEST ")"); } while(false) -#define ASSERT_EQUAL(WANT, GOT) \ - test::assert_equal((WANT), (GOT), FAIL_MSG("failed ASSERT_EQUAL(" #WANT ", " #GOT ")")) -#define ASSERT_EQUALISH(WANT, GOT, DELTA) \ - test::assert_equalish((WANT), (GOT), (DELTA), FAIL_MSG("failed ASSERT_EQUALISH(" #WANT ", " #GOT ")")) - -#define RUN_TEST(BAD_COUNT, TEST) \ - do { \ - try { \ - TEST; \ - break; \ - } catch(const test::fail& e) { \ - std::cout << "FAIL " << #TEST << std::endl << e.what() << std::endl; \ - } catch(const std::exception& e) { \ - std::cout << "ERROR " << #TEST << std::endl << __FILE__ << ":" << __LINE__ << ": " << e.what() << std::endl; \ - } \ - ++BAD_COUNT; \ - } while(0) - -template<class T> std::string str(const T& x) { - std::ostringstream s; s << std::boolalpha << x; return s.str(); -} - -// A way to easily create literal collections that can be compared to std:: collections -// and to print std collections -// e.g. -// std::vector<string> v = ...; -// ASSERT_EQUAL(many<string>() + "a" + "b" + "c", v); -template <class T> struct many : public std::vector<T> { - many() {} - template<class S> explicit many(const S& s) : std::vector<T>(s.begin(), s.end()) {} - many& operator+=(const T& t) { this->push_back(t); return *this; } - many& operator<<(const T& t) { return *this += t; } - many operator+(const T& t) { many<T> l(*this); return l += t; } -}; - -template <class T, class S> bool operator==(const many<T>& m, const S& s) { - return m.size() == s.size() && S(m.begin(), m.end()) == s; -} - -template <class T, class S> bool operator==(const S& s, const many<T>& m) { - return m.size() == s.size() && S(m.begin(), m.end()) == s; -} - -template <class T> std::ostream& operator<<(std::ostream& o, const many<T>& m) { - std::ostream_iterator<T> oi(o, " "); - std::copy(m.begin(), m.end(), oi); - return o; -} - -} - -namespace std { -template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>& s) { - return o << test::many<T>(s); -} - -template <class T> std::ostream& operator<<(std::ostream& o, const std::deque<T>& s) { - return o << test::many<T>(s); -} - -template <class T> std::ostream& operator<<(std::ostream& o, const std::list<T>& s) { - return o << test::many<T>(s); -} - -template <class K, class T> std::ostream& operator<<(std::ostream& o, const std::map<K, T>& x) { - return o << test::many<std::pair<K, T> >(x); -} - -template <class U, class V> std::ostream& operator<<(std::ostream& o, const std::pair<U, V>& p) { - return o << "( " << p.first << " , " << p.second << " )"; -} - -#if PN_CPP_HAS_CPP11 -template <class K, class T> std::ostream& operator<<(std::ostream& o, const std::unordered_map<K, T>& x) { - return o << test::many<std::pair<const K, T> >(x); -} - -template <class T> std::ostream& operator<<(std::ostream& o, const std::forward_list<T>& s) { - return o << test::many<T>(s); -} -#endif -} - -#endif // TEST_BITS_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/test_dummy_container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/test_dummy_container.hpp b/proton-c/bindings/cpp/src/include/test_dummy_container.hpp deleted file mode 100644 index 4af432a..0000000 --- a/proton-c/bindings/cpp/src/include/test_dummy_container.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef TEST_DUMMY_CONTAINER_HPP -#define TEST_DUMMY_CONTAINER_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/container.hpp" -#include "proton/event_loop.hpp" -#include "proton/thread_safe.hpp" - -namespace test { - -using namespace proton; - - -class dummy_container : public standard_container { - public: - dummy_container(const std::string cid="") : - id_(cid), fail("not implemented for dummy_container") {} - - // Pull in base class functions here so that name search finds all the overloads - using standard_container::stop; - using standard_container::connect; - using standard_container::listen; - using standard_container::open_receiver; - using standard_container::open_sender; - - returned<connection> connect(const std::string&, const connection_options&) { throw fail; } - listener listen(const std::string& , listen_handler& ) { throw fail; } - void stop_listening(const std::string&) { throw fail; } - void run() { throw fail; } - void auto_stop(bool) { throw fail; } - void stop(const proton::error_condition& ) { throw fail; } - returned<sender> open_sender(const std::string &, const proton::sender_options &, const connection_options&) { throw fail; } - returned<receiver> open_receiver( const std::string &, const proton::receiver_options &, const connection_options &) { throw fail; } - std::string id() const { return id_; } - void client_connection_options(const connection_options &o) { ccopts_ = o; } - connection_options client_connection_options() const { return ccopts_; } - void server_connection_options(const connection_options &o) { scopts_ = o; } - connection_options server_connection_options() const { return scopts_; } - void sender_options(const class sender_options &o) { sopts_ = o; } - class sender_options sender_options() const { return sopts_; } - void receiver_options(const class receiver_options &o) { ropts_ = o; } - class receiver_options receiver_options() const { return ropts_; } -#if PN_CPP_HAS_STD_FUNCTION - void schedule(duration, std::function<void()>) { throw fail; } -#endif - void schedule(duration, void_function0&) { throw fail; } - - private: - std::string id_; - connection_options ccopts_, scopts_; - class sender_options sopts_; - class receiver_options ropts_; - std::runtime_error fail; -}; - -class dummy_event_loop : public event_loop { -#if PN_CPP_HAS_CPP11 - bool inject(std::function<void()> f) PN_CPP_OVERRIDE { f(); return true; } -#endif - bool inject(proton::void_function0& h) PN_CPP_OVERRIDE { h(); return true; } -}; - -} - -#endif // TEST_DUMMY_CONTAINER_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/include/types_internal.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/include/types_internal.hpp b/proton-c/bindings/cpp/src/include/types_internal.hpp deleted file mode 100644 index bff93a0..0000000 --- a/proton-c/bindings/cpp/src/include/types_internal.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef TYPES_INTERNAL_HPP -#define TYPES_INTERNAL_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/internal/type_traits.hpp" -#include "proton/error.hpp" -#include "proton/binary.hpp" -#include <sstream> - -///@file -/// Inline helpers for encode/decode/type conversion/ostream operators. - -namespace proton { - -/// Byte copy between two objects, only enabled if their sizes are equal. -template <class T, class U> -typename internal::enable_if<sizeof(T) == sizeof(U)>::type byte_copy(T &to, const U &from) { - const char *p = reinterpret_cast<const char*>(&from); - std::copy(p, p + sizeof(T), reinterpret_cast<char*>(&to)); -} - -inline conversion_error -make_conversion_error(type_id want, type_id got, const std::string& msg=std::string()) { - std::ostringstream s; - s << "unexpected type, want: " << want << " got: " << got; - if (!msg.empty()) s << ": " << msg; - return conversion_error(s.str()); -} - -/// Convert std::string to pn_bytes_t -inline pn_bytes_t pn_bytes(const std::string& s) { - pn_bytes_t b = { s.size(), s.empty() ? 0 : const_cast<char*>(&s[0]) }; - return b; -} - -inline pn_bytes_t pn_bytes(const binary& s) { - pn_bytes_t b = { s.size(), s.empty() ? 0 : reinterpret_cast<const char*>(&s[0]) }; - return b; -} - -inline std::string str(const pn_bytes_t& b) { return std::string(b.start, b.size); } -inline binary bin(const pn_bytes_t& b) { return binary(b.start, b.start+b.size); } - -// Save all stream format state, restore in destructor. -struct ios_guard { - std::ios &guarded; - std::ios old; - ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); } - ~ios_guard() { guarded.copyfmt(old); } -}; - -// Convert a char (signed or unsigned) into an unsigned 1 byte integer that will ostream -// as a numeric byte value, not a character and will not get sign-extended. -inline unsigned int printable_byte(uint8_t byte) { return byte; } - -} -#endif // TYPES_INTERNAL_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/interop_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/interop_test.cpp b/proton-c/bindings/cpp/src/interop_test.cpp deleted file mode 100644 index de6ae63..0000000 --- a/proton-c/bindings/cpp/src/interop_test.cpp +++ /dev/null @@ -1,115 +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/codec/decoder.hpp" -#include "proton/codec/encoder.hpp" -#include "proton/error.hpp" -#include "proton/value.hpp" -#include "test_bits.hpp" -#include <string> -#include <sstream> -#include <fstream> -#include <streambuf> -#include <iosfwd> - -namespace { - -using namespace std; -using namespace proton; - -using proton::codec::encoder; -using proton::codec::decoder; - -using proton::internal::data; - -using test::str; - -std::string tests_dir; - -string read(string filename) { - filename = tests_dir+string("/interop/")+filename+string(".amqp"); - ifstream ifs(filename.c_str()); - if (!ifs.good()) FAIL("Can't open " << filename); - return string(istreambuf_iterator<char>(ifs), istreambuf_iterator<char>()); -} - -// Test data ostream operator -void test_data_ostream() { - data dt(data::create()); - decoder d(dt); - d.decode(read("primitives")); - ASSERT_EQUAL("true, false, 42, 42, -42, 12345, -12345, 12345, -12345, 0.125, 0.125", str(dt)); -} - -// Test extracting to exact AMQP types works corectly, extrating to invalid types fails. -void test_decoder_primitves_exact() { - value dv; - decoder d(dv); - d.decode(read("primitives")); - ASSERT(d.more()); - try { get< ::int8_t>(d); FAIL("got bool as byte"); } catch(conversion_error){} - ASSERT_EQUAL(true, get<bool>(d)); - ASSERT_EQUAL(false, get<bool>(d)); - try { get< ::int8_t>(d); FAIL("got ubyte as byte"); } catch(conversion_error){} - ASSERT_EQUAL(42, get< ::uint8_t>(d)); - try { get< ::int32_t>(d); FAIL("got uint as ushort"); } catch(conversion_error){} - ASSERT_EQUAL(42, get< ::uint16_t>(d)); - try { get< ::uint16_t>(d); FAIL("got short as ushort"); } catch(conversion_error){} - ASSERT_EQUAL(-42, get< ::int16_t>(d)); - ASSERT_EQUAL(12345u, get< ::uint32_t>(d)); - ASSERT_EQUAL(-12345, get< ::int32_t>(d)); - ASSERT_EQUAL(12345u, get< ::uint64_t>(d)); - ASSERT_EQUAL(-12345, get< ::int64_t>(d)); - try { get<double>(d); FAIL("got float as double"); } catch(conversion_error){} - ASSERT_EQUAL(0.125f, get<float>(d)); - try { get<float>(d); FAIL("got double as float"); } catch(conversion_error){} - ASSERT_EQUAL(0.125, get<double>(d)); - ASSERT(!d.more()); -} - -// Test inserting primitive sand encoding as AMQP. -void test_encoder_primitives() { - value dv; - encoder e(dv); - e << true << false; - e << ::uint8_t(42); - e << ::uint16_t(42) << ::int16_t(-42); - e << ::uint32_t(12345) << ::int32_t(-12345); - e << ::uint64_t(12345) << ::int64_t(-12345); - e << float(0.125) << double(0.125); - ASSERT_EQUAL("true, false, 42, 42, -42, 12345, -12345, 12345, -12345, 0.125, 0.125", str(e)); - std::string data = e.encode(); - ASSERT_EQUAL(read("primitives"), data); -} - -} - -int main(int argc, char** argv) { - int failed = 0; - if (argc != 2) { - cerr << "Usage: " << argv[0] << " tests-dir" << endl; - return 1; - } - tests_dir = argv[1]; - - RUN_TEST(failed, test_data_ostream()); - RUN_TEST(failed, test_decoder_primitves_exact()); - RUN_TEST(failed, test_encoder_primitives()); - return failed; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/io/connection_driver.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/io/connection_driver.cpp b/proton-c/bindings/cpp/src/io/connection_driver.cpp deleted file mode 100644 index 148a00b..0000000 --- a/proton-c/bindings/cpp/src/io/connection_driver.cpp +++ /dev/null @@ -1,167 +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/io/connection_driver.hpp" - -#include "proton/event_loop.hpp" -#include "proton/error.hpp" -#include "proton/messaging_handler.hpp" -#include "proton/uuid.hpp" - -#include "contexts.hpp" -#include "messaging_adapter.hpp" -#include "msg.hpp" -#include "proton_bits.hpp" -#include "proton_event.hpp" - -#include <proton/connection.h> -#include <proton/transport.h> -#include <proton/event.h> - -#include <algorithm> - - -namespace proton { -namespace io { - -void connection_driver::init() { - if (pn_connection_driver_init(&driver_, pn_connection(), pn_transport()) != 0) { - this->~connection_driver(); // Dtor won't be called on throw from ctor. - throw proton::error(std::string("connection_driver allocation failed")); - } -} - -connection_driver::connection_driver() : handler_(0), container_(0) { init(); } - -connection_driver::connection_driver(class container& cont) : handler_(0), container_(&cont) { - init(); - connection_context& ctx = connection_context::get(connection()); - ctx.container = container_; -} - -#if PN_CPP_HAS_RVALUE_REFERENCES -connection_driver::connection_driver(class container& cont, event_loop&& loop) : handler_(0), container_(&cont) { - init(); - connection_context& ctx = connection_context::get(connection()); - ctx.container = container_; - ctx.event_loop_ = loop.impl_.get(); -} -#endif - -connection_driver::~connection_driver() { - pn_connection_driver_destroy(&driver_); -} - -// FIXME aconway 2016-11-16: rename _engine > _driver -void connection_driver::configure(const connection_options& opts, bool server) { - proton::connection c(connection()); - opts.apply_unbound(c); - if (server) pn_transport_set_server(driver_.transport); - pn_connection_driver_bind(&driver_); - opts.apply_bound(c); - handler_ = opts.handler(); -} - -void connection_driver::connect(const connection_options& opts) { - connection_options all; - if (container_) { - all.container_id(container_->id()); - all.update(container_->client_connection_options()); - } - all.update(opts); - configure(all, false); - connection().open(); -} - -void connection_driver::accept(const connection_options& opts) { - connection_options all; - if (container_) { - all.container_id(container_->id()); - all.update(container_->server_connection_options()); - } - all.update(opts); - configure(all, true); -} - -bool connection_driver::dispatch() { - pn_event_t* c_event; - while ((c_event = pn_connection_driver_next_event(&driver_)) != NULL) { - proton_event cpp_event(c_event, container_); - try { - if (handler_ != 0) { - messaging_adapter adapter(*handler_); - cpp_event.dispatch(adapter); - } - } catch (const std::exception& e) { - pn_condition_t *cond = pn_transport_condition(driver_.transport); - if (!pn_condition_is_set(cond)) { - pn_condition_format(cond, "exception", "%s", e.what()); - } - } - } - return !pn_connection_driver_finished(&driver_); -} - -mutable_buffer connection_driver::read_buffer() { - pn_rwbytes_t buffer = pn_connection_driver_read_buffer(&driver_); - return mutable_buffer(buffer.start, buffer.size); -} - -void connection_driver::read_done(size_t n) { - return pn_connection_driver_read_done(&driver_, n); -} - -void connection_driver::read_close() { - pn_connection_driver_read_close(&driver_); -} - -const_buffer connection_driver::write_buffer() { - pn_bytes_t buffer = pn_connection_driver_write_buffer(&driver_); - return const_buffer(buffer.start, buffer.size); -} - -void connection_driver::write_done(size_t n) { - return pn_connection_driver_write_done(&driver_, n); -} - -void connection_driver::write_close() { - pn_connection_driver_write_close(&driver_); -} - -void connection_driver::disconnected(const proton::error_condition& err) { - pn_condition_t* condition = pn_transport_condition(driver_.transport); - if (!pn_condition_is_set(condition)) { - set_error_condition(err, condition); - } - pn_connection_driver_close(&driver_); -} - -proton::connection connection_driver::connection() const { - return make_wrapper(driver_.connection); -} - -proton::transport connection_driver::transport() const { - return make_wrapper(driver_.transport); -} - -proton::container* connection_driver::container() const { - return container_; -} - -}} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/bindings/cpp/src/io/link_namer.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/io/link_namer.cpp b/proton-c/bindings/cpp/src/io/link_namer.cpp deleted file mode 100644 index 307c423..0000000 --- a/proton-c/bindings/cpp/src/io/link_namer.cpp +++ /dev/null @@ -1,30 +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/io/link_namer.hpp" -#include "contexts.hpp" - -namespace proton { -namespace io { - -void set_link_namer(connection& c, link_namer& l) { - connection_context::get(c).link_gen = &l; -} - -}} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org