PROTON-865: Move types out of reactor namespace, clean up Message. Move AMQP types and general type manipulation, including Message, into proton namespace. Keep proton::reactor namespace for reactive, event-driven API.
Message cleanup - use Value and Values for complex AMQP types. - drop get/set prefixes for attributes. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/327f358e Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/327f358e Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/327f358e Branch: refs/heads/cjansen-cpp-client Commit: 327f358e73a1bd3a9611032084b21d0e5b160690 Parents: 38f57e9 Author: Alan Conway <[email protected]> Authored: Tue Jun 16 20:42:20 2015 -0400 Committer: Alan Conway <[email protected]> Committed: Thu Jun 18 17:28:44 2015 -0400 ---------------------------------------------------------------------- examples/cpp/README.md | 18 +- examples/cpp/broker.cpp | 1 + examples/cpp/encode_decode.cpp | 14 +- examples/cpp/example_test.py | 5 +- examples/cpp/helloworld.cpp | 6 +- examples/cpp/helloworld_blocking.cpp | 6 +- examples/cpp/helloworld_direct.cpp | 6 +- examples/cpp/simple_recv.cpp | 11 +- examples/cpp/simple_send.cpp | 10 +- proton-c/bindings/cpp/CMakeLists.txt | 1 + proton-c/bindings/cpp/README.md | 43 ++- .../bindings/cpp/include/proton/Acceptor.hpp | 3 +- proton-c/bindings/cpp/include/proton/Acking.hpp | 2 +- .../cpp/include/proton/BlockingConnection.hpp | 3 +- .../cpp/include/proton/BlockingLink.hpp | 3 +- .../cpp/include/proton/BlockingSender.hpp | 3 +- .../bindings/cpp/include/proton/Connection.hpp | 3 +- .../bindings/cpp/include/proton/Container.hpp | 2 +- proton-c/bindings/cpp/include/proton/Data.hpp | 29 +- .../bindings/cpp/include/proton/Decoder.hpp | 12 +- .../bindings/cpp/include/proton/Delivery.hpp | 3 +- .../bindings/cpp/include/proton/Duration.hpp | 33 +- .../bindings/cpp/include/proton/Encoder.hpp | 16 +- .../bindings/cpp/include/proton/Endpoint.hpp | 2 +- proton-c/bindings/cpp/include/proton/Error.hpp | 42 +++ proton-c/bindings/cpp/include/proton/Event.hpp | 3 +- proton-c/bindings/cpp/include/proton/Handle.hpp | 4 +- .../bindings/cpp/include/proton/Handler.hpp | 3 +- proton-c/bindings/cpp/include/proton/Link.hpp | 3 +- .../bindings/cpp/include/proton/Message.hpp | 112 +++--- .../cpp/include/proton/MessagingAdapter.hpp | 4 +- .../cpp/include/proton/MessagingEvent.hpp | 3 +- .../cpp/include/proton/MessagingHandler.hpp | 3 +- .../bindings/cpp/include/proton/ProtonEvent.hpp | 3 +- .../cpp/include/proton/ProtonHandle.hpp | 4 +- .../cpp/include/proton/ProtonHandler.hpp | 3 +- .../bindings/cpp/include/proton/Receiver.hpp | 3 +- proton-c/bindings/cpp/include/proton/Sender.hpp | 2 +- .../bindings/cpp/include/proton/Session.hpp | 3 +- .../bindings/cpp/include/proton/Terminus.hpp | 2 +- .../bindings/cpp/include/proton/Transport.hpp | 2 +- proton-c/bindings/cpp/include/proton/Value.hpp | 24 +- proton-c/bindings/cpp/include/proton/Values.hpp | 13 +- .../cpp/include/proton/WaitCondition.hpp | 2 +- .../bindings/cpp/include/proton/exceptions.hpp | 49 --- proton-c/bindings/cpp/include/proton/types.hpp | 10 +- proton-c/bindings/cpp/src/Acceptor.cpp | 2 +- proton-c/bindings/cpp/src/Connection.cpp | 2 +- proton-c/bindings/cpp/src/ConnectionImpl.cpp | 12 +- proton-c/bindings/cpp/src/Container.cpp | 2 +- proton-c/bindings/cpp/src/ContainerImpl.cpp | 30 +- proton-c/bindings/cpp/src/Data.cpp | 35 +- proton-c/bindings/cpp/src/Decoder.cpp | 22 +- proton-c/bindings/cpp/src/Duration.cpp | 26 +- proton-c/bindings/cpp/src/Encoder.cpp | 11 +- proton-c/bindings/cpp/src/Error.cpp | 30 ++ proton-c/bindings/cpp/src/Event.cpp | 16 +- proton-c/bindings/cpp/src/Link.cpp | 2 +- proton-c/bindings/cpp/src/Message.cpp | 361 ++++--------------- proton-c/bindings/cpp/src/MessagingAdapter.cpp | 4 +- proton-c/bindings/cpp/src/MessagingEvent.cpp | 20 +- proton-c/bindings/cpp/src/ProtonEvent.cpp | 12 +- proton-c/bindings/cpp/src/Receiver.cpp | 4 +- proton-c/bindings/cpp/src/Sender.cpp | 4 +- proton-c/bindings/cpp/src/Url.cpp | 4 +- proton-c/bindings/cpp/src/Value.cpp | 6 +- proton-c/bindings/cpp/src/Values.cpp | 5 +- .../cpp/src/blocking/BlockingConnection.cpp | 2 +- .../cpp/src/blocking/BlockingConnectionImpl.cpp | 8 +- .../bindings/cpp/src/blocking/BlockingLink.cpp | 4 +- .../cpp/src/blocking/BlockingSender.cpp | 4 +- proton-c/bindings/cpp/src/contexts.cpp | 4 +- proton-c/bindings/cpp/src/interop_test.cpp | 17 +- proton-c/bindings/cpp/src/proton_bits.cpp | 2 +- proton-c/bindings/cpp/src/proton_bits.hpp | 4 +- proton-c/bindings/cpp/src/types.cpp | 5 +- 76 files changed, 525 insertions(+), 667 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/README.md ---------------------------------------------------------------------- diff --git a/examples/cpp/README.md b/examples/cpp/README.md index 867c671..52b73e7 100644 --- a/examples/cpp/README.md +++ b/examples/cpp/README.md @@ -1,10 +1,20 @@ # C++ examples +Many of the examples expect a broker to be running on the standard AMQP +port. You can use any broker that supports AMQP 1.0, or you can use the simple +example `broker` provided here. Run the broker in a separate window before +running the other examples. + +If you use another broker you will need to create a queue named `examples`. + ## broker.cpp A very simple "mini broker". You can use this to run other examples that reqiure -an intermediary, or you can use a real AMQP 1.0 broker. It creates queues -automatically when a client tries to send to or subscribe from a node. +an intermediary, or you can use any AMQP 1.0 broker. This broker creates queues +automatically when a client tries to send or subscribe. + + $ ./broker + broker listening on :5672 ## helloworld.cpp @@ -40,3 +50,7 @@ an intermediary accessible on port 5672 on localhost. Subscribes to the 'examples' node on an intermediary accessible on port 5672 on localhost. Simply prints out the body of received messages. + +## encode_decode.cpp + +Shows how C++ data types can be converted to and from AMQP types. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/broker.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/broker.cpp b/examples/cpp/broker.cpp index ccecefa..468af48 100644 --- a/examples/cpp/broker.cpp +++ b/examples/cpp/broker.cpp @@ -29,6 +29,7 @@ #include <stdlib.h> #include <string.h> +using namespace proton; using namespace proton::reactor; std::string generateUuid(){ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/encode_decode.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/encode_decode.cpp b/examples/cpp/encode_decode.cpp index bf1dba9..cad4c0e 100644 --- a/examples/cpp/encode_decode.cpp +++ b/examples/cpp/encode_decode.cpp @@ -28,7 +28,7 @@ #include <vector> using namespace std; -using namespace proton::reactor; +using namespace proton; // Examples of how to use the Encoder and Decoder to create and examine AMQP values. // @@ -49,7 +49,13 @@ void simple_insert_extract() { values.rewind(); values >> i >> s >> b; cout << "Extracted: " << i << ", " << s << ", " << b << endl; - cout << "Encoded as AMQP in " << values.encode().size() << " bytes" << endl; + // Encode and decode as AMQP + string amqpData = values.encode(); + cout << "Encoded as AMQP in " << amqpData.size() << " bytes" << endl; + Values values2; + values.decode(amqpData); + values >> i >> s >> b; + cout << "Decoded: " << i << ", " << s << ", " << b << endl; } // Inserting values as a specific AMQP type @@ -71,12 +77,12 @@ void simple_insert_extract_exact_type() { values.rewind(); // Byte(1) << Long(2) << Symbol("bar"); Long l; // Fails, extracting Byte as Long - try { values >> as<LONG>(l); throw logic_error("expected error"); } catch (Decoder::Error) {} + try { values >> as<LONG>(l); throw logic_error("expected error"); } catch (DecodeError) {} Byte b; values >> as<BYTE>(b) >> as<LONG>(l); // OK, extract Byte as Byte, Long as Long. std::string str; // Fails, extracting Symbol as String. - try { values >> as<STRING>(str); throw logic_error("expected error"); } catch (Decoder::Error) {} + try { values >> as<STRING>(str); throw logic_error("expected error"); } catch (DecodeError) {} values >> as<SYMBOL>(str); // OK, extract Symbol as Symbol cout << "Extracted (exact) " << b << ", " << l << ", " << str << endl; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/example_test.py ---------------------------------------------------------------------- diff --git a/examples/cpp/example_test.py b/examples/cpp/example_test.py index 3da1ddb..2e2d91c 100644 --- a/examples/cpp/example_test.py +++ b/examples/cpp/example_test.py @@ -17,6 +17,8 @@ # under the License # +# This is a test script to run the examples and verify that they behave as expected. + import unittest import os, sys, socket, time from random import randrange @@ -86,7 +88,7 @@ class ExampleTest(unittest.TestCase): self.assertEqual("all messages confirmed\n", send) recv = check_output(["./simple_recv", "-a", b.addr, "-m", str(n)]) recv_expect = "simple_recv listening on %s\n" % (b.addr) - recv_expect += "".join(['[%d]: b"some arbitrary binary data"\n' % (i+1) for i in range(n)]) + recv_expect += "".join(['{"sequence"=%s}\n' % (i+1) for i in range(n)]) self.assertEqual(recv_expect, recv) # FIXME aconway 2015-06-16: bug when receiver is started before sender, messages @@ -117,6 +119,7 @@ class ExampleTest(unittest.TestCase): Values: int(42), string("foo"), bool(true) Extracted: 42, foo, 1 Encoded as AMQP in 8 bytes +Decoded: 42, foo, 1 == Specific AMQP types: byte, long, symbol Values: byte(120), long(123456789123456789), symbol(:bar) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/helloworld.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld.cpp b/examples/cpp/helloworld.cpp index 5ac73da..9546218 100644 --- a/examples/cpp/helloworld.cpp +++ b/examples/cpp/helloworld.cpp @@ -25,6 +25,7 @@ #include <iostream> +using namespace proton; using namespace proton::reactor; class HelloWorld : public MessagingHandler { @@ -43,14 +44,13 @@ class HelloWorld : public MessagingHandler { void onSendable(Event &e) { Message m; - m.setBody("Hello World!"); + m.body("Hello World!"); e.getSender().send(m); e.getSender().close(); } void onMessage(Event &e) { - std::string body = e.getMessage().getBody(); - std::cout << body << std::endl; + std::cout << e.getMessage().body().get<String>() << std::endl; e.getConnection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/helloworld_blocking.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_blocking.cpp b/examples/cpp/helloworld_blocking.cpp index c0ef4c5..b5aee8d 100644 --- a/examples/cpp/helloworld_blocking.cpp +++ b/examples/cpp/helloworld_blocking.cpp @@ -26,6 +26,7 @@ #include <iostream> +using namespace proton; using namespace proton::reactor; class HelloWorldBlocking : public MessagingHandler { @@ -42,8 +43,7 @@ class HelloWorldBlocking : public MessagingHandler { } void onMessage(Event &e) { - std::string body = e.getMessage().getBody(); - std::cout << body << std::endl; + std::cout << e.getMessage().body().get<String>() << std::endl; e.getConnection().close(); } @@ -56,7 +56,7 @@ int main(int argc, char **argv) { BlockingConnection conn = BlockingConnection(server); BlockingSender sender = conn.createSender(addr); Message m; - m.setBody("Hello World!"); + m.body("Hello World!"); sender.send(m); conn.close(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/helloworld_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_direct.cpp b/examples/cpp/helloworld_direct.cpp index 965ba04..536aba8 100644 --- a/examples/cpp/helloworld_direct.cpp +++ b/examples/cpp/helloworld_direct.cpp @@ -26,6 +26,7 @@ #include <iostream> +using namespace proton; using namespace proton::reactor; @@ -44,14 +45,13 @@ class HelloWorldDirect : public MessagingHandler { void onSendable(Event &e) { Message m; - m.setBody("Hello World!"); + m.body("Hello World!"); e.getSender().send(m); e.getSender().close(); } void onMessage(Event &e) { - std::string body = e.getMessage().getBody(); - std::cout << body << std::endl; + std::cout << e.getMessage().body().get<String>() << std::endl; } void onAccepted(Event &e) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/simple_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/simple_recv.cpp b/examples/cpp/simple_recv.cpp index 48ba8a4..b4572f5 100644 --- a/examples/cpp/simple_recv.cpp +++ b/examples/cpp/simple_recv.cpp @@ -24,11 +24,13 @@ #include "proton/Link.hpp" #include <iostream> +#include <map> #include <stdlib.h> #include <stdio.h> #include <string.h> +using namespace proton; using namespace proton::reactor; class Recv : public MessagingHandler { @@ -46,15 +48,14 @@ class Recv : public MessagingHandler { } void onMessage(Event &e) { - int64_t id = 0; Message msg = e.getMessage(); - if (msg.getIdType() == PN_ULONG) { - id = msg.getId(); - if (id < received) + Value id = msg.id(); + if (id.type() == ULONG) { + if (id.get<int>() < received) return; // ignore duplicate } if (expected == 0 || received < expected) { - std::cout << '[' << id << "]: " << msg.getBody() << std::endl; + std::cout << msg.body() << std::endl; received++; if (received == expected) { e.getReceiver().close(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/examples/cpp/simple_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/simple_send.cpp b/examples/cpp/simple_send.cpp index 59222e4..f7518c1 100644 --- a/examples/cpp/simple_send.cpp +++ b/examples/cpp/simple_send.cpp @@ -24,11 +24,13 @@ #include "proton/Connection.hpp" #include <iostream> +#include <map> #include <string.h> #include <stdlib.h> #include <stdio.h> +using namespace proton; using namespace proton::reactor; class Send : public MessagingHandler { @@ -49,10 +51,10 @@ class Send : public MessagingHandler { Sender sender = e.getSender(); while (sender.getCredit() && sent < total) { Message msg; - msg.setId(sent + 1); - // TODO: fancy map body content as in Python example. Simple binary for now. - const char *bin = "some arbitrary binary data"; - msg.setBody(bin, strlen(bin)); + msg.id(Value(sent + 1)); + std::map<std::string, int> m; + m["sequence"] = sent+1; + msg.body(as<MAP>(m)); sender.send(msg); sent++; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt index b7e198f..f3fbb44 100644 --- a/proton-c/bindings/cpp/CMakeLists.txt +++ b/proton-c/bindings/cpp/CMakeLists.txt @@ -36,6 +36,7 @@ set(qpid-proton-cpp-source src/Duration.cpp src/Encoder.cpp src/Endpoint.cpp + src/Error.cpp src/Event.cpp src/Handler.cpp src/Link.cpp http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/README.md ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/README.md b/proton-c/bindings/cpp/README.md index 9a30e35..b6640e5 100644 --- a/proton-c/bindings/cpp/README.md +++ b/proton-c/bindings/cpp/README.md @@ -7,24 +7,33 @@ API documentation in doxygen format. # TO DO -There are a number of things that remain to be done. - -- Mapping of complex types. - -- Finish blocking API & demos. -- API documentation, HTML docs on website. -- FIXME and TODO notes in code, esp. error handling, missing sender/receiver/connection methods. - -- Valgrind for automated tests and demos. -- More automated tests and examples. - -- Security: SASL/SSL support. +Doc & examples +- Example set with tutorial documentation. Follow pyton examples + C++ encode/decode example. + - Consistent option parsing for examples, like other languages. + - Auto tests for all examples validating all statements & code in tutorial. +- API documentation, fill out & organize for readable doxygen HTML. +- C++ section on website. + +Bugs +- Memory management + - Drop PIMPL pattern in API: pn_foo pointer is already hiding the impl. + - Proper ownership of pn_objects created by user, e.g. Message. Let user choose pointer style? +- Error handling, examples crash on error e.g. queue not found. +- FIXME and TODO notes in code. + +Tests +- Interop/type testing for full AMQP type coverage. +- Unit testing for reasonable code coverage. +- Valgrind for automated unit and example tests. + +Features +- SASL/SSL support with interop tests. - Reconnection - +- Finish blocking API & examples. +- Described types, full support and tests. +- Durable subscriptions & demos (see python changes) # Nice to have -Subclasses of Encoder/Decoder that push to/pull from a std::ostream/istream as -values are inserted/extracted. - -Better support for Decimal type. +- Helpers (or at least doc) for multi-threaded use (reactor/engine per connection) +- Usable support for decimal types. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Acceptor.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Acceptor.hpp b/proton-c/bindings/cpp/include/proton/Acceptor.hpp index 5fd0004..591af2c 100644 --- a/proton-c/bindings/cpp/include/proton/Acceptor.hpp +++ b/proton-c/bindings/cpp/include/proton/Acceptor.hpp @@ -44,7 +44,6 @@ class Acceptor : public ProtonHandle<pn_acceptor_t> friend class ProtonImplRef<Acceptor>; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_ACCEPTOR_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Acking.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Acking.hpp b/proton-c/bindings/cpp/include/proton/Acking.hpp index f9f079f..67da0b1 100644 --- a/proton-c/bindings/cpp/include/proton/Acking.hpp +++ b/proton-c/bindings/cpp/include/proton/Acking.hpp @@ -39,6 +39,6 @@ class Acking }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_ACKING_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/BlockingConnection.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/BlockingConnection.hpp b/proton-c/bindings/cpp/include/proton/BlockingConnection.hpp index 138b239..77345c4 100644 --- a/proton-c/bindings/cpp/include/proton/BlockingConnection.hpp +++ b/proton-c/bindings/cpp/include/proton/BlockingConnection.hpp @@ -61,7 +61,6 @@ class BlockingConnection : public Handle<BlockingConnectionImpl> friend class PrivateImplRef<BlockingConnection>; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_BLOCKINGCONNECTION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/BlockingLink.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/BlockingLink.hpp b/proton-c/bindings/cpp/include/proton/BlockingLink.hpp index 3eec755..80df739 100644 --- a/proton-c/bindings/cpp/include/proton/BlockingLink.hpp +++ b/proton-c/bindings/cpp/include/proton/BlockingLink.hpp @@ -53,7 +53,6 @@ class BlockingLink friend class BlockingReceiver; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_BLOCKINGLINK_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/BlockingSender.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/BlockingSender.hpp b/proton-c/bindings/cpp/include/proton/BlockingSender.hpp index 64cbdfd..25f09bb 100644 --- a/proton-c/bindings/cpp/include/proton/BlockingSender.hpp +++ b/proton-c/bindings/cpp/include/proton/BlockingSender.hpp @@ -48,7 +48,6 @@ class BlockingSender : public BlockingLink friend class BlockingConnection; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_BLOCKINGSENDER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Connection.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Connection.hpp b/proton-c/bindings/cpp/include/proton/Connection.hpp index e72b091..5656889 100644 --- a/proton-c/bindings/cpp/include/proton/Connection.hpp +++ b/proton-c/bindings/cpp/include/proton/Connection.hpp @@ -64,7 +64,6 @@ class Connection : public Endpoint, public Handle<ConnectionImpl> friend class ConnectionImpl; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_CONNECTION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Container.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Container.hpp b/proton-c/bindings/cpp/include/proton/Container.hpp index 0f61599..7333566 100644 --- a/proton-c/bindings/cpp/include/proton/Container.hpp +++ b/proton-c/bindings/cpp/include/proton/Container.hpp @@ -72,6 +72,6 @@ class Container : public Handle<ContainerImpl> friend class PrivateImplRef<Container>; }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_CONTAINER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Data.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Data.hpp b/proton-c/bindings/cpp/include/proton/Data.hpp index 7f9dad0..30f85b7 100644 --- a/proton-c/bindings/cpp/include/proton/Data.hpp +++ b/proton-c/bindings/cpp/include/proton/Data.hpp @@ -29,31 +29,44 @@ struct pn_data_t; namespace proton { -namespace reactor { /** Base for classes that hold AMQP data. */ -class Data { +PN_CPP_EXTERN class Data { public: + explicit Data(); virtual ~Data(); + Data(const Data&); - /** Copies the data */ Data& operator=(const Data&); /** Clear the data. */ - PN_CPP_EXTERN void clear(); + void clear(); /** True if there are no values. */ - PN_CPP_EXTERN bool empty() const; + bool empty() const; /** Human readable representation of data. */ friend std::ostream& operator<<(std::ostream&, const Data&); + /** The underlying pn_data_t */ + pn_data_t* pnData() { return data; } + + /** True if this Data object owns it's own pn_data_t, false if it is acting as a "view" */ + bool own() const { return own_; } + + void swap(Data&); + protected: - /** Takes ownership of pd */ - explicit Data(pn_data_t* pd=0); + /** Does not take ownership, just a view on the data */ + explicit Data(pn_data_t*); + + /** Does not take ownership, just a view on the data */ + void view(pn_data_t*); + mutable pn_data_t* data; + bool own_; }; -}} +} #endif // DATA_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Decoder.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Decoder.hpp b/proton-c/bindings/cpp/include/proton/Decoder.hpp index 814fb05..c3da9dc 100644 --- a/proton-c/bindings/cpp/include/proton/Decoder.hpp +++ b/proton-c/bindings/cpp/include/proton/Decoder.hpp @@ -21,14 +21,16 @@ #include "proton/Data.hpp" #include "proton/types.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include <iosfwd> namespace proton { -namespace reactor { class Value; +/** Raised by Decoder operations on error */ +struct DecodeError : public Error { explicit DecodeError(const std::string&) throw(); }; + /**@file * Stream-like decoder from AMQP bytes to C++ values. * @ingroup cpp @@ -64,10 +66,6 @@ You can also extract container values element-by-element, see the Start class. */ PN_CPP_EXTERN class Decoder : public virtual Data { public: - /** Raised if a Decoder operation fails */ - struct Error : public ProtonException { - explicit Error(const std::string& msg) throw() : ProtonException(msg) {} - }; PN_CPP_EXTERN Decoder(); PN_CPP_EXTERN ~Decoder(); @@ -215,5 +213,5 @@ template <class T> Decoder& operator>>(Decoder& d, Ref<T, MAP> ref) { return d; } -}} // namespace proton::reactor +} #endif // DECODER_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Delivery.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Delivery.hpp b/proton-c/bindings/cpp/include/proton/Delivery.hpp index 63ecfcd..b90f7fa 100644 --- a/proton-c/bindings/cpp/include/proton/Delivery.hpp +++ b/proton-c/bindings/cpp/include/proton/Delivery.hpp @@ -55,7 +55,6 @@ class Delivery : public ProtonHandle<pn_delivery_t> friend class ProtonImplRef<Delivery>; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_DELIVERY_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Duration.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Duration.hpp b/proton-c/bindings/cpp/include/proton/Duration.hpp index 0265e73..288ef9d 100644 --- a/proton-c/bindings/cpp/include/proton/Duration.hpp +++ b/proton-c/bindings/cpp/include/proton/Duration.hpp @@ -23,34 +23,33 @@ */ #include "proton/ImportExport.hpp" -#include "proton/types.h" +#include "proton/types.hpp" namespace proton { -namespace reactor { /** @ingroup cpp * A duration is a time in milliseconds. */ -class Duration +class Duration : public Comparable<Duration> { public: - PN_CPP_EXTERN explicit Duration(uint64_t milliseconds); - PN_CPP_EXTERN uint64_t getMilliseconds() const; - PN_CPP_EXTERN static const Duration FOREVER; - PN_CPP_EXTERN static const Duration IMMEDIATE; - PN_CPP_EXTERN static const Duration SECOND; - PN_CPP_EXTERN static const Duration MINUTE; - private: uint64_t milliseconds; + explicit Duration(uint64_t ms) : milliseconds(ms) {} + + bool operator<(Duration d) { return milliseconds < d.milliseconds; } + bool operator==(Duration d) { return milliseconds == d.milliseconds; } + + static const Duration FOREVER; + static const Duration IMMEDIATE; + static const Duration SECOND; + static const Duration MINUTE; }; -PN_CPP_EXTERN Duration operator*(const Duration& duration, - uint64_t multiplier); -PN_CPP_EXTERN Duration operator*(uint64_t multiplier, - const Duration& duration); -PN_CPP_EXTERN bool operator==(const Duration& a, const Duration& b); -PN_CPP_EXTERN bool operator!=(const Duration& a, const Duration& b); +inline Duration operator*(Duration d, uint64_t n) { return Duration(d.milliseconds*n); } +inline Duration operator*(uint64_t n, Duration d) { return d * n; } -}} // namespace proton::reactor +inline Timestamp operator+(Timestamp ts, Duration d) { return Timestamp(ts.milliseconds+d.milliseconds); } +inline Timestamp operator+(Duration d, Timestamp ts) { return ts + d; } +} #endif /*!PROTON_CPP_DURATION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Encoder.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Encoder.hpp b/proton-c/bindings/cpp/include/proton/Encoder.hpp index e32fce5..aaa8d93 100644 --- a/proton-c/bindings/cpp/include/proton/Encoder.hpp +++ b/proton-c/bindings/cpp/include/proton/Encoder.hpp @@ -21,13 +21,13 @@ #include "proton/Data.hpp" #include "proton/types.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include <iosfwd> struct pn_data_t; namespace proton { -namespace reactor { + class Value; @@ -36,6 +36,9 @@ class Value; * @ingroup cpp */ +/** Raised by Encoder operations on error */ +struct EncodeError : public Error { explicit EncodeError(const std::string&) throw(); }; + /** @ingroup cpp @@ -56,11 +59,6 @@ You can also insert containers element-by-element, see the Start class. */ class Encoder : public virtual Data { public: - /** Raised if a Encoder operation fails */ - struct Error : public ProtonException { - explicit Error(const std::string& msg) throw() : ProtonException(msg) {} - }; - PN_CPP_EXTERN Encoder(); PN_CPP_EXTERN ~Encoder(); @@ -127,6 +125,8 @@ class Encoder : public virtual Data { // TODO aconway 2015-06-16: DESCRIBED. ///@} + /** Copy data from a raw pn_data_t */ + PN_CPP_EXTERN friend Encoder& operator<<(Encoder&, pn_data_t*); private: PN_CPP_EXTERN Encoder(pn_data_t* pd); @@ -180,5 +180,5 @@ template <class T> Encoder& operator<<(Encoder& e, CRef<T, MAP> m){ } -}} +} #endif // ENCODER_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Endpoint.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Endpoint.hpp b/proton-c/bindings/cpp/include/proton/Endpoint.hpp index e68ffbf..2736047 100644 --- a/proton-c/bindings/cpp/include/proton/Endpoint.hpp +++ b/proton-c/bindings/cpp/include/proton/Endpoint.hpp @@ -53,6 +53,6 @@ class Endpoint }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_ENDPOINT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Error.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Error.hpp b/proton-c/bindings/cpp/include/proton/Error.hpp new file mode 100644 index 0000000..a3d3242 --- /dev/null +++ b/proton-c/bindings/cpp/include/proton/Error.hpp @@ -0,0 +1,42 @@ +#ifndef PROTON_CPP_EXCEPTIONS_H +#define PROTON_CPP_EXCEPTIONS_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <stdexcept> + +namespace proton { + +/** @ingroup cpp + * Functions in the proton namespace throw a subclass of proton::Error on error. + */ +struct Error : public std::runtime_error { explicit Error(const std::string&) throw(); }; + +/** Raised if a message is rejected */ +struct MessageReject : public Error { explicit MessageReject(const std::string&) throw(); }; + +/** Raised if a message is released */ +struct MessageRelease : public Error { explicit MessageRelease(const std::string&) throw(); }; + + +} + +#endif /*!PROTON_CPP_EXCEPTIONS_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Event.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Event.hpp b/proton-c/bindings/cpp/include/proton/Event.hpp index f808dd1..db85c9c 100644 --- a/proton-c/bindings/cpp/include/proton/Event.hpp +++ b/proton-c/bindings/cpp/include/proton/Event.hpp @@ -54,7 +54,6 @@ class Event PN_CPP_EXTERN Event& operator=(const Event&); }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_EVENT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Handle.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Handle.hpp b/proton-c/bindings/cpp/include/proton/Handle.hpp index f8fc81b..648658b 100644 --- a/proton-c/bindings/cpp/include/proton/Handle.hpp +++ b/proton-c/bindings/cpp/include/proton/Handle.hpp @@ -69,11 +69,11 @@ template <class T> class Handle { typedef T Impl; PROTON_CPP_INLINE_EXTERN Handle() :impl() {} - Impl* impl; + mutable Impl* impl; friend class PrivateImplRef<T>; }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_HANDLE_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Handler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Handler.hpp b/proton-c/bindings/cpp/include/proton/Handler.hpp index d20fbeb..c66eecb 100644 --- a/proton-c/bindings/cpp/include/proton/Handler.hpp +++ b/proton-c/bindings/cpp/include/proton/Handler.hpp @@ -44,7 +44,6 @@ class PN_CPP_EXTERN Handler std::vector<Handler *>childHandlers; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_HANDLER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Link.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Link.hpp b/proton-c/bindings/cpp/include/proton/Link.hpp index bf5a9a7..5500041 100644 --- a/proton-c/bindings/cpp/include/proton/Link.hpp +++ b/proton-c/bindings/cpp/include/proton/Link.hpp @@ -61,8 +61,7 @@ class Link : public Endpoint, public ProtonHandle<pn_link_t> bool senderLink; }; - -}} // namespace proton::reactor +}} #include "proton/Sender.hpp" #include "proton/Receiver.hpp" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Message.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Message.hpp b/proton-c/bindings/cpp/include/proton/Message.hpp index f94f58b..b35eb18 100644 --- a/proton-c/bindings/cpp/include/proton/Message.hpp +++ b/proton-c/bindings/cpp/include/proton/Message.hpp @@ -23,94 +23,90 @@ */ #include "proton/ImportExport.hpp" #include "proton/ProtonHandle.hpp" -#include "proton/message.h" +#include "proton/Value.hpp" +#include "proton/Message.hpp" #include <string> +struct pn_message_t; +struct pn_data_t; namespace proton { -namespace reactor { -class Message : public ProtonHandle<pn_message_t> +// FIXME aconway 2015-06-17: documentation of properties. +PN_CPP_EXTERN class Message : public reactor::ProtonHandle<pn_message_t> { public: - PN_CPP_EXTERN Message(); - PN_CPP_EXTERN Message(pn_message_t *); - PN_CPP_EXTERN Message(const Message&); - PN_CPP_EXTERN Message& operator=(const Message&); - PN_CPP_EXTERN ~Message(); + Message(); + Message(pn_message_t *); + Message(const Message&); + Message& operator=(const Message&); + ~Message(); - PN_CPP_EXTERN pn_message_t *getPnMessage() const; + pn_message_t *pnMessage() const; - // FIXME aconway 2015-06-11: get rid of get/set prefixes + void id(const Value& id); + Value id() const; - // FIXME aconway 2015-06-11: use Value not string to allow full range of AMQP types. - PN_CPP_EXTERN void setId(uint64_t id); - PN_CPP_EXTERN uint64_t getId(); - PN_CPP_EXTERN void setId(const std::string &id); - PN_CPP_EXTERN std::string getStringId(); - PN_CPP_EXTERN void setId(const char *p, size_t len); - PN_CPP_EXTERN size_t getId(const char **p); - PN_CPP_EXTERN pn_type_t getIdType(); + void user(const std::string &user); + std::string user() const; - PN_CPP_EXTERN void setUserId(const std::string &id); - PN_CPP_EXTERN std::string getUserId(); + void address(const std::string &addr); + std::string address() const; - PN_CPP_EXTERN void setAddress(const std::string &addr); - PN_CPP_EXTERN std::string getAddress(); + void subject(const std::string &s); + std::string subject() const; - PN_CPP_EXTERN void setSubject(const std::string &s); - PN_CPP_EXTERN std::string getSubject(); + void replyTo(const std::string &s); + std::string replyTo() const; - PN_CPP_EXTERN void setReplyTo(const std::string &s); - PN_CPP_EXTERN std::string getReplyTo(); + void correlationId(const Value&); + Value correlationId() const; - PN_CPP_EXTERN void setCorrelationId(uint64_t id); - PN_CPP_EXTERN uint64_t getCorrelationId(); - PN_CPP_EXTERN void setCorrelationId(const std::string &id); - PN_CPP_EXTERN std::string getStringCorrelationId(); - PN_CPP_EXTERN void setCorrelationId(const char *p, size_t len); - PN_CPP_EXTERN size_t getCorrelationId(const char **p); + void contentType(const std::string &s); + std::string contentType() const; - // FIXME aconway 2015-06-11: use Value not string to allow full range of AMQP types. - PN_CPP_EXTERN pn_type_t getCorrelationIdType(); + void contentEncoding(const std::string &s); + std::string contentEncoding() const; - PN_CPP_EXTERN void setContentType(const std::string &s); - PN_CPP_EXTERN std::string getContentType(); + void expiry(Timestamp t); + Timestamp expiry() const; - PN_CPP_EXTERN void setContentEncoding(const std::string &s); - PN_CPP_EXTERN std::string getContentEncoding(); + void creationTime(Timestamp t); + Timestamp creationTime() const; - PN_CPP_EXTERN void setExpiry(pn_timestamp_t t); - PN_CPP_EXTERN pn_timestamp_t getExpiry(); + void groupId(const std::string &s); + std::string groupId() const; - PN_CPP_EXTERN void setCreationTime(pn_timestamp_t t); - PN_CPP_EXTERN pn_timestamp_t getCreationTime(); + void replyToGroupId(const std::string &s); + std::string replyToGroupId() const; - PN_CPP_EXTERN void setGroupId(const std::string &s); - PN_CPP_EXTERN std::string getGroupId(); + /** Set the body to an AMQP value. */ + void body(const Value&); - PN_CPP_EXTERN void setReplyToGroupId(const std::string &s); - PN_CPP_EXTERN std::string getReplyToGroupId(); + /** Template to convert any type to a Value and set as the body */ + template <class T> void body(const T& v) { body(Value(v)); } - // FIXME aconway 2015-06-11: use Values for body. - PN_CPP_EXTERN void setBody(const std::string &data); - PN_CPP_EXTERN std::string getBody(); + /** Set the body to a sequence of sections containing AMQP values. */ + void body(const Values&); - PN_CPP_EXTERN void getBody(std::string &str); + const Values& body() const; - PN_CPP_EXTERN void setBody(const char *, size_t len); - PN_CPP_EXTERN size_t getBody(char *, size_t len); - PN_CPP_EXTERN size_t getBinaryBodySize(); + Values& body(); ///< Allows in-place modification of body sections. + // FIXME aconway 2015-06-17: consistent and flexible treatment of buffers. + // Allow convenient std::string encoding/decoding (with re-use of existing + // string capacity) but also need to allow encoding/decoding of non-string + // buffers. Introduce a buffer type with begin/end pointers? - PN_CPP_EXTERN void encode(std::string &data); - PN_CPP_EXTERN void decode(const std::string &data); + void encode(std::string &data); + std::string encode(); + void decode(const std::string &data); private: - friend class ProtonImplRef<Message>; + mutable Values body_; + friend class reactor::ProtonImplRef<Message>; }; - -}} // namespace proton::reactor +} #endif /*!PROTON_CPP_MESSAGE_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/MessagingAdapter.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/MessagingAdapter.hpp b/proton-c/bindings/cpp/include/proton/MessagingAdapter.hpp index 7c6fa79..243e049 100644 --- a/proton-c/bindings/cpp/include/proton/MessagingAdapter.hpp +++ b/proton-c/bindings/cpp/include/proton/MessagingAdapter.hpp @@ -34,7 +34,6 @@ namespace reactor { // Combine's Python's: EndpointStateHandler, IncomingMessageHandler, OutgoingMessageHandler - class MessagingAdapter : public MessagingHandler { public: @@ -73,7 +72,6 @@ class MessagingAdapter : public MessagingHandler MessagingHandler &delegate; // The handler for generated MessagingEvent's }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_MESSAGING_ADAPTER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/MessagingEvent.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/MessagingEvent.hpp b/proton-c/bindings/cpp/include/proton/MessagingEvent.hpp index a73a7ad..e80f44b 100644 --- a/proton-c/bindings/cpp/include/proton/MessagingEvent.hpp +++ b/proton-c/bindings/cpp/include/proton/MessagingEvent.hpp @@ -94,7 +94,6 @@ class MessagingEvent : public ProtonEvent MessagingEvent(const MessagingEvent&); }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_MESSAGINGEVENT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/MessagingHandler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/MessagingHandler.hpp b/proton-c/bindings/cpp/include/proton/MessagingHandler.hpp index ea712a6..06858e3 100644 --- a/proton-c/bindings/cpp/include/proton/MessagingHandler.hpp +++ b/proton-c/bindings/cpp/include/proton/MessagingHandler.hpp @@ -91,7 +91,6 @@ class PN_CPP_EXTERN MessagingHandler : public ProtonHandler , public Acking void createHelpers(); }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_MESSAGING_HANDLER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/ProtonEvent.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/ProtonEvent.hpp b/proton-c/bindings/cpp/include/proton/ProtonEvent.hpp index 88358c9..0d1d534 100644 --- a/proton-c/bindings/cpp/include/proton/ProtonEvent.hpp +++ b/proton-c/bindings/cpp/include/proton/ProtonEvent.hpp @@ -51,7 +51,6 @@ class ProtonEvent : public Event Container &container; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_PROTONEVENT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/ProtonHandle.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/ProtonHandle.hpp b/proton-c/bindings/cpp/include/proton/ProtonHandle.hpp index 1170753..213bc14 100644 --- a/proton-c/bindings/cpp/include/proton/ProtonHandle.hpp +++ b/proton-c/bindings/cpp/include/proton/ProtonHandle.hpp @@ -58,11 +58,11 @@ template <class T> class ProtonHandle { typedef T Impl; PROTON_CPP_INLINE_EXTERN ProtonHandle() :impl() {} - Impl* impl; + mutable Impl* impl; friend class ProtonImplRef<T>; }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_PROTONHANDLE_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/ProtonHandler.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/ProtonHandler.hpp b/proton-c/bindings/cpp/include/proton/ProtonHandler.hpp index 91d8bd9..799ca89 100644 --- a/proton-c/bindings/cpp/include/proton/ProtonHandler.hpp +++ b/proton-c/bindings/cpp/include/proton/ProtonHandler.hpp @@ -77,7 +77,6 @@ class ProtonHandler : public Handler virtual void onUnhandled(Event &e); }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_PROTONHANDLER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Receiver.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Receiver.hpp b/proton-c/bindings/cpp/include/proton/Receiver.hpp index a913b7b..ad22302 100644 --- a/proton-c/bindings/cpp/include/proton/Receiver.hpp +++ b/proton-c/bindings/cpp/include/proton/Receiver.hpp @@ -42,7 +42,6 @@ class Receiver : public Link virtual void verifyType(pn_link_t *l); }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_RECEIVER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Sender.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Sender.hpp b/proton-c/bindings/cpp/include/proton/Sender.hpp index bb39b6d..3a3ee41 100644 --- a/proton-c/bindings/cpp/include/proton/Sender.hpp +++ b/proton-c/bindings/cpp/include/proton/Sender.hpp @@ -47,6 +47,6 @@ class Sender : public Link }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_SENDER_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Session.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Session.hpp b/proton-c/bindings/cpp/include/proton/Session.hpp index 4a3eccc..1f19b32 100644 --- a/proton-c/bindings/cpp/include/proton/Session.hpp +++ b/proton-c/bindings/cpp/include/proton/Session.hpp @@ -57,7 +57,6 @@ class Transport; friend class ProtonImplRef<Session>; }; - -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_SESSION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Terminus.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Terminus.hpp b/proton-c/bindings/cpp/include/proton/Terminus.hpp index 0b798b3..b13165e 100644 --- a/proton-c/bindings/cpp/include/proton/Terminus.hpp +++ b/proton-c/bindings/cpp/include/proton/Terminus.hpp @@ -76,6 +76,6 @@ class Terminus : public ProtonHandle<pn_terminus_t> }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_TERMINUS_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Transport.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Transport.hpp b/proton-c/bindings/cpp/include/proton/Transport.hpp index ca93674..f81e483 100644 --- a/proton-c/bindings/cpp/include/proton/Transport.hpp +++ b/proton-c/bindings/cpp/include/proton/Transport.hpp @@ -43,6 +43,6 @@ class Transport }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_TRANSPORT_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Value.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Value.hpp b/proton-c/bindings/cpp/include/proton/Value.hpp index 9448dc5..a5f2edf 100644 --- a/proton-c/bindings/cpp/include/proton/Value.hpp +++ b/proton-c/bindings/cpp/include/proton/Value.hpp @@ -21,23 +21,29 @@ #include "proton/Values.hpp" +struct pn_data_t; + /**@file * Holder for an AMQP value. * @ingroup cpp */ namespace proton { -namespace reactor { /** Holds a single AMQP value. */ PN_CPP_EXTERN class Value { public: - PN_CPP_EXTERN Value(); - PN_CPP_EXTERN Value(const Value&); + Value(); + Value(const Value&); + /** Converting constructor from any settable value */ template <class T> explicit Value(const T& v); - PN_CPP_EXTERN ~Value(); - PN_CPP_EXTERN Value& operator=(const Value&); + ~Value(); + + Value& operator=(const Value&); + + /** Copy the first value from a raw pn_data_t. */ + Value& operator=(pn_data_t*); TypeId type() const; @@ -55,13 +61,13 @@ PN_CPP_EXTERN class Value { template<class T> operator T() const; /** insert a value into an Encoder. */ - PN_CPP_EXTERN friend Encoder& operator<<(Encoder&, const Value&); + friend Encoder& operator<<(Encoder&, const Value&); /** Extract a value from a decoder. */ - PN_CPP_EXTERN friend Decoder& operator>>(Decoder&, Value&); + friend Decoder& operator>>(Decoder&, Value&); /** Human readable format */ - PN_CPP_EXTERN friend std::ostream& operator<<(std::ostream&, const Value&); + friend std::ostream& operator<<(std::ostream&, const Value&); bool operator==(const Value&) const; bool operator !=(const Value& v) const{ return !(*this == v); } @@ -93,6 +99,6 @@ template<class T> Value& Value::operator=(const T& value) { set(value); return * template<class T> Value::operator T() const { return get<T>(); } template<class T> Value::Value(const T& value) { set(value); } -}} +} #endif // VALUE_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/Values.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/Values.hpp b/proton-c/bindings/cpp/include/proton/Values.hpp index 0377c0c..604d2be 100644 --- a/proton-c/bindings/cpp/include/proton/Values.hpp +++ b/proton-c/bindings/cpp/include/proton/Values.hpp @@ -28,7 +28,7 @@ */ namespace proton { -namespace reactor { + /** Holds a sequence of AMQP values, allows inserting and extracting. * @@ -38,19 +38,24 @@ PN_CPP_EXTERN class Values : public Encoder, public Decoder { public: Values(); Values(const Values&); + + /** Does not take ownership, just a view on the data */ + Values(pn_data_t*); + ~Values(); /** Copy data from another Values */ Values& operator=(const Values&); - PN_CPP_EXTERN Values& rewind(); + Values& rewind(); + - private: friend class Value; + friend class Message; }; PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const Values&); -}} +} #endif // VALUES_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/WaitCondition.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/WaitCondition.hpp b/proton-c/bindings/cpp/include/proton/WaitCondition.hpp index a960c42..12c7708 100644 --- a/proton-c/bindings/cpp/include/proton/WaitCondition.hpp +++ b/proton-c/bindings/cpp/include/proton/WaitCondition.hpp @@ -40,6 +40,6 @@ class WaitCondition }; -}} // namespace proton::reactor +}} #endif /*!PROTON_CPP_WAITCONDITION_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/exceptions.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/exceptions.hpp b/proton-c/bindings/cpp/include/proton/exceptions.hpp deleted file mode 100644 index 9fdef94..0000000 --- a/proton-c/bindings/cpp/include/proton/exceptions.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef PROTON_CPP_EXCEPTIONS_H -#define PROTON_CPP_EXCEPTIONS_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -#include <stdexcept> - -namespace proton { -namespace reactor { - -class ProtonException : public std::runtime_error -{ - public: - explicit ProtonException(const std::string& msg) throw() : std::runtime_error(msg) {} -}; - -class MessageReject : public ProtonException -{ - public: - explicit MessageReject(const std::string& msg) throw() : ProtonException(msg) {} -}; - -class MessageRelease : public ProtonException -{ - public: - explicit MessageRelease(const std::string& msg) throw() : ProtonException(msg) {} -}; - -}} // namespace proton::reactor - -#endif /*!PROTON_CPP_EXCEPTIONS_H*/ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/include/proton/types.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/types.hpp b/proton-c/bindings/cpp/include/proton/types.hpp index 819abb1..62b2f53 100644 --- a/proton-c/bindings/cpp/include/proton/types.hpp +++ b/proton-c/bindings/cpp/include/proton/types.hpp @@ -33,7 +33,7 @@ */ namespace proton { -namespace reactor { + /** TypeId identifies an AMQP type */ enum TypeId { @@ -98,11 +98,14 @@ typedef double Double; ///@internal pn_bytes_t pn_bytes(const std::string&); +//@internal +std::string str(const pn_bytes_t& b); ///@internal #define STRING_LIKE(NAME) \ PN_CPP_EXTERN struct NAME : public std::string{ \ NAME(const std::string& s=std::string()) : std::string(s) {} \ + NAME(const char* s) : std::string(s) {} \ NAME(const pn_bytes_t& b) : std::string(b.start, b.size) {} \ operator pn_bytes_t() const { return pn_bytes(*this); } \ } @@ -141,10 +144,11 @@ typedef Decimal<pn_decimal32_t> Decimal32; typedef Decimal<pn_decimal64_t> Decimal64; typedef Decimal<pn_decimal128_t> Decimal128; -PN_CPP_EXTERN struct Timestamp { +PN_CPP_EXTERN struct Timestamp : public Comparable<Timestamp> { pn_timestamp_t milliseconds; ///< Since the epoch 00:00:00 (UTC), 1 January 1970. Timestamp(int64_t ms=0) : milliseconds(ms) {} operator pn_timestamp_t() const { return milliseconds; } + bool operator==(const Timestamp& x) { return milliseconds == x.milliseconds; } bool operator<(const Timestamp& x) { return milliseconds < x.milliseconds; } }; @@ -245,6 +249,6 @@ inline Finish finish() { return Finish(); } PN_CPP_EXTERN struct Skip{}; inline Skip skip() { return Skip(); } -}} +} #endif // TYPES_H http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/Acceptor.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Acceptor.cpp b/proton-c/bindings/cpp/src/Acceptor.cpp index 6d3d1af..2756a0a 100644 --- a/proton-c/bindings/cpp/src/Acceptor.cpp +++ b/proton-c/bindings/cpp/src/Acceptor.cpp @@ -20,7 +20,7 @@ */ #include "proton/Acceptor.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "ProtonImplRef.hpp" #include "Msg.hpp" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/Connection.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Connection.cpp b/proton-c/bindings/cpp/src/Connection.cpp index 006b567..2f31013 100644 --- a/proton-c/bindings/cpp/src/Connection.cpp +++ b/proton-c/bindings/cpp/src/Connection.cpp @@ -21,7 +21,7 @@ #include "proton/Container.hpp" #include "proton/Connection.hpp" #include "proton/Handler.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "Msg.hpp" #include "contexts.hpp" #include "ConnectionImpl.hpp" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/ConnectionImpl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ConnectionImpl.cpp b/proton-c/bindings/cpp/src/ConnectionImpl.cpp index 450d504..5fa2fb2 100644 --- a/proton-c/bindings/cpp/src/ConnectionImpl.cpp +++ b/proton-c/bindings/cpp/src/ConnectionImpl.cpp @@ -20,7 +20,7 @@ */ #include "proton/Container.hpp" #include "proton/Handler.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "ConnectionImpl.hpp" #include "proton/Transport.hpp" #include "Msg.hpp" @@ -73,7 +73,7 @@ ConnectionImpl::~ConnectionImpl() { Transport &ConnectionImpl::getTransport() { if (transport) return *transport; - throw ProtonException(MSG("Connection has no transport")); + throw Error(MSG("Connection has no transport")); } Handler* ConnectionImpl::getOverride() { return override; } @@ -99,7 +99,7 @@ std::string ConnectionImpl::getHostname() { Connection &ConnectionImpl::getConnection() { // Endpoint interface. Should be implemented in the Connection object. - throw ProtonException(MSG("Internal error")); + throw Error(MSG("Internal error")); } Container &ConnectionImpl::getContainer() { @@ -117,16 +117,16 @@ void ConnectionImpl::reactorDetach() { Connection &ConnectionImpl::getReactorReference(pn_connection_t *conn) { if (!conn) - throw ProtonException(MSG("Null Proton connection")); + throw Error(MSG("Null Proton connection")); ConnectionImpl *impl = getConnectionContext(conn); if (!impl) { // First time we have seen this connection pn_reactor_t *reactor = pn_object_reactor(conn); if (!reactor) - throw ProtonException(MSG("Invalid Proton connection specifier")); + throw Error(MSG("Invalid Proton connection specifier")); Container container(getContainerContext(reactor)); if (!container) // can't be one created by our container - throw ProtonException(MSG("Unknown Proton connection specifier")); + throw Error(MSG("Unknown Proton connection specifier")); impl = new ConnectionImpl(container, *conn); } return impl->reactorReference; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/Container.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Container.cpp b/proton-c/bindings/cpp/src/Container.cpp index 4fa6c6a..16de0c1 100644 --- a/proton-c/bindings/cpp/src/Container.cpp +++ b/proton-c/bindings/cpp/src/Container.cpp @@ -24,7 +24,7 @@ #include "proton/Session.hpp" #include "proton/MessagingAdapter.hpp" #include "proton/Acceptor.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "ContainerImpl.hpp" #include "PrivateImplRef.hpp" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/ContainerImpl.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/ContainerImpl.cpp b/proton-c/bindings/cpp/src/ContainerImpl.cpp index 80137b5..29c1e72 100644 --- a/proton-c/bindings/cpp/src/ContainerImpl.cpp +++ b/proton-c/bindings/cpp/src/ContainerImpl.cpp @@ -24,7 +24,7 @@ #include "proton/Session.hpp" #include "proton/MessagingAdapter.hpp" #include "proton/Acceptor.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "Msg.hpp" #include "ContainerImpl.hpp" @@ -205,7 +205,7 @@ ContainerImpl::~ContainerImpl() { } Connection ContainerImpl::connect(std::string &host, Handler *h) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); Container cntnr(this); Connection connection(cntnr, handler); Connector *connector = new Connector(connection); @@ -229,17 +229,17 @@ Duration ContainerImpl::getTimeout() { } void ContainerImpl::setTimeout(Duration timeout) { - if (timeout == Duration::FOREVER || timeout.getMilliseconds() > PN_MILLIS_MAX) + if (timeout == Duration::FOREVER || timeout.milliseconds > PN_MILLIS_MAX) pn_reactor_set_timeout(reactor, PN_MILLIS_MAX); else { - pn_millis_t tmo = timeout.getMilliseconds(); + pn_millis_t tmo = timeout.milliseconds; pn_reactor_set_timeout(reactor, tmo); } } Sender ContainerImpl::createSender(Connection &connection, std::string &addr, Handler *h) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); Session session = getDefaultSession(connection.getPnConnection(), &getImpl(connection)->defaultSession); Sender snd = session.createSender(containerId + '-' + addr); pn_link_t *lnk = snd.getPnLink(); @@ -253,7 +253,7 @@ Sender ContainerImpl::createSender(Connection &connection, std::string &addr, Ha } Sender ContainerImpl::createSender(std::string &urlString) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); Connection conn = connect(urlString, 0); Session session = getDefaultSession(conn.getPnConnection(), &getImpl(conn)->defaultSession); std::string path = Url(urlString).getPath(); @@ -264,7 +264,7 @@ Sender ContainerImpl::createSender(std::string &urlString) { } Receiver ContainerImpl::createReceiver(Connection &connection, std::string &addr) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); ConnectionImpl *connImpl = getImpl(connection); Session session = getDefaultSession(connImpl->pnConnection, &connImpl->defaultSession); Receiver rcv = session.createReceiver(containerId + '-' + addr); @@ -274,7 +274,7 @@ Receiver ContainerImpl::createReceiver(Connection &connection, std::string &addr } Receiver ContainerImpl::createReceiver(const std::string &urlString) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); // TODO: const cleanup of API Connection conn = connect(const_cast<std::string &>(urlString), 0); Session session = getDefaultSession(conn.getPnConnection(), &getImpl(conn)->defaultSession); @@ -290,11 +290,11 @@ Acceptor ContainerImpl::acceptor(const std::string &host, const std::string &por if (acptr) return Acceptor(acptr); else - throw ProtonException(MSG("accept fail: " << pn_error_text(pn_io_error(pn_reactor_io(reactor))) << "(" << host << ":" << port << ")")); + throw Error(MSG("accept fail: " << pn_error_text(pn_io_error(pn_reactor_io(reactor))) << "(" << host << ":" << port << ")")); } Acceptor ContainerImpl::listen(const std::string &urlString) { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); Url url(urlString); // TODO: SSL return acceptor(url.getHost(), url.getPort()); @@ -307,7 +307,7 @@ pn_handler_t *ContainerImpl::wrapHandler(Handler *h) { void ContainerImpl::initializeReactor() { - if (reactor) throw ProtonException(MSG("Container already running")); + if (reactor) throw Error(MSG("Container already running")); reactor = pn_reactor(); // Set our context on the reactor @@ -343,26 +343,26 @@ void ContainerImpl::start() { } bool ContainerImpl::process() { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); bool result = pn_reactor_process(reactor); // TODO: check errors return result; } void ContainerImpl::stop() { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); pn_reactor_stop(reactor); // TODO: check errors } void ContainerImpl::wakeup() { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); pn_reactor_wakeup(reactor); // TODO: check errors } bool ContainerImpl::isQuiesced() { - if (!reactor) throw ProtonException(MSG("Container not started")); + if (!reactor) throw Error(MSG("Container not started")); return pn_reactor_quiesced(reactor); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/Data.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Data.cpp b/proton-c/bindings/cpp/src/Data.cpp index 3cfa715..dc017ae 100644 --- a/proton-c/bindings/cpp/src/Data.cpp +++ b/proton-c/bindings/cpp/src/Data.cpp @@ -18,20 +18,39 @@ */ #include "proton/Data.hpp" -#include <proton/codec.h> +#include "proton/codec.h" #include "proton_bits.hpp" +#include <utility> namespace proton { -namespace reactor { -Data::Data(pn_data_t* p) : data(p ? p : pn_data(0)) {} +Data::Data() : data(pn_data(0)), own_(true) {} -Data::~Data() { if (data) pn_data_free(data); } +Data::Data(pn_data_t* p) : data(p), own_(false) { } + +Data::Data(const Data& x) : data(pn_data(0)), own_(true) { *this = x; } + +Data::~Data() { if (own_ && data) pn_data_free(data); } + +void Data::view(pn_data_t* newData) { + if (data && own_) pn_data_free(data); + data = newData; + own_ = false; +} + +void Data::swap(Data& x) { + std::swap(data, x.data); + std::swap(own_, x.own_); +} Data& Data::operator=(const Data& x) { if (this != &x) { - pn_data_free(data); - data = pn_data(pn_data_size(x.data)); + if (!own_) { + data = pn_data(pn_data_size(x.data)); + own_ = true; + } else { + clear(); + } pn_data_copy(data, x.data); } return *this; @@ -41,6 +60,6 @@ void Data::clear() { pn_data_clear(data); } bool Data::empty() const { return pn_data_size(data) == 0; } -std::ostream& operator<<(std::ostream& o, const Data& d) { return o << Object(d.data); } +std::ostream& operator<<(std::ostream& o, const Data& d) { return o << PnObject(d.data); } -}} // namespace proton::reactor +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/proton-c/bindings/cpp/src/Decoder.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/Decoder.cpp b/proton-c/bindings/cpp/src/Decoder.cpp index 6f5b73b..50e6a12 100644 --- a/proton-c/bindings/cpp/src/Decoder.cpp +++ b/proton-c/bindings/cpp/src/Decoder.cpp @@ -24,8 +24,6 @@ #include "Msg.hpp" namespace proton { -namespace reactor { - /**@file * @@ -38,6 +36,8 @@ Decoder::Decoder(const char* buffer, size_t size) { decode(buffer, size); } Decoder::Decoder(const std::string& buffer) { decode(buffer); } Decoder::~Decoder() {} +DecodeError::DecodeError(const std::string& msg) throw() : Error("decode: "+msg) {} + namespace { struct SaveState { pn_data_t* data; @@ -55,12 +55,10 @@ struct Narrow { template <class T> T check(T result) { if (result < 0) - throw Decoder::Error("decode: " + errorStr(result)); + throw DecodeError("" + errorStr(result)); return result; } -std::string str(const pn_bytes_t& b) { return std::string(b.start, b.size); } - } void Decoder::decode(const char* i, size_t size) { @@ -84,13 +82,13 @@ namespace { void badType(TypeId want, TypeId got) { if (want != got) - throw Decoder::Error("decode: expected "+typeName(want)+" found "+typeName(got)); + throw DecodeError("expected "+typeName(want)+" found "+typeName(got)); } TypeId preGet(pn_data_t* data) { - if (!pn_data_next(data)) throw Decoder::Error("decode: no more data"); + if (!pn_data_next(data)) throw DecodeError("no more data"); TypeId t = TypeId(pn_data_type(data)); - if (t < 0) throw Decoder::Error("decode: invalid data"); + if (t < 0) throw DecodeError("invalid data"); return t; } @@ -134,7 +132,7 @@ Decoder& operator>>(Decoder& d, Start& s) { s.size = 1; break; default: - throw Decoder::Error(MSG("decode: " << s.type << " is not a container type")); + throw DecodeError(MSG("" << s.type << " is not a container type")); } pn_data_enter(d.data); ss.cancel(); @@ -146,13 +144,13 @@ Decoder& operator>>(Decoder& d, Finish) { pn_data_exit(d.data); return d; } Decoder& operator>>(Decoder& d, Skip) { pn_data_next(d.data); return d; } Decoder& operator>>(Decoder& d, Value& v) { - if (d.data == v.values.data) throw Decoder::Error("decode: extract into self"); + if (d.data == v.values.data) throw DecodeError("extract into self"); pn_data_clear(v.values.data); { Narrow n(d.data); check(pn_data_appendn(v.values.data, d.data, 1)); } - if (!pn_data_next(d.data)) throw Decoder::Error("decode: no more data"); + if (!pn_data_next(d.data)) throw DecodeError("no more data"); return d; } @@ -325,4 +323,4 @@ Decoder& operator>>(Decoder& d, std::string& value) { return d; } -}} // namespace proton::reactor +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/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 index 1c5c5ea..7a11819 100644 --- a/proton-c/bindings/cpp/src/Duration.cpp +++ b/proton-c/bindings/cpp/src/Duration.cpp @@ -22,34 +22,10 @@ #include <limits> namespace proton { -namespace reactor { - -Duration::Duration(uint64_t ms) : milliseconds(ms) {} -uint64_t Duration::getMilliseconds() const { return milliseconds; } - -Duration operator*(const Duration& duration, uint64_t multiplier) -{ - return Duration(duration.getMilliseconds() * multiplier); -} - -Duration operator*(uint64_t multiplier, const Duration& duration) -{ - return Duration(duration.getMilliseconds() * multiplier); -} - -bool operator==(const Duration& a, const Duration& b) -{ - return a.getMilliseconds() == b.getMilliseconds(); -} - -bool operator!=(const Duration& a, const Duration& b) -{ - return a.getMilliseconds() != b.getMilliseconds(); -} const Duration Duration::FOREVER(std::numeric_limits<uint64_t>::max()); const Duration Duration::IMMEDIATE(0); const Duration Duration::SECOND(1000); const Duration Duration::MINUTE(SECOND * 60); -}} // namespace proton::reactor +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/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 index 0bd6943..892c338 100644 --- a/proton-c/bindings/cpp/src/Encoder.cpp +++ b/proton-c/bindings/cpp/src/Encoder.cpp @@ -24,11 +24,12 @@ #include "Msg.hpp" namespace proton { -namespace reactor { Encoder::Encoder() {} Encoder::~Encoder() {} +EncodeError::EncodeError(const std::string& msg) throw() : Error("encode: "+msg) {} + namespace { struct SaveState { pn_data_t* data; @@ -40,7 +41,7 @@ struct SaveState { void check(int result, pn_data_t* data) { if (result < 0) - throw Encoder::Error("encode: " + errorStr(pn_data_error(data), result)); + throw EncodeError(errorStr(pn_data_error(data), result)); } } @@ -82,7 +83,7 @@ Encoder& operator<<(Encoder& e, const Start& s) { case LIST: pn_data_put_list(e.data); break; case DESCRIBED: pn_data_put_described(e.data); break; default: - throw Encoder::Error(MSG("encode: " << s.type << " is not a container type")); + throw EncodeError(MSG("" << s.type << " is not a container type")); } pn_data_enter(e.data); return e; @@ -150,9 +151,9 @@ 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 Encoder::Error("encode: cannot insert into self"); + 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; } -}} // namespace proton::reactor +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/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 new file mode 100644 index 0000000..e97bf5f --- /dev/null +++ b/proton-c/bindings/cpp/src/Error.cpp @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "proton/Error.hpp" + +namespace proton { + +Error::Error(const std::string& msg) throw() : std::runtime_error("proton: "+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/327f358e/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 index 937e3ed..69825a8 100644 --- a/proton-c/bindings/cpp/src/Event.cpp +++ b/proton-c/bindings/cpp/src/Event.cpp @@ -24,7 +24,7 @@ #include "proton/Event.hpp" #include "proton/Handler.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "Msg.hpp" #include "contexts.hpp" @@ -39,31 +39,31 @@ Event::~Event() {} Container &Event::getContainer() { // Subclasses to override as appropriate - throw ProtonException(MSG("No container context for event")); + throw Error(MSG("No container context for event")); } Connection &Event::getConnection() { - throw ProtonException(MSG("No connection context for Event")); + throw Error(MSG("No connection context for Event")); } Sender Event::getSender() { - throw ProtonException(MSG("No Sender context for event")); + throw Error(MSG("No Sender context for event")); } Receiver Event::getReceiver() { - throw ProtonException(MSG("No Receiver context for event")); + throw Error(MSG("No Receiver context for event")); } Link Event::getLink() { - throw ProtonException(MSG("No Link context for event")); + throw Error(MSG("No Link context for event")); } Message Event::getMessage() { - throw ProtonException(MSG("No message associated with event")); + throw Error(MSG("No message associated with event")); } void Event::setMessage(Message &) { - throw ProtonException(MSG("Operation not supported for this type of event")); + throw Error(MSG("Operation not supported for this type of event")); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/327f358e/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 index 9065524..76c100c 100644 --- a/proton-c/bindings/cpp/src/Link.cpp +++ b/proton-c/bindings/cpp/src/Link.cpp @@ -19,7 +19,7 @@ * */ #include "proton/Link.hpp" -#include "proton/exceptions.hpp" +#include "proton/Error.hpp" #include "proton/Connection.hpp" #include "ConnectionImpl.hpp" #include "Msg.hpp" --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
