PROTON-1164: [C++ binding] Change on_timer(event&) -> on_timer(event&, container&)
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d4ec34fc Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d4ec34fc Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d4ec34fc Branch: refs/heads/master Commit: d4ec34fc84276202c5220ad2565652025159f3bf Parents: 5c35609 Author: Andrew Stitcher <[email protected]> Authored: Wed Mar 23 23:44:37 2016 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Thu Mar 24 10:12:40 2016 -0400 ---------------------------------------------------------------------- examples/cpp/recurring_timer.cpp | 20 ++++++++++---------- .../bindings/cpp/include/proton/handler.hpp | 2 +- proton-c/bindings/cpp/src/handler.cpp | 2 +- proton-c/bindings/cpp/src/messaging_adapter.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4ec34fc/examples/cpp/recurring_timer.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/recurring_timer.cpp b/examples/cpp/recurring_timer.cpp index 540bab4..e4e3ef1 100644 --- a/examples/cpp/recurring_timer.cpp +++ b/examples/cpp/recurring_timer.cpp @@ -32,13 +32,13 @@ #include "fake_cpp11.hpp" class ticker : public proton::handler { - void on_timer(proton::event &e) override { + void on_timer(proton::event &e, proton::container &) override { std::cout << "Tick..." << std::endl; } }; class tocker : public proton::handler { - void on_timer(proton::event &e) override { + void on_timer(proton::event &e, proton::container &) override { std::cout << "Tock..." << std::endl; } }; @@ -54,28 +54,28 @@ class recurring : public proton::handler { recurring(int msecs, int tickms) : remaining_msecs(msecs), tick_ms(tickms), cancel_task(0) {} - proton::task ticktock(proton::event &e) { + proton::task ticktock(proton::container &c) { // Show timer events in separate handlers. - e.container().schedule(tick_ms, &tick_handler); - return e.container().schedule(tick_ms * 3, &tock_handler); + c.schedule(tick_ms, &tick_handler); + return c.schedule(tick_ms * 3, &tock_handler); } void on_container_start(proton::event &e, proton::container &c) override { // Demonstrate cancel(), we will cancel the first tock on the first recurring::on_timer_task - cancel_task = ticktock(e); + cancel_task = ticktock(c); c.schedule(0); } - void on_timer(proton::event &e) override { + void on_timer(proton::event &e, proton::container &c) override { if (!!cancel_task) { cancel_task.cancel(); cancel_task = 0; - e.container().schedule(tick_ms * 4); + c.schedule(tick_ms * 4); } else { remaining_msecs -= tick_ms * 4; if (remaining_msecs > 0) { - ticktock(e); - e.container().schedule(tick_ms * 4); + ticktock(c); + c.schedule(tick_ms * 4); } } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4ec34fc/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 c9a8910..e04b26e 100644 --- a/proton-c/bindings/cpp/include/proton/handler.hpp +++ b/proton-c/bindings/cpp/include/proton/handler.hpp @@ -136,7 +136,7 @@ PN_CPP_CLASS_EXTERN handler /// XXX settle API questions around task /// XXX register functions instead of having these funny generic events /// A timer fired. - PN_CPP_EXTERN virtual void on_timer(event &e); + PN_CPP_EXTERN virtual void on_timer(event &e, container &c); /// @endcond /// Fallback event handling. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4ec34fc/proton-c/bindings/cpp/src/handler.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/handler.cpp b/proton-c/bindings/cpp/src/handler.cpp index 920ee12..59319de 100644 --- a/proton-c/bindings/cpp/src/handler.cpp +++ b/proton-c/bindings/cpp/src/handler.cpp @@ -39,7 +39,7 @@ handler::~handler(){} void handler::on_container_start(event &e, container &) { on_unhandled(e); } void handler::on_message(event &e, message &) { on_unhandled(e); } void handler::on_sendable(event &e, sender &) { on_unhandled(e); } -void handler::on_timer(event &e) { on_unhandled(e); } +void handler::on_timer(event &e, container &) { on_unhandled(e); } void handler::on_transport_close(event &e, transport &) { on_unhandled(e); } void handler::on_transport_error(event &e, transport &t) { on_unhandled_error(e, t.condition()); } void handler::on_connection_close(event &e, connection &) { on_unhandled(e); } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4ec34fc/proton-c/bindings/cpp/src/messaging_adapter.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/messaging_adapter.cpp b/proton-c/bindings/cpp/src/messaging_adapter.cpp index bfab77d..02e4bc6 100644 --- a/proton-c/bindings/cpp/src/messaging_adapter.cpp +++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp @@ -253,8 +253,10 @@ void messaging_adapter::on_transport_tail_closed(proton_event &pe) { void messaging_adapter::on_timer_task(proton_event& pe) { - messaging_event mevent(messaging_event::TIMER, pe); - delegate_.on_timer(mevent); + if (pe.container()) { + messaging_event mevent(messaging_event::TIMER, pe); + delegate_.on_timer(mevent, *pe.container()); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
