Repository: qpid-proton Updated Branches: refs/heads/master 54b297f3d -> 04e948972
PROTON-1163: Start to use C++11 override to catch problems with handlers - Add #define to null out override if c++ earlier than C++11 Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/04e94897 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/04e94897 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/04e94897 Branch: refs/heads/master Commit: 04e948972204eb1f6cb150582827a6c9554c5713 Parents: 54b297f Author: Andrew Stitcher <[email protected]> Authored: Fri Mar 18 15:14:13 2016 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Tue Mar 22 15:00:16 2016 -0400 ---------------------------------------------------------------------- examples/cpp/broker.cpp | 4 ++- examples/cpp/broker.hpp | 17 ++++++------ examples/cpp/client.cpp | 8 +++--- examples/cpp/connection_options.cpp | 6 +++-- examples/cpp/direct_recv.cpp | 6 +++-- examples/cpp/direct_send.cpp | 12 +++++---- examples/cpp/engine/broker.cpp | 5 +++- examples/cpp/engine/client.cpp | 8 +++--- examples/cpp/engine/direct_recv.cpp | 6 +++-- examples/cpp/engine/direct_send.cpp | 10 ++++--- examples/cpp/engine/helloworld.cpp | 8 +++--- examples/cpp/engine/server.cpp | 6 +++-- examples/cpp/engine/simple_recv.cpp | 6 ++--- examples/cpp/engine/simple_send.cpp | 10 ++++--- examples/cpp/fake_cpp11.hpp | 36 ++++++++++++++++++++++++++ examples/cpp/helloworld.cpp | 8 +++--- examples/cpp/helloworld_direct.cpp | 12 +++++---- examples/cpp/queue_browser.cpp | 6 +++-- examples/cpp/recurring_timer.cpp | 6 +++-- examples/cpp/selected_recv.cpp | 6 +++-- examples/cpp/server.cpp | 6 +++-- examples/cpp/server_direct.cpp | 8 +++--- examples/cpp/simple_recv.cpp | 18 +++++++------ examples/cpp/simple_send.cpp | 16 +++++++----- examples/cpp/ssl.cpp | 14 +++++----- examples/cpp/ssl_client_cert.cpp | 14 +++++----- proton-c/bindings/cpp/src/engine_test.cpp | 16 +++++++----- 27 files changed, 183 insertions(+), 95 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/broker.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/broker.cpp b/examples/cpp/broker.cpp index ae42b20..39a725c 100644 --- a/examples/cpp/broker.cpp +++ b/examples/cpp/broker.cpp @@ -32,6 +32,8 @@ #include <list> #include <string> +#include "fake_cpp11.hpp" + class broker { public: broker(const proton::url& url) : handler_(url, queues_) {} @@ -43,7 +45,7 @@ class broker { public: my_handler(const proton::url& u, queues& qs) : broker_handler(qs), url_(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.container().listen(url_); std::cout << "broker listening on " << url_ << std::endl; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/broker.hpp ---------------------------------------------------------------------- diff --git a/examples/cpp/broker.hpp b/examples/cpp/broker.hpp index de84b32..37f27b8 100644 --- a/examples/cpp/broker.hpp +++ b/examples/cpp/broker.hpp @@ -147,13 +147,14 @@ class queues { uint64_t next_id_; // Use to generate unique queue IDs. }; +#include "fake_cpp11.hpp" /** Common handler logic for brokers. */ class broker_handler : public proton::handler { public: broker_handler(queues& qs) : queues_(qs) {} - void on_link_open(proton::event &e) { + void on_link_open(proton::event &e) override { proton::link lnk = e.link(); if (!!lnk.sender()) { @@ -182,7 +183,7 @@ class broker_handler : public proton::handler { } } - void on_link_close(proton::event &e) { + void on_link_close(proton::event &e) override { proton::link lnk = e.link(); if (!!lnk.sender()) { @@ -190,19 +191,19 @@ class broker_handler : public proton::handler { } } - void on_connection_close(proton::event &e) { + void on_connection_close(proton::event &e) override { remove_stale_consumers(e.connection()); } - void on_transport_close(proton::event &e) { + void on_transport_close(proton::event &e) override { remove_stale_consumers(e.connection()); } - void on_transport_error(proton::event &e) { + void on_transport_error(proton::event &e) override { std::cout << "broker client disconnect: " << e.transport().condition().what() << std::endl; } - void on_unhandled_error(proton::event &e, const proton::condition &c) { + void on_unhandled_error(proton::event &e, const proton::condition &c) override { std::cerr << "broker error: " << e.name() << ":" << c.what() << std::endl; } @@ -214,7 +215,7 @@ class broker_handler : public proton::handler { } } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::link lnk = e.link(); std::string address = lnk.local_source().address(); proton::sender s = lnk.sender(); @@ -222,7 +223,7 @@ class broker_handler : public proton::handler { queues_.get(address).dispatch(&s); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::string address = e.link().local_target().address(); queues_.get(address).publish(e.message(), e.link().receiver()); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/client.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/client.cpp b/examples/cpp/client.cpp index 43ccb3c..cb2b748 100644 --- a/examples/cpp/client.cpp +++ b/examples/cpp/client.cpp @@ -28,6 +28,8 @@ #include <iostream> #include <vector> +#include "fake_cpp11.hpp" + class client : public proton::handler { private: proton::url url; @@ -38,7 +40,7 @@ class client : public proton::handler { public: client(const proton::url &u, const std::vector<std::string>& r) : url(u), requests(r) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { sender = e.container().open_sender(url); // Create a receiver with a dynamically chosen unique address. receiver = sender.connection().open_receiver("", proton::link_options().dynamic_address(true)); @@ -52,13 +54,13 @@ class client : public proton::handler { sender.send(req); } - void on_link_open(proton::event &e) { + void on_link_open(proton::event &e) override { if (e.link() == receiver) { send_request(); } } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { if (requests.empty()) return; // Spurious extra message! proton::message& response = e.message(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/connection_options.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/connection_options.cpp b/examples/cpp/connection_options.cpp index 1052b55..0e5eecf 100644 --- a/examples/cpp/connection_options.cpp +++ b/examples/cpp/connection_options.cpp @@ -29,6 +29,8 @@ using proton::connection_options; +#include "fake_cpp11.hpp" + class handler_2 : public proton::handler { void on_connection_open(proton::event &e) { std::cout << "connection events going to handler_2" << std::endl; @@ -46,13 +48,13 @@ class main_handler : public proton::handler { public: main_handler(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { // Connection options for this connection. Merged with and overriding the container's // client_connection_options() settings. e.container().connect(url, connection_options().handler(&conn_handler).max_frame_size(2468)); } - void on_connection_open(proton::event &e) { + void on_connection_open(proton::event &e) override { std::cout << "unexpected connection event on main handler" << std::endl; e.connection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/direct_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/direct_recv.cpp b/examples/cpp/direct_recv.cpp index 89bb966..ec62c96 100644 --- a/examples/cpp/direct_recv.cpp +++ b/examples/cpp/direct_recv.cpp @@ -32,6 +32,8 @@ #include <iostream> #include <map> +#include "fake_cpp11.hpp" + class direct_recv : public proton::handler { private: proton::url url; @@ -42,12 +44,12 @@ class direct_recv : public proton::handler { public: direct_recv(const std::string &s, int c) : url(s), expected(c), received(0) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { acceptor = e.container().listen(url); std::cout << "direct_recv listening on " << url << std::endl; } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { proton::message& msg = e.message(); if (proton::coerce<uint64_t>(msg.id()) < received) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/direct_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/direct_send.cpp b/examples/cpp/direct_send.cpp index edd7102..fcede83 100644 --- a/examples/cpp/direct_send.cpp +++ b/examples/cpp/direct_send.cpp @@ -31,6 +31,8 @@ #include <iostream> #include <map> +#include "fake_cpp11.hpp" + class simple_send : public proton::handler { private: proton::url url; @@ -42,12 +44,12 @@ class simple_send : public proton::handler { public: simple_send(const std::string &s, int c) : url(s), sent(0), confirmed(0), total(c) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { acceptor = e.container().listen(url); std::cout << "direct_send listening on " << url << std::endl; } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::sender sender = e.sender(); while (sender.credit() && sent < total) { @@ -63,7 +65,7 @@ class simple_send : public proton::handler { } } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { confirmed++; if (confirmed == total) { @@ -74,7 +76,7 @@ class simple_send : public proton::handler { } } - void on_transport_close(proton::event &e) { + void on_transport_close(proton::event &e) override { sent = confirmed; } }; @@ -83,7 +85,7 @@ int main(int argc, char **argv) { std::string address("127.0.0.1:5672/examples"); int message_count = 100; options opts(argc, argv); - + opts.add_value(address, 'a', "address", "listen and send on URL", "URL"); opts.add_value(message_count, 'm', "messages", "send COUNT messages", "COUNT"); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/broker.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/broker.cpp b/examples/cpp/engine/broker.cpp index f5e9205..de08991 100644 --- a/examples/cpp/engine/broker.cpp +++ b/examples/cpp/engine/broker.cpp @@ -29,6 +29,9 @@ #include "proton/container.hpp" #include "proton/value.hpp" + +#include "fake_cpp11.hpp" + class broker { public: broker(const proton::url& url) : handler_(url, queues_) {} @@ -41,7 +44,7 @@ class broker { public: my_handler(const proton::url& u, queues& qs) : broker_handler(qs), url_(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.container().listen(url_); std::cout << "broker listening on " << url_ << std::endl; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/client.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/client.cpp b/examples/cpp/engine/client.cpp index a010d0f..d2d37c0 100644 --- a/examples/cpp/engine/client.cpp +++ b/examples/cpp/engine/client.cpp @@ -29,6 +29,8 @@ #include <iostream> #include <vector> +#include "../fake_cpp11.hpp" + class client : public proton::handler { private: proton::url url; @@ -39,7 +41,7 @@ class client : public proton::handler { public: client(const proton::url &u, const std::vector<std::string>& r) : url(u), requests(r) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); sender = e.connection().open_sender(url.path()); receiver = e.connection().open_receiver("", proton::link_options().dynamic_address(true)); @@ -52,12 +54,12 @@ class client : public proton::handler { sender.send(req); } - void on_link_open(proton::event &e) { + void on_link_open(proton::event &e) override { if (e.link() == receiver) send_request(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { if (requests.empty()) return; // Spurious extra message! proton::message& response = e.message(); std::cout << requests.front() << " => " << response.body() << std::endl; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/direct_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/direct_recv.cpp b/examples/cpp/engine/direct_recv.cpp index 3579310..3fcc28e 100644 --- a/examples/cpp/engine/direct_recv.cpp +++ b/examples/cpp/engine/direct_recv.cpp @@ -31,6 +31,8 @@ #include <iostream> #include <map> +#include "../fake_cpp11.hpp" + class direct_recv : public proton::handler { private: uint64_t expected; @@ -39,11 +41,11 @@ class direct_recv : public proton::handler { public: direct_recv(int c) : expected(c), received(0) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { proton::message& msg = e.message(); if (msg.id().get<uint64_t>() < received) return; // ignore duplicate http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/direct_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/direct_send.cpp b/examples/cpp/engine/direct_send.cpp index e3c632d..28ea845 100644 --- a/examples/cpp/engine/direct_send.cpp +++ b/examples/cpp/engine/direct_send.cpp @@ -32,6 +32,8 @@ #include <iostream> #include <map> +#include "../fake_cpp11.hpp" + class simple_send : public proton::handler { private: int sent; @@ -40,11 +42,11 @@ class simple_send : public proton::handler { public: simple_send(int c) : sent(0), confirmed(0), total(c) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::sender sender = e.sender(); while (sender.credit() && sent < total) { proton::message msg; @@ -57,7 +59,7 @@ class simple_send : public proton::handler { } } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { confirmed++; if (confirmed == total) { std::cout << "all messages confirmed" << std::endl; @@ -65,7 +67,7 @@ class simple_send : public proton::handler { } } - void on_transport_close(proton::event &e) { + void on_transport_close(proton::event &e) override { sent = confirmed; } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/helloworld.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/helloworld.cpp b/examples/cpp/engine/helloworld.cpp index 43c4a03..d5a9f44 100644 --- a/examples/cpp/engine/helloworld.cpp +++ b/examples/cpp/engine/helloworld.cpp @@ -26,6 +26,8 @@ #include <iostream> +#include "../fake_cpp11.hpp" + class hello_world : public proton::handler { private: std::string address_; @@ -33,19 +35,19 @@ class hello_world : public proton::handler { public: hello_world(const std::string& address) : address_(address) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); e.connection().open_receiver(address_); e.connection().open_sender(address_); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::message m("Hello World!"); e.sender().send(m); e.sender().close(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; e.connection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/server.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/server.cpp b/examples/cpp/engine/server.cpp index 92ee044..794d27e 100644 --- a/examples/cpp/engine/server.cpp +++ b/examples/cpp/engine/server.cpp @@ -33,6 +33,8 @@ #include <string> #include <cctype> +#include "../fake_cpp11.hpp" + class server : public proton::handler { private: typedef std::map<std::string, proton::sender> sender_map; @@ -43,7 +45,7 @@ class server : public proton::handler { server(const std::string &u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); e.connection().open_receiver(url.path()); std::cout << "server connected to " << url << std::endl; @@ -56,7 +58,7 @@ class server : public proton::handler { return uc; } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << "Received " << e.message().body() << std::endl; std::string reply_to = e.message().reply_to(); proton::message reply; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/simple_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/simple_recv.cpp b/examples/cpp/engine/simple_recv.cpp index 1d07a96..5b6cf21 100644 --- a/examples/cpp/engine/simple_recv.cpp +++ b/examples/cpp/engine/simple_recv.cpp @@ -32,7 +32,7 @@ #include <iostream> #include <map> - +#include "../fake_cpp11.hpp" class simple_recv : public proton::handler { private: @@ -44,13 +44,13 @@ class simple_recv : public proton::handler { simple_recv(const std::string &s, int c) : url(s), expected(c), received(0) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); receiver = e.connection().open_receiver(url.path()); std::cout << "simple_recv listening on " << url << std::endl; } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { proton::message& msg = e.message(); if (msg.id().get<uint64_t>() < received) return; // ignore duplicate http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/engine/simple_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/engine/simple_send.cpp b/examples/cpp/engine/simple_send.cpp index 5bb0142..39d8939 100644 --- a/examples/cpp/engine/simple_send.cpp +++ b/examples/cpp/engine/simple_send.cpp @@ -31,6 +31,8 @@ #include <iostream> #include <map> +#include "../fake_cpp11.hpp" + class simple_send : public proton::handler { private: proton::url url; @@ -42,12 +44,12 @@ class simple_send : public proton::handler { simple_send(const std::string &s, int c) : url(s), sent(0), confirmed(0), total(c) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.connection().open(); sender = e.connection().open_sender(url.path()); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::sender sender = e.sender(); while (sender.credit() && sent < total) { proton::message msg; @@ -60,7 +62,7 @@ class simple_send : public proton::handler { } } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { confirmed++; if (confirmed == total) { std::cout << "all messages confirmed" << std::endl; @@ -68,7 +70,7 @@ class simple_send : public proton::handler { } } - void on_transport_close(proton::event &e) { + void on_transport_close(proton::event &e) override { sent = confirmed; } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/fake_cpp11.hpp ---------------------------------------------------------------------- diff --git a/examples/cpp/fake_cpp11.hpp b/examples/cpp/fake_cpp11.hpp new file mode 100644 index 0000000..235484d --- /dev/null +++ b/examples/cpp/fake_cpp11.hpp @@ -0,0 +1,36 @@ +#ifndef FAKE_CPP11_HPP +#define FAKE_CPP11_HPP + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/// These definitions allow us to use some new C++11 features in previous compilers +/// by defining the new keywords to macro replace with nothing. +/// +/// This is a bit of a hack and works with this small controlled source base because +/// we know we don't use any of the new context sensitive keywords anywhere. +/// +/// It is not recommended to copy this - just use C++11/C++14 instead! + +#if __cplusplus < 201103L +#define override +#endif + + +#endif // FAKE_CPP11_HPP http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/helloworld.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld.cpp b/examples/cpp/helloworld.cpp index 5d92981..a81cfbd 100644 --- a/examples/cpp/helloworld.cpp +++ b/examples/cpp/helloworld.cpp @@ -26,6 +26,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + class hello_world : public proton::handler { private: proton::url url; @@ -33,19 +35,19 @@ class hello_world : public proton::handler { public: hello_world(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { proton::connection conn = e.container().connect(url); conn.open_receiver(url.path()); conn.open_sender(url.path()); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::message m("Hello World!"); e.sender().send(m); e.sender().close(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; e.connection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/helloworld_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/helloworld_direct.cpp b/examples/cpp/helloworld_direct.cpp index 05ae8a2..11b1c9c 100644 --- a/examples/cpp/helloworld_direct.cpp +++ b/examples/cpp/helloworld_direct.cpp @@ -26,6 +26,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + class hello_world_direct : public proton::handler { private: proton::url url; @@ -34,26 +36,26 @@ class hello_world_direct : public proton::handler { public: hello_world_direct(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { acceptor = e.container().listen(url); e.container().open_sender(url); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::message m("Hello World!"); e.sender().send(m); e.sender().close(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { e.connection().close(); } - void on_connection_close(proton::event &e) { + void on_connection_close(proton::event &e) override { acceptor.close(); } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/queue_browser.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/queue_browser.cpp b/examples/cpp/queue_browser.cpp index 02c0b30..c5b71e8 100644 --- a/examples/cpp/queue_browser.cpp +++ b/examples/cpp/queue_browser.cpp @@ -27,6 +27,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + class browser : public proton::handler { private: proton::url url; @@ -34,12 +36,12 @@ class browser : public proton::handler { public: browser(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { proton::connection conn = e.container().connect(url); conn.open_receiver(url.path(), proton::link_options().browsing(true)); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; if (e.receiver().queued() == 0 && e.receiver().drained() > 0) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/recurring_timer.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/recurring_timer.cpp b/examples/cpp/recurring_timer.cpp index a4fb4bd..5853b63 100644 --- a/examples/cpp/recurring_timer.cpp +++ b/examples/cpp/recurring_timer.cpp @@ -29,6 +29,8 @@ #include <iostream> #include <map> +#include "fake_cpp11.hpp" + class ticker : public proton::handler { void on_timer(proton::event &e) { std::cout << "Tick..." << std::endl; @@ -58,13 +60,13 @@ class recurring : public proton::handler { return e.container().schedule(tick_ms * 3, &tock_handler); } - void on_start(proton::event &e) { + void on_start(proton::event &e) override { // Demonstrate cancel(), we will cancel the first tock on the first recurring::on_timer_task cancel_task = ticktock(e); e.container().schedule(0); } - void on_timer(proton::event &e) { + void on_timer(proton::event &e) override { if (!!cancel_task) { cancel_task.cancel(); cancel_task = 0; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/selected_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/selected_recv.cpp b/examples/cpp/selected_recv.cpp index a07d9a5..df627ec 100644 --- a/examples/cpp/selected_recv.cpp +++ b/examples/cpp/selected_recv.cpp @@ -27,6 +27,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + class selected_recv : public proton::handler { private: proton::url url; @@ -34,12 +36,12 @@ class selected_recv : public proton::handler { public: selected_recv(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { proton::connection conn = e.container().connect(url); conn.open_receiver(url.path(), proton::link_options().selector("colour = 'green'")); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/server.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/server.cpp b/examples/cpp/server.cpp index 58fe52d..699cfc3 100644 --- a/examples/cpp/server.cpp +++ b/examples/cpp/server.cpp @@ -32,6 +32,8 @@ #include <string> #include <cctype> +#include "fake_cpp11.hpp" + class server : public proton::handler { private: typedef std::map<std::string, proton::sender> sender_map; @@ -42,7 +44,7 @@ class server : public proton::handler { public: server(const std::string &u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { connection = e.container().connect(url); connection.open_receiver(url.path()); @@ -58,7 +60,7 @@ class server : public proton::handler { return uc; } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << "Received " << e.message().body() << std::endl; std::string reply_to = e.message().reply_to(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/server_direct.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/server_direct.cpp b/examples/cpp/server_direct.cpp index c166917..9a154e0 100644 --- a/examples/cpp/server_direct.cpp +++ b/examples/cpp/server_direct.cpp @@ -33,6 +33,8 @@ #include <sstream> #include <cctype> +#include "fake_cpp11.hpp" + class server : public proton::handler { private: typedef std::map<std::string, proton::sender> sender_map; @@ -43,7 +45,7 @@ class server : public proton::handler { public: server(const std::string &u) : url(u), address_counter(0) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { e.container().listen(url); std::cout << "server listening on " << url << std::endl; } @@ -64,7 +66,7 @@ class server : public proton::handler { return addr.str(); } - void on_link_open(proton::event& e) { + void on_link_open(proton::event& e) override { proton::link link = e.link(); if (!!link.sender() && link.remote_source().dynamic()) { @@ -73,7 +75,7 @@ class server : public proton::handler { } } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << "Received " << e.message().body() << std::endl; std::string reply_to = e.message().reply_to(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/simple_recv.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/simple_recv.cpp b/examples/cpp/simple_recv.cpp index 22d603e..c8d5701 100644 --- a/examples/cpp/simple_recv.cpp +++ b/examples/cpp/simple_recv.cpp @@ -31,6 +31,8 @@ #include <iostream> #include <map> +#include "fake_cpp11.hpp" + class simple_recv : public proton::handler { private: proton::url url; @@ -41,22 +43,22 @@ class simple_recv : public proton::handler { public: simple_recv(const std::string &s, int c) : url(s), expected(c), received(0) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { receiver = e.container().open_receiver(url); std::cout << "simple_recv listening on " << url << std::endl; } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { proton::message& msg = e.message(); - + if (msg.id().get<uint64_t>() < received) { return; // Ignore duplicate } - + if (expected == 0 || received < expected) { std::cout << msg.body() << std::endl; received++; - + if (received == expected) { e.receiver().close(); e.connection().close(); @@ -67,7 +69,7 @@ class simple_recv : public proton::handler { int main(int argc, char **argv) { std::string address("127.0.0.1:5672/examples"); - + int message_count = 100; options opts(argc, argv); @@ -76,7 +78,7 @@ int main(int argc, char **argv) { try { opts.parse(); - + simple_recv recv(address, message_count); proton::container(recv).run(); @@ -86,6 +88,6 @@ int main(int argc, char **argv) { } catch (const std::exception& e) { std::cerr << e.what() << std::endl; } - + return 1; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/simple_send.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/simple_send.cpp b/examples/cpp/simple_send.cpp index 8598fe0..5cd9f84 100644 --- a/examples/cpp/simple_send.cpp +++ b/examples/cpp/simple_send.cpp @@ -30,6 +30,8 @@ #include <iostream> #include <map> +#include "fake_cpp11.hpp" + class simple_send : public proton::handler { private: proton::url url; @@ -41,18 +43,18 @@ class simple_send : public proton::handler { public: simple_send(const std::string &s, int c) : url(s), sent(0), confirmed(0), total(c) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { sender = e.container().open_sender(url); } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::sender sender = e.sender(); - + while (sender.credit() && sent < total) { proton::message msg; std::map<std::string, int> m; m["sequence"] = sent + 1; - + msg.id(sent + 1); msg.body(m); @@ -61,16 +63,16 @@ class simple_send : public proton::handler { } } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { confirmed++; - + if (confirmed == total) { std::cout << "all messages confirmed" << std::endl; e.connection().close(); } } - void on_transport_close(proton::event &e) { + void on_transport_close(proton::event &e) override { sent = confirmed; } }; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/ssl.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/ssl.cpp b/examples/cpp/ssl.cpp index 209a766..c1bc8b2 100644 --- a/examples/cpp/ssl.cpp +++ b/examples/cpp/ssl.cpp @@ -29,6 +29,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + using proton::connection_options; using proton::ssl_client_options; using proton::ssl_server_options; @@ -45,13 +47,13 @@ std::string find_CN(const std::string &); struct server_handler : public proton::handler { proton::acceptor acceptor; - void on_connection_open(proton::event &e) { + void on_connection_open(proton::event &e) override { std::cout << "Inbound server connection connected via SSL. Protocol: " << e.connection().transport().ssl().protocol() << std::endl; acceptor.close(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; } }; @@ -65,7 +67,7 @@ class hello_world_direct : public proton::handler { public: hello_world_direct(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { // Configure listener. Details vary by platform. ssl_certificate server_cert = platform_certificate("tserver", "tserverpw"); ssl_server_options ssl_srv(server_cert); @@ -85,20 +87,20 @@ class hello_world_direct : public proton::handler { e.container().open_sender(url); } - void on_connection_open(proton::event &e) { + void on_connection_open(proton::event &e) override { std::string subject = e.connection().transport().ssl().remote_subject(); std::cout << "Outgoing client connection connected via SSL. Server certificate identity " << find_CN(subject) << std::endl; } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::message m; m.body("Hello World!"); e.sender().send(m); e.sender().close(); } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { // All done. e.connection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/examples/cpp/ssl_client_cert.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/ssl_client_cert.cpp b/examples/cpp/ssl_client_cert.cpp index c49957a..c8cee43 100644 --- a/examples/cpp/ssl_client_cert.cpp +++ b/examples/cpp/ssl_client_cert.cpp @@ -30,6 +30,8 @@ #include <iostream> +#include "fake_cpp11.hpp" + using proton::connection_options; using proton::ssl_client_options; using proton::ssl_server_options; @@ -47,7 +49,7 @@ std::string find_CN(const std::string &); struct server_handler : public proton::handler { proton::acceptor inbound_listener; - void on_connection_open(proton::event &e) { + void on_connection_open(proton::event &e) override { std::cout << "Inbound server connection connected via SSL. Protocol: " << e.connection().transport().ssl().protocol() << std::endl; if (e.connection().transport().sasl().outcome() == sasl::OK) { @@ -61,7 +63,7 @@ struct server_handler : public proton::handler { inbound_listener.close(); } - void on_message(proton::event &e) { + void on_message(proton::event &e) override { std::cout << e.message().body() << std::endl; } }; @@ -75,7 +77,7 @@ class hello_world_direct : public proton::handler { public: hello_world_direct(const proton::url& u) : url(u) {} - void on_start(proton::event &e) { + void on_start(proton::event &e) override { // Configure listener. Details vary by platform. ssl_certificate server_cert = platform_certificate("tserver", "tserverpw"); std::string client_CA = platform_CA("tclient"); @@ -100,20 +102,20 @@ class hello_world_direct : public proton::handler { e.container().open_sender(url); } - void on_connection_open(proton::event &e) { + void on_connection_open(proton::event &e) override { std::string subject = e.connection().transport().ssl().remote_subject(); std::cout << "Outgoing client connection connected via SSL. Server certificate identity " << find_CN(subject) << std::endl; } - void on_sendable(proton::event &e) { + void on_sendable(proton::event &e) override { proton::message m; m.body("Hello World!"); e.sender().send(m); e.sender().close(); } - void on_delivery_accept(proton::event &e) { + void on_delivery_accept(proton::event &e) override { // All done. e.connection().close(); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/04e94897/proton-c/bindings/cpp/src/engine_test.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/engine_test.cpp b/proton-c/bindings/cpp/src/engine_test.cpp index a10842a..74a7a6a 100644 --- a/proton-c/bindings/cpp/src/engine_test.cpp +++ b/proton-c/bindings/cpp/src/engine_test.cpp @@ -28,6 +28,10 @@ #include <deque> #include <algorithm> +#if __cplusplus < 201103L +#define override +#endif + using namespace proton; using namespace test; @@ -51,7 +55,7 @@ struct mem_engine : public connection_engine { mem_engine(mem_pipe s, handler &h, const connection_options &opts) : connection_engine(h, opts), socket(s) {} - std::pair<size_t, bool> io_read(char* buf, size_t size) { + std::pair<size_t, bool> io_read(char* buf, size_t size) override { if (!read_error.empty()) throw io_error(read_error); size = std::min(socket.read.size(), size); copy(socket.read.begin(), socket.read.begin()+size, buf); @@ -59,26 +63,26 @@ struct mem_engine : public connection_engine { return std::make_pair(size, true); } - size_t io_write(const char* buf, size_t size) { + size_t io_write(const char* buf, size_t size) override { if (!write_error.empty()) throw io_error(write_error); socket.write.insert(socket.write.begin(), buf, buf+size); return size; } - void io_close() { + void io_close() override { read_error = write_error = "closed"; } }; struct debug_handler : handler { - void on_unhandled(event& e) { + void on_unhandled(event& e) override { std::cout << e.name() << std::endl; } }; struct record_handler : handler { std::deque<std::string> events; - void on_unhandled(event& e) { + void on_unhandled(event& e) override { events.push_back(e.name()); } }; @@ -122,7 +126,7 @@ void test_process_amqp() { struct link_handler : public record_handler { std::deque<proton::link> links; - void on_link_open(event& e) { + void on_link_open(event& e) override { links.push_back(e.link()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
