http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Delivery.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Delivery.cpp b/proton-c/bindings/cpp/src/Delivery.cpp deleted file mode 100644 index 60cd0d3..0000000 --- a/proton-c/bindings/cpp/src/Delivery.cpp +++ /dev/null @@ -1,58 +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/delivery.h" -#include "ProtonImplRef.hpp" - -namespace proton { -namespace reactor { - -template class ProtonHandle<pn_delivery_t>; -typedef ProtonImplRef<Delivery> PI; - -Delivery::Delivery(pn_delivery_t *p) { - PI::ctor(*this, p); -} -Delivery::Delivery() { - PI::ctor(*this, 0); -} -Delivery::Delivery(const Delivery& c) : ProtonHandle<pn_delivery_t>() { - PI::copy(*this, c); -} -Delivery& Delivery::operator=(const Delivery& c) { - return PI::assign(*this, c); -} -Delivery::~Delivery() { - PI::dtor(*this); -} - -bool Delivery::settled() { - return pn_delivery_settled(impl); -} - -void Delivery::settle() { - pn_delivery_settle(impl); -} - -pn_delivery_t *Delivery::getPnDelivery() { return impl; } - -}} // namespace proton::reactor
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Duration.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Duration.cpp b/proton-c/bindings/cpp/src/Duration.cpp deleted file mode 100644 index b14be50..0000000 --- a/proton-c/bindings/cpp/src/Duration.cpp +++ /dev/null @@ -1,31 +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/Duration.hpp" -#include <limits> - -namespace proton { - -const Duration Duration::FOREVER(std::numeric_limits<std::uint64_t>::max()); -const Duration Duration::IMMEDIATE(0); -const Duration Duration::SECOND(1000); -const Duration Duration::MINUTE(SECOND * 60); - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Encoder.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Encoder.cpp b/proton-c/bindings/cpp/src/Encoder.cpp deleted file mode 100644 index 551a21a..0000000 --- a/proton-c/bindings/cpp/src/Encoder.cpp +++ /dev/null @@ -1,160 +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/Encoder.hpp" -#include "proton/Value.hpp" -#include <proton/codec.h> -#include "proton_bits.hpp" -#include "Msg.hpp" - -namespace proton { - -Encoder::Encoder() {} -Encoder::~Encoder() {} - -static const std::string prefix("encode: "); -EncodeError::EncodeError(const std::string& msg) throw() : Error(prefix+msg) {} - -namespace { -struct SaveState { - pn_data_t* data; - pn_handle_t handle; - SaveState(pn_data_t* d) : data(d), handle(pn_data_point(d)) {} - ~SaveState() { if (data) pn_data_restore(data, handle); } - void cancel() { data = 0; } -}; - -void check(int result, pn_data_t* data) { - if (result < 0) - throw EncodeError(errorStr(pn_data_error(data), result)); -} -} - -bool Encoder::encode(char* buffer, size_t& size) { - SaveState ss(data); // In case of error - ssize_t result = pn_data_encode(data, buffer, size); - if (result == PN_OVERFLOW) { - result = pn_data_encoded_size(data); - if (result >= 0) { - size = result; - return false; - } - } - check(result, data); - size = result; - ss.cancel(); // Don't restore state, all is well. - pn_data_clear(data); - return true; -} - -void Encoder::encode(std::string& s) { - size_t size = s.size(); - if (!encode(&s[0], size)) { - s.resize(size); - encode(&s[0], size); - } -} - -std::string Encoder::encode() { - std::string s; - encode(s); - return s; -} - -Encoder& operator<<(Encoder& e, const Start& s) { - switch (s.type) { - case ARRAY: pn_data_put_array(e.data, s.isDescribed, pn_type_t(s.element)); break; - case MAP: pn_data_put_map(e.data); break; - case LIST: pn_data_put_list(e.data); break; - case DESCRIBED: pn_data_put_described(e.data); break; - default: - throw EncodeError(MSG("" << s.type << " is not a container type")); - } - pn_data_enter(e.data); - return e; -} - -Encoder& operator<<(Encoder& e, Finish) { - pn_data_exit(e.data); - return e; -} - -namespace { -template <class T, class U> -Encoder& insert(Encoder& e, pn_data_t* data, T& value, int (*put)(pn_data_t*, U)) { - SaveState ss(data); // Save state in case of error. - check(put(data, value), data); - ss.cancel(); // Don't restore state, all is good. - return e; -} -} - -Encoder& operator<<(Encoder& e, Null) { pn_data_put_null(e.data); return e; } -Encoder& operator<<(Encoder& e, Bool value) { return insert(e, e.data, value, pn_data_put_bool); } -Encoder& operator<<(Encoder& e, Ubyte value) { return insert(e, e.data, value, pn_data_put_ubyte); } -Encoder& operator<<(Encoder& e, Byte value) { return insert(e, e.data, value, pn_data_put_byte); } -Encoder& operator<<(Encoder& e, Ushort value) { return insert(e, e.data, value, pn_data_put_ushort); } -Encoder& operator<<(Encoder& e, Short value) { return insert(e, e.data, value, pn_data_put_short); } -Encoder& operator<<(Encoder& e, Uint value) { return insert(e, e.data, value, pn_data_put_uint); } -Encoder& operator<<(Encoder& e, Int value) { return insert(e, e.data, value, pn_data_put_int); } -Encoder& operator<<(Encoder& e, Char value) { return insert(e, e.data, value, pn_data_put_char); } -Encoder& operator<<(Encoder& e, Ulong value) { return insert(e, e.data, value, pn_data_put_ulong); } -Encoder& operator<<(Encoder& e, Long value) { return insert(e, e.data, value, pn_data_put_long); } -Encoder& operator<<(Encoder& e, Timestamp value) { return insert(e, e.data, value, pn_data_put_timestamp); } -Encoder& operator<<(Encoder& e, Float value) { return insert(e, e.data, value, pn_data_put_float); } -Encoder& operator<<(Encoder& e, Double value) { return insert(e, e.data, value, pn_data_put_double); } -Encoder& operator<<(Encoder& e, Decimal32 value) { return insert(e, e.data, value, pn_data_put_decimal32); } -Encoder& operator<<(Encoder& e, Decimal64 value) { return insert(e, e.data, value, pn_data_put_decimal64); } -Encoder& operator<<(Encoder& e, Decimal128 value) { return insert(e, e.data, value, pn_data_put_decimal128); } -Encoder& operator<<(Encoder& e, Uuid value) { return insert(e, e.data, value, pn_data_put_uuid); } -Encoder& operator<<(Encoder& e, String value) { return insert(e, e.data, value, pn_data_put_string); } -Encoder& operator<<(Encoder& e, Symbol value) { return insert(e, e.data, value, pn_data_put_symbol); } -Encoder& operator<<(Encoder& e, Binary value) { return insert(e, e.data, value, pn_data_put_binary); } - -// Meta-function to get the class from the type ID. -template <TypeId A> struct ClassOf {}; -template<> struct ClassOf<NULL_> { typedef Null ValueType; }; -template<> struct ClassOf<BOOL> { typedef Bool ValueType; }; -template<> struct ClassOf<UBYTE> { typedef Ubyte ValueType; }; -template<> struct ClassOf<BYTE> { typedef Byte ValueType; }; -template<> struct ClassOf<USHORT> { typedef Ushort ValueType; }; -template<> struct ClassOf<SHORT> { typedef Short ValueType; }; -template<> struct ClassOf<UINT> { typedef Uint ValueType; }; -template<> struct ClassOf<INT> { typedef Int ValueType; }; -template<> struct ClassOf<CHAR> { typedef Char ValueType; }; -template<> struct ClassOf<ULONG> { typedef Ulong ValueType; }; -template<> struct ClassOf<LONG> { typedef Long ValueType; }; -template<> struct ClassOf<TIMESTAMP> { typedef Timestamp ValueType; }; -template<> struct ClassOf<FLOAT> { typedef Float ValueType; }; -template<> struct ClassOf<DOUBLE> { typedef Double ValueType; }; -template<> struct ClassOf<DECIMAL32> { typedef Decimal32 ValueType; }; -template<> struct ClassOf<DECIMAL64> { typedef Decimal64 ValueType; }; -template<> struct ClassOf<DECIMAL128> { typedef Decimal128 ValueType; }; -template<> struct ClassOf<UUID> { typedef Uuid ValueType; }; -template<> struct ClassOf<BINARY> { typedef Binary ValueType; }; -template<> struct ClassOf<STRING> { typedef String ValueType; }; -template<> struct ClassOf<SYMBOL> { typedef Symbol ValueType; }; - -Encoder& operator<<(Encoder& e, const Value& v) { - if (e.data == v.values.data) throw EncodeError("cannot insert into self"); - check(pn_data_appendn(e.data, v.values.data, 1), e.data); - return e; -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Endpoint.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Endpoint.cpp b/proton-c/bindings/cpp/src/Endpoint.cpp deleted file mode 100644 index ad96e0a..0000000 --- a/proton-c/bindings/cpp/src/Endpoint.cpp +++ /dev/null @@ -1,37 +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/Endpoint.hpp" -#include "proton/Connection.hpp" -#include "proton/Transport.hpp" - -namespace proton { -namespace reactor { - -Endpoint::Endpoint() {} - -Endpoint::~Endpoint() {} - -Transport &Endpoint::getTransport() { - return getConnection().getTransport(); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Error.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Error.cpp b/proton-c/bindings/cpp/src/Error.cpp deleted file mode 100644 index 4fd7f43..0000000 --- a/proton-c/bindings/cpp/src/Error.cpp +++ /dev/null @@ -1,32 +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" - -namespace proton { - -static const std::string prefix("proton: "); - -Error::Error(const std::string& msg) throw() : std::runtime_error(prefix+msg) {} - -MessageReject::MessageReject(const std::string& msg) throw() : Error(msg) {} - -MessageRelease::MessageRelease(const std::string& msg) throw() : Error(msg) {} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Event.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Event.cpp b/proton-c/bindings/cpp/src/Event.cpp deleted file mode 100644 index 69825a8..0000000 --- a/proton-c/bindings/cpp/src/Event.cpp +++ /dev/null @@ -1,71 +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/reactor.h" -#include "proton/event.h" - -#include "proton/Event.hpp" -#include "proton/Handler.hpp" -#include "proton/Error.hpp" - -#include "Msg.hpp" -#include "contexts.hpp" - -namespace proton { -namespace reactor { - -Event::Event() {} - -Event::~Event() {} - - -Container &Event::getContainer() { - // Subclasses to override as appropriate - throw Error(MSG("No container context for event")); -} - -Connection &Event::getConnection() { - throw Error(MSG("No connection context for Event")); -} - -Sender Event::getSender() { - throw Error(MSG("No Sender context for event")); -} - -Receiver Event::getReceiver() { - throw Error(MSG("No Receiver context for event")); -} - -Link Event::getLink() { - throw Error(MSG("No Link context for event")); -} - -Message Event::getMessage() { - throw Error(MSG("No message associated with event")); -} - -void Event::setMessage(Message &) { - throw Error(MSG("Operation not supported for this type of event")); -} - - - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/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 235bff7..0000000 --- a/proton-c/bindings/cpp/src/Handler.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/Handler.hpp" -#include "proton/Event.hpp" - -namespace proton { -namespace reactor { - -Handler::Handler() {} -Handler::~Handler() {} - -void Handler::onUnhandled(Event &e) {} - -void Handler::addChildHandler(Handler &e) { - childHandlers.push_back(&e); -} - -std::vector<Handler *>::iterator Handler::childHandlersBegin() { - return childHandlers.begin(); -} - -std::vector<Handler *>::iterator Handler::childHandlersEnd() { - return childHandlers.end(); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Link.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Link.cpp b/proton-c/bindings/cpp/src/Link.cpp deleted file mode 100644 index 76c100c..0000000 --- a/proton-c/bindings/cpp/src/Link.cpp +++ /dev/null @@ -1,114 +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/Link.hpp" -#include "proton/Error.hpp" -#include "proton/Connection.hpp" -#include "ConnectionImpl.hpp" -#include "Msg.hpp" -#include "contexts.hpp" -#include "ProtonImplRef.hpp" - -#include "proton/connection.h" -#include "proton/session.h" -#include "proton/link.h" - -namespace proton { -namespace reactor { - -template class ProtonHandle<pn_link_t>; -typedef ProtonImplRef<Link> PI; - -Link::Link(pn_link_t* p) { - verifyType(p); - PI::ctor(*this, p); - if (p) senderLink = pn_link_is_sender(p); -} -Link::Link() { - PI::ctor(*this, 0); -} -Link::Link(const Link& c) : ProtonHandle<pn_link_t>() { - verifyType(impl); - PI::copy(*this, c); - senderLink = c.senderLink; -} -Link& Link::operator=(const Link& c) { - verifyType(impl); - senderLink = c.senderLink; - return PI::assign(*this, c); -} -Link::~Link() { PI::dtor(*this); } - -void Link::verifyType(pn_link_t *l) {} // Generic link can be sender or receiver - -pn_link_t *Link::getPnLink() const { return impl; } - -void Link::open() { - pn_link_open(impl); -} - -void Link::close() { - pn_link_close(impl); -} - -bool Link::isSender() { - return impl && senderLink; -} - -bool Link::isReceiver() { - return impl && !senderLink; -} - -int Link::getCredit() { - return pn_link_credit(impl); -} - -Terminus Link::getSource() { - return Terminus(pn_link_source(impl), this); -} - -Terminus Link::getTarget() { - return Terminus(pn_link_target(impl), this); -} - -Terminus Link::getRemoteSource() { - return Terminus(pn_link_remote_source(impl), this); -} - -Terminus Link::getRemoteTarget() { - return Terminus(pn_link_remote_target(impl), this); -} - -std::string Link::getName() { - return std::string(pn_link_name(impl)); -} - -Connection &Link::getConnection() { - pn_session_t *s = pn_link_session(impl); - pn_connection_t *c = pn_session_connection(s); - return ConnectionImpl::getReactorReference(c); -} - -Link Link::getNext(Endpoint::State mask) { - - return Link(pn_link_next(impl, (pn_state_t) mask)); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Message.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Message.cpp b/proton-c/bindings/cpp/src/Message.cpp deleted file mode 100644 index 540ba15..0000000 --- a/proton-c/bindings/cpp/src/Message.cpp +++ /dev/null @@ -1,253 +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/Message.hpp" -#include "proton/Error.hpp" -#include "proton/message.h" -#include "Msg.hpp" -#include "proton_bits.hpp" -#include "ProtonImplRef.hpp" - -#include <cstring> - -namespace proton { - -namespace reactor { -template class ProtonHandle<pn_message_t>; -} -typedef reactor::ProtonImplRef<Message> PI; - -Message::Message() : body_(0) { - PI::ctor(*this, 0); -} -Message::Message(pn_message_t *p) : body_(0) { - PI::ctor(*this, p); -} -Message::Message(const Message& m) : ProtonHandle<pn_message_t>(), body_(0) { - PI::copy(*this, m); -} - -// FIXME aconway 2015-06-17: Message should be a value type, needs to own pn_message_t -// and do appropriate _copy and _free operations. -Message& Message::operator=(const Message& m) { - return PI::assign(*this, m); -} -Message::~Message() { PI::dtor(*this); } - -namespace { -void confirm(pn_message_t * const& p) { - if (p) return; - const_cast<pn_message_t*&>(p) = pn_message(); // Correct refcount of 1 - if (!p) - throw Error(MSG("No memory")); -} - -void check(int err) { - if (err) throw Error(errorStr(err)); -} - -void setValue(pn_data_t* d, const Value& v) { - Values values(d); - values.clear(); - values << v; -} - -Value getValue(pn_data_t* d) { - Values values(d); - values.rewind(); - return values.get<Value>(); -} -} // namespace - -void Message::id(const Value& id) { - confirm(impl); - setValue(pn_message_id(impl), id); -} - -Value Message::id() const { - confirm(impl); - return getValue(pn_message_id(impl)); -} -void Message::user(const std::string &id) { - confirm(impl); - check(pn_message_set_user_id(impl, pn_bytes(id))); -} - -std::string Message::user() const { - confirm(impl); - return str(pn_message_get_user_id(impl)); -} - -void Message::address(const std::string &addr) { - confirm(impl); - check(pn_message_set_address(impl, addr.c_str())); -} - -std::string Message::address() const { - confirm(impl); - const char* addr = pn_message_get_address(impl); - return addr ? std::string(addr) : std::string(); -} - -void Message::subject(const std::string &s) { - confirm(impl); - check(pn_message_set_subject(impl, s.c_str())); -} - -std::string Message::subject() const { - confirm(impl); - const char* s = pn_message_get_subject(impl); - return s ? std::string(s) : std::string(); -} - -void Message::replyTo(const std::string &s) { - confirm(impl); - check(pn_message_set_reply_to(impl, s.c_str())); -} - -std::string Message::replyTo() const { - confirm(impl); - const char* s = pn_message_get_reply_to(impl); - return s ? std::string(s) : std::string(); -} - -void Message::correlationId(const Value& id) { - confirm(impl); - setValue(pn_message_correlation_id(impl), id); -} - -Value Message::correlationId() const { - confirm(impl); - return getValue(pn_message_correlation_id(impl)); -} - -void Message::contentType(const std::string &s) { - confirm(impl); - check(pn_message_set_content_type(impl, s.c_str())); -} - -std::string Message::contentType() const { - confirm(impl); - const char* s = pn_message_get_content_type(impl); - return s ? std::string(s) : std::string(); -} - -void Message::contentEncoding(const std::string &s) { - confirm(impl); - check(pn_message_set_content_encoding(impl, s.c_str())); -} - -std::string Message::contentEncoding() const { - confirm(impl); - const char* s = pn_message_get_content_encoding(impl); - return s ? std::string(s) : std::string(); -} - -void Message::expiry(Timestamp t) { - confirm(impl); - pn_message_set_expiry_time(impl, t.milliseconds); -} -Timestamp Message::expiry() const { - confirm(impl); - return Timestamp(pn_message_get_expiry_time(impl)); -} - -void Message::creationTime(Timestamp t) { - confirm(impl); - pn_message_set_creation_time(impl, t); -} -Timestamp Message::creationTime() const { - confirm(impl); - return pn_message_get_creation_time(impl); -} - -void Message::groupId(const std::string &s) { - confirm(impl); - check(pn_message_set_group_id(impl, s.c_str())); -} - -std::string Message::groupId() const { - confirm(impl); - const char* s = pn_message_get_group_id(impl); - return s ? std::string(s) : std::string(); -} - -void Message::replyToGroupId(const std::string &s) { - confirm(impl); - check(pn_message_set_reply_to_group_id(impl, s.c_str())); -} - -std::string Message::replyToGroupId() const { - confirm(impl); - const char* s = pn_message_get_reply_to_group_id(impl); - return s ? std::string(s) : std::string(); -} - -void Message::body(const Value& v) { - confirm(impl); - setValue(pn_message_body(impl), v); -} - -void Message::body(const Values& v) { - confirm(impl); - pn_data_copy(pn_message_body(impl), v.data); -} - -const Values& Message::body() const { - confirm(impl); - body_.view(pn_message_body(impl)); - return body_; -} - -Values& Message::body() { - confirm(impl); - body_.view(pn_message_body(impl)); - return body_; -} - -void Message::encode(std::string &s) { - confirm(impl); - size_t sz = s.capacity(); - if (sz < 512) sz = 512; - while (true) { - s.resize(sz); - int err = pn_message_encode(impl, (char *) s.data(), &sz); - if (err) { - if (err != PN_OVERFLOW) - check(err); - } else { - s.resize(sz); - return; - } - sz *= 2; - } -} - -void Message::decode(const std::string &s) { - confirm(impl); - check(pn_message_decode(impl, s.data(), s.size())); -} - -pn_message_t *Message::pnMessage() const { - return impl; -} - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/MessagingAdapter.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/MessagingAdapter.cpp b/proton-c/bindings/cpp/src/MessagingAdapter.cpp deleted file mode 100644 index 90ad510..0000000 --- a/proton-c/bindings/cpp/src/MessagingAdapter.cpp +++ /dev/null @@ -1,412 +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/MessagingAdapter.hpp" -#include "proton/MessagingEvent.hpp" -#include "proton/Sender.hpp" -#include "proton/Error.hpp" -#include "Msg.hpp" - -#include "proton/link.h" -#include "proton/handlers.h" -#include "proton/delivery.h" -#include "proton/connection.h" -#include "proton/session.h" - -namespace proton { -namespace reactor { -MessagingAdapter::MessagingAdapter(MessagingHandler &delegate_) : - MessagingHandler(true, delegate_.prefetch, delegate_.autoSettle, delegate_.autoAccept, delegate_.peerCloseIsError), - delegate(delegate_) -{} - - -MessagingAdapter::~MessagingAdapter(){} - - -void MessagingAdapter::onReactorInit(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - MessagingEvent mevent(PN_MESSAGING_START, *pe); - delegate.onStart(mevent); - } -} - -void MessagingAdapter::onLinkFlow(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_event_t *pne = pe->getPnEvent(); - pn_link_t *lnk = pn_event_link(pne); - if (lnk && pn_link_is_sender(lnk) && pn_link_credit(lnk) > 0) { - // create onMessage extended event - MessagingEvent mevent(PN_MESSAGING_SENDABLE, *pe); - delegate.onSendable(mevent);; - } - } -} - -namespace { -Message receiveMessage(pn_link_t *lnk, pn_delivery_t *dlv) { - std::string buf; - size_t sz = pn_delivery_pending(dlv); - buf.resize(sz); - ssize_t n = pn_link_recv(lnk, (char *) buf.data(), sz); - if (n != (ssize_t) sz) - throw Error(MSG("link read failure")); - Message m; - m. decode(buf); - pn_link_advance(lnk); - return m; -} -} // namespace - -void MessagingAdapter::onDelivery(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_event_t *cevent = pe->getPnEvent(); - pn_link_t *lnk = pn_event_link(cevent); - pn_delivery_t *dlv = pn_event_delivery(cevent); - - if (pn_link_is_receiver(lnk)) { - if (!pn_delivery_partial(dlv) && pn_delivery_readable(dlv)) { - // generate onMessage - MessagingEvent mevent(PN_MESSAGING_MESSAGE, *pe); - Message m(receiveMessage(lnk, dlv)); - mevent.setMessage(m); - if (pn_link_state(lnk) & PN_LOCAL_CLOSED) { - if (autoAccept) { - pn_delivery_update(dlv, PN_RELEASED); - pn_delivery_settle(dlv); - } - } - else { - try { - delegate.onMessage(mevent); - if (autoAccept) { - pn_delivery_update(dlv, PN_ACCEPTED); - pn_delivery_settle(dlv); - } - } - catch (MessageReject &) { - pn_delivery_update(dlv, PN_REJECTED); - pn_delivery_settle(dlv); - } - catch (MessageRelease &) { - pn_delivery_update(dlv, PN_REJECTED); - pn_delivery_settle(dlv); - } - } - } - else if (pn_delivery_updated(dlv) && pn_delivery_settled(dlv)) { - MessagingEvent mevent(PN_MESSAGING_SETTLED, *pe); - delegate.onSettled(mevent); - } - } else { - // Sender - if (pn_delivery_updated(dlv)) { - std::uint64_t rstate = pn_delivery_remote_state(dlv); - if (rstate == PN_ACCEPTED) { - MessagingEvent mevent(PN_MESSAGING_ACCEPTED, *pe); - delegate.onAccepted(mevent); - } - else if (rstate == PN_REJECTED) { - MessagingEvent mevent(PN_MESSAGING_REJECTED, *pe); - delegate.onRejected(mevent); - } - else if (rstate == PN_RELEASED || rstate == PN_MODIFIED) { - MessagingEvent mevent(PN_MESSAGING_RELEASED, *pe); - delegate.onReleased(mevent); - } - - if (pn_delivery_settled(dlv)) { - MessagingEvent mevent(PN_MESSAGING_SETTLED, *pe); - delegate.onSettled(mevent); - } - if (autoSettle) - pn_delivery_settle(dlv); - } - } - } -} - -namespace { - -bool isLocalOpen(pn_state_t state) { - return state & PN_LOCAL_ACTIVE; -} - -bool isLocalUnititialised(pn_state_t state) { - return state & PN_LOCAL_UNINIT; -} - -bool isLocalClosed(pn_state_t state) { - return state & PN_LOCAL_CLOSED; -} - -bool isRemoteOpen(pn_state_t state) { - return state & PN_REMOTE_ACTIVE; -} - -} // namespace - -void MessagingAdapter::onLinkRemoteClose(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_event_t *cevent = pe->getPnEvent(); - pn_link_t *lnk = pn_event_link(cevent); - pn_state_t state = pn_link_state(lnk); - if (pn_condition_is_set(pn_link_remote_condition(lnk))) { - MessagingEvent mevent(PN_MESSAGING_LINK_ERROR, *pe); - onLinkError(mevent); - } - else if (isLocalClosed(state)) { - MessagingEvent mevent(PN_MESSAGING_LINK_CLOSED, *pe); - onLinkClosed(mevent); - } - else { - MessagingEvent mevent(PN_MESSAGING_LINK_CLOSING, *pe); - onLinkClosing(mevent); - } - pn_link_close(lnk); - } -} - -void MessagingAdapter::onSessionRemoteClose(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_event_t *cevent = pe->getPnEvent(); - pn_session_t *session = pn_event_session(cevent); - pn_state_t state = pn_session_state(session); - if (pn_condition_is_set(pn_session_remote_condition(session))) { - MessagingEvent mevent(PN_MESSAGING_SESSION_ERROR, *pe); - onSessionError(mevent); - } - else if (isLocalClosed(state)) { - MessagingEvent mevent(PN_MESSAGING_SESSION_CLOSED, *pe); - onSessionClosed(mevent); - } - else { - MessagingEvent mevent(PN_MESSAGING_SESSION_CLOSING, *pe); - onSessionClosing(mevent); - } - pn_session_close(session); - } -} - -void MessagingAdapter::onConnectionRemoteClose(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_event_t *cevent = pe->getPnEvent(); - pn_connection_t *connection = pn_event_connection(cevent); - pn_state_t state = pn_connection_state(connection); - if (pn_condition_is_set(pn_connection_remote_condition(connection))) { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_ERROR, *pe); - onConnectionError(mevent); - } - else if (isLocalClosed(state)) { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_CLOSED, *pe); - onConnectionClosed(mevent); - } - else { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_CLOSING, *pe); - onConnectionClosing(mevent); - } - pn_connection_close(connection); - } -} - -void MessagingAdapter::onConnectionLocalOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_connection_t *connection = pn_event_connection(pe->getPnEvent()); - if (isRemoteOpen(pn_connection_state(connection))) { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_OPENED, *pe); - onConnectionOpened(mevent); - } - } -} - -void MessagingAdapter::onConnectionRemoteOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_connection_t *connection = pn_event_connection(pe->getPnEvent()); - if (isLocalOpen(pn_connection_state(connection))) { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_OPENED, *pe); - onConnectionOpened(mevent); - } - else if (isLocalUnititialised(pn_connection_state(connection))) { - MessagingEvent mevent(PN_MESSAGING_CONNECTION_OPENING, *pe); - onConnectionOpening(mevent); - pn_connection_open(connection); - } - } -} - -void MessagingAdapter::onSessionLocalOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_session_t *session = pn_event_session(pe->getPnEvent()); - if (isRemoteOpen(pn_session_state(session))) { - MessagingEvent mevent(PN_MESSAGING_SESSION_OPENED, *pe); - onSessionOpened(mevent); - } - } -} - -void MessagingAdapter::onSessionRemoteOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_session_t *session = pn_event_session(pe->getPnEvent()); - if (isLocalOpen(pn_session_state(session))) { - MessagingEvent mevent(PN_MESSAGING_SESSION_OPENED, *pe); - onSessionOpened(mevent); - } - else if (isLocalUnititialised(pn_session_state(session))) { - MessagingEvent mevent(PN_MESSAGING_SESSION_OPENING, *pe); - onSessionOpening(mevent); - pn_session_open(session); - } - } -} - -void MessagingAdapter::onLinkLocalOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_link_t *link = pn_event_link(pe->getPnEvent()); - if (isRemoteOpen(pn_link_state(link))) { - MessagingEvent mevent(PN_MESSAGING_LINK_OPENED, *pe); - onLinkOpened(mevent); - } - } -} - -void MessagingAdapter::onLinkRemoteOpen(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_link_t *link = pn_event_link(pe->getPnEvent()); - if (isLocalOpen(pn_link_state(link))) { - MessagingEvent mevent(PN_MESSAGING_LINK_OPENED, *pe); - onLinkOpened(mevent); - } - else if (isLocalUnititialised(pn_link_state(link))) { - MessagingEvent mevent(PN_MESSAGING_LINK_OPENING, *pe); - onLinkOpening(mevent); - pn_link_open(link); - } - } -} - -void MessagingAdapter::onTransportTailClosed(Event &e) { - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_connection_t *conn = pn_event_connection(pe->getPnEvent()); - if (conn && isLocalOpen(pn_connection_state(conn))) { - MessagingEvent mevent(PN_MESSAGING_DISCONNECTED, *pe); - delegate.onDisconnected(mevent); - } - } -} - - -void MessagingAdapter::onConnectionOpened(Event &e) { - delegate.onConnectionOpened(e); -} - -void MessagingAdapter::onSessionOpened(Event &e) { - delegate.onSessionOpened(e); -} - -void MessagingAdapter::onLinkOpened(Event &e) { - delegate.onLinkOpened(e); -} - -void MessagingAdapter::onConnectionOpening(Event &e) { - delegate.onConnectionOpening(e); -} - -void MessagingAdapter::onSessionOpening(Event &e) { - delegate.onSessionOpening(e); -} - -void MessagingAdapter::onLinkOpening(Event &e) { - delegate.onLinkOpening(e); -} - -void MessagingAdapter::onConnectionError(Event &e) { - delegate.onConnectionError(e); - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_connection_t *connection = pn_event_connection(pe->getPnEvent()); - pn_connection_close(connection); - } -} - -void MessagingAdapter::onSessionError(Event &e) { - delegate.onSessionError(e); - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_session_t *session = pn_event_session(pe->getPnEvent()); - pn_session_close(session); - } -} - -void MessagingAdapter::onLinkError(Event &e) { - delegate.onLinkError(e); - ProtonEvent *pe = dynamic_cast<ProtonEvent*>(&e); - if (pe) { - pn_link_t *link = pn_event_link(pe->getPnEvent()); - pn_link_close(link); - } -} - -void MessagingAdapter::onConnectionClosed(Event &e) { - delegate.onConnectionClosed(e); -} - -void MessagingAdapter::onSessionClosed(Event &e) { - delegate.onSessionClosed(e); -} - -void MessagingAdapter::onLinkClosed(Event &e) { - delegate.onLinkClosed(e); -} - -void MessagingAdapter::onConnectionClosing(Event &e) { - delegate.onConnectionClosing(e); - if (peerCloseIsError) - onConnectionError(e); -} - -void MessagingAdapter::onSessionClosing(Event &e) { - delegate.onSessionClosing(e); - if (peerCloseIsError) - onSessionError(e); -} - -void MessagingAdapter::onLinkClosing(Event &e) { - delegate.onLinkClosing(e); - if (peerCloseIsError) - onLinkError(e); -} - -void MessagingAdapter::onUnhandled(Event &e) { -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/MessagingEvent.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/MessagingEvent.cpp b/proton-c/bindings/cpp/src/MessagingEvent.cpp deleted file mode 100644 index 083180a..0000000 --- a/proton-c/bindings/cpp/src/MessagingEvent.cpp +++ /dev/null @@ -1,150 +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/reactor.h" -#include "proton/event.h" -#include "proton/link.h" - -#include "proton/MessagingEvent.hpp" -#include "proton/Message.hpp" -#include "proton/ProtonHandler.hpp" -#include "proton/MessagingHandler.hpp" -#include "proton/Error.hpp" -#include "Msg.hpp" -#include "contexts.hpp" - -namespace proton { -namespace reactor { - -MessagingEvent::MessagingEvent(pn_event_t *ce, pn_event_type_t t, Container &c) : - ProtonEvent(ce, t, c), messagingType(PN_MESSAGING_PROTON), parentEvent(0), message(0) -{} - -MessagingEvent::MessagingEvent(MessagingEventType_t t, ProtonEvent &p) : - ProtonEvent(NULL, PN_EVENT_NONE, p.getContainer()), messagingType(t), parentEvent(&p), message(0) { - if (messagingType == PN_MESSAGING_PROTON) - throw Error(MSG("invalid messaging event type")); -} - -MessagingEvent::~MessagingEvent() { - delete message; -} - -Connection &MessagingEvent::getConnection() { - if (messagingType == PN_MESSAGING_PROTON) - return ProtonEvent::getConnection(); - if (parentEvent) - return parentEvent->getConnection(); - throw Error(MSG("No connection context for event")); -} - -Sender MessagingEvent::getSender() { - if (messagingType == PN_MESSAGING_PROTON) - return ProtonEvent::getSender(); - if (parentEvent) - return parentEvent->getSender(); - throw Error(MSG("No sender context for event")); -} - -Receiver MessagingEvent::getReceiver() { - if (messagingType == PN_MESSAGING_PROTON) - return ProtonEvent::getReceiver(); - if (parentEvent) - return parentEvent->getReceiver(); - throw Error(MSG("No receiver context for event")); -} - -Link MessagingEvent::getLink() { - if (messagingType == PN_MESSAGING_PROTON) - return ProtonEvent::getLink(); - if (parentEvent) - return parentEvent->getLink(); - throw Error(MSG("No link context for event")); -} - -Message MessagingEvent::getMessage() { - if (parentEvent) { - pn_message_t *m = getEventContext(parentEvent->getPnEvent()); - if (m) - return Message(m); - } - throw Error(MSG("No message context for event")); -} - -void MessagingEvent::setMessage(Message &m) { - if (messagingType != PN_MESSAGING_MESSAGE || !parentEvent) - throw Error(MSG("Event type does not provide message")); - setEventContext(parentEvent->getPnEvent(), m.pnMessage()); -} - -void MessagingEvent::dispatch(Handler &h) { - if (messagingType == PN_MESSAGING_PROTON) { - ProtonEvent::dispatch(h); - return; - } - - MessagingHandler *handler = dynamic_cast<MessagingHandler*>(&h); - if (handler) { - switch(messagingType) { - - case PN_MESSAGING_START: handler->onStart(*this); break; - case PN_MESSAGING_SENDABLE: handler->onSendable(*this); break; - case PN_MESSAGING_MESSAGE: handler->onMessage(*this); break; - case PN_MESSAGING_ACCEPTED: handler->onAccepted(*this); break; - case PN_MESSAGING_REJECTED: handler->onRejected(*this); break; - case PN_MESSAGING_RELEASED: handler->onReleased(*this); break; - case PN_MESSAGING_SETTLED: handler->onSettled(*this); break; - - case PN_MESSAGING_CONNECTION_CLOSING: handler->onConnectionClosing(*this); break; - case PN_MESSAGING_CONNECTION_CLOSED: handler->onConnectionClosed(*this); break; - case PN_MESSAGING_CONNECTION_ERROR: handler->onConnectionError(*this); break; - case PN_MESSAGING_CONNECTION_OPENING: handler->onConnectionOpening(*this); break; - case PN_MESSAGING_CONNECTION_OPENED: handler->onConnectionOpened(*this); break; - - case PN_MESSAGING_LINK_CLOSED: handler->onLinkClosed(*this); break; - case PN_MESSAGING_LINK_CLOSING: handler->onLinkClosing(*this); break; - case PN_MESSAGING_LINK_ERROR: handler->onLinkError(*this); break; - case PN_MESSAGING_LINK_OPENING: handler->onLinkOpening(*this); break; - case PN_MESSAGING_LINK_OPENED: handler->onLinkOpened(*this); break; - - case PN_MESSAGING_SESSION_CLOSED: handler->onSessionClosed(*this); break; - case PN_MESSAGING_SESSION_CLOSING: handler->onSessionClosing(*this); break; - case PN_MESSAGING_SESSION_ERROR: handler->onSessionError(*this); break; - case PN_MESSAGING_SESSION_OPENING: handler->onSessionOpening(*this); break; - case PN_MESSAGING_SESSION_OPENED: handler->onSessionOpened(*this); break; - - case PN_MESSAGING_TRANSPORT_CLOSED: handler->onTransportClosed(*this); break; - default: - throw Error(MSG("Unkown messaging event type " << messagingType)); - break; - } - } else { - h.onUnhandled(*this); - } - - // recurse through children - for (std::vector<Handler *>::iterator child = h.childHandlersBegin(); - child != h.childHandlersEnd(); ++child) { - dispatch(**child); - } -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/MessagingHandler.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/MessagingHandler.cpp b/proton-c/bindings/cpp/src/MessagingHandler.cpp deleted file mode 100644 index 9076014..0000000 --- a/proton-c/bindings/cpp/src/MessagingHandler.cpp +++ /dev/null @@ -1,126 +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/MessagingHandler.hpp" -#include "proton/ProtonEvent.hpp" -#include "proton/MessagingAdapter.hpp" -#include "proton/handlers.h" - -namespace proton { -namespace reactor { - -namespace { -class CFlowController : public ProtonHandler -{ - public: - pn_handler_t *flowcontroller; - - CFlowController(int window) : flowcontroller(pn_flowcontroller(window)) {} - ~CFlowController() { - pn_decref(flowcontroller); - } - - void redirect(Event &e) { - ProtonEvent *pne = dynamic_cast<ProtonEvent *>(&e); - pn_handler_dispatch(flowcontroller, pne->getPnEvent(), (pn_event_type_t) pne->getType()); - } - - virtual void onLinkLocalOpen(Event &e) { redirect(e); } - virtual void onLinkRemoteOpen(Event &e) { redirect(e); } - virtual void onLinkFlow(Event &e) { redirect(e); } - virtual void onDelivery(Event &e) { redirect(e); } -}; - -} // namespace - - - - -MessagingHandler::MessagingHandler(int prefetch0, bool autoAccept0, bool autoSettle0, bool peerCloseIsError0) : - prefetch(prefetch0), autoAccept(autoAccept0), autoSettle(autoSettle0), peerCloseIsError(peerCloseIsError0) -{ - createHelpers(); -} - -MessagingHandler::MessagingHandler(bool rawHandler, int prefetch0, bool autoAccept0, bool autoSettle0, - bool peerCloseIsError0) : - prefetch(prefetch0), autoAccept(autoAccept0), autoSettle(autoSettle0), peerCloseIsError(peerCloseIsError0) -{ - if (rawHandler) { - flowController = 0; - messagingAdapter = 0; - } else { - createHelpers(); - } -} - -void MessagingHandler::createHelpers() { - if (prefetch > 0) { - flowController = new CFlowController(prefetch); - addChildHandler(*flowController); - } - messagingAdapter = new MessagingAdapter(*this); - addChildHandler(*messagingAdapter); -} - -MessagingHandler::~MessagingHandler(){ - delete flowController; - delete messagingAdapter; -} - -void MessagingHandler::onAbort(Event &e) { onUnhandled(e); } -void MessagingHandler::onAccepted(Event &e) { onUnhandled(e); } -void MessagingHandler::onCommit(Event &e) { onUnhandled(e); } -void MessagingHandler::onConnectionClosed(Event &e) { onUnhandled(e); } -void MessagingHandler::onConnectionClosing(Event &e) { onUnhandled(e); } -void MessagingHandler::onConnectionError(Event &e) { onUnhandled(e); } -void MessagingHandler::onConnectionOpened(Event &e) { onUnhandled(e); } -void MessagingHandler::onConnectionOpening(Event &e) { onUnhandled(e); } -void MessagingHandler::onDisconnected(Event &e) { onUnhandled(e); } -void MessagingHandler::onFetch(Event &e) { onUnhandled(e); } -void MessagingHandler::onIdLoaded(Event &e) { onUnhandled(e); } -void MessagingHandler::onLinkClosed(Event &e) { onUnhandled(e); } -void MessagingHandler::onLinkClosing(Event &e) { onUnhandled(e); } -void MessagingHandler::onLinkError(Event &e) { onUnhandled(e); } -void MessagingHandler::onLinkOpened(Event &e) { onUnhandled(e); } -void MessagingHandler::onLinkOpening(Event &e) { onUnhandled(e); } -void MessagingHandler::onMessage(Event &e) { onUnhandled(e); } -void MessagingHandler::onQuit(Event &e) { onUnhandled(e); } -void MessagingHandler::onRecordInserted(Event &e) { onUnhandled(e); } -void MessagingHandler::onRecordsLoaded(Event &e) { onUnhandled(e); } -void MessagingHandler::onRejected(Event &e) { onUnhandled(e); } -void MessagingHandler::onReleased(Event &e) { onUnhandled(e); } -void MessagingHandler::onRequest(Event &e) { onUnhandled(e); } -void MessagingHandler::onResponse(Event &e) { onUnhandled(e); } -void MessagingHandler::onSendable(Event &e) { onUnhandled(e); } -void MessagingHandler::onSessionClosed(Event &e) { onUnhandled(e); } -void MessagingHandler::onSessionClosing(Event &e) { onUnhandled(e); } -void MessagingHandler::onSessionError(Event &e) { onUnhandled(e); } -void MessagingHandler::onSessionOpened(Event &e) { onUnhandled(e); } -void MessagingHandler::onSessionOpening(Event &e) { onUnhandled(e); } -void MessagingHandler::onSettled(Event &e) { onUnhandled(e); } -void MessagingHandler::onStart(Event &e) { onUnhandled(e); } -void MessagingHandler::onTimer(Event &e) { onUnhandled(e); } -void MessagingHandler::onTransactionAborted(Event &e) { onUnhandled(e); } -void MessagingHandler::onTransactionCommitted(Event &e) { onUnhandled(e); } -void MessagingHandler::onTransactionDeclared(Event &e) { onUnhandled(e); } -void MessagingHandler::onTransportClosed(Event &e) { onUnhandled(e); } - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Msg.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Msg.hpp b/proton-c/bindings/cpp/src/Msg.hpp deleted file mode 100644 index 2b4c6da..0000000 --- a/proton-c/bindings/cpp/src/Msg.hpp +++ /dev/null @@ -1,59 +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 { -namespace reactor { - -/** A simple wrapper 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::reactor::Msg() << message) - -}} // namespace proton::reactor - -#endif /*!PROTON_MSG_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/PrivateImplRef.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/PrivateImplRef.hpp b/proton-c/bindings/cpp/src/PrivateImplRef.hpp deleted file mode 100644 index 560e740..0000000 --- a/proton-c/bindings/cpp/src/PrivateImplRef.hpp +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef PROTON_CPP_PRIVATEIMPL_H -#define PROTON_CPP_PRIVATEIMPL_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "proton/export.hpp" - -namespace proton { -namespace reactor { - -// Modified from qpid::messaging version to work without -// boost::intrusive_ptr but integrate with Proton's pn_class_t -// reference counting. Thread safety currently absent but fluid in -// intention... - - -/** - * Helper class to implement a class with a private, reference counted - * implementation and reference semantics. - * - * Such classes are used in the public API to hide implementation, they - * should. Example of use: - * - * === Foo.h - * - * template <class T> PrivateImplRef; - * class FooImpl; - * - * Foo : public Handle<FooImpl> { - * public: - * Foo(FooImpl* = 0); - * Foo(const Foo&); - * ~Foo(); - * Foo& operator=(const Foo&); - * - * int fooDo(); // and other Foo functions... - * - * private: - * typedef FooImpl Impl; - * Impl* impl; - * friend class PrivateImplRef<Foo>; - * - * === Foo.cpp - * - * typedef PrivateImplRef<Foo> PI; - * Foo::Foo(FooImpl* p) { PI::ctor(*this, p); } - * Foo::Foo(const Foo& c) : Handle<FooImpl>() { PI::copy(*this, c); } - * Foo::~Foo() { PI::dtor(*this); } - * Foo& Foo::operator=(const Foo& c) { return PI::assign(*this, c); } - * - * int foo::fooDo() { return impl->fooDo(); } - * - */ -template <class T> class PrivateImplRef { - public: - typedef typename T::Impl Impl; - - /** Get the implementation pointer from a handle */ - static Impl* get(const T& t) { return t.impl; } - - /** Set the implementation pointer in a handle */ - static void set(T& t, const Impl* p) { - if (t.impl == p) return; - if (t.impl) Impl::decref(t.impl); - t.impl = const_cast<Impl *>(p); - if (t.impl) Impl::incref(t.impl); - } - - // Helper functions to implement the ctor, dtor, copy, assign - static void ctor(T& t, Impl* p) { t.impl = p; if (p) Impl::incref(p); } - static void copy(T& t, const T& x) { if (&t == &x) return; t.impl = 0; assign(t, x); } - static void dtor(T& t) { if(t.impl) Impl::decref(t.impl); } - static T& assign(T& t, const T& x) { set(t, get(x)); return t;} -}; - -}} // namespace proton::reactor - -#endif /*!PROTON_CPP_PRIVATEIMPL_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/ProtonEvent.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ProtonEvent.cpp b/proton-c/bindings/cpp/src/ProtonEvent.cpp deleted file mode 100644 index 8d32f35..0000000 --- a/proton-c/bindings/cpp/src/ProtonEvent.cpp +++ /dev/null @@ -1,153 +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/reactor.h" -#include "proton/event.h" -#include "proton/link.h" - -#include "proton/ProtonEvent.hpp" -#include "proton/ProtonHandler.hpp" -#include "proton/Error.hpp" -#include "proton/Container.hpp" - -#include "ConnectionImpl.hpp" -#include "Msg.hpp" -#include "contexts.hpp" - -namespace proton { -namespace reactor { - -ProtonEvent::ProtonEvent(pn_event_t *ce, pn_event_type_t t, Container &c) : - pnEvent(ce), - type((int) t), - container(c) -{} - -int ProtonEvent::getType() { return type; } - -pn_event_t *ProtonEvent::getPnEvent() { return pnEvent; } - -Container &ProtonEvent::getContainer() { return container; } - -Connection &ProtonEvent::getConnection() { - pn_connection_t *conn = pn_event_connection(getPnEvent()); - if (!conn) - throw Error(MSG("No connection context for this event")); - return ConnectionImpl::getReactorReference(conn); -} - -Sender ProtonEvent::getSender() { - pn_link_t *lnk = pn_event_link(getPnEvent()); - if (lnk && pn_link_is_sender(lnk)) - return Sender(lnk); - throw Error(MSG("No sender context for this event")); -} - -Receiver ProtonEvent::getReceiver() { - pn_link_t *lnk = pn_event_link(getPnEvent()); - if (lnk && pn_link_is_receiver(lnk)) - return Receiver(lnk); - throw Error(MSG("No receiver context for this event")); -} - -Link ProtonEvent::getLink() { - pn_link_t *lnk = pn_event_link(getPnEvent()); - if (lnk) { - if (pn_link_is_sender(lnk)) - return Sender(lnk); - else - return Receiver(lnk); - } - throw Error(MSG("No link context for this event")); -} - - - - -void ProtonEvent::dispatch(Handler &h) { - ProtonHandler *handler = dynamic_cast<ProtonHandler*>(&h); - - if (handler) { - switch(type) { - - case PN_REACTOR_INIT: handler->onReactorInit(*this); break; - case PN_REACTOR_QUIESCED: handler->onReactorQuiesced(*this); break; - case PN_REACTOR_FINAL: handler->onReactorFinal(*this); break; - - case PN_TIMER_TASK: handler->onTimerTask(*this); break; - - case PN_CONNECTION_INIT: handler->onConnectionInit(*this); break; - case PN_CONNECTION_BOUND: handler->onConnectionBound(*this); break; - case PN_CONNECTION_UNBOUND: handler->onConnectionUnbound(*this); break; - case PN_CONNECTION_LOCAL_OPEN: handler->onConnectionLocalOpen(*this); break; - case PN_CONNECTION_LOCAL_CLOSE: handler->onConnectionLocalClose(*this); break; - case PN_CONNECTION_REMOTE_OPEN: handler->onConnectionRemoteOpen(*this); break; - case PN_CONNECTION_REMOTE_CLOSE: handler->onConnectionRemoteClose(*this); break; - case PN_CONNECTION_FINAL: handler->onConnectionFinal(*this); break; - - case PN_SESSION_INIT: handler->onSessionInit(*this); break; - case PN_SESSION_LOCAL_OPEN: handler->onSessionLocalOpen(*this); break; - case PN_SESSION_LOCAL_CLOSE: handler->onSessionLocalClose(*this); break; - case PN_SESSION_REMOTE_OPEN: handler->onSessionRemoteOpen(*this); break; - case PN_SESSION_REMOTE_CLOSE: handler->onSessionRemoteClose(*this); break; - case PN_SESSION_FINAL: handler->onSessionFinal(*this); break; - - case PN_LINK_INIT: handler->onLinkInit(*this); break; - case PN_LINK_LOCAL_OPEN: handler->onLinkLocalOpen(*this); break; - case PN_LINK_LOCAL_CLOSE: handler->onLinkLocalClose(*this); break; - case PN_LINK_LOCAL_DETACH: handler->onLinkLocalDetach(*this); break; - case PN_LINK_REMOTE_OPEN: handler->onLinkRemoteOpen(*this); break; - case PN_LINK_REMOTE_CLOSE: handler->onLinkRemoteClose(*this); break; - case PN_LINK_REMOTE_DETACH: handler->onLinkRemoteDetach(*this); break; - case PN_LINK_FLOW: handler->onLinkFlow(*this); break; - case PN_LINK_FINAL: handler->onLinkFinal(*this); break; - - case PN_DELIVERY: handler->onDelivery(*this); break; - - case PN_TRANSPORT: handler->onTransport(*this); break; - case PN_TRANSPORT_ERROR: handler->onTransportError(*this); break; - case PN_TRANSPORT_HEAD_CLOSED: handler->onTransportHeadClosed(*this); break; - case PN_TRANSPORT_TAIL_CLOSED: handler->onTransportTailClosed(*this); break; - case PN_TRANSPORT_CLOSED: handler->onTransportClosed(*this); break; - - case PN_SELECTABLE_INIT: handler->onSelectableInit(*this); break; - case PN_SELECTABLE_UPDATED: handler->onSelectableUpdated(*this); break; - case PN_SELECTABLE_READABLE: handler->onSelectableReadable(*this); break; - case PN_SELECTABLE_WRITABLE: handler->onSelectableWritable(*this); break; - case PN_SELECTABLE_EXPIRED: handler->onSelectableExpired(*this); break; - case PN_SELECTABLE_ERROR: handler->onSelectableError(*this); break; - case PN_SELECTABLE_FINAL: handler->onSelectableFinal(*this); break; - default: - throw Error(MSG("Invalid Proton event type " << type)); - break; - } - } else { - h.onUnhandled(*this); - } - - // recurse through children - for (std::vector<Handler *>::iterator child = h.childHandlersBegin(); - child != h.childHandlersEnd(); ++child) { - dispatch(**child); - } -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/ProtonHandler.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ProtonHandler.cpp b/proton-c/bindings/cpp/src/ProtonHandler.cpp deleted file mode 100644 index d4705d5..0000000 --- a/proton-c/bindings/cpp/src/ProtonHandler.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/ProtonHandler.hpp" -#include "proton/ProtonEvent.hpp" - -namespace proton { -namespace reactor { - -ProtonHandler::ProtonHandler(){} - -// Everything goes to onUnhandled() unless overriden by subclass - -void ProtonHandler::onReactorInit(Event &e) { onUnhandled(e); } -void ProtonHandler::onReactorQuiesced(Event &e) { onUnhandled(e); } -void ProtonHandler::onReactorFinal(Event &e) { onUnhandled(e); } -void ProtonHandler::onTimerTask(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionInit(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionBound(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionUnbound(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionLocalOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionLocalClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionRemoteOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionRemoteClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onConnectionFinal(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionInit(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionLocalOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionLocalClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionRemoteOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionRemoteClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onSessionFinal(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkInit(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkLocalOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkLocalClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkLocalDetach(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkRemoteOpen(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkRemoteClose(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkRemoteDetach(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkFlow(Event &e) { onUnhandled(e); } -void ProtonHandler::onLinkFinal(Event &e) { onUnhandled(e); } -void ProtonHandler::onDelivery(Event &e) { onUnhandled(e); } -void ProtonHandler::onTransport(Event &e) { onUnhandled(e); } -void ProtonHandler::onTransportError(Event &e) { onUnhandled(e); } -void ProtonHandler::onTransportHeadClosed(Event &e) { onUnhandled(e); } -void ProtonHandler::onTransportTailClosed(Event &e) { onUnhandled(e); } -void ProtonHandler::onTransportClosed(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableInit(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableUpdated(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableReadable(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableWritable(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableExpired(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableError(Event &e) { onUnhandled(e); } -void ProtonHandler::onSelectableFinal(Event &e) { onUnhandled(e); } - -void ProtonHandler::onUnhandled(Event &e) {} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/ProtonImplRef.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ProtonImplRef.hpp b/proton-c/bindings/cpp/src/ProtonImplRef.hpp deleted file mode 100644 index 426fb6d..0000000 --- a/proton-c/bindings/cpp/src/ProtonImplRef.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef PROTON_CPP_PROTONIMPL_H -#define PROTON_CPP_PROTONIMPL_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "proton/export.hpp" -#include "proton/object.h" - -namespace proton { -namespace reactor { - -// Modified from qpid::messaging version to work without -// boost::intrusive_ptr but integrate with Proton's pn_class_t -// reference counting. Thread safety currently absent but fluid in -// intention... - - -/** - * See PrivateImplRef.h This is for lightly wrapped Proton pn_object_t targets. - * class Foo : ProtonHandle<pn_foo_t> {...} - */ - -template <class T> class ProtonImplRef { - public: - typedef typename T::Impl Impl; - - /** Get the implementation pointer from a handle */ - static Impl* get(const T& t) { return t.impl; } - - /** Set the implementation pointer in a handle */ - static void set(T& t, const Impl* p) { - if (t.impl == p) return; - if (t.impl) pn_decref(t.impl); - t.impl = const_cast<Impl *>(p); - if (t.impl) pn_incref(t.impl); - } - - // Helper functions to implement the ctor, dtor, copy, assign - static void ctor(T& t, Impl* p) { t.impl = p; if (p) pn_incref(p); } - static void copy(T& t, const T& x) { if (&t == &x) return; t.impl = 0; assign(t, x); } - static void dtor(T& t) { if(t.impl) pn_decref(t.impl); } - static T& assign(T& t, const T& x) { set(t, get(x)); return t;} -}; - -}} // namespace proton::reactor - -#endif /*!PROTON_CPP_PROTONIMPL_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Receiver.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Receiver.cpp b/proton-c/bindings/cpp/src/Receiver.cpp deleted file mode 100644 index b46ab87..0000000 --- a/proton-c/bindings/cpp/src/Receiver.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/Link.hpp" -#include "proton/Receiver.hpp" -#include "proton/Error.hpp" -#include "Msg.hpp" - -#include "proton/connection.h" -#include "proton/session.h" -#include "proton/link.h" - -namespace proton { -namespace reactor { - - -Receiver::Receiver(pn_link_t *lnk) : Link(lnk) {} -Receiver::Receiver() : Link(0) {} - -Receiver::Receiver(const Link& c) : Link(c.getPnLink()) {} - -void Receiver::verifyType(pn_link_t *lnk) { - if (lnk && pn_link_is_sender(lnk)) - throw Error(MSG("Creating receiver with sender context")); -} - - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/proton-c/bindings/cpp/src/Sender.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Sender.cpp b/proton-c/bindings/cpp/src/Sender.cpp deleted file mode 100644 index 3998d62..0000000 --- a/proton-c/bindings/cpp/src/Sender.cpp +++ /dev/null @@ -1,72 +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/Link.hpp" -#include "proton/Sender.hpp" -#include "proton/Error.hpp" -#include "Msg.hpp" -#include "contexts.hpp" - -#include "proton/connection.h" -#include "proton/session.h" -#include "proton/link.h" -#include "proton/types.h" -#include "proton/codec.h" -#include "proton/message.h" -#include "proton/delivery.h" -#include <stdlib.h> -#include <string.h> - -namespace proton { -namespace reactor { - - -Sender::Sender(pn_link_t *lnk) : Link(lnk) {} - -void Sender::verifyType(pn_link_t *lnk) { - if (lnk && pn_link_is_receiver(lnk)) - throw Error(MSG("Creating sender with receiver context")); -} - -Sender::Sender(const Link& c) : Link(c.getPnLink()) {} - - -namespace{ -// revisit if thread safety required -std::uint64_t tagCounter = 0; -} - -Delivery Sender::send(Message &message) { - char tag[8]; - void *ptr = &tag; - std::uint64_t id = ++tagCounter; - *((std::uint64_t *) ptr) = id; - pn_delivery_t *dlv = pn_delivery(getPnLink(), pn_dtag(tag, 8)); - std::string buf; - message.encode(buf); - pn_link_t *link = getPnLink(); - pn_link_send(link, buf.data(), buf.size()); - pn_link_advance(link); - if (pn_link_snd_settle_mode(link) == PN_SND_SETTLED) - pn_delivery_settle(dlv); - return Delivery(dlv); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/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 594d192..0000000 --- a/proton-c/bindings/cpp/src/Session.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.hpp" -#include "contexts.hpp" - -#include "proton/connection.h" -#include "proton/session.h" -#include "proton/Session.hpp" -#include "proton/Connection.hpp" -#include "ConnectionImpl.hpp" -#include "ProtonImplRef.hpp" - -namespace proton { -namespace reactor { - -template class ProtonHandle<pn_session_t>; -typedef ProtonImplRef<Session> PI; - -Session::Session(pn_session_t *p) { - PI::ctor(*this, p); -} -Session::Session() { - PI::ctor(*this, 0); -} -Session::Session(const Session& c) : ProtonHandle<pn_session_t>() { - PI::copy(*this, c); -} -Session& Session::operator=(const Session& c) { - return PI::assign(*this, c); -} -Session::~Session() { - PI::dtor(*this); -} - -pn_session_t *Session::getPnSession() { return impl; } - -void Session::open() { - pn_session_open(impl); -} - -Connection &Session::getConnection() { - pn_connection_t *c = pn_session_connection(impl); - return ConnectionImpl::getReactorReference(c); -} - -Receiver Session::createReceiver(std::string name) { - pn_link_t *link = pn_receiver(impl, name.c_str()); - return Receiver(link); -} - -Sender Session::createSender(std::string name) { - pn_link_t *link = pn_sender(impl, name.c_str()); - return Sender(link); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/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 0022805..0000000 --- a/proton-c/bindings/cpp/src/Terminus.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/Link.hpp" -#include "proton/link.h" - -namespace proton { -namespace reactor { - -template class ProtonHandle<pn_terminus_t>; -typedef ProtonImplRef<Terminus> PI; - -// Note: the pn_terminus_t is not ref counted. We count the parent link. - -Terminus::Terminus() : link(0) { - impl = 0; -} - -Terminus::Terminus(pn_terminus_t *p, Link *l) : link(l) { - impl = p; - pn_incref(link->getPnLink()); -} -Terminus::Terminus(const Terminus& c) : ProtonHandle<pn_terminus_t>() { - impl = c.impl; - link = c.link; - pn_incref(link->getPnLink()); -} -Terminus& Terminus::operator=(const Terminus& c) { - if (impl == c.impl) return *this; - if (impl) pn_decref(link->getPnLink()); - impl = c.impl; - link = c.link; - pn_incref(link->getPnLink()); - return *this; -} -Terminus::~Terminus() { - if (impl) - pn_decref(link->getPnLink()); -} - -pn_terminus_t *Terminus::getPnTerminus() { return impl; } - -Terminus::Type Terminus::getType() { - return (Type) pn_terminus_get_type(impl); -} - -void Terminus::setType(Type type) { - pn_terminus_set_type(impl, (pn_terminus_type_t) type); -} - -Terminus::ExpiryPolicy Terminus::getExpiryPolicy() { - return (ExpiryPolicy) pn_terminus_get_type(impl); -} - -void Terminus::setExpiryPolicy(ExpiryPolicy policy) { - pn_terminus_set_expiry_policy(impl, (pn_expiry_policy_t) policy); -} - -Terminus::DistributionMode Terminus::getDistributionMode() { - return (DistributionMode) pn_terminus_get_type(impl); -} - -void Terminus::setDistributionMode(DistributionMode mode) { - pn_terminus_set_distribution_mode(impl, (pn_distribution_mode_t) mode); -} - -std::string Terminus::getAddress() { - const char *addr = pn_terminus_get_address(impl); - return addr ? std::string(addr) : std::string(); -} - -void Terminus::setAddress(std::string &addr) { - pn_terminus_set_address(impl, addr.c_str()); -} - -bool Terminus::isDynamic() { - return (Type) pn_terminus_is_dynamic(impl); -} - -void Terminus::setDynamic(bool d) { - pn_terminus_set_dynamic(impl, d); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/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 98f03f5..0000000 --- a/proton-c/bindings/cpp/src/Transport.cpp +++ /dev/null @@ -1,39 +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/Transport.hpp" -#include "proton/Connection.hpp" - -#include "proton/transport.h" - -namespace proton { -namespace reactor { - - -Transport::Transport() : connection(0), pnTransport(pn_transport()) {} - -Transport::~Transport() { pn_decref(pnTransport); } - -void Transport::bind(Connection &c) { - connection = &c; - pn_transport_bind(pnTransport, c.getPnConnection()); -} - -}} // namespace proton::reactor http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/69783099/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 60ab58d..0000000 --- a/proton-c/bindings/cpp/src/Url.cpp +++ /dev/null @@ -1,77 +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 "Url.hpp" -#include "ProtonImplRef.hpp" -#include "Msg.hpp" - -namespace proton { -namespace reactor { - -template class ProtonHandle<pn_url_t>; -typedef ProtonImplRef<Url> PI; - - -Url::Url(const std::string &url) { - pn_url_t *up = pn_url_parse(url.c_str()); - // refcount is 1, no need to incref - if (!up) - throw Error(MSG("invalid URL: " << url)); - impl = up; -} - -Url::~Url() { PI::dtor(*this); } - -Url::Url(const Url& c) : ProtonHandle<pn_url_t>() { - PI::copy(*this, c); -} - -Url& Url::operator=(const Url& c) { - return PI::assign(*this, c); -} - -std::string Url::getPort() { - const char *p = pn_url_get_port(impl); - if (!p) - return std::string("5672"); - else - return std::string(p); -} - -std::string Url::getHost() { - const char *p = pn_url_get_host(impl); - if (!p) - return std::string("0.0.0.0"); - else - return std::string(p); -} - -std::string Url::getPath() { - const char *p = pn_url_get_path(impl); - if (!p) - return std::string(""); - else - return std::string(p); -} - - -}} // namespace proton::reactor --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
